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

Expose Stackdriver's useSemanticMetricTypes property #28403

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -47,6 +47,14 @@ public class StackdriverProperties extends StepRegistryProperties {
*/
private Map<String, String> resourceLabels;

/**
* Whether to use semantically correct metric types. When this is false, counter
Copy link
Member Author

Choose a reason for hiding this comment

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

* metrics are published as the GAUGE MetricKind. When this is true, counter metrics
* are published as the CUMULATIVE MetricKind. This is false by default for the sake
* of backwards compatibility.
*/
private boolean useSemanticMetricTypes = false;

public String getProjectId() {
return this.projectId;
}
Expand All @@ -71,4 +79,12 @@ public void setResourceLabels(Map<String, String> resourceLabels) {
this.resourceLabels = resourceLabels;
}

boolean isUseSemanticMetricTypes() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This feels weird.

return this.useSemanticMetricTypes;
}

void setUseSemanticMetricTypes(boolean useSemanticMetricTypes) {
this.useSemanticMetricTypes = useSemanticMetricTypes;
}

}
Expand Up @@ -55,4 +55,9 @@ public Map<String, String> resourceLabels() {
return get(StackdriverProperties::getResourceLabels, StackdriverConfig.super::resourceLabels);
}

@Override
public boolean useSemanticMetricTypes() {
return get(StackdriverProperties::isUseSemanticMetricTypes, StackdriverConfig.super::useSemanticMetricTypes);
}

}
Expand Up @@ -55,4 +55,13 @@ void whenPropertiesResourceLabelsAreSetAdapterResourceLabelsReturnsThem() {
.containsExactlyInAnyOrderEntriesOf(labels);
}

@Test
void whenPropertiesUseSemanticMetricTypesIsSetAdapterResourceTypeReturnsIt() {
StackdriverProperties properties = new StackdriverProperties();
properties.setUseSemanticMetricTypes(true);
assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isTrue();
properties.setUseSemanticMetricTypes(false);
assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isFalse();
}

}
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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 @@ -36,6 +36,7 @@ void defaultValuesAreConsistent() {
StackdriverConfig config = (key) -> null;
assertStepRegistryDefaultValues(properties, config);
assertThat(properties.getResourceType()).isEqualTo(config.resourceType());
assertThat(properties.isUseSemanticMetricTypes()).isEqualTo(config.useSemanticMetricTypes());
}

}