From 21d989cd9fd26abfe77aab890b6d80e7dcf65291 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Thu, 10 Jul 2025 03:13:04 +0200 Subject: [PATCH 1/6] refactor: replace x/exp/maps with stdlib maps maps was added to the stdlib in new go versions replace old x/exp/maps with stdlib package --- go.mod | 2 +- .../metricbeat/module/autoops_es/cat_shards/cache.go | 6 +++--- .../metricbeat/module/autoops_es/cat_shards/data.go | 6 +++--- .../module/autoops_es/cat_shards/data_test.go | 6 +++--- .../module/autoops_es/tasks_management/data.go | 6 +++--- .../autoops_es/tasks_management/parse_child_nodes.go | 6 +----- .../tasks_management/parse_child_nodes_test.go | 7 ++++--- .../module/autoops_es/templates/templates.go | 12 ++++++------ x-pack/metricbeat/module/autoops_es/utils/utils.go | 9 ++++----- 9 files changed, 28 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index d48db3c25f03..112ecbc78732 100644 --- a/go.mod +++ b/go.mod @@ -230,7 +230,6 @@ require ( go.opentelemetry.io/collector/pdata v1.35.0 go.opentelemetry.io/collector/receiver v1.35.0 go.uber.org/mock v0.5.0 - golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 golang.org/x/term v0.32.0 google.golang.org/genproto/googleapis/api v0.0.0-20250519155744-55703ea1f237 gopkg.in/natefinch/lumberjack.v2 v2.2.1 @@ -480,6 +479,7 @@ require ( go.opentelemetry.io/otel/trace v1.36.0 // indirect go.opentelemetry.io/proto/otlp v1.6.0 // indirect go.uber.org/ratelimit v0.3.1 // indirect + golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect gonum.org/v1/gonum v0.16.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250519155744-55703ea1f237 // indirect diff --git a/x-pack/metricbeat/module/autoops_es/cat_shards/cache.go b/x-pack/metricbeat/module/autoops_es/cat_shards/cache.go index f1c7d27b3d3e..f72d6c5710cb 100644 --- a/x-pack/metricbeat/module/autoops_es/cat_shards/cache.go +++ b/x-pack/metricbeat/module/autoops_es/cat_shards/cache.go @@ -5,10 +5,10 @@ package cat_shards import ( + "maps" + "slices" "time" - "golang.org/x/exp/maps" - "github.com/elastic/beats/v7/x-pack/metricbeat/module/autoops_es/utils" ) @@ -101,7 +101,7 @@ func enrichNodeIndexShards(nodeIndexShardsMap map[string]NodeIndexShards, indexM timestampDiff = &diff } - nodeIndexShardsList := maps.Values(nodeIndexShardsMap) + nodeIndexShardsList := slices.Collect(maps.Values(nodeIndexShardsMap)) for i := range nodeIndexShardsList { nodeIndexShardsList[i].TotalFractions = size diff --git a/x-pack/metricbeat/module/autoops_es/cat_shards/data.go b/x-pack/metricbeat/module/autoops_es/cat_shards/data.go index d569c685cbb3..1643fde648bb 100644 --- a/x-pack/metricbeat/module/autoops_es/cat_shards/data.go +++ b/x-pack/metricbeat/module/autoops_es/cat_shards/data.go @@ -7,12 +7,12 @@ package cat_shards import ( "encoding/json" "fmt" + "maps" "math" + "slices" "github.com/elastic/beats/v7/x-pack/metricbeat/module/autoops_es/events" - "golang.org/x/exp/maps" - "github.com/elastic/elastic-agent-libs/mapstr" "github.com/elastic/beats/v7/metricbeat/mb" @@ -82,7 +82,7 @@ func eventsMapping(m *elasticsearch.MetricSet, r mb.ReporterV2, info *utils.Clus transactionID := utils.NewUUIDV4() - sendNodeShardsEvent(r, info, maps.Values(nodeShards), transactionID) + sendNodeShardsEvent(r, info, slices.Collect(maps.Values(nodeShards)), transactionID) indexMetadata, err := getResolvedIndices(m) diff --git a/x-pack/metricbeat/module/autoops_es/cat_shards/data_test.go b/x-pack/metricbeat/module/autoops_es/cat_shards/data_test.go index f2eaaaa1d15d..dd787e769447 100644 --- a/x-pack/metricbeat/module/autoops_es/cat_shards/data_test.go +++ b/x-pack/metricbeat/module/autoops_es/cat_shards/data_test.go @@ -8,6 +8,7 @@ package cat_shards import ( + "maps" "net/http" "net/http/httptest" "slices" @@ -16,7 +17,6 @@ import ( "github.com/elastic/beats/v7/x-pack/metricbeat/module/autoops_es/auto_ops_testing" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" "github.com/elastic/beats/v7/x-pack/metricbeat/module/autoops_es/metricset" @@ -74,7 +74,7 @@ func TestSendNodeShardsEvent(t *testing.T) { func TestSendNodeIndexShardsEventInBatch(t *testing.T) { reporter := &mbtest.CapturingReporterV2{} info := auto_ops_testing.CreateClusterInfo("8.15.3") - nodeIndexShards := maps.Values(getNodeIndexShards()) + nodeIndexShards := slices.Collect(maps.Values(getNodeIndexShards())) transactionId := "xyz" sendNodeIndexShardsEvent(reporter, &info, nodeIndexShards, transactionId) @@ -94,7 +94,7 @@ func TestSendNodeIndexShardsEvent(t *testing.T) { reporter := &mbtest.CapturingReporterV2{} info := auto_ops_testing.CreateClusterInfo("8.15.3") - nodeIndexShards := maps.Values(getNodeIndexShards()) + nodeIndexShards := slices.Collect(maps.Values(getNodeIndexShards())) transactionId := "xyz" sendNodeIndexShardsEvent(reporter, &info, nodeIndexShards, transactionId) diff --git a/x-pack/metricbeat/module/autoops_es/tasks_management/data.go b/x-pack/metricbeat/module/autoops_es/tasks_management/data.go index 0e014618ba9d..322fcb0205fb 100644 --- a/x-pack/metricbeat/module/autoops_es/tasks_management/data.go +++ b/x-pack/metricbeat/module/autoops_es/tasks_management/data.go @@ -7,11 +7,11 @@ package tasks_management import ( "errors" "fmt" + "maps" + "slices" e "github.com/elastic/beats/v7/x-pack/metricbeat/module/autoops_es/events" - "golang.org/x/exp/maps" - s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" "github.com/elastic/beats/v7/metricbeat/mb" @@ -85,7 +85,7 @@ func eventsMapping(r mb.ReporterV2, info *utils.ClusterInfo, nodeTasks *GroupedT // guarantee the parent node is in the list (it may not be) nodeMap[node] = true - task["node"] = maps.Keys(nodeMap) + task["node"] = slices.Collect(maps.Keys(nodeMap)) // remove the children node delete(task, "children") diff --git a/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes.go b/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes.go index 91475ef1c2eb..29932b7ba0b7 100644 --- a/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes.go +++ b/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes.go @@ -4,10 +4,6 @@ package tasks_management -import ( - "golang.org/x/exp/maps" -) - // Extract the Node ID from each child task and add it to the map (treated as a Set). func parseChildNodes(children []any, ok bool) map[string]bool { nodeMap := map[string]bool{} @@ -37,7 +33,7 @@ func parseChildNodes(children []any, ok bool) map[string]bool { if ok && innerChildren != nil { innerChildren, ok := innerChildren.([]any) - for _, node := range maps.Keys(parseChildNodes(innerChildren, ok)) { + for node := range parseChildNodes(innerChildren, ok) { nodeMap[node] = true } } diff --git a/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go b/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go index 64e98a16e229..1a1c6e7c43c5 100644 --- a/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go +++ b/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go @@ -8,10 +8,11 @@ package tasks_management import ( + "maps" + "slices" "testing" "github.com/stretchr/testify/require" - "golang.org/x/exp/maps" ) // Expect an empty array to return an empty map. @@ -42,7 +43,7 @@ func TestParseChildNodesReturnsNodeIdsWithDuplicates(t *testing.T) { }, } - require.ElementsMatch(t, []string{"node1", "node2"}, maps.Keys(parseChildNodes(children, true))) + require.ElementsMatch(t, []string{"node1", "node2"}, slices.Collect(maps.Keys(parseChildNodes(children, true)))) } // Expect an empty array to returns node IDs without recursion. @@ -56,7 +57,7 @@ func TestParseChildNodesReturnsFlatNodeIds(t *testing.T) { }, } - require.ElementsMatch(t, []string{"node1", "node2"}, maps.Keys(parseChildNodes(children, true))) + require.ElementsMatch(t, []string{"node1", "node2"}, slices.Collect(maps.Keys(parseChildNodes(children, true)))) } // Expect an empty array to returns node IDs with recursion. diff --git a/x-pack/metricbeat/module/autoops_es/templates/templates.go b/x-pack/metricbeat/module/autoops_es/templates/templates.go index 4b252194653f..3e7aa7acd4ab 100644 --- a/x-pack/metricbeat/module/autoops_es/templates/templates.go +++ b/x-pack/metricbeat/module/autoops_es/templates/templates.go @@ -7,15 +7,15 @@ package templates import ( "errors" "fmt" + "maps" "os" + "slices" "strings" "time" "github.com/elastic/beats/v7/x-pack/metricbeat/module/autoops_es/events" "github.com/elastic/beats/v7/x-pack/metricbeat/module/autoops_es/utils" - "golang.org/x/exp/maps" - "github.com/elastic/beats/v7/metricbeat/mb" "github.com/elastic/beats/v7/metricbeat/module/elasticsearch" "github.com/elastic/elastic-agent-libs/mapstr" @@ -110,9 +110,9 @@ func GetPartitionedTemplates[T any](templates []T, namer utils.Supplier[*T, stri nameLimit := utils.GetIntEnvParam(TEMPLATE_BATCH_SIZE_NAME, 1500) - return maps.Values(utils.PartitionByMaxValue(nameLimit, templateNames, func(template string) int { + return slices.Collect(maps.Values(utils.PartitionByMaxValue(nameLimit, templateNames, func(template string) int { return len(template) - })) + }))) } func GetPartitionedTemplatesWithErrors[T any](templates []T, namer utils.Supplier[*T, string], filter utils.CheckedPredicate[*T]) ([][]string, []error) { @@ -128,9 +128,9 @@ func GetPartitionedTemplatesWithErrors[T any](templates []T, namer utils.Supplie nameLimit := utils.GetIntEnvParam(TEMPLATE_BATCH_SIZE_NAME, 1500) - return maps.Values(utils.PartitionByMaxValue(nameLimit, templateNames, func(template string) int { + return slices.Collect(maps.Values(utils.PartitionByMaxValue(nameLimit, templateNames, func(template string) int { return len(template) - })), predicateErrors + }))), predicateErrors } // Loop across the `partitionedTemplates` and request them in associated batches, then extract and report them as events sharing a Transaction ID. diff --git a/x-pack/metricbeat/module/autoops_es/utils/utils.go b/x-pack/metricbeat/module/autoops_es/utils/utils.go index 78281dd45390..63b7abbc6e91 100644 --- a/x-pack/metricbeat/module/autoops_es/utils/utils.go +++ b/x-pack/metricbeat/module/autoops_es/utils/utils.go @@ -5,11 +5,10 @@ package utils import ( + "maps" "net/url" - "sort" + "slices" "strings" - - "golang.org/x/exp/maps" ) type Supplier[T any, R any] func(T) R @@ -98,8 +97,8 @@ func PartitionByMaxValue[T any](limit int, items []T, valueExtractor func(T) int itemKey := valueExtractor(item) sortedValues[itemKey] = append(sortedValues[itemKey], item) } - allKeys := maps.Keys(sortedValues) - sort.Ints(allKeys) + allKeys := slices.Collect(maps.Keys(sortedValues)) + slices.Sort(allKeys) var sortedItems = make(map[int][]T) currentCapacity := 0 cursor := 0 From 6cdf48a1527b80635f9d77cca4df4cc654355f73 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Thu, 10 Jul 2025 03:59:57 +0200 Subject: [PATCH 2/6] lint: regenerate notice --- NOTICE.txt | 74 +++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 74b623fdd4f7..470afe6df873 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -27491,43 +27491,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------------- -Dependency : golang.org/x/exp -Version: v0.0.0-20250106191152-7588d65b2ba8 -Licence type (autodetected): BSD-3-Clause --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/golang.org/x/exp@v0.0.0-20250106191152-7588d65b2ba8/LICENSE: - -Copyright 2009 The Go Authors. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google LLC nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -------------------------------------------------------------------------------- Dependency : golang.org/x/mod Version: v0.25.0 @@ -79377,6 +79340,43 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-------------------------------------------------------------------------------- +Dependency : golang.org/x/exp +Version: v0.0.0-20250106191152-7588d65b2ba8 +Licence type (autodetected): BSD-3-Clause +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/golang.org/x/exp@v0.0.0-20250106191152-7588d65b2ba8/LICENSE: + +Copyright 2009 The Go Authors. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google LLC nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------------------------------------------------------------------------------- Dependency : golang.org/x/xerrors Version: v0.0.0-20240903120638-7835f813f4da From 3f8575a40ac511f04662f04a4135ff73656f1895 Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Fri, 11 Jul 2025 02:52:52 +0200 Subject: [PATCH 3/6] Update parse_child_nodes_test.go --- .../autoops_es/tasks_management/parse_child_nodes_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go b/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go index 1a1c6e7c43c5..c7c197e5dc7d 100644 --- a/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go +++ b/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go @@ -84,7 +84,7 @@ func TestParseChildNodesReturnsRecursiveNodeIds(t *testing.T) { }, } - require.ElementsMatch(t, []string{"node1", "node2", "node3", "node4", "node5"}, maps.Keys(parseChildNodes(children, true))) + require.ElementsMatch(t, []string{"node1", "node2", "node3", "node4", "node5"}, slices.Collect(maps.Keys(parseChildNodes(children, true)))) } // Expect an empty array to returns node IDs with recursion and ignores unspecified node IDs. From 8f092da91360b920dba7b544788f23a5951d9efe Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Fri, 11 Jul 2025 02:53:26 +0200 Subject: [PATCH 4/6] Update parse_child_nodes_test.go --- .../autoops_es/tasks_management/parse_child_nodes_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go b/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go index c7c197e5dc7d..1e0700b50edf 100644 --- a/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go +++ b/x-pack/metricbeat/module/autoops_es/tasks_management/parse_child_nodes_test.go @@ -111,5 +111,5 @@ func TestParseChildNodesIgnoresEmptyNodeId(t *testing.T) { }, } - require.ElementsMatch(t, []string{"node1", "node2", "node3", "node4"}, maps.Keys(parseChildNodes(children, true))) + require.ElementsMatch(t, []string{"node1", "node2", "node3", "node4"}, slices.Collect(maps.Keys(parseChildNodes(children, true)))) } From 9186f05cf61c4ddca060ace37e8b2c6d99c18a88 Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Wed, 23 Jul 2025 03:50:38 +0200 Subject: [PATCH 5/6] Update data_test.go --- x-pack/metricbeat/module/autoops_es/cat_shards/data_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/metricbeat/module/autoops_es/cat_shards/data_test.go b/x-pack/metricbeat/module/autoops_es/cat_shards/data_test.go index f8887a523dae..ee4242578989 100644 --- a/x-pack/metricbeat/module/autoops_es/cat_shards/data_test.go +++ b/x-pack/metricbeat/module/autoops_es/cat_shards/data_test.go @@ -9,8 +9,6 @@ package cat_shards import ( "maps" - "net/http" - "net/http/httptest" "slices" "testing" From bdb5c4586f39e57a82fac5d8a8cbfe8d45ca88e3 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Thu, 24 Jul 2025 22:24:16 +0200 Subject: [PATCH 6/6] lint: deny superseded x/exp pkgs --- .golangci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index fa0b4d34d5bd..20fbe3b1fff8 100755 --- a/.golangci.yml +++ b/.golangci.yml @@ -42,6 +42,10 @@ linters: deny: - pkg: math/rand$ desc: superseded by math/rand/v2 + - pkg: golang.org/x/exp/maps$ + desc: superseded by maps + - pkg: golang.org/x/exp/slices$ + desc: superseded by slices errcheck: check-type-assertions: true check-blank: false