-
Notifications
You must be signed in to change notification settings - Fork 45
[File based config] Implement profiler configuration customizer to support JFR #2519
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 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
87f1339
Initial configuration refactoring
robsunday 480405a
Additional cleanup of Configuration class.
robsunday 41cc08e
Additional cleanup of Configuration class.
robsunday c56343d
Revert "Additional cleanup of Configuration class."
robsunday 3695261
Spotless
robsunday 43bd074
Tests fixed
robsunday bc840e9
Update profiler/src/main/java/com/splunk/opentelemetry/profiler/Confi…
robsunday c98a601
Code review followup
robsunday 8dd45fe
Fixed issue with getConfigUrl() method
robsunday d1ec23b
Reverting an unnecessary change
robsunday 838c47a
Merge branch 'main' into fbc-profiler
robsunday a6d691d
Merge branch 'main' into fbc-profiler
robsunday 8196c59
Refactoring to let Configuration.getIngestUrl(config) return not null…
robsunday 12d2f70
Merge branch 'main' into fbc-profiler
robsunday 5fdc2dc
Implement profiler configuration customizer to support JFR
robsunday 1be7e49
Code review followup - refactoring JFR support
robsunday 1603c2e
Code review followup - refactoring JFR support
robsunday 851781d
Code review followup - refactoring JFR support
robsunday 52c4101
Spotless
robsunday 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
49 changes: 0 additions & 49 deletions
49
profiler/src/main/java/com/splunk/opentelemetry/profiler/SdkCustomizer.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
...r/src/main/java/com/splunk/opentelemetry/profiler/util/ProfilerDeclarativeConfigUtil.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,48 @@ | ||
| /* | ||
| * Copyright Splunk 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 | ||
| * | ||
| * 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 com.splunk.opentelemetry.profiler.util; | ||
|
|
||
| import static io.opentelemetry.sdk.autoconfigure.AdditionalPropertiesUtil.getAdditionalPropertyOrDefault; | ||
|
|
||
| import com.splunk.opentelemetry.SplunkConfiguration; | ||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalLanguageSpecificInstrumentationModel; | ||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel; | ||
| import java.util.Map; | ||
|
|
||
| public class ProfilerDeclarativeConfigUtil { | ||
|
||
| public static boolean isProfilerEnabled(OpenTelemetryConfigurationModel model) { | ||
| return getBoolean(model, SplunkConfiguration.PROFILER_ENABLED_PROPERTY); | ||
| } | ||
|
|
||
| private static boolean getBoolean(OpenTelemetryConfigurationModel model, String propertyName) { | ||
| if (model.getInstrumentationDevelopment() != null) { | ||
| ExperimentalLanguageSpecificInstrumentationModel java = | ||
| model.getInstrumentationDevelopment().getJava(); | ||
|
|
||
| if (java != null) { | ||
| Map<String, Object> javaInstrumentationProperties = java.getAdditionalProperties(); | ||
| return getBoolean(javaInstrumentationProperties, propertyName); | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static boolean getBoolean( | ||
| Map<String, Object> javaInstrumentationProperties, String propertyName) { | ||
| return getAdditionalPropertyOrDefault(javaInstrumentationProperties, propertyName, false); | ||
| } | ||
| } | ||
114 changes: 114 additions & 0 deletions
114
profiler/src/test/java/com/splunk/opentelemetry/profiler/JfrActivatorTest.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,114 @@ | ||
| package com.splunk.opentelemetry.profiler; | ||
|
|
||
| import static com.splunk.opentelemetry.testing.declarativeconfig.DeclarativeConfigTestUtil.createAutoConfiguredSdk; | ||
| import static com.splunk.opentelemetry.testing.declarativeconfig.DeclarativeConfigTestUtil.toYamlString; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.mockStatic; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import io.opentelemetry.context.ContextStorage; | ||
| import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; | ||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.concurrent.ExecutorService; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
| import org.mockito.MockedStatic; | ||
|
|
||
| class JfrActivatorTest { | ||
| @Test | ||
| void shouldActivateJfrRecording(@TempDir Path tempDir) throws IOException { | ||
| try (MockedStatic<JFR> jfrMock = mockStatic(JFR.class); | ||
| MockedStatic<ContextStorage> contextStorageMock = mockStatic(ContextStorage.class)) { | ||
|
|
||
| // given | ||
| String yaml = toYamlString( | ||
| "file_format: \"1.0-rc.1\"", | ||
| "instrumentation/development:", | ||
| " java:", | ||
| " splunk:", | ||
| " profiler:", | ||
| " enabled: true" | ||
| ); | ||
| AutoConfiguredOpenTelemetrySdk sdk = createAutoConfiguredSdk(yaml, tempDir); | ||
|
|
||
| var jfrInstanceMock = mock(JFR.class); | ||
| when(jfrInstanceMock.isAvailable()).thenReturn(true); | ||
| jfrMock.when(JFR::getInstance).thenReturn(jfrInstanceMock); | ||
|
|
||
| ExecutorService executorMock = mock(ExecutorService.class); | ||
| JfrActivator activator = new JfrActivator(executorMock); | ||
|
|
||
| // when | ||
| activator.afterAgent(sdk); | ||
|
|
||
| // then | ||
| contextStorageMock.verify(() -> ContextStorage.addWrapper(any())); | ||
| verify(executorMock).submit(any(Runnable.class)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotActivateJfrRecording_JfrNotAvailable(@TempDir Path tempDir) throws IOException { | ||
| try (MockedStatic<JFR> jfrMock = mockStatic(JFR.class); | ||
| MockedStatic<ContextStorage> contextStorageMock = mockStatic(ContextStorage.class)) { | ||
|
|
||
| // given | ||
| String yaml = toYamlString( | ||
| "file_format: \"1.0-rc.1\"", | ||
| "instrumentation/development:", | ||
| " java:", | ||
| " splunk:", | ||
| " profiler:", | ||
| " enabled: true" | ||
| ); | ||
| AutoConfiguredOpenTelemetrySdk sdk = createAutoConfiguredSdk(yaml, tempDir); | ||
|
|
||
| var jfrInstanceMock = mock(JFR.class); | ||
| when(jfrInstanceMock.isAvailable()).thenReturn(false); | ||
| jfrMock.when(JFR::getInstance).thenReturn(jfrInstanceMock); | ||
|
|
||
| ExecutorService executorMock = mock(ExecutorService.class); | ||
| JfrActivator activator = new JfrActivator(executorMock); | ||
|
|
||
| // when | ||
| activator.afterAgent(sdk); | ||
|
|
||
| // then | ||
| contextStorageMock.verifyNoInteractions(); | ||
| verifyNoInteractions(executorMock); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotActivateJfrRecording_profilerDisabled(@TempDir Path tempDir) throws IOException { | ||
| try (MockedStatic<JFR> jfrMock = mockStatic(JFR.class); | ||
| MockedStatic<ContextStorage> contextStorageMock = mockStatic(ContextStorage.class)) { | ||
|
|
||
| // given | ||
| String yaml = toYamlString( | ||
| "file_format: \"1.0-rc.1\"", | ||
| "instrumentation/development:", | ||
| " java:" | ||
| ); | ||
| AutoConfiguredOpenTelemetrySdk sdk = createAutoConfiguredSdk(yaml, tempDir); | ||
|
|
||
| var jfrInstanceMock = mock(JFR.class); | ||
| when(jfrInstanceMock.isAvailable()).thenReturn(true); | ||
| jfrMock.when(JFR::getInstance).thenReturn(jfrInstanceMock); | ||
|
|
||
| ExecutorService executorMock = mock(ExecutorService.class); | ||
| JfrActivator activator = new JfrActivator(executorMock); | ||
|
|
||
| // when | ||
| activator.afterAgent(sdk); | ||
|
|
||
| // then | ||
| contextStorageMock.verifyNoInteractions(); | ||
| verifyNoInteractions(executorMock); | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.
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 reviewer] Refactored to make it more OO and mockable.