Skip to content

Commit 63281fa

Browse files
committed
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 elastic/elasticsearch#78311 that is likely being fixed by elastic/elasticsearch#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
1 parent 9005e28 commit 63281fa

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
elasticsearch:
3-
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION:-7.14.2}
3+
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION:-7.15.0}
44
hostname: elasticsearch
55
environment:
66
- cluster.name=elasticsearch
@@ -28,7 +28,7 @@ services:
2828
ports:
2929
- 9200:9200
3030
platinum:
31-
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION:-7.14.2}
31+
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION:-7.15.0}
3232
hostname: elasticsearch-platinum
3333
environment:
3434
- cluster.name=platinum

nodes_stats.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ type NodesStatsNode struct {
333333

334334
type NodesStatsIndex struct {
335335
Docs *NodesStatsDocsStats `json:"docs"`
336+
Shards *NodesStatsShardCountStats `json:"shards_stats"`
336337
Store *NodesStatsStoreStats `json:"store"`
337338
Indexing *NodesStatsIndexingStats `json:"indexing"`
338339
Get *NodesStatsGetStats `json:"get"`
@@ -343,23 +344,25 @@ type NodesStatsIndex struct {
343344
Warmer *NodesStatsWarmerStats `json:"warmer"`
344345
QueryCache *NodesStatsQueryCacheStats `json:"query_cache"`
345346
Fielddata *NodesStatsFielddataStats `json:"fielddata"`
346-
Percolate *NodesStatsPercolateStats `json:"percolate"`
347347
Completion *NodesStatsCompletionStats `json:"completion"`
348348
Segments *NodesStatsSegmentsStats `json:"segments"`
349349
Translog *NodesStatsTranslogStats `json:"translog"`
350-
Suggest *NodesStatsSuggestStats `json:"suggest"`
351350
RequestCache *NodesStatsRequestCacheStats `json:"request_cache"`
352351
Recovery NodesStatsRecoveryStats `json:"recovery"`
353352

354-
Indices map[string]*NodesStatsIndex `json:"indices"` // for level=indices
355-
Shards map[string]*NodesStatsIndex `json:"shards"` // for level=shards
353+
IndicesLevel map[string]*NodesStatsIndex `json:"indices"` // for level=indices
354+
ShardsLevel map[string]*NodesStatsIndex `json:"shards"` // for level=shards
356355
}
357356

358357
type NodesStatsDocsStats struct {
359358
Count int64 `json:"count"`
360359
Deleted int64 `json:"deleted"`
361360
}
362361

362+
type NodesStatsShardCountStats struct {
363+
TotalCount int64 `json:"total_count"`
364+
}
365+
363366
type NodesStatsStoreStats struct {
364367
Size string `json:"size"`
365368
SizeInBytes int64 `json:"size_in_bytes"`
@@ -473,16 +476,6 @@ type NodesStatsFielddataStats struct {
473476
} `json:"fields"`
474477
}
475478

476-
type NodesStatsPercolateStats struct {
477-
Total int64 `json:"total"`
478-
Time string `json:"time"`
479-
TimeInMillis int64 `json:"time_in_millis"`
480-
Current int64 `json:"current"`
481-
MemorySize string `json:"memory_size"`
482-
MemorySizeInBytes int64 `json:"memory_size_in_bytes"`
483-
Queries int64 `json:"queries"`
484-
}
485-
486479
type NodesStatsCompletionStats struct {
487480
Size string `json:"size"`
488481
SizeInBytes int64 `json:"size_in_bytes"`
@@ -522,13 +515,6 @@ type NodesStatsTranslogStats struct {
522515
SizeInBytes int64 `json:"size_in_bytes"`
523516
}
524517

525-
type NodesStatsSuggestStats struct {
526-
Total int64 `json:"total"`
527-
TotalTime string `json:"total_time"`
528-
TotalTimeInMillis int64 `json:"total_time_in_millis"`
529-
Current int64 `json:"current"`
530-
}
531-
532518
type NodesStatsRequestCacheStats struct {
533519
MemorySize string `json:"memory_size"`
534520
MemorySizeInBytes int64 `json:"memory_size_in_bytes"`

nodes_stats_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@ package elastic
66

77
import (
88
"context"
9+
"log"
10+
"os"
911
"testing"
1012
)
1113

1214
func TestNodesStats(t *testing.T) {
13-
client, err := NewClient()
15+
client, err := NewClient(SetTraceLog(log.New(os.Stdout, "", 0)))
16+
if err != nil {
17+
t.Fatal(err)
18+
}
19+
20+
// TODO(oe) Remove this hack after a fix for https://github.com/elastic/elasticsearch/issues/78311 is released
21+
version, err := client.ElasticsearchVersion(DefaultURL)
1422
if err != nil {
1523
t.Fatal(err)
1624
}
25+
if version == "7.15.0" {
26+
t.Skip("skipping NodesStats test for 7.15.0 because of https://github.com/elastic/elasticsearch/issues/78311")
27+
return
28+
}
1729

18-
info, err := client.NodesStats().Human(true).Do(context.TODO())
30+
info, err := client.NodesStats().Human(true).Pretty(true).Do(context.TODO())
1931
if err != nil {
2032
t.Fatal(err)
2133
}

0 commit comments

Comments
 (0)