Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify field name from source_labels to sourceLabels #250

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@
/**
* Supports a subset of ServiceMonitorSpec's relabeling rules.
*
* - source_labels: [subsystem, server]
* separator: "@"
* regex: "kata@webserver"
* action: "drop"
* - sourceLabels: [subsystem, server]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example where your indent configs do not work. This automated indent messed up the comment's readability.

* 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__";

public static final String CASSANDRA_METRIC_NAME_LABELNAME = "__origname__";

public static final String DEFAULT_SEPARATOR = "@";

@JsonProperty("source_labels")
@JsonProperty("sourceLabels")
private List<String> sourceLabels;

@JsonProperty(value = "separator", defaultValue = DEFAULT_SEPARATOR)
Expand All @@ -54,7 +57,7 @@ public boolean filter(Map<String, String> 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);
Expand All @@ -64,7 +67,7 @@ public boolean filter(Map<String, String> labels) {

boolean match = regexp.matcher(value).matches();

switch(action) {
switch (action) {
case drop:
return !match;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class SingleFilterTests {
/**
- source_labels: [__name__]
- sourceLabels: [__name__]
separator: "@"
regex: "org_apache_cassandra_metrics_table_.*"
action: "drop"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions management-api-agent-common/src/test/resources/collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"