Add missing Stackdriver metric-type-prefix property

Closes gh-36499
pull/37018/head
Andy Wilkinson 1 year ago
parent 45624c0a78
commit d290d05f63

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,6 +54,12 @@ public class StackdriverProperties extends StepRegistryProperties {
*/ */
private boolean useSemanticMetricTypes = false; 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() { public String getProjectId() {
return this.projectId; return this.projectId;
} }
@ -86,4 +92,12 @@ public class StackdriverProperties extends StepRegistryProperties {
this.useSemanticMetricTypes = useSemanticMetricTypes; this.useSemanticMetricTypes = useSemanticMetricTypes;
} }
public String getMetricTypePrefix() {
return this.metricTypePrefix;
}
public void setMetricTypePrefix(String metricTypePrefix) {
this.metricTypePrefix = metricTypePrefix;
}
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -60,4 +60,9 @@ public class StackdriverPropertiesConfigAdapter extends StepRegistryPropertiesCo
return get(StackdriverProperties::isUseSemanticMetricTypes, StackdriverConfig.super::useSemanticMetricTypes); return get(StackdriverProperties::isUseSemanticMetricTypes, StackdriverConfig.super::useSemanticMetricTypes);
} }
@Override
public String metricTypePrefix() {
return get(StackdriverProperties::getMetricTypePrefix, StackdriverConfig.super::metricTypePrefix);
}
} }

@ -62,4 +62,12 @@ class StackdriverPropertiesConfigAdapterTests {
assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isTrue(); 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");
}
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,6 +37,7 @@ class StackdriverPropertiesTests extends StepRegistryPropertiesTests {
assertStepRegistryDefaultValues(properties, config); assertStepRegistryDefaultValues(properties, config);
assertThat(properties.getResourceType()).isEqualTo(config.resourceType()); assertThat(properties.getResourceType()).isEqualTo(config.resourceType());
assertThat(properties.isUseSemanticMetricTypes()).isEqualTo(config.useSemanticMetricTypes()); assertThat(properties.isUseSemanticMetricTypes()).isEqualTo(config.useSemanticMetricTypes());
assertThat(properties.getMetricTypePrefix()).isEqualTo(config.metricTypePrefix());
} }
} }

Loading…
Cancel
Save