Skip to content

Commit

Permalink
NoElasticLogsBackend shouldn't activate otel.logs.exporter=otlp (#499)
Browse files Browse the repository at this point in the history
* NoElasticLogsBackend shouldn't activate `otel.logs.exporter=otlp`

* Add unit tests
  • Loading branch information
cyrille-leclerc authored Aug 25, 2022
1 parent 386b392 commit 154caf8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import hudson.util.FormValidation;
import io.jenkins.plugins.opentelemetry.TemplateBindingsProvider;
import io.jenkins.plugins.opentelemetry.backend.elastic.ElasticLogsBackend;
import io.jenkins.plugins.opentelemetry.backend.elastic.NoElasticLogsBackend;
import io.jenkins.plugins.opentelemetry.job.log.LogStorageRetriever;
import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
Expand Down Expand Up @@ -199,7 +200,7 @@ public Map<String, String> getOtelConfigurationProperties() {
if (elasticLogsBackend == null) {
return Collections.emptyMap();
} else {
return Collections.singletonMap("otel.logs.exporter", "otlp");
return elasticLogsBackend.getOtelConfigurationProperties();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -76,6 +78,10 @@ public Template getBuildLogsVisualizationUrlTemplate() {
return buildLogsVisualizationUrlGTemplate;
}

public Map<String, String> getOtelConfigurationProperties() {
return Collections.singletonMap("otel.logs.exporter", "otlp");
}

private String getKibanaSpaceIdentifier() {
// FIXME implement getKibanaSpaceIdentifier
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import io.jenkins.plugins.opentelemetry.job.log.LogStorageRetriever;
import org.kohsuke.stapler.DataBoundConstructor;

import java.util.Collections;
import java.util.Map;

public class NoElasticLogsBackend extends ElasticLogsBackend {
@DataBoundConstructor
public NoElasticLogsBackend() {
Expand All @@ -21,6 +24,10 @@ public LogStorageRetriever newLogStorageRetriever(TemplateBindingsProvider templ
return null;
}

public Map<String, String> getOtelConfigurationProperties() {
return Collections.emptyMap();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright The Original Author or Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.jenkins.plugins.opentelemetry.backend;

import io.jenkins.plugins.opentelemetry.backend.elastic.ElasticLogsBackendWithJenkinsVisualization;
import io.jenkins.plugins.opentelemetry.backend.elastic.ElasticLogsBackendWithoutJenkinsVisualization;
import io.jenkins.plugins.opentelemetry.backend.elastic.NoElasticLogsBackend;
import org.junit.Assert;
import org.junit.Test;

import java.util.Collections;
import java.util.Map;

public class ElasticBackendTest {

@Test
public void testNoElasticLogsBackend() {
ElasticBackend elasticBackend = new ElasticBackend();
elasticBackend.setElasticLogsBackend(new NoElasticLogsBackend());
Map<String, String> actual = elasticBackend.getOtelConfigurationProperties();
Map<String, String> expected = Collections.emptyMap();
Assert.assertEquals(actual, expected);
}

@Test
public void testElasticLogsBackendWithJenkinsVisualization() {
ElasticBackend elasticBackend = new ElasticBackend();
elasticBackend.setElasticLogsBackend(new ElasticLogsBackendWithJenkinsVisualization());
Map<String, String> actual = elasticBackend.getOtelConfigurationProperties();
Map<String, String> expected = Collections.singletonMap("otel.logs.exporter", "otlp");
Assert.assertEquals(actual, expected);
}

@Test
public void testElasticLogsBackendWithoutJenkinsVisualization() {
ElasticBackend elasticBackend = new ElasticBackend();
elasticBackend.setElasticLogsBackend(new ElasticLogsBackendWithoutJenkinsVisualization());
Map<String, String> actual = elasticBackend.getOtelConfigurationProperties();
Map<String, String> expected = Collections.singletonMap("otel.logs.exporter", "otlp");
Assert.assertEquals(actual, expected);
}
}

0 comments on commit 154caf8

Please sign in to comment.