-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config for OTLP Resource attributes (#3159)
* Config for OTLP Resource attributes Adds a config method for attributes that are set on the Resource shared by all metrics published from the OtlpMeterRegistry. Of note, this allows configuring the `service.name` to identify your service, but is generic enough to allow configuration of arbitrary attributes. The use cases for this largely overlaps with how we expect common tags are used, and it is a shame I could not come up with a way to better connect these now. There is precedent for this approach in e.g. the StackdriverMeterRegistry. But it potentially creates inconsistency or duplicated work when using multiple registries. * Load resource attributes from config/env Since there is a specified environment variable to set resource attributes, we can support that. And since it defines a format for key-value pairs, we can use that for loading the map from the `get` method. * Make parsing more robust and tested * Polish JavaDoc
- Loading branch information
Showing
5 changed files
with
149 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ns/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2022 VMware, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.registry.otlp; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class OtlpConfigTest { | ||
|
||
@Test | ||
void resourceAttributesInputParsing() { | ||
OtlpConfig config = k -> "key1=value1,"; | ||
assertThat(config.resourceAttributes()).containsEntry("key1", "value1").hasSize(1); | ||
config = k -> "k=v,a"; | ||
assertThat(config.resourceAttributes()).containsEntry("k", "v").hasSize(1); | ||
config = k -> "k=v,a=="; | ||
assertThat(config.resourceAttributes()).containsEntry("k", "v").containsEntry("a", "=").hasSize(2); | ||
config = k -> " k = v, a= b "; | ||
assertThat(config.resourceAttributes()).containsEntry("k", "v").containsEntry("a", "b").hasSize(2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
implementations/micrometer-registry-otlp/src/test/resources/otlp-config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright 2022 VMware, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
otlp.resourceAttributes=key1=value1,key2=value2 |