From 92dd004375849af7b53344a7e7f7f81c3eb14963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Sat, 28 Jan 2023 20:18:50 -0500 Subject: [PATCH] Add property `headers` in `OtlpProperties` In Micrometer 1.11, headers property has been introduced. See gh-34004 --- .../metrics/export/otlp/OtlpProperties.java | 15 ++++++++++++++- .../export/otlp/OtlpPropertiesConfigAdapter.java | 7 ++++++- .../otlp/OtlpPropertiesConfigAdapterTests.java | 9 ++++++++- .../spring-boot-dependencies/build.gradle | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpProperties.java index 00b47d8754..f3de0dd5d9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpProperties.java @@ -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. @@ -41,6 +41,11 @@ public class OtlpProperties extends StepRegistryProperties { */ private Map resourceAttributes; + /** + * Headers for the exported metrics. + */ + private Map headers; + public String getUrl() { return this.url; } @@ -57,4 +62,12 @@ public class OtlpProperties extends StepRegistryProperties { this.resourceAttributes = resourceAttributes; } + public Map getHeaders() { + return this.headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapter.java index 45acea47a3..7d8eed7ee4 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapter.java @@ -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. @@ -48,4 +48,9 @@ class OtlpPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter headers() { + return get(OtlpProperties::getHeaders, OtlpConfig.super::headers); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapterTests.java index 5a893c55ec..3253e01ccd 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapterTests.java @@ -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. @@ -44,4 +44,11 @@ class OtlpPropertiesConfigAdapterTests { "boot-service"); } + @Test + void whenPropertiesHeadersIsSetAdapterHeadersReturnsIt() { + OtlpProperties properties = new OtlpProperties(); + properties.setHeaders(Map.of("header", "value")); + assertThat(new OtlpPropertiesConfigAdapter(properties).headers()).containsEntry("header", "value"); + } + } diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 8d6a835c93..a5cdecc143 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -932,7 +932,7 @@ bom { ] } } - library("Micrometer", "1.10.3") { + library("Micrometer", "1.11.0-SNAPSHOT") { group("io.micrometer") { modules = [ "micrometer-registry-stackdriver" {