Skip to content

feat: Add system property override for service.instance.id#1227

Open
kuisathaverat wants to merge 4 commits intojenkinsci:mainfrom
kuisathaverat:feat/service-instance-id-override
Open

feat: Add system property override for service.instance.id#1227
kuisathaverat wants to merge 4 commits intojenkinsci:mainfrom
kuisathaverat:feat/service-instance-id-override

Conversation

@kuisathaverat
Copy link
Copy Markdown
Contributor

@kuisathaverat kuisathaverat commented Feb 2, 2026

Summary

Add ability to override service.instance.id via system property for CloudBees CI high availability scenarios where multiple controller replicas need unique instance identifiers.

Changes

  • UPDATE: JenkinsOpenTelemetryPluginConfiguration.java

    • Add system property check: io.jenkins.plugins.opentelemetry.service.instance.id
    • Fall back to Jenkins.getLegacyInstanceId() when property not set
    • Maintain 100% backward compatibility
  • NEW: ServiceInstanceIdConfigurationTest.java

    • Integration test for default behavior (backward compatibility)
    • Integration test for system property override
    • Edge case tests (empty string, whitespace-only values)
    • Uses Jenkins Test Harness and InMemoryMetricExporter

Testing

  • 4 integration tests using Jenkins Test Harness
  • Tests validate both default and override behaviors
  • Edge cases covered (empty/whitespace values)

Additional Information

  • Property name: io.jenkins.plugins.opentelemetry.service.instance.id
  • Usage: Set via JVM system property (e.g., -Dio.jenkins.plugins.opentelemetry.service.instance.id=replica-01)
  • No configuration UI changes needed
  • No breaking changes

Closes #1154

Copilot AI review requested due to automatic review settings February 2, 2026 07:34
@kuisathaverat kuisathaverat self-assigned this Feb 2, 2026
@kuisathaverat kuisathaverat added the enhancement New feature or request label Feb 2, 2026
@kuisathaverat kuisathaverat requested a review from a team February 2, 2026 07:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds the ability to override service.instance.id via a system property (io.jenkins.plugins.opentelemetry.service.instance.id) to support CloudBees CI high availability scenarios where multiple controller replicas require unique instance identifiers while maintaining the same service name.

Changes:

  • Added system property check with fallback to Jenkins.getLegacyInstanceId() for backward compatibility
  • Created integration tests to validate default behavior, system property override, and edge cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.

File Description
src/main/java/io/jenkins/plugins/opentelemetry/JenkinsOpenTelemetryPluginConfiguration.java Adds system property check for service.instance.id with proper validation and fallback logic
src/test/java/io/jenkins/plugins/opentelemetry/ServiceInstanceIdConfigurationTest.java New test file with integration tests (contains multiple critical issues preventing compilation)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*
* @see <a href="https://github.com/jenkinsci/opentelemetry-plugin/issues/1154">Issue #1154</a>
*/
@WithJenkins
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The test uses @WithJenkins annotation from JUnit Jupiter (org.jvnet.hudson.test.junit.jupiter.WithJenkins), but this is inconsistent with the rest of the test suite which uses JUnit 4 with @rule or @ClassRule JenkinsRule patterns. Looking at BaseIntegrationTest.java:77-79 and OtelLocaLogMirroringTest.java:36-37, the established pattern is to use JenkinsConfiguredWithCodeRule or JenkinsRule with JUnit 4 annotations. This test should follow the same pattern to ensure it integrates properly with the existing test infrastructure.

Copilot uses AI. Check for mistakes.
private String getServiceInstanceIdFromLastExportedMetric() {
List<InMemoryMetricExporter.FinishedMetricItem> metrics = inMemoryMetricExporter.getFinishedMetricItems();
assertThat("At least one metric should be exported", metrics, notNullValue());
assertThat("Metrics list should not be empty", !metrics.isEmpty());
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The assertion assertThat("Metrics list should not be empty", !metrics.isEmpty()) is syntactically incorrect for Hamcrest. The correct form should be assertThat("Metrics list should not be empty", metrics, is(not(empty()))) or simply check the condition with a standard assertion. The current form passes a boolean as the actual value instead of using a proper Hamcrest matcher.

Copilot uses AI. Check for mistakes.
v1v
v1v previously approved these changes Feb 2, 2026
Allow service.instance.id to be overridden via system property
io.jenkins.plugins.opentelemetry.service.instance.id for environments
like CloudBees CI HA where multiple replicas need unique IDs.

- UPDATE: JenkinsOpenTelemetryPluginConfiguration.java
  - Add system property check before using Jenkins.getLegacyInstanceId()
  - Fall back to legacy ID when property is null or empty
  - Maintain 100% backward compatibility
- NEW: ServiceInstanceIdConfigurationTest.java
  - Test default behavior (backward compatibility)
  - Test system property override
  - Test edge cases (empty string, whitespace-only values)
  - 4 comprehensive integration tests using Jenkins Test Harness

Closes jenkinsci#1154
@kuisathaverat kuisathaverat force-pushed the feat/service-instance-id-override branch from eaa5176 to fb03bac Compare February 22, 2026 15:14
@ArpanC6
Copy link
Copy Markdown

ArpanC6 commented Mar 18, 2026

Great addition @kuisathaverat! The system property override approach for
CloudBees CI HA scenarios is clean and maintains full backward compatibility.

A few observations after reviewing the changes:

  1. Branch out-of-date — The branch is currently behind main. A rebase
    might be worth doing before final review to ensure no merge conflicts with
    recent changes.

  2. JUnit 5 migration — I can see the test was moved to JUnit 5
    (@WithJenkins) via commit de7630b to address Copilot's feedback about
    consistency. This looks good now.

  3. Edge case consideration — The tests cover empty string and
    whitespace-only values, which is thorough. One additional edge case worth
    considering: what happens if the system property is set to a value
    containing only special characters or exceeds a reasonable length limit?
    A validation or trim + length check in the property reading logic could
    make this more robust.

  4. Documentation — Would it be worth adding a note to the plugin wiki
    or README about this new system property
    (io.jenkins.plugins.opentelemetry.service.instance.id) for operators
    managing CloudBees CI HA deployments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to override service.instance.id programmatically

4 participants