From 20875d30ed006f10e0cbdcf40dc3db4a834adac8 Mon Sep 17 00:00:00 2001 From: hoenn Date: Thu, 16 Nov 2023 12:25:03 -0500 Subject: [PATCH 1/4] Add a GetShardRecovery with query params function to the ES client --- es.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/es.go b/es.go index 83a5539..a8ffc22 100644 --- a/es.go +++ b/es.go @@ -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" + + var 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 { From c983f696315b9554952cfd021c80bd96737c63ab Mon Sep 17 00:00:00 2001 From: hoenn Date: Thu, 16 Nov 2023 12:27:27 -0500 Subject: [PATCH 2/4] Preallocate querystrings --- es.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es.go b/es.go index a8ffc22..c51b61b 100644 --- a/es.go +++ b/es.go @@ -1518,7 +1518,7 @@ func (c *Client) GetShardRecoveryWithQueryParams(nodes []string, params map[stri var allRecoveries []ShardRecovery uri := "_cat/recovery" - var queryStrings []string + queryStrings := []string{} for param, val := range params { queryStrings = append(queryStrings, fmt.Sprintf("%s=%s", param, val)) } From af4946cc5233a438033e99c4294c93e897f5fed0 Mon Sep 17 00:00:00 2001 From: hoenn Date: Wed, 20 Dec 2023 10:49:46 -0500 Subject: [PATCH 3/4] Remove deprecated linters, specify go version in lint workflow --- .github/workflows/golangci-lint.yml | 7 +++++-- .golangci.yaml | 3 --- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index afa95b5..43b682b 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -16,7 +16,10 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v2 + - name: Set up Go 1.15 + uses: actions/setup-go@v2 + with: + go-version: 1.15 - uses: actions/checkout@v2 - name: golangci-lint uses: golangci/golangci-lint-action@v2 @@ -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 \ No newline at end of file + # skip-build-cache: true diff --git a/.golangci.yaml b/.golangci.yaml index 1f00192..7548cb3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -13,7 +13,6 @@ linters-settings: linters: enable: - - deadcode - depguard - errcheck - exportloopref @@ -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 From a3cbe498f518f593ed50748029b9b10f5c3775b2 Mon Sep 17 00:00:00 2001 From: hoenn Date: Wed, 20 Dec 2023 10:58:15 -0500 Subject: [PATCH 4/4] Update action versions --- .github/workflows/golangci-lint.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 43b682b..07ef9e4 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -17,12 +17,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Go 1.15 - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: - go-version: 1.15 + 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