Skip to content

Commit

Permalink
Add missing Stackdriver metric-type-prefix property
Browse files Browse the repository at this point in the history
Closes gh-36499
  • Loading branch information
wilkinsona committed Jul 25, 2023
1 parent 45624c0 commit d290d05
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,12 @@ public class StackdriverProperties extends StepRegistryProperties {
*/
private boolean useSemanticMetricTypes = false;

/**
* Prefix for metric type. Valid prefixes are described in the Google Cloud
* documentation (https://cloud.google.com/monitoring/custom-metrics#identifier).
*/
private String metricTypePrefix = "custom.googleapis.com/";

public String getProjectId() {
return this.projectId;
}
Expand Down Expand Up @@ -86,4 +92,12 @@ public void setUseSemanticMetricTypes(boolean useSemanticMetricTypes) {
this.useSemanticMetricTypes = useSemanticMetricTypes;
}

public String getMetricTypePrefix() {
return this.metricTypePrefix;
}

public void setMetricTypePrefix(String metricTypePrefix) {
this.metricTypePrefix = metricTypePrefix;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,4 +60,9 @@ public boolean useSemanticMetricTypes() {
return get(StackdriverProperties::isUseSemanticMetricTypes, StackdriverConfig.super::useSemanticMetricTypes);
}

@Override
public String metricTypePrefix() {
return get(StackdriverProperties::getMetricTypePrefix, StackdriverConfig.super::metricTypePrefix);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ void whenPropertiesUseSemanticMetricTypesIsSetAdapterUseSemanticMetricTypesRetur
assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isTrue();
}

@Test
void whenPropertiesMetricTypePrefixIsSetAdapterMetricTypePrefixReturnsIt() {
StackdriverProperties properties = new StackdriverProperties();
properties.setMetricTypePrefix("external.googleapis.com/prometheus");
assertThat(new StackdriverPropertiesConfigAdapter(properties).metricTypePrefix())
.isEqualTo("external.googleapis.com/prometheus");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,7 @@ void defaultValuesAreConsistent() {
assertStepRegistryDefaultValues(properties, config);
assertThat(properties.getResourceType()).isEqualTo(config.resourceType());
assertThat(properties.isUseSemanticMetricTypes()).isEqualTo(config.useSemanticMetricTypes());
assertThat(properties.getMetricTypePrefix()).isEqualTo(config.metricTypePrefix());
}

}

0 comments on commit d290d05

Please sign in to comment.