Skip to content

Commit 25df307

Browse files
sysadmindrtkkroland
authored andcommitted
Refactor tests for nodes collector
- Drop extra test for authenticated requests to elasticsearch. Auth is common across all collectors, so it doesn't make sense to have specific tests for an individual collector. - Add missing descriptions - Drop tests for minor versions besides the most recent. The output is very large for this collector, and there is little value in testing every single minor version. - Update tests to test the output of the metrics - Refactor the node roles metric to have the role be dynamic, and to export 0 values for roles that are missing. Signed-off-by: Joe Adams <github@joeadams.io>
1 parent 075fde1 commit 25df307

File tree

7 files changed

+1629
-169
lines changed

7 files changed

+1629
-169
lines changed

collector/nodes.go

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,13 @@ func getRoles(node NodeStatsNodeResponse) map[string]bool {
7070
return roles
7171
}
7272

73-
func createRoleMetric(role string) *nodeMetric {
74-
return &nodeMetric{
75-
Type: prometheus.GaugeValue,
76-
Desc: prometheus.NewDesc(
77-
prometheus.BuildFQName(namespace, "nodes", "roles"),
78-
"Node roles",
79-
defaultRoleLabels, prometheus.Labels{"role": role},
80-
),
81-
Value: func(node NodeStatsNodeResponse) float64 {
82-
return 1.0
83-
},
84-
Labels: func(cluster string, node NodeStatsNodeResponse) []string {
85-
return []string{
86-
cluster,
87-
node.Host,
88-
node.Name,
89-
}
90-
},
91-
}
92-
}
73+
var (
74+
nodesRolesMetric = prometheus.NewDesc(
75+
prometheus.BuildFQName(namespace, "nodes", "roles"),
76+
"Node roles",
77+
append(defaultRoleLabels, "role"), nil,
78+
)
79+
)
9380

9481
var (
9582
defaultNodeLabels = []string{"cluster", "host", "name", "es_master_node", "es_data_node", "es_ingest_node", "es_client_node"}
@@ -1859,12 +1846,20 @@ func NewNodes(logger log.Logger, client *http.Client, url *url.URL, all bool, no
18591846

18601847
// Describe add metrics descriptions
18611848
func (c *Nodes) Describe(ch chan<- *prometheus.Desc) {
1849+
ch <- nodesRolesMetric
1850+
18621851
for _, metric := range c.nodeMetrics {
18631852
ch <- metric.Desc
18641853
}
18651854
for _, metric := range c.gcCollectionMetrics {
18661855
ch <- metric.Desc
18671856
}
1857+
for _, metric := range c.breakerMetrics {
1858+
ch <- metric.Desc
1859+
}
1860+
for _, metric := range c.indexingPressureMetrics {
1861+
ch <- metric.Desc
1862+
}
18681863
for _, metric := range c.threadPoolMetrics {
18691864
ch <- metric.Desc
18701865
}
@@ -1948,15 +1943,24 @@ func (c *Nodes) Collect(ch chan<- prometheus.Metric) {
19481943
roles := getRoles(node)
19491944

19501945
for role, roleEnabled := range roles {
1946+
val := 0.0
19511947
if roleEnabled {
1952-
metric := createRoleMetric(role)
1953-
ch <- prometheus.MustNewConstMetric(
1954-
metric.Desc,
1955-
metric.Type,
1956-
metric.Value(node),
1957-
metric.Labels(nodeStatsResp.ClusterName, node)...,
1958-
)
1948+
val = 1.0
1949+
}
1950+
1951+
labels := []string{
1952+
nodeStatsResp.ClusterName,
1953+
node.Host,
1954+
node.Name,
1955+
role,
19591956
}
1957+
1958+
ch <- prometheus.MustNewConstMetric(
1959+
nodesRolesMetric,
1960+
prometheus.GaugeValue,
1961+
val,
1962+
labels...,
1963+
)
19601964
}
19611965

19621966
for _, metric := range c.nodeMetrics {

collector/nodes_test.go

Lines changed: 1598 additions & 137 deletions
Large diffs are not rendered by default.

fixtures/nodestats/5.4.2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

fixtures/nodestats/6.5.4.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)