From 63281fa70d8c5da21789116ccc7c4bf759631c0a Mon Sep 17 00:00:00 2001 From: Oliver Eilhard Date: Wed, 6 Oct 2021 15:27:53 +0200 Subject: [PATCH] Update Nodes Stats API to latest API This commit brings the Nodes Stats API to the latest version. Notice that 7.15.0 has a https://github.com/elastic/elasticsearch/issues/78311 that is likely being fixed by https://github.com/elastic/elasticsearch/pull/78531, so we're skipping the given test for that specific release. Once 7.15.1 is released, the bug might reappear unless the PR is being merged into that version. See #1535 --- docker-compose.yml | 4 ++-- nodes_stats.go | 28 +++++++--------------------- nodes_stats_test.go | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c284cedf9..336362abb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: elasticsearch: - image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION:-7.14.2} + image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION:-7.15.0} hostname: elasticsearch environment: - cluster.name=elasticsearch @@ -28,7 +28,7 @@ services: ports: - 9200:9200 platinum: - image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION:-7.14.2} + image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION:-7.15.0} hostname: elasticsearch-platinum environment: - cluster.name=platinum diff --git a/nodes_stats.go b/nodes_stats.go index a57651e3b..783bd5e92 100644 --- a/nodes_stats.go +++ b/nodes_stats.go @@ -333,6 +333,7 @@ type NodesStatsNode struct { type NodesStatsIndex struct { Docs *NodesStatsDocsStats `json:"docs"` + Shards *NodesStatsShardCountStats `json:"shards_stats"` Store *NodesStatsStoreStats `json:"store"` Indexing *NodesStatsIndexingStats `json:"indexing"` Get *NodesStatsGetStats `json:"get"` @@ -343,16 +344,14 @@ type NodesStatsIndex struct { Warmer *NodesStatsWarmerStats `json:"warmer"` QueryCache *NodesStatsQueryCacheStats `json:"query_cache"` Fielddata *NodesStatsFielddataStats `json:"fielddata"` - Percolate *NodesStatsPercolateStats `json:"percolate"` Completion *NodesStatsCompletionStats `json:"completion"` Segments *NodesStatsSegmentsStats `json:"segments"` Translog *NodesStatsTranslogStats `json:"translog"` - Suggest *NodesStatsSuggestStats `json:"suggest"` RequestCache *NodesStatsRequestCacheStats `json:"request_cache"` Recovery NodesStatsRecoveryStats `json:"recovery"` - Indices map[string]*NodesStatsIndex `json:"indices"` // for level=indices - Shards map[string]*NodesStatsIndex `json:"shards"` // for level=shards + IndicesLevel map[string]*NodesStatsIndex `json:"indices"` // for level=indices + ShardsLevel map[string]*NodesStatsIndex `json:"shards"` // for level=shards } type NodesStatsDocsStats struct { @@ -360,6 +359,10 @@ type NodesStatsDocsStats struct { Deleted int64 `json:"deleted"` } +type NodesStatsShardCountStats struct { + TotalCount int64 `json:"total_count"` +} + type NodesStatsStoreStats struct { Size string `json:"size"` SizeInBytes int64 `json:"size_in_bytes"` @@ -473,16 +476,6 @@ type NodesStatsFielddataStats struct { } `json:"fields"` } -type NodesStatsPercolateStats struct { - Total int64 `json:"total"` - Time string `json:"time"` - TimeInMillis int64 `json:"time_in_millis"` - Current int64 `json:"current"` - MemorySize string `json:"memory_size"` - MemorySizeInBytes int64 `json:"memory_size_in_bytes"` - Queries int64 `json:"queries"` -} - type NodesStatsCompletionStats struct { Size string `json:"size"` SizeInBytes int64 `json:"size_in_bytes"` @@ -522,13 +515,6 @@ type NodesStatsTranslogStats struct { SizeInBytes int64 `json:"size_in_bytes"` } -type NodesStatsSuggestStats struct { - Total int64 `json:"total"` - TotalTime string `json:"total_time"` - TotalTimeInMillis int64 `json:"total_time_in_millis"` - Current int64 `json:"current"` -} - type NodesStatsRequestCacheStats struct { MemorySize string `json:"memory_size"` MemorySizeInBytes int64 `json:"memory_size_in_bytes"` diff --git a/nodes_stats_test.go b/nodes_stats_test.go index 4b249a2f4..fa3a203e0 100644 --- a/nodes_stats_test.go +++ b/nodes_stats_test.go @@ -6,16 +6,28 @@ package elastic import ( "context" + "log" + "os" "testing" ) func TestNodesStats(t *testing.T) { - client, err := NewClient() + client, err := NewClient(SetTraceLog(log.New(os.Stdout, "", 0))) + if err != nil { + t.Fatal(err) + } + + // TODO(oe) Remove this hack after a fix for https://github.com/elastic/elasticsearch/issues/78311 is released + version, err := client.ElasticsearchVersion(DefaultURL) if err != nil { t.Fatal(err) } + if version == "7.15.0" { + t.Skip("skipping NodesStats test for 7.15.0 because of https://github.com/elastic/elasticsearch/issues/78311") + return + } - info, err := client.NodesStats().Human(true).Do(context.TODO()) + info, err := client.NodesStats().Human(true).Pretty(true).Do(context.TODO()) if err != nil { t.Fatal(err) }