From 1417ee04f2c70a851a4cc967f80e44c04a989313 Mon Sep 17 00:00:00 2001 From: Miles-Garnsey Date: Fri, 20 Jan 2023 16:52:11 +1100 Subject: [PATCH] Modify field name from source_labels to sourceLabels. --- .../metrics/builder/filter/FilteringSpec.java | 21 +++++++++++-------- .../builder/filter/SingleFilterTests.java | 6 +++--- .../src/test/resources/collector.yaml | 4 ++-- .../src/test/resources/collector_tls.yaml | 4 ++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/management-api-agent-common/src/main/java/io/k8ssandra/metrics/builder/filter/FilteringSpec.java b/management-api-agent-common/src/main/java/io/k8ssandra/metrics/builder/filter/FilteringSpec.java index ac552bfd..97c7a35e 100644 --- a/management-api-agent-common/src/main/java/io/k8ssandra/metrics/builder/filter/FilteringSpec.java +++ b/management-api-agent-common/src/main/java/io/k8ssandra/metrics/builder/filter/FilteringSpec.java @@ -10,16 +10,19 @@ /** * Supports a subset of ServiceMonitorSpec's relabeling rules. * - * - source_labels: [subsystem, server] - * separator: "@" - * regex: "kata@webserver" - * action: "drop" + * - sourceLabels: [subsystem, server] + * separator: "@" + * regex: "kata@webserver" + * action: "drop" * - * Like Prometheus, the metric name is available as source_label "__name__" and the original Cassandra metric + * Like Prometheus, the metric name is available as source_label "__name__" and + * the original Cassandra metric * name is available as "__origname__" */ public class FilteringSpec { - public enum Action { drop, keep }; + public enum Action { + drop, keep + }; public static final String METRIC_NAME_LABELNAME = "__name__"; @@ -27,7 +30,7 @@ public enum Action { drop, keep }; public static final String DEFAULT_SEPARATOR = "@"; - @JsonProperty("source_labels") + @JsonProperty("sourceLabels") private List sourceLabels; @JsonProperty(value = "separator", defaultValue = DEFAULT_SEPARATOR) @@ -54,7 +57,7 @@ public boolean filter(Map labels) { StringJoiner joiner = new StringJoiner(DEFAULT_SEPARATOR); for (String sourceLabel : sourceLabels) { String labelValue = labels.get(sourceLabel); - if(labelValue == null) { + if (labelValue == null) { labelValue = ""; } joiner.add(labelValue); @@ -64,7 +67,7 @@ public boolean filter(Map labels) { boolean match = regexp.matcher(value).matches(); - switch(action) { + switch (action) { case drop: return !match; default: diff --git a/management-api-agent-common/src/test/java/io/k8ssandra/metrics/builder/filter/SingleFilterTests.java b/management-api-agent-common/src/test/java/io/k8ssandra/metrics/builder/filter/SingleFilterTests.java index 5547d090..f733308f 100644 --- a/management-api-agent-common/src/test/java/io/k8ssandra/metrics/builder/filter/SingleFilterTests.java +++ b/management-api-agent-common/src/test/java/io/k8ssandra/metrics/builder/filter/SingleFilterTests.java @@ -9,7 +9,7 @@ public class SingleFilterTests { /** - - source_labels: [__name__] + - sourceLabels: [__name__] separator: "@" regex: "org_apache_cassandra_metrics_table_.*" action: "drop" @@ -33,7 +33,7 @@ public void TestDropWithName() { } /** - - source_labels: [__name__, table] + - sourceLabels: [__name__, table] separator: "@" regex: "(org_apache_cassandra_metrics_table_.*)@dropped_columns" action: "keep" @@ -64,7 +64,7 @@ public void TestDropWithNameLabelCombo() { * Drop all table metrics, except those with label table=dropped_columns * Don't drop other metrics - - source_labels: [__name__, table] + - sourceLabels: [__name__, table] separator: "@" regex: "(org_apache_cassandra_metrics_table_.*)@\b(?!dropped_columns\b)\w+" action: "drop" diff --git a/management-api-agent-common/src/test/resources/collector.yaml b/management-api-agent-common/src/test/resources/collector.yaml index ecc67464..16c697dc 100644 --- a/management-api-agent-common/src/test/resources/collector.yaml +++ b/management-api-agent-common/src/test/resources/collector.yaml @@ -2,11 +2,11 @@ endpoint: address: "127.0.0.1" port: 9001 filters: - - source_labels: ["__tag1__", "__tag2__"] + - sourceLabels: ["__tag1__", "__tag2__"] separator: ";" regex: "(.*);(b.*)" action: "drop" - - source_labels: ["__tag1__", "__tag2__"] + - sourceLabels: ["__tag1__", "__tag2__"] separator: "," regex: "^(a|b|c),.*" action: "drop" diff --git a/management-api-agent-common/src/test/resources/collector_tls.yaml b/management-api-agent-common/src/test/resources/collector_tls.yaml index 92882c93..cb666e74 100644 --- a/management-api-agent-common/src/test/resources/collector_tls.yaml +++ b/management-api-agent-common/src/test/resources/collector_tls.yaml @@ -5,11 +5,11 @@ endpoint: tls.crt: "/etc/ssl/tls.crt" tls.key: "/etc/ssl/tls.key" filters: - - source_labels: ["__tag1__", "__tag2__"] + - sourceLabels: ["__tag1__", "__tag2__"] separator: ";" regex: "(.*);(b.*)" action: "drop" - - source_labels: ["__tag1__", "__tag2__"] + - sourceLabels: ["__tag1__", "__tag2__"] separator: "," regex: "^(a|b|c),.*" action: "drop"