Skip to content

switch alternative approach to declarative config#1060

Merged
SylvainJuge merged 10 commits intoelastic:mainfrom
SylvainJuge:disable-wip-declarative-config
Apr 21, 2026
Merged

switch alternative approach to declarative config#1060
SylvainJuge merged 10 commits intoelastic:mainfrom
SylvainJuge:disable-wip-declarative-config

Conversation

@SylvainJuge
Copy link
Copy Markdown
Member

@SylvainJuge SylvainJuge commented Apr 20, 2026

part of #1054

  • removing the "magic" modification of runtime declarative configuration
    • keep the user-agent modification for now
    • keep the distribution attribute provider added transparently as it does not make sense to expose this to user-visible configuration and might create issues if not properly defined/used.
  • provide a static yaml configuration included in the agent jar
  • provide simple testing of yaml file
  • add --default-config-yaml CLI option to access the embedded yaml configuration in agent jar.

possible follow-up:

  • add integration test to ensure the configuration is 100% correct and can be loaded by the agent, for example we can easily add a missing resource attribute provider without any failure with this implementation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

Warning

Rate limit exceeded

@SylvainJuge has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 34 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 34 minutes and 28 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9f59daea-c191-4cc1-b29a-0ca5d0a3caba

📥 Commits

Reviewing files that changed from the base of the PR and between f640cf2 and 6ec4d45.

📒 Files selected for processing (2)
  • custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java
  • smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java
📝 Walkthrough

Walkthrough

ElasticAgent.main(...) now handles --default-config-yaml: it prints the bundled co/elastic/otel/config.yaml to stdout and skips delegating to OpenTelemetryAgent.main(...). A bundled declarative config file was added. The declarative-config customizer removed experimental runtime-telemetry mutation and now defensively instantiates a model when null. New unit tests validate the default config; existing customizer tests were adjusted. Smoke tests and test harness code were added/updated to extract, modify, and load the generated config and to adjust container environment and process handling.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@agent/entrypoint/src/main/java/co/elastic/otel/agent/ElasticAgent.java`:
- Around line 77-82: The code in ElasticAgent.printDefaultConfigYaml is loading
the resource at "inst/co/elastic/otel/config.yaml" which doesn't match the
packaged resource path "co/elastic/otel/config.yaml"; update the resource lookup
in printDefaultConfigYaml (the getResourceAsStream call and its String literal)
to use the packaged path "co/elastic/otel/config.yaml" (or resolve both paths
defensively) so --default-config-yaml can find and print the bundled config.

In
`@custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java`:
- Around line 63-67: In DefaultDeclarativeConfigTest, the four expected JSON
literals passed to json(...) are malformed with an extra closing brace; update
each call to use correctly balanced JSON strings (e.g., change
json("{\"process\":{}}}") to json("{\"process\":{}}") and likewise for
json("{\"container\":{}}}"), json("{\"service\":{}}}"), json("{\"host\":{}}}"),
ensuring the json(...) calls in the test class compile and parse the expected
values correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ca31295-8c04-4e64-832d-6d9324e7ab03

📥 Commits

Reviewing files that changed from the base of the PR and between 166f60e and 8f71a1d.

📒 Files selected for processing (5)
  • agent/entrypoint/src/main/java/co/elastic/otel/agent/ElasticAgent.java
  • custom/src/main/java/co/elastic/otel/declarativeconfig/ElasticDeclarativeConfigurationCustomizer.java
  • custom/src/main/resources/co/elastic/otel/config.yaml
  • custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java
  • custom/src/test/java/co/elastic/otel/declarativeconfig/ElasticDeclarativeConfigurationCustomizerTest.java
💤 Files with no reviewable changes (1)
  • custom/src/main/java/co/elastic/otel/declarativeconfig/ElasticDeclarativeConfigurationCustomizer.java

LikeTheSalad
LikeTheSalad previously approved these changes Apr 21, 2026
Comment thread custom/src/main/resources/co/elastic/otel/config.yaml Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java`:
- Around line 70-84: Remove the redundant outer assertThat wrappers around the
inner hasSize(1) calls: replace
assertThat(assertThat(config.getTracerProvider().getProcessors()).hasSize(1))
with assertThat(config.getTracerProvider().getProcessors()).hasSize(1), and
similarly replace the double-wrapped assertions for
config.getMeterProvider().getReaders() and
config.getLoggerProvider().getProcessors() in DefaultDeclarativeConfigTest (use
the direct assertThat(...).hasSize(1) form so the size assertion is the actual
assertion).
- Around line 76-88: The test is asserting wrong exporter paths for meters and
logs: update the inPath lookups in DefaultDeclarativeConfigTest to match the
configured otlp_grpc exporter; specifically, when asserting
config.getMeterProvider().getReaders().get(0) use
inPath("periodic.exporter.otlp_grpc") and when asserting
config.getLoggerProvider().getProcessors().get(0) use
inPath("batch.exporter.otlp_grpc") so the endpoint assertions target the actual
exporters defined in the YAML.

In
`@smoke-tests/src/test/java/com/example/javaagent/smoketest/DeclarativeConfigSmokeTest.java`:
- Around line 41-52: The test launches a child JVM (Process created in
DeclarativeConfigSmokeTest) and on waitFor timeout currently throws without
killing the subprocess; update the exit/timeout handling to destroy the process
when process.waitFor(5, TimeUnit.SECONDS) returns false or when
process.exitValue() != 0 (call process.destroyForcibly() and/or
process.destroy() as appropriate) before throwing the IllegalStateException, and
also ensure the catch block for InterruptedException/IOException destroys the
process if it was started; locate the Process variable created by new
ProcessBuilder(...).start() and add safe teardown (destroy/destroyForcibly and
optionally waitFor after destroy) to prevent leaking child JVMs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9f286abf-191a-4dc1-adbb-2c0d99984efa

📥 Commits

Reviewing files that changed from the base of the PR and between 8f71a1d and ca2f395.

📒 Files selected for processing (6)
  • custom/src/main/java/co/elastic/otel/declarativeconfig/ElasticDeclarativeConfigurationCustomizer.java
  • custom/src/main/resources/co/elastic/otel/config.yaml
  • custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java
  • smoke-tests/src/test/java/com/example/javaagent/smoketest/DeclarativeConfigSmokeTest.java
  • smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java
  • smoke-tests/src/test/java/com/example/javaagent/smoketest/TestAppSmokeTest.java
✅ Files skipped from review due to trivial changes (1)
  • custom/src/main/resources/co/elastic/otel/config.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • custom/src/main/java/co/elastic/otel/declarativeconfig/ElasticDeclarativeConfigurationCustomizer.java

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java`:
- Around line 387-391: getResourceAttributes currently collects flattened
KeyValue pairs into a Map using Collectors.toMap which throws
IllegalStateException on duplicate keys (e.g., repeated "service.name"); update
getResourceAttributes to handle duplicate keys by supplying a merge function to
Collectors.toMap (e.g., choose first or last value) and optionally use a
deterministic map supplier (like LinkedHashMap) to preserve order; locate
getResourceAttributes and the KeyValue::getKey / KeyValue::getValue usage and
replace the collector with Collectors.toMap(KeyValue::getKey,
KeyValue::getValue, (v1,v2)->v1, LinkedHashMap::new) or an equivalent merge
strategy.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 46ab1fd3-8f8a-4e83-ad8b-6472868ae898

📥 Commits

Reviewing files that changed from the base of the PR and between ca2f395 and f640cf2.

📒 Files selected for processing (5)
  • custom/src/main/resources/co/elastic/otel/config.yaml
  • custom/src/test/java/co/elastic/otel/declarativeconfig/DefaultDeclarativeConfigTest.java
  • smoke-tests/src/test/java/com/example/javaagent/smoketest/DeclarativeConfigSmokeTest.java
  • smoke-tests/src/test/java/com/example/javaagent/smoketest/JavaExecutable.java
  • smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java
✅ Files skipped from review due to trivial changes (1)
  • custom/src/main/resources/co/elastic/otel/config.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • smoke-tests/src/test/java/com/example/javaagent/smoketest/DeclarativeConfigSmokeTest.java

Comment thread smoke-tests/src/test/java/com/example/javaagent/smoketest/SmokeTest.java Outdated
public void customize(DeclarativeConfigurationCustomizer customizer) {
customizer.addModelCustomizer(
model -> {
if (model == null) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] this just prevents a confusing NPE when the configuration can't be parsed, hence making it harder to debug for the end-user.


customizeResources(model);
customizeUserAgent(model);
customizeExperimentalRuntimeTelemetryMetrics(model);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] we remove the "magic" implementation, this is replaced with the default config in yaml (unfortunately we don't have a test for it, at least yet).

// For now, we can't override env variable for testing, thus we just verify the default values
// in the configuration we provide.
@Test
void testDefaults() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] this tests that the yaml has a correct structure and contains the things we hope it contains, it does not really checks that everything in it is actually correct, which is what the smoke test provides.

}

@Test
void optOutExperimentalRuntimeMetrics() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] I'm happy to get rid of this "half hadooken code"

@SylvainJuge SylvainJuge merged commit 04bb692 into elastic:main Apr 21, 2026
16 of 21 checks passed
@SylvainJuge SylvainJuge deleted the disable-wip-declarative-config branch April 21, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants