Add resource labels to Stackdriver metrics configuration properties
Using resource labels is mandatory for most Stackdriver resources other than 'Global', i.e. k8s_pod. Configuring valid resource type along with related labels makes it possible to use given metric in a wider set of GCP solutions, i.e. custom metric based GKE pod horizontal autoscaler. See gh-26961
This commit is contained in:
parent
9b82836f0e
commit
4e3958e5aa
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.metrics.export.stackdriver;
|
package org.springframework.boot.actuate.autoconfigure.metrics.export.stackdriver;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties;
|
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
@ -40,6 +42,11 @@ public class StackdriverProperties extends StepRegistryProperties {
|
||||||
*/
|
*/
|
||||||
private String resourceType = "global";
|
private String resourceType = "global";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monitored resource's labels.
|
||||||
|
*/
|
||||||
|
private Map<String, String> resourceLabels;
|
||||||
|
|
||||||
public String getProjectId() {
|
public String getProjectId() {
|
||||||
return this.projectId;
|
return this.projectId;
|
||||||
}
|
}
|
||||||
|
@ -56,4 +63,12 @@ public class StackdriverProperties extends StepRegistryProperties {
|
||||||
this.resourceType = resourceType;
|
this.resourceType = resourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getResourceLabels() {
|
||||||
|
return this.resourceLabels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourceLabels(Map<String, String> resourceLabels) {
|
||||||
|
this.resourceLabels = resourceLabels;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.metrics.export.stackdriver;
|
package org.springframework.boot.actuate.autoconfigure.metrics.export.stackdriver;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import io.micrometer.stackdriver.StackdriverConfig;
|
import io.micrometer.stackdriver.StackdriverConfig;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter;
|
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter;
|
||||||
|
@ -48,4 +50,9 @@ public class StackdriverPropertiesConfigAdapter extends StepRegistryPropertiesCo
|
||||||
return get(StackdriverProperties::getResourceType, StackdriverConfig.super::resourceType);
|
return get(StackdriverProperties::getResourceType, StackdriverConfig.super::resourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> resourceLabels() {
|
||||||
|
return get(StackdriverProperties::getResourceLabels, StackdriverConfig.super::resourceLabels);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.metrics.export.stackdriver;
|
package org.springframework.boot.actuate.autoconfigure.metrics.export.stackdriver;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -41,4 +44,15 @@ class StackdriverPropertiesConfigAdapterTests {
|
||||||
assertThat(new StackdriverPropertiesConfigAdapter(properties).resourceType()).isEqualTo("my-resource-type");
|
assertThat(new StackdriverPropertiesConfigAdapter(properties).resourceType()).isEqualTo("my-resource-type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenPropertiesResourceLabelsAreSetAdapterResourceTypeReturnsThem() {
|
||||||
|
final Map<String, String> labels = new HashMap<>();
|
||||||
|
labels.put("labelOne", "valueOne");
|
||||||
|
labels.put("labelTwo", "valueTwo");
|
||||||
|
StackdriverProperties properties = new StackdriverProperties();
|
||||||
|
properties.setResourceLabels(labels);
|
||||||
|
assertThat(new StackdriverPropertiesConfigAdapter(properties).resourceLabels())
|
||||||
|
.containsExactlyInAnyOrderEntriesOf(labels);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue