-
Notifications
You must be signed in to change notification settings - Fork 23
add support for elastic.otel.opamp.headers config #848
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
beea87d
add okhttp as direct dependency
SylvainJuge ffa0411
add headers config + rename endpoint url
SylvainJuge 68a2674
get opamp endpoint through dedicated method
SylvainJuge 68d90f4
remove useless log message
SylvainJuge 93ed7ef
make opamp log messages consistent
SylvainJuge ec2e655
environment is nullable
SylvainJuge e2fb467
implement testing
SylvainJuge 6fbde5f
plug setting headers + provide some debug info
SylvainJuge 606e79f
reformat
SylvainJuge 14dd527
add some testing for config
SylvainJuge 3e2aeb8
add tests for service name
SylvainJuge 44c7014
more tests + simplify a bit
SylvainJuge a7efd4c
reformat
SylvainJuge 8dd3ca5
add changelog entry
SylvainJuge 07cf82d
Merge branch 'main' of github.com:elastic/elastic-otel-java into opam…
SylvainJuge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
120 changes: 120 additions & 0 deletions
120
custom/src/test/java/co/elastic/otel/dynamicconfig/CentralConfigTest.java
This file contains hidden or 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,120 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you 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 | ||
| * | ||
| * http://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 co.elastic.otel.dynamicconfig; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class CentralConfigTest { | ||
|
|
||
| @Test | ||
| void getEndpoint() { | ||
| testEndpoint(null, null, "missing config should return null"); | ||
| testEndpoint("", null, "empty config should return null"); | ||
| testEndpoint( | ||
| "http://localhost:8080/v1/opamp", | ||
| "http://localhost:8080/v1/opamp", | ||
| "opamp suffix should be automatically added"); | ||
| testEndpoint( | ||
| "http://localhost:8080/", | ||
| "http://localhost:8080/v1/opamp", | ||
| "opamp suffix should be automatically added"); | ||
| testEndpoint( | ||
| "http://localhost:8080", | ||
| "http://localhost:8080/v1/opamp", | ||
| "opamp suffix should be automatically added"); | ||
| } | ||
|
|
||
| private static void testEndpoint( | ||
| String configValue, String expectedEndpoint, String description) { | ||
| Map<String, String> map = Collections.emptyMap(); | ||
| if (configValue != null) { | ||
| map = Collections.singletonMap("elastic.otel.opamp.endpoint", configValue); | ||
| } | ||
| assertThat(CentralConfig.getEndpoint(DefaultConfigProperties.createFromMap(map))) | ||
| .describedAs(description) | ||
| .isEqualTo(expectedEndpoint); | ||
| } | ||
|
|
||
| @Test | ||
| void getServiceName() { | ||
| Map<String, String> map = Collections.emptyMap(); | ||
| testServiceName(map, "unknown_service:java", "default service name should be provided"); | ||
|
|
||
| map = Collections.singletonMap("otel.service.name", "my-service-1"); | ||
| testServiceName(map, "my-service-1", "set through service name config"); | ||
|
|
||
| map = Collections.singletonMap("otel.resource.attributes", "service.name=my-service-2"); | ||
| testServiceName(map, "my-service-2", "set through resource attributes config"); | ||
|
|
||
| map = new HashMap<>(); | ||
| map.put("otel.service.name", "my-service-3"); | ||
| map.put("otel.resource.attributes", "service.name=my-service-4"); | ||
| testServiceName(map, "my-service-3", "service name takes precedence over resource attributes"); | ||
|
|
||
| map.clear(); | ||
| map.put("otel.resource.attributes", ""); | ||
| testServiceName(map, "unknown_service:java", "default service name should be provided"); | ||
|
|
||
| map.clear(); | ||
| map.put("otel.resource.attributes", "service.name="); | ||
| testServiceName(map, "unknown_service:java", "default service name should be provided"); | ||
| } | ||
|
|
||
| private static void testServiceName( | ||
| Map<String, String> map, String expectedServiceName, String description) { | ||
| ConfigProperties configProperties = DefaultConfigProperties.createFromMap(map); | ||
| assertThat(CentralConfig.getServiceName(configProperties)) | ||
| .isNotNull() | ||
| .describedAs(description) | ||
| .isEqualTo(expectedServiceName); | ||
| } | ||
|
|
||
| @Test | ||
| void getServiceEnvironment() { | ||
| Map<String, String> map = Collections.emptyMap(); | ||
| testServiceEnvironment(map, null, "no environment by default"); | ||
|
|
||
| map = Collections.singletonMap("otel.resource.attributes", "deployment.environment.name=test1"); | ||
| testServiceEnvironment(map, "test1", "environment set through resource attribute"); | ||
|
|
||
| map = Collections.singletonMap("otel.resource.attributes", "deployment.environment=test2"); | ||
| testServiceEnvironment(map, "test2", "environment set through legacy resource attribute"); | ||
|
|
||
| map = | ||
| Collections.singletonMap( | ||
| "otel.resource.attributes", | ||
| "deployment.environment=test3,deployment.environment.name=test4"); | ||
| testServiceEnvironment(map, "test4", "when both set semconv attribute takes precedence"); | ||
| } | ||
|
|
||
| private static void testServiceEnvironment( | ||
| Map<String, String> map, String expectedEnvironment, String description) { | ||
| ConfigProperties configProperties = DefaultConfigProperties.createFromMap(map); | ||
| assertThat(CentralConfig.getServiceEnvironment(configProperties)) | ||
| .describedAs(description) | ||
| .isEqualTo(expectedEnvironment); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for review: here we can simplify a bit because an empty map is returned, we never get a
nullcollection (now covered by tests).