Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetShardRecoveryWithQueryParams #106

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
- name: Set up Go 1.15
uses: actions/setup-go@v4
with:
go-version: '1.15'
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3.7.0
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.46.2
Expand All @@ -41,4 +44,4 @@ jobs:
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
# skip-build-cache: true
3 changes: 0 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ linters-settings:

linters:
enable:
- deadcode
- depguard
- errcheck
- exportloopref
Expand All @@ -30,11 +29,9 @@ linters:
- prealloc
- revive
- staticcheck
- structcheck
- typecheck
- unconvert
- unused
- varcheck
disable:
- gochecknoglobals # we allow global variables in packages
- gochecknoinits # we allow inits in packages
Expand Down
53 changes: 53 additions & 0 deletions es.go
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,59 @@ func (c *Client) GetShardRecovery(nodes []string, onlyActive bool) ([]ShardRecov
return filteredRecoveries, nil
}

// Get details regarding shard recovery operations across a set of cluster nodes sending the desired query parameters
//
// Use case: You can view the shard recovery progress of the cluster with the bytes=b parameter.
func (c *Client) GetShardRecoveryWithQueryParams(nodes []string, params map[string]string) ([]ShardRecovery, error) {
var allRecoveries []ShardRecovery
uri := "_cat/recovery"

queryStrings := []string{}
for param, val := range params {
queryStrings = append(queryStrings, fmt.Sprintf("%s=%s", param, val))
}

uri = fmt.Sprintf("%s?%s", uri, strings.Join(queryStrings, "&"))

req := c.buildGetRequest(uri)
err := handleErrWithStruct(req, &allRecoveries)

if err != nil {
return nil, err
}

// No nodes passed, so return all shards
if len(nodes) == 0 {
return allRecoveries, nil
}

var filteredRecoveries []ShardRecovery
nodeRegexps := make([]*regexp.Regexp, 0, len(nodes))

for _, node := range nodes {
nodeRegexp, err := regexp.Compile(node)
if err != nil {
return nil, err
}
nodeRegexps = append(nodeRegexps, nodeRegexp)
}

for _, shard := range allRecoveries {
for _, nodeRegexp := range nodeRegexps {
// Support regexp matching of node name
matchesSource := nodeRegexp.MatchString(shard.SourceNode)
matchesTarget := nodeRegexp.MatchString(shard.TargetNode)

// Return if either source node or target node matches
if matchesSource || matchesTarget {
filteredRecoveries = append(filteredRecoveries, shard)
}
}
}

return filteredRecoveries, nil
}

// GetDuration gets the total duration of a snapshot
func (s *Snapshot) GetDuration() int {
if s.DurationMillis > 0 {
Expand Down
Loading