Skip to content

Commit

Permalink
Fix Cluster Stats response structure
Browse files Browse the repository at this point in the history
This commit fixes a change in the cluster stats response structure.

Close #1494
  • Loading branch information
olivere committed Jun 16, 2021
1 parent fb742c1 commit 107c379
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 20 deletions.
189 changes: 189 additions & 0 deletions cluster_stats_test.go
Expand Up @@ -5,6 +5,7 @@
package elastic

import (
"encoding/json"
"net/url"
"testing"
)
Expand Down Expand Up @@ -67,3 +68,191 @@ func TestClusterStatsURLs(t *testing.T) {
}
}
}

func TestClusterStatsErrorResponse(t *testing.T) {
body := `{
"_nodes": {
"total": 2,
"successful": 1,
"failed": 1,
"failures": [
{
"type": "failed_node_exception",
"reason": "Failed node [mhUZF1sPTcu2b-pIJfqQRg]",
"node_id": "mhUZF1sPTcu2b-pIJfqQRg",
"caused_by": {
"type": "node_not_connected_exception",
"reason": "[es02][172.27.0.2:9300] Node not connected"
}
}
]
},
"cluster_name": "es-docker-cluster",
"cluster_uuid": "r-OkEGlJTFOE8wP36G-VSg",
"timestamp": 1621834319499,
"indices": {
"count": 0,
"shards": {},
"docs": {
"count": 0,
"deleted": 0
},
"store": {
"size_in_bytes": 0,
"reserved_in_bytes": 0
},
"fielddata": {
"memory_size_in_bytes": 0,
"evictions": 0
},
"query_cache": {
"memory_size_in_bytes": 0,
"total_count": 0,
"hit_count": 0,
"miss_count": 0,
"cache_size": 0,
"cache_count": 0,
"evictions": 0
},
"completion": {
"size_in_bytes": 0
},
"segments": {
"count": 0,
"memory_in_bytes": 0,
"terms_memory_in_bytes": 0,
"stored_fields_memory_in_bytes": 0,
"term_vectors_memory_in_bytes": 0,
"norms_memory_in_bytes": 0,
"points_memory_in_bytes": 0,
"doc_values_memory_in_bytes": 0,
"index_writer_memory_in_bytes": 0,
"version_map_memory_in_bytes": 0,
"fixed_bit_set_memory_in_bytes": 0,
"max_unsafe_auto_id_timestamp": -9223372036854775808,
"file_sizes": {}
},
"mappings": {
"field_types": []
},
"analysis": {
"char_filter_types": [],
"tokenizer_types": [],
"filter_types": [],
"analyzer_types": [],
"built_in_char_filters": [],
"built_in_tokenizers": [],
"built_in_filters": [],
"built_in_analyzers": []
}
},
"nodes": {
"count": {
"total": 1,
"coordinating_only": 0,
"data": 1,
"data_cold": 1,
"data_content": 1,
"data_hot": 1,
"data_warm": 1,
"ingest": 1,
"master": 1,
"ml": 1,
"remote_cluster_client": 1,
"transform": 1,
"voting_only": 0
},
"versions": [
"7.10.0"
],
"os": {
"available_processors": 6,
"allocated_processors": 6,
"names": [
{
"name": "Linux",
"count": 1
}
],
"pretty_names": [
{
"pretty_name": "CentOS Linux 8 (Core)",
"count": 1
}
],
"mem": {
"total_in_bytes": 2084679680,
"free_in_bytes": 590282752,
"used_in_bytes": 1494396928,
"free_percent": 28,
"used_percent": 72
}
},
"process": {
"cpu": {
"percent": 0
},
"open_file_descriptors": {
"min": 260,
"max": 260,
"avg": 260
}
},
"jvm": {
"max_uptime_in_millis": 1042623,
"versions": [
{
"version": "15.0.1",
"vm_name": "OpenJDK 64-Bit Server VM",
"vm_version": "15.0.1+9",
"vm_vendor": "AdoptOpenJDK",
"bundled_jdk": true,
"using_bundled_jdk": true,
"count": 1
}
],
"mem": {
"heap_used_in_bytes": 208299344,
"heap_max_in_bytes": 314572800
},
"threads": 32
},
"fs": {
"total_in_bytes": 62725623808,
"free_in_bytes": 26955173888,
"available_in_bytes": 23738458112
},
"plugins": [],
"network_types": {
"transport_types": {
"security4": 1
},
"http_types": {
"security4": 1
}
},
"discovery_types": {
"zen": 1
},
"packaging_types": [
{
"flavor": "default",
"type": "docker",
"count": 1
}
],
"ingest": {
"number_of_pipelines": 0,
"processor_stats": {}
}
}
}`

var resp ClusterStatsResponse
if err := json.Unmarshal([]byte(body), &resp); err != nil {
t.Fatal(err)
}
if want, have := 1, len(resp.NodesStats.Failures); want != have {
t.Fatalf("expected %d errors, got %d", want, have)
}
}
26 changes: 11 additions & 15 deletions errors.go
Expand Up @@ -204,19 +204,15 @@ func IsStatusCode(err interface{}, code int) bool {

// ShardsInfo represents information from a shard.
type ShardsInfo struct {
Total int `json:"total"`
Successful int `json:"successful"`
Failed int `json:"failed"`
Failures []*ShardFailure `json:"failures,omitempty"`
Skipped int `json:"skipped,omitempty"`
}

// ShardFailure represents details about a failure.
type ShardFailure struct {
Index string `json:"_index,omitempty"`
Shard int `json:"_shard,omitempty"`
Node string `json:"_node,omitempty"`
Reason map[string]interface{} `json:"reason,omitempty"`
Status string `json:"status,omitempty"`
Primary bool `json:"primary,omitempty"`
Total int `json:"total"`
Successful int `json:"successful"`
Failed int `json:"failed"`
Failures []*FailedNodeException `json:"failures,omitempty"`
Skipped int `json:"skipped,omitempty"`
}

// FailedNodeException returns an error on the node level.
type FailedNodeException struct {
*ErrorDetails
NodeId string `json:"node_id"`
}
5 changes: 0 additions & 5 deletions tasks_list.go
Expand Up @@ -239,11 +239,6 @@ type TaskOperationFailure struct {
Reason *ErrorDetails `json:"reason"`
}

type FailedNodeException struct {
*ErrorDetails
NodeId string `json:"node_id"`
}

type DiscoveryNode struct {
Name string `json:"name"`
TransportAddress string `json:"transport_address"`
Expand Down

0 comments on commit 107c379

Please sign in to comment.