1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
package ai.vespa.metricsproxy.service;
import ai.vespa.metricsproxy.metric.Metric;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/**
* @author gjoranv
*/
public class MetricsParserTest {
private static class MetricsCollector implements MetricsParser.Collector {
List<Metric> metrics = new ArrayList<>();
@Override
public void accept(Metric metric) {
metrics.add(metric);
}
}
@Test
public void different_dimension_values_are_not_treated_as_equal() throws Exception {
var collector = new MetricsCollector();
MetricsParser.parse(metricsJsonDistinctButDuplicateDimensionDalues(), collector);
assertEquals(2, collector.metrics.size());
assertNotEquals("Dimensions should not be equal",
collector.metrics.get(0).getDimensions(),
collector.metrics.get(1).getDimensions());
}
@Test
public void different_swapped_dimension_values_are_not_treated_as_equal() throws Exception {
var collector = new MetricsCollector();
MetricsParser.parse(metricsJsonDistinctButDuplicateSwappedDimensionDalues(), collector);
assertEquals(2, collector.metrics.size());
assertNotEquals("Dimensions should not be equal",
collector.metrics.get(0).getDimensions(),
collector.metrics.get(1).getDimensions());
}
// The duplicate dimension values for 'cluster' and 'clusterid' exposed a bug in a previously used hashing algo for dimensions.
private String metricsJsonDistinctButDuplicateDimensionDalues() {
return """
{
"time": 1671035366573,
"status": {
"code": "up"
},
"metrics": {
"snapshot": {
"from": 1671035306.562,
"to": 1671035366.562
},
"values": [
{
"name": "cluster-controller.resource_usage.nodes_above_limit",
"values": {
"last": 1.0
},
"dimensions": {
"controller-index": "0",
"cluster": "CLUSTER-1",
"clusterid": "CLUSTER-1"
}
},
{
"name": "cluster-controller.resource_usage.nodes_above_limit",
"values": {
"last": 2.0
},
"dimensions": {
"controller-index": "0",
"cluster": "CLUSTER-2",
"clusterid": "CLUSTER-2"
}
}
]
}
}
""";
}
// The duplicate dimension values for 'cluster' and 'clusterid' exposed a bug in a previously used hashing algo for dimensions.
private String metricsJsonDistinctButDuplicateSwappedDimensionDalues() {
return """
{
"time": 1671035366573,
"status": {
"code": "up"
},
"metrics": {
"snapshot": {
"from": 1671035306.562,
"to": 1671035366.562
},
"values": [
{
"name": "cluster-controller.resource_usage.nodes_above_limit",
"values": {
"last": 1.0
},
"dimensions": {
"controller-index": "0",
"cluster": "CLUSTER-1",
"clusterid": "CLUSTER-2"
}
},
{
"name": "cluster-controller.resource_usage.nodes_above_limit",
"values": {
"last": 2.0
},
"dimensions": {
"controller-index": "0",
"cluster": "CLUSTER-2",
"clusterid": "CLUSTER-1"
}
}
]
}
}
""";
}
}
|