()
| 68 | } |
| 69 | |
| 70 | func (d *Driver) getVersion() (string, error) { |
| 71 | if d.isOpenSearch && d.opensearchAPI != nil { |
| 72 | ctx := context.Background() |
| 73 | info, err := d.opensearchAPI.Info(ctx, &opensearchapi.InfoReq{}) |
| 74 | if err != nil { |
| 75 | return "", err |
| 76 | } |
| 77 | return info.Version.Number, nil |
| 78 | } |
| 79 | resp, err := d.basicAuthClient.Do("GET", []byte("/"), nil) |
| 80 | if err != nil { |
| 81 | return "", err |
| 82 | } |
| 83 | defer resp.Body.Close() |
| 84 | |
| 85 | bytes, err := io.ReadAll(resp.Body) |
| 86 | if err != nil { |
| 87 | return "", errors.Wrap(err, "failed to read response body") |
| 88 | } |
| 89 | |
| 90 | // Check HTTP status code |
| 91 | if resp.StatusCode != http.StatusOK { |
| 92 | // Include response body for debugging |
| 93 | return "", errors.Errorf("unexpected status code %d: %s", resp.StatusCode, string(bytes)) |
| 94 | } |
| 95 | |
| 96 | var result VersionResult |
| 97 | err = json.Unmarshal(bytes, &result) |
| 98 | if err != nil { |
| 99 | // Include response body to help debug parsing issues |
| 100 | bodyPreview, truncated := common.TruncateString(string(bytes), 500) |
| 101 | if truncated { |
| 102 | bodyPreview += "..." |
| 103 | } |
| 104 | return "", errors.Wrapf(err, "failed to parse version response: %s", bodyPreview) |
| 105 | } |
| 106 | |
| 107 | return result.Version.Number, nil |
| 108 | } |
| 109 | |
| 110 | type IndicesResult struct { |
| 111 | IndexSize string `json:"store.size"` |
no test coverage detected