Skip to content

Commit

Permalink
Update Nodes Stats API to latest API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
olivere committed Oct 6, 2021
1 parent 9005e28 commit 63281fa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions 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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 7 additions & 21 deletions nodes_stats.go
Expand Up @@ -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"`
Expand All @@ -343,23 +344,25 @@ 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 {
Count int64 `json:"count"`
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"`
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
16 changes: 14 additions & 2 deletions nodes_stats_test.go
Expand Up @@ -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)
}
Expand Down

0 comments on commit 63281fa

Please sign in to comment.