diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-12-18 16:03:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-18 16:03:23 +0100 |
commit | d98918a1419fd9b893852dc8d6e64bf2b1010314 (patch) | |
tree | 3cb38477d5a7b06029820f68965771c3a9036ba9 /metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsParserTest.java | |
parent | b36fdededf2cb62c5be8814f4d6bf4038dc86dfc (diff) | |
parent | a8751ad4b039b958f29da98e074103ba437c50d9 (diff) |
Merge pull request #25280 from vespa-engine/fix-dimension-hashing-bugv8.101.28
Fix dimension hashing bug
Diffstat (limited to 'metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsParserTest.java')
-rw-r--r-- | metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsParserTest.java | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsParserTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsParserTest.java new file mode 100644 index 00000000000..17dc9e643f0 --- /dev/null +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsParserTest.java @@ -0,0 +1,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" + } + } + ] + } + } + """; + } + +} |