From 027560b21da3c8b1353caab2b742140d0e0ed15c Mon Sep 17 00:00:00 2001 From: yanxin Date: Tue, 26 May 2026 21:13:17 +0800 Subject: [PATCH] Fix duplicate index throttling metric registration Signed-off-by: yanxin --- collector/indices.go | 2 +- collector/indices_test.go | 54 +++++++++++++++++++-------------------- collector/nodes_test.go | 12 +++++++++ 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/collector/indices.go b/collector/indices.go index 4e2080cf..116075f7 100644 --- a/collector/indices.go +++ b/collector/indices.go @@ -283,7 +283,7 @@ var ( indicesLabels, nil, ) indicesIndexingIsThrottled = prometheus.NewDesc( - prometheus.BuildFQName(namespace, "indices", "indexing_is_throttled"), + prometheus.BuildFQName(namespace, "index_stats", "indexing_is_throttled"), "Whether indexing is currently throttled for an index (1=throttled, 0=not throttled)", indicesLabels, nil, ) diff --git a/collector/indices_test.go b/collector/indices_test.go index 76bfdab6..f1c51b48 100644 --- a/collector/indices_test.go +++ b/collector/indices_test.go @@ -107,10 +107,10 @@ func TestIndices(t *testing.T) { # TYPE elasticsearch_index_stats_indexing_delete_current gauge elasticsearch_index_stats_indexing_delete_current{cluster="unknown_cluster",index="foo_1"} 0 elasticsearch_index_stats_indexing_delete_current{cluster="unknown_cluster",index="foo_2"} 0 - # HELP elasticsearch_indices_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) - # TYPE elasticsearch_indices_indexing_is_throttled gauge - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 + # HELP elasticsearch_index_stats_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) + # TYPE elasticsearch_index_stats_indexing_is_throttled gauge + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 # HELP elasticsearch_index_stats_merge_auto_throttle_bytes_total Total bytes that were auto-throttled during merging # TYPE elasticsearch_index_stats_merge_auto_throttle_bytes_total counter elasticsearch_index_stats_merge_auto_throttle_bytes_total{cluster="unknown_cluster",index="foo_1"} 0 @@ -425,10 +425,10 @@ func TestIndices(t *testing.T) { # TYPE elasticsearch_index_stats_indexing_index_failed_total counter elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_1"} 0 elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_2"} 0 - # HELP elasticsearch_indices_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) - # TYPE elasticsearch_indices_indexing_is_throttled gauge - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 + # HELP elasticsearch_index_stats_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) + # TYPE elasticsearch_index_stats_indexing_is_throttled gauge + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 # HELP elasticsearch_index_stats_merge_auto_throttle_bytes_total Total bytes that were auto-throttled during merging # TYPE elasticsearch_index_stats_merge_auto_throttle_bytes_total counter elasticsearch_index_stats_merge_auto_throttle_bytes_total{cluster="unknown_cluster",index="foo_1"} 1.048576e+08 @@ -789,13 +789,13 @@ func TestIndices(t *testing.T) { elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index=".watches"} 0 elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_1"} 0 elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_2"} 0 - # HELP elasticsearch_indices_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) - # TYPE elasticsearch_indices_indexing_is_throttled gauge - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index=".monitoring-data-2"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index=".monitoring-es-2-2017.08.23"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index=".watches"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 + # HELP elasticsearch_index_stats_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) + # TYPE elasticsearch_index_stats_indexing_is_throttled gauge + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index=".monitoring-data-2"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index=".monitoring-es-2-2017.08.23"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index=".watches"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 # HELP elasticsearch_index_stats_merge_auto_throttle_bytes_total Total bytes that were auto-throttled during merging # TYPE elasticsearch_index_stats_merge_auto_throttle_bytes_total counter elasticsearch_index_stats_merge_auto_throttle_bytes_total{cluster="unknown_cluster",index=".monitoring-data-2"} 2.097152e+07 @@ -1324,12 +1324,12 @@ func TestIndices(t *testing.T) { elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_1"} 0 elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_2"} 0 elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_3"} 0 - # HELP elasticsearch_indices_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) - # TYPE elasticsearch_indices_indexing_is_throttled gauge - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index=".geoip_databases"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_3"} 0 + # HELP elasticsearch_index_stats_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) + # TYPE elasticsearch_index_stats_indexing_is_throttled gauge + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index=".geoip_databases"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_3"} 0 # HELP elasticsearch_index_stats_merge_auto_throttle_bytes_total Total bytes that were auto-throttled during merging # TYPE elasticsearch_index_stats_merge_auto_throttle_bytes_total counter elasticsearch_index_stats_merge_auto_throttle_bytes_total{cluster="unknown_cluster",index=".geoip_databases"} 2.097152e+07 @@ -1797,12 +1797,12 @@ func TestIndices(t *testing.T) { elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_1"} 0 elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_2"} 0 elasticsearch_index_stats_indexing_index_failed_total{cluster="unknown_cluster",index="foo_3"} 0 - # HELP elasticsearch_indices_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) - # TYPE elasticsearch_indices_indexing_is_throttled gauge - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index=".geoip_databases"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 - elasticsearch_indices_indexing_is_throttled{cluster="unknown_cluster",index="foo_3"} 0 + # HELP elasticsearch_index_stats_indexing_is_throttled Whether indexing is currently throttled for an index (1=throttled, 0=not throttled) + # TYPE elasticsearch_index_stats_indexing_is_throttled gauge + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index=".geoip_databases"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_1"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_2"} 0 + elasticsearch_index_stats_indexing_is_throttled{cluster="unknown_cluster",index="foo_3"} 0 # HELP elasticsearch_index_stats_merge_auto_throttle_bytes_total Total bytes that were auto-throttled during merging # TYPE elasticsearch_index_stats_merge_auto_throttle_bytes_total counter elasticsearch_index_stats_merge_auto_throttle_bytes_total{cluster="unknown_cluster",index=".geoip_databases"} 2.097152e+07 diff --git a/collector/nodes_test.go b/collector/nodes_test.go index 2fcbfcd1..bfd9326b 100644 --- a/collector/nodes_test.go +++ b/collector/nodes_test.go @@ -22,6 +22,7 @@ import ( "strings" "testing" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/prometheus/common/promslog" ) @@ -1604,3 +1605,14 @@ func TestNodesStats(t *testing.T) { }) } } + +func TestNodesAndIndicesRegisterTogether(t *testing.T) { + u, err := url.Parse("http://example.com") + if err != nil { + t.Fatal(err) + } + + reg := prometheus.NewRegistry() + reg.MustRegister(NewNodes(promslog.NewNopLogger(), http.DefaultClient, u, true, "_local")) + reg.MustRegister(NewIndices(promslog.NewNopLogger(), http.DefaultClient, u, false, true)) +}