Skip to content

Commit

Permalink
Use otel.metric.export.interval instead of the no longer used `otel…
Browse files Browse the repository at this point in the history
….imr.export.interval` (#1021)

Use `otel.metric.export.interval` instead of the no longer used  `otel.imr.export.interval` + replace static config entries by the usage of the generic properties text field
  • Loading branch information
cyrille-leclerc authored Jan 14, 2025
1 parent 25d84e3 commit 23e541c
Show file tree
Hide file tree
Showing 33 changed files with 57 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
import static io.jenkins.plugins.opentelemetry.OtelUtils.UNKNOWN;
import static io.jenkins.plugins.opentelemetry.backend.ObservabilityBackend.ICONS_PREFIX;

@Extension(ordinal = Integer.MAX_VALUE-1 /* initialize OTel ASAP, just after loading JenkinsControllerOpenTelemetry as GlobalOpenTelemetry */)
@Extension(ordinal = Integer.MAX_VALUE - 1 /* initialize OTel ASAP, just after loading JenkinsControllerOpenTelemetry as GlobalOpenTelemetry */)
@Symbol("openTelemetry")
public class JenkinsOpenTelemetryPluginConfiguration extends GlobalConfiguration {
private final static Logger LOGGER = Logger.getLogger(JenkinsOpenTelemetryPluginConfiguration.class.getName());
Expand Down Expand Up @@ -121,8 +121,10 @@ public class JenkinsOpenTelemetryPluginConfiguration extends GlobalConfiguration

private List<ObservabilityBackend> observabilityBackends = new ArrayList<>();

@Deprecated
private Integer exporterTimeoutMillis = null;

@Deprecated
private Integer exporterIntervalMillis = null;

private String ignoredSteps = "dir,echo,isUnix,pwd,properties";
Expand Down Expand Up @@ -188,8 +190,33 @@ public boolean configure(StaplerRequest2 req, JSONObject json) throws FormExcept

protected Object readResolve() {
LOGGER.log(Level.FINE, "readResolve()");
boolean configModified = false;
if (this.disabledResourceProviders == null) {
this.disabledResourceProviders = JenkinsControllerOpenTelemetry.DEFAULT_OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS;
LOGGER.log(Level.INFO, "Migration of the 'disabledResourceProviders' config param");
configModified = true;
}
if (this.exporterTimeoutMillis != null) {
this.configurationProperties =
this.configurationProperties + "\n" +
"# Migration of the 'exporterTimeoutMillis' config param to 'otel.exporter.otlp.timeout' property\n" +
OTEL_EXPORTER_OTLP_TIMEOUT.asProperty() + "=" + this.exporterTimeoutMillis;
this.exporterTimeoutMillis = null;
LOGGER.log(Level.INFO, "Migration of the 'exporterTimeoutMillis' config param to 'otel.exporter.otlp.timeout' property");
configModified = true;
}
if (this.exporterIntervalMillis != null) {
this.configurationProperties =
this.configurationProperties + "\n" +
"# Migration of the 'exporterIntervalMillis' config param to 'otel.metric.export.interval' property\n" +
OTEL_METRIC_EXPORT_INTERVAL.asProperty() + "=" + this.exporterIntervalMillis;
this.exporterIntervalMillis = null;
LOGGER.log(Level.INFO, "Migration of the 'exporterIntervalMillis' config param to 'otel.metric.export.interval' property");
configModified = true;
}

if (configModified) {
save();

Check warning on line 219 in src/main/java/io/jenkins/plugins/opentelemetry/JenkinsOpenTelemetryPluginConfiguration.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 193-219 are not covered by tests
}
return this;
}
Expand Down Expand Up @@ -218,8 +245,6 @@ public OpenTelemetryConfiguration toOpenTelemetryConfiguration() {
Optional.ofNullable(this.getEndpoint()),
Optional.ofNullable(this.getTrustedCertificatesPem()),
Optional.of(this.getAuthentication()),
Optional.ofNullable(this.getExporterTimeoutMillis()),
Optional.ofNullable(this.getExporterIntervalMillis()),
Optional.ofNullable(this.getServiceName()),
Optional.ofNullable(this.getServiceNamespace()),
Optional.ofNullable(this.getDisabledResourceProviders()),
Expand Down Expand Up @@ -318,24 +343,26 @@ public List<ObservabilityBackend> getObservabilityBackends() {
return observabilityBackends;
}

@Deprecated
public Integer getExporterTimeoutMillis() {
return exporterTimeoutMillis;
}

@Deprecated
@DataBoundSetter
public void setExporterTimeoutMillis(Integer exporterTimeoutMillis) {
this.exporterTimeoutMillis = exporterTimeoutMillis;

}

@Deprecated
public Integer getExporterIntervalMillis() {
return exporterIntervalMillis;
}

@DataBoundSetter
public void setExporterIntervalMillis(Integer exporterIntervalMillis) {
this.exporterIntervalMillis = exporterIntervalMillis;

}

public String getIgnoredSteps() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,16 @@ public class OpenTelemetryConfiguration {
private final Optional<String> endpoint;
private final Optional<String> trustedCertificatesPem;
private final Optional<OtlpAuthentication> authentication;
private final Optional<Integer> exporterTimeoutMillis;
private final Optional<Integer> exporterIntervalMillis;
private final Optional<String> serviceName;
private final Optional<String> serviceNamespace;
private final Optional<String> disabledResourceProviders;
private final Map<String, String> configurationProperties;

public OpenTelemetryConfiguration(Optional<String> endpoint, Optional<String> trustedCertificatesPem, Optional<OtlpAuthentication> authentication,
Optional<Integer> exporterTimeoutMillis, Optional<Integer> exporterIntervalMillis,
Optional<String> serviceName, Optional<String> serviceNamespace, Optional<String> disabledResourceProviders, Map<String, String> configurationProperties) {
this.endpoint = endpoint.filter(StringUtils::isNotBlank);
this.trustedCertificatesPem = trustedCertificatesPem.filter(StringUtils::isNotBlank);
this.authentication = authentication;
this.exporterTimeoutMillis = exporterTimeoutMillis;
this.exporterIntervalMillis = exporterIntervalMillis;
this.serviceName = serviceName.filter(StringUtils::isNotBlank);
this.serviceNamespace = serviceNamespace.filter(StringUtils::isNotBlank);
this.disabledResourceProviders = disabledResourceProviders.filter(StringUtils::isNotBlank);
Expand Down Expand Up @@ -81,14 +76,6 @@ public Optional<String> getTrustedCertificatesPem() {
return trustedCertificatesPem;
}

public Optional<Integer> getExporterTimeoutMillis() {
return exporterTimeoutMillis;
}

public Optional<Integer> getExporterIntervalMillis() {
return exporterIntervalMillis;
}

public Optional<String> getDisabledResourceProviders() {
return disabledResourceProviders;
}
Expand All @@ -102,7 +89,7 @@ public Map<String, String> toOpenTelemetryProperties() {
if (TESTING_INMEMORY_MODE) {
properties.put(OTEL_TRACES_EXPORTER.asProperty(), "testing");
properties.put(OTEL_METRICS_EXPORTER.asProperty(), "testing");
properties.put(OTEL_IMR_EXPORT_INTERVAL.asProperty(), "10ms");
properties.put(OTEL_METRIC_EXPORT_INTERVAL.asProperty(), "10ms");
} else if (this.getEndpoint().isPresent()) {
this.getEndpoint().ifPresent(endpoint -> { // prepare of Optional.ifPResentOrElse()
properties.compute(OTEL_TRACES_EXPORTER.asProperty(), (key, oldValue) -> {
Expand Down Expand Up @@ -142,14 +129,8 @@ public Map<String, String> toOpenTelemetryProperties() {
this.getAuthentication().ifPresent(authentication ->
authentication.enrichOpenTelemetryAutoConfigureConfigProperties(properties));

this.getExporterTimeoutMillis().map(Object::toString).ifPresent(exporterTimeoutMillis ->
properties.put(OTEL_EXPORTER_OTLP_TIMEOUT.asProperty(), exporterTimeoutMillis));

this.getExporterIntervalMillis().map(Object::toString).ifPresent(exporterIntervalMillis ->
properties.put(OTEL_IMR_EXPORT_INTERVAL.asProperty(), exporterIntervalMillis));

this.getDisabledResourceProviders().ifPresent(disabledResourceProviders ->
properties.put("otel.java.disabled.resource.providers", disabledResourceProviders));
properties.put(OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS.asProperty(), disabledResourceProviders));

return properties;
}
Expand Down Expand Up @@ -193,16 +174,15 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
OpenTelemetryConfiguration that = (OpenTelemetryConfiguration) o;
return Objects.equals(endpoint, that.endpoint) && Objects.equals(authentication, that.authentication) &&
Objects.equals(trustedCertificatesPem, that.trustedCertificatesPem) && Objects.equals(exporterTimeoutMillis, that.exporterTimeoutMillis) &&
Objects.equals(exporterIntervalMillis, that.exporterIntervalMillis) &&
Objects.equals(trustedCertificatesPem, that.trustedCertificatesPem) &&
Objects.equals(serviceName, that.serviceName) && Objects.equals(serviceNamespace, that.serviceNamespace) &&
Objects.equals(disabledResourceProviders, that.disabledResourceProviders) &&
Objects.equals(configurationProperties, that.configurationProperties);
}

@Override
public int hashCode() {
return Objects.hash(endpoint, authentication, trustedCertificatesPem, exporterTimeoutMillis, exporterIntervalMillis, serviceName, serviceNamespace, disabledResourceProviders, configurationProperties);
return Objects.hash(endpoint, authentication, trustedCertificatesPem, serviceName, serviceNamespace, disabledResourceProviders, configurationProperties);

Check warning on line 185 in src/main/java/io/jenkins/plugins/opentelemetry/OpenTelemetryConfiguration.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 177-185 are not covered by tests
}

@Override
Expand All @@ -211,8 +191,6 @@ public String toString() {
"endpoint='" + endpoint + '\'' +
", trustedCertificatesPem.defined=" + trustedCertificatesPem.isPresent() +
", authentication=" + authentication +
", exporterTimeoutMillis=" + exporterTimeoutMillis +
", exporterIntervalMillis=" + exporterIntervalMillis +
", serviceName=" + serviceName +
", serviceNamespace=" + serviceNamespace +
", disabledResourceProviders=" + disabledResourceProviders +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class OtelEnvironmentContributorService {
OTEL_EXPORTER_OTLP_INSECURE,
OTEL_EXPORTER_OTLP_PROTOCOL,
OTEL_EXPORTER_OTLP_TIMEOUT,
OTEL_IMR_EXPORT_INTERVAL,
OTEL_METRIC_EXPORT_INTERVAL,
OTEL_LOGS_EXPORTER,
OTEL_METRICS_EXPORTER,
OTEL_TRACES_EXPORTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ public final class ConfigurationKey {
public static final ConfigurationKey OTEL_EXPORTER_OTLP_TIMEOUT = new ConfigurationKey("otel.exporter.otlp.timeout");
public static final ConfigurationKey OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = new ConfigurationKey("otel.exporter.otlp.traces.endpoint");
public static final ConfigurationKey OTEL_EXPORTER_PROMETHEUS_PORT = new ConfigurationKey("otel.exporter.prometheus.port");
public static final ConfigurationKey OTEL_IMR_EXPORT_INTERVAL = new ConfigurationKey("otel.imr.export.interval");

public static final ConfigurationKey OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS = new ConfigurationKey("otel.java.disabled.resource.providers");

public static final ConfigurationKey OTEL_LOGS_EXPORTER = new ConfigurationKey("otel.logs.exporter");
public static final ConfigurationKey OTEL_LOGS_MIRROR_TO_DISK = new ConfigurationKey("otel.logs.mirror_to_disk");

public static final ConfigurationKey OTEL_METRIC_EXPORT_INTERVAL = new ConfigurationKey("otel.metric.export.interval");
public static final ConfigurationKey OTEL_METRICS_EXPORTER = new ConfigurationKey("otel.metrics.exporter");

public static final ConfigurationKey OTEL_RESOURCE_ATTRIBUTES = new ConfigurationKey("otel.resource.attributes");

public static final ConfigurationKey OTEL_SERVICE_NAME = new ConfigurationKey("otel.service.name");

public static final ConfigurationKey OTEL_TRACES_EXPORTER = new ConfigurationKey("otel.traces.exporter");

public static final ConfigurationKey OTEL_INSTRUMENTATION_JENKINS_WEB_ENABLED = new ConfigurationKey("otel.instrumentation.jenkins.web.enabled");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:c="/lib/credentials">
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:section title="OpenTelemetry">
<f:entry title="OTLP Endpoint" field="endpoint" description="e.g. 'http://otel.example.com:4317', aka OTEL_EXPORTER_OTLP_ENDPOINT">
<f:textbox />
Expand Down Expand Up @@ -27,7 +27,10 @@
/>
</f:entry>
<f:advanced>
<f:entry title="Service name" field="serviceName" description="e.g. 'my-jenkins.example.com', the Logical name of the service. Aka OTEL_SERVICE_NAME">
<f:entry title="Service name" field="serviceName" description="e.g. 'my-jenkins.example.com', the Logical name of the service. Aka 'OTEL_SERVICE_NAME'">
<f:textbox />
</f:entry>
<f:entry title="Service namespace" field="serviceNamespace" description="e.g. 'ci', a namespace for service name. Aka 'OTEL_SERVICE_NAMESPACE'">
<f:textbox />
</f:entry>
<f:entry field="disabledResourceProviders" title="Disabled resource providers" description="Coma separated list of class names. Aka 'OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS'">
Expand All @@ -39,16 +42,7 @@
<f:entry title="Configuration properties" field="configurationProperties" description="Additional OpenTelemetry SDK configuration properties.">
<f:textarea />
</f:entry>
<f:entry title="Service namespace" field="serviceNamespace" description="e.g. 'ci', a namespace for service name">
<f:textbox />
</f:entry>
<f:entry field="exporterTimeoutMillis" title="Exporter Timeout (ms)" description="e.g. '30000'. Aka OTEL_EXPORTER_OTLP_TIMEOUT">
<f:number clazz="required positive number" min="1" default="${exporterTimeoutMillis}"/>
</f:entry>
<f:entry field="exporterIntervalMillis" title="Metrics Exporter Interval (ms)" description="e.g. '60000'. Aka OTEL_IMR_EXPORT_INTERVAL">
<f:number clazz="required positive number" min="1" default="${exporterIntervalMillis}"/>
</f:entry>
<f:entry title="OTLP Endpoint Certificates" field="trustedCertificatesPem" description="OTLP endpoint certificates (PEM format)">
<f:entry title="OTLP Endpoint Certificates" field="trustedCertificatesPem" description="OTLP endpoint certificates (PEM format). Aka 'OTEL_EXPORTER_OTLP_CERTIFICATE'">
<f:textarea />
</f:entry>
<f:entry title="Noteworthy active configuration properties" description="Noteworthy config properties of the active OpenTelemetry SDK.">
Expand All @@ -57,7 +51,7 @@
</textarea>
</f:entry>

<f:entry title="Active resource attributes" description="Resource attributes of the active OpenTelemetry SDK. See 'OTEL_RESOURCE_ATTRIBUTES'.">
<f:entry title="Active resource attributes" description="Resource attributes of the active OpenTelemetry SDK. Aka 'OTEL_RESOURCE_ATTRIBUTES'.">
<textarea rows="10" cols="100" wrap="off" readonly="readonly" style="overflow:scroll;background-color:lightgrey">
${instance.resourceAsText}
</textarea>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</table>

<p>The configuration properties of the OpenTelemetry SDK are also supported. See: <a
href="https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md">
OpenTelemetry SDK Autoconfigure</a>
href="https://opentelemetry.io/docs/languages/java/configuration/">
OpenTelemetry Docs / Java / Configure the SDK</a>
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</p>
<p>See <a
href="https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md#resource-provider-spi">
OpenTelemetry SDK Autoconfigure / OpenTelemetry Resource / Disabling Automatic ResourceProviders</a>
OpenTelemetry SDK Autoconfigure / OpenTelemetry Resource / Disabling Automatic ResourceProviders <code>otel.java.disabled.resource.providers</code></a>
</p>

</div>

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public static void beforeClass() throws Exception {
OpenTelemetryConfiguration configuration = new OpenTelemetryConfiguration(
of("http://localhost:4317"), empty(),
empty(),
empty(), empty(),
empty(), empty(), empty(),
Collections.emptyMap());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ private void testDefaultConfigurationOverwrite(String serviceNameDefinedInConfig
OpenTelemetryConfiguration openTelemetryConfiguration = new OpenTelemetryConfiguration(
Optional.of("http://localhost:4317/"),
Optional.empty(),
Optional.empty(),
Optional.empty(),

Optional.empty(),
Optional.ofNullable(serviceNameDefinedInConfig),
Optional.ofNullable(serviceNamespaceDefinedInConfig),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ private static void testOpenTelemetryExportersConfiguration(String expectedTrace
Optional.ofNullable(otlpEndpoint),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of("my-jenkins"),
Optional.empty(),
Optional.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public void should_support_configuration_as_code() {
OtlpAuthentication authentication = configuration.getAuthentication();
MatcherAssert.assertThat(authentication, CoreMatchers.is(instanceOf(NoAuthentication.class)));

MatcherAssert.assertThat(configuration.getExporterTimeoutMillis(), CoreMatchers.nullValue());
MatcherAssert.assertThat(configuration.getExporterIntervalMillis(), CoreMatchers.nullValue());

MatcherAssert.assertThat(configuration.getIgnoredSteps(), CoreMatchers.is("dir,echo,isUnix,pwd,properties"));

MatcherAssert.assertThat(configuration.getServiceName(), CoreMatchers.is("jenkins"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public void should_support_configuration_as_code() {
OtlpAuthentication authentication = configuration.getAuthentication();
MatcherAssert.assertThat(authentication, CoreMatchers.is(instanceOf(NoAuthentication.class)));

MatcherAssert.assertThat(configuration.getExporterTimeoutMillis(), CoreMatchers.nullValue());
MatcherAssert.assertThat(configuration.getExporterIntervalMillis(), CoreMatchers.nullValue());

MatcherAssert.assertThat(configuration.getIgnoredSteps(), CoreMatchers.is("dir,echo,isUnix,pwd,properties"));

MatcherAssert.assertThat(configuration.getServiceName(), CoreMatchers.is("jenkins"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public void should_support_configuration_as_code() {
OtlpAuthentication authentication = configuration.getAuthentication();
MatcherAssert.assertThat(authentication, CoreMatchers.is(instanceOf(NoAuthentication.class)));

MatcherAssert.assertThat(configuration.getExporterTimeoutMillis(), CoreMatchers.nullValue());
MatcherAssert.assertThat(configuration.getExporterIntervalMillis(), CoreMatchers.nullValue());

MatcherAssert.assertThat(configuration.getIgnoredSteps(), CoreMatchers.is("dir,echo,isUnix,pwd,properties"));

MatcherAssert.assertThat(configuration.getServiceName(), CoreMatchers.is("jenkins"));
Expand Down
Loading

0 comments on commit 23e541c

Please sign in to comment.