getReadConverter(HierarchicalStreamReader reader)
String versionString = reader.getAttribute(VERSION_ATTRIBUTE);
if (versionString == null) {
// no attribute, data was written by an old version of the plugin
- return null;
+ return legacyConverter;
}
int version = Integer.parseInt(versionString);
return readConverters.get(version);
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/util/conversion/PolymorphicReflectionConverter.java b/src/main/java/org/datadog/jenkins/plugins/datadog/util/conversion/PolymorphicReflectionConverter.java
new file mode 100644
index 000000000..98c02c023
--- /dev/null
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/util/conversion/PolymorphicReflectionConverter.java
@@ -0,0 +1,31 @@
+package org.datadog.jenkins.plugins.datadog.util.conversion;
+
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter;
+import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
+import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+import com.thoughtworks.xstream.mapper.Mapper;
+
+/**
+ * A subtype of reflection converter that is capable of handling polymorphic fields
+ * (when the declared field type is an interface or a parent class and its value is an instance of an implementation or a child class).
+ *
+ * When marshalling, the converter writes additional {@code resolves-to} attribute that contains the name of the serialized class.
+ * When unmarshalling, the {@link AbstractReflectionConverter#instantiateNewInstance(HierarchicalStreamReader, UnmarshallingContext)} method
+ * reads the attribute and creates an instance of the correct class.
+ */
+public class PolymorphicReflectionConverter extends ReflectionConverter {
+
+ public PolymorphicReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
+ super(mapper, reflectionProvider);
+ }
+
+ @Override
+ public void marshal(Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) {
+ writer.addAttribute("resolves-to", mapper.serializedClass(original.getClass()));
+ super.marshal(original, writer, context);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/util/conversion/VersionedConverter.java b/src/main/java/org/datadog/jenkins/plugins/datadog/util/conversion/VersionedConverter.java
index f38c0065f..749092286 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/util/conversion/VersionedConverter.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/util/conversion/VersionedConverter.java
@@ -32,4 +32,9 @@ protected F readField(HierarchicalStreamReader reader, UnmarshallingContext
reader.moveUp();
return value;
}
+
+ public static VersionedConverter ignoreOldData() {
+ // syntax sugar to indicate that old data will be discarded
+ return null;
+ }
}
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/config.jelly b/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/config.jelly
index fa805dac1..8e71b1872 100644
--- a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/config.jelly
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/config.jelly
@@ -14,54 +14,7 @@
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -70,9 +23,9 @@
@@ -91,12 +44,12 @@
-
-
+
+
-
-
+
+
@@ -136,12 +89,10 @@
-
-
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-traceServiceNameEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-ciInstanceName.html
similarity index 100%
rename from src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-traceServiceNameEntry.html
rename to src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-ciInstanceName.html
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-blacklistEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-excludedEntry.html
similarity index 100%
rename from src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-blacklistEntry.html
rename to src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-excludedEntry.html
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-whitelistEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-includedEntry.html
similarity index 100%
rename from src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-whitelistEntry.html
rename to src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-includedEntry.html
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetApiKeyEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetApiKeyEntry.html
deleted file mode 100644
index 85559287d..000000000
--- a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetApiKeyEntry.html
+++ /dev/null
@@ -1,4 +0,0 @@
-
- Enter your Datadog API key, which can be found
-
here .
-
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetCredentialsApiKeyEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetCredentialsApiKeyEntry.html
deleted file mode 100644
index 417a9dec3..000000000
--- a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetCredentialsApiKeyEntry.html
+++ /dev/null
@@ -1,6 +0,0 @@
-
- Enter your Datadog API key, which can be found
-
here .
- This field is optional, use it only if you would like to store your API key with
-
Jenkins Credentials.
-
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetMetricURLEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetMetricURLEntry.html
deleted file mode 100644
index 5c85be45b..000000000
--- a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetMetricURLEntry.html
+++ /dev/null
@@ -1,4 +0,0 @@
-
- API URL which the plugin reports to. Defaults to https://api.datadoghq.com/api/
- To submit metrics to a Datadog EU site organization, use: https://api.datadoghq.eu/api
-
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetSite.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetSite.html
deleted file mode 100644
index 1e2a8e725..000000000
--- a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetSite.html
+++ /dev/null
@@ -1,6 +0,0 @@
-
- Datadog offers different sites throughout the world.
- Each site is completely independent, and you cannot share data across sites.
- Each site gives you benefits (for example, government security regulations) or allows you to store your data in specific locations around the world.
- See
Datadog documentation for more information about sites.
-
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/config.jelly b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/config.jelly
new file mode 100644
index 000000000..39b64252d
--- /dev/null
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/config.jelly
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetHostEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/help-agentHost.html
similarity index 100%
rename from src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetHostEntry.html
rename to src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/help-agentHost.html
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetLogCollectionPortEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/help-agentLogCollectionPort.html
similarity index 100%
rename from src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetLogCollectionPortEntry.html
rename to src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/help-agentLogCollectionPort.html
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetPortEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/help-agentPort.html
similarity index 100%
rename from src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetPortEntry.html
rename to src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/help-agentPort.html
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetTraceCollectionPortEntry.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/help-agentTraceCollectionPort.html
similarity index 100%
rename from src/main/resources/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-targetTraceCollectionPortEntry.html
rename to src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration/help-agentTraceCollectionPort.html
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogApiConfiguration/config.jelly b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogApiConfiguration/config.jelly
new file mode 100644
index 000000000..959c25a5d
--- /dev/null
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/DatadogApiConfiguration/config.jelly
@@ -0,0 +1,30 @@
+
+
+
+
+
+ Datadog Site
+
+
+
+
+
+
+
+
+
+
+
+
+ Datadog API key
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite/config.jelly b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite/config.jelly
new file mode 100644
index 000000000..b131989ab
--- /dev/null
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite/config.jelly
@@ -0,0 +1,8 @@
+
+
+
+
+ ${it}
+
+
+
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite/help-siteBlock.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite/help-siteBlock.html
new file mode 100644
index 000000000..dba2ad97c
--- /dev/null
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite/help-siteBlock.html
@@ -0,0 +1,4 @@
+
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrls/config.jelly b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrls/config.jelly
new file mode 100644
index 000000000..5a46fe7d5
--- /dev/null
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrls/config.jelly
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey/config.jelly b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey/config.jelly
new file mode 100644
index 000000000..bcaa2e0bf
--- /dev/null
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey/config.jelly
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey/help-credentialsKeyBlock.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey/help-credentialsKeyBlock.html
new file mode 100644
index 000000000..454350eb3
--- /dev/null
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey/help-credentialsKeyBlock.html
@@ -0,0 +1,4 @@
+
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey/config.jelly b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey/config.jelly
new file mode 100644
index 000000000..cbda599e0
--- /dev/null
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey/config.jelly
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey/help-textKeyBlock.html b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey/help-textKeyBlock.html
new file mode 100644
index 000000000..6d17e472c
--- /dev/null
+++ b/src/main/resources/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey/help-textKeyBlock.html
@@ -0,0 +1,3 @@
+
+ Enter your Datadog API key (can be found
here ).
+
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationAsCodeTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationAsCodeTest.java
new file mode 100644
index 000000000..dce1d13dc
--- /dev/null
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationAsCodeTest.java
@@ -0,0 +1,193 @@
+package org.datadog.jenkins.plugins.datadog;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
+import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
+import org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration;
+import org.datadog.jenkins.plugins.datadog.configuration.DatadogApiConfiguration;
+import org.datadog.jenkins.plugins.datadog.configuration.DatadogClientConfiguration;
+import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntake;
+import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogSite;
+import org.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogCredentialsApiKey;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class DatadogGlobalConfigurationAsCodeTest {
+
+ @Rule
+ public JenkinsConfiguredWithCodeRule r = new JenkinsConfiguredWithCodeRule();
+
+ @Test
+ @ConfiguredWithCode("test-config.yml")
+ public void testConfigurationAsCodeCompatibility() {
+ DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
+
+ DatadogClientConfiguration datadogClientConfiguration = cfg.getDatadogClientConfiguration();
+ Assert.assertTrue(datadogClientConfiguration instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration apiConfiguration = (DatadogApiConfiguration) datadogClientConfiguration;
+
+ DatadogIntake intake = apiConfiguration.getIntake();
+ Assert.assertEquals("my-api-url", intake.getApiUrl());
+ Assert.assertEquals("my-log-intake-url", intake.getLogsUrl());
+ Assert.assertEquals("my-webhook-intake-url", intake.getWebhooksUrl());
+
+ assertTrue(apiConfiguration.getApiKey() instanceof DatadogCredentialsApiKey);
+ DatadogCredentialsApiKey credentialsApiKey = (DatadogCredentialsApiKey) apiConfiguration.getApiKey();
+ assertEquals("my-api-key-credentials-id", credentialsApiKey.getCredentialsId());
+
+ Assert.assertTrue(cfg.getEnableCiVisibility());
+ Assert.assertEquals("my-ci-instance-name", cfg.getCiInstanceName());
+ Assert.assertEquals("my-excluded", cfg.getExcluded());
+ Assert.assertEquals("my-included", cfg.getIncluded());
+ Assert.assertEquals("my-hostname", cfg.getHostname());
+ Assert.assertEquals("my-global-tag-file", cfg.getGlobalTagFile());
+ Assert.assertEquals("my-global-tags", cfg.getGlobalTags());
+ Assert.assertEquals("my-global-job-tags", cfg.getGlobalJobTags());
+ Assert.assertEquals("my-include-events", cfg.getIncludeEvents());
+ Assert.assertEquals("my-exclude-events", cfg.getExcludeEvents());
+ Assert.assertTrue(cfg.isEmitSecurityEvents());
+ Assert.assertTrue(cfg.isEmitSystemEvents());
+ Assert.assertTrue(cfg.isCollectBuildLogs());
+ Assert.assertTrue(cfg.isRefreshDogstatsdClient());
+ Assert.assertTrue(cfg.isCacheBuildRuns());
+ Assert.assertTrue(cfg.isUseAwsInstanceHostname());
+ }
+
+ @Test
+ @ConfiguredWithCode("test-config-site.yml")
+ public void testSiteConfigurationAsCodeCompatibility() {
+ DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
+
+ DatadogClientConfiguration datadogClientConfiguration = cfg.getDatadogClientConfiguration();
+ Assert.assertTrue(datadogClientConfiguration instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration apiConfiguration = (DatadogApiConfiguration) datadogClientConfiguration;
+
+ DatadogIntake intake = apiConfiguration.getIntake();
+ assertEquals(DatadogSite.US3.getApiUrl(), intake.getApiUrl());
+ assertEquals(DatadogSite.US3.getLogsUrl(), intake.getLogsUrl());
+ assertEquals(DatadogSite.US3.getWebhooksUrl(), intake.getWebhooksUrl());
+
+ assertTrue(apiConfiguration.getApiKey() instanceof DatadogCredentialsApiKey);
+ DatadogCredentialsApiKey credentialsApiKey = (DatadogCredentialsApiKey) apiConfiguration.getApiKey();
+ assertEquals("my-api-key-credentials-id", credentialsApiKey.getCredentialsId());
+
+ Assert.assertTrue(cfg.getEnableCiVisibility());
+ Assert.assertEquals("my-ci-instance-name", cfg.getCiInstanceName());
+ Assert.assertEquals("my-excluded", cfg.getExcluded());
+ Assert.assertEquals("my-included", cfg.getIncluded());
+ Assert.assertEquals("my-hostname", cfg.getHostname());
+ Assert.assertEquals("my-global-tag-file", cfg.getGlobalTagFile());
+ Assert.assertEquals("my-global-tags", cfg.getGlobalTags());
+ Assert.assertEquals("my-global-job-tags", cfg.getGlobalJobTags());
+ Assert.assertEquals("my-include-events", cfg.getIncludeEvents());
+ Assert.assertEquals("my-exclude-events", cfg.getExcludeEvents());
+ Assert.assertTrue(cfg.isEmitSecurityEvents());
+ Assert.assertTrue(cfg.isEmitSystemEvents());
+ Assert.assertTrue(cfg.isCollectBuildLogs());
+ Assert.assertTrue(cfg.isRefreshDogstatsdClient());
+ Assert.assertTrue(cfg.isCacheBuildRuns());
+ Assert.assertTrue(cfg.isUseAwsInstanceHostname());
+ }
+
+ @Test
+ @ConfiguredWithCode("test-config-agent.yml")
+ public void testAgentConfigurationAsCodeCompatibility() {
+ DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
+ DatadogClientConfiguration datadogClientConfiguration = cfg.getDatadogClientConfiguration();
+ Assert.assertTrue(datadogClientConfiguration instanceof DatadogAgentConfiguration);
+
+ DatadogAgentConfiguration agentConfiguration = (DatadogAgentConfiguration) datadogClientConfiguration;
+ Assert.assertEquals("my-agent-host", agentConfiguration.getAgentHost());
+ Assert.assertEquals((Integer) 1357, agentConfiguration.getAgentPort());
+ Assert.assertEquals((Integer) 2468, agentConfiguration.getAgentLogCollectionPort());
+ Assert.assertEquals((Integer) 3579, agentConfiguration.getAgentTraceCollectionPort());
+
+ Assert.assertTrue(cfg.getEnableCiVisibility());
+ Assert.assertEquals("my-ci-instance-name", cfg.getCiInstanceName());
+ Assert.assertEquals("my-excluded", cfg.getExcluded());
+ Assert.assertEquals("my-included", cfg.getIncluded());
+ Assert.assertEquals("my-hostname", cfg.getHostname());
+ Assert.assertEquals("my-global-tag-file", cfg.getGlobalTagFile());
+ Assert.assertEquals("my-global-tags", cfg.getGlobalTags());
+ Assert.assertEquals("my-global-job-tags", cfg.getGlobalJobTags());
+ Assert.assertEquals("my-include-events", cfg.getIncludeEvents());
+ Assert.assertEquals("my-exclude-events", cfg.getExcludeEvents());
+ Assert.assertFalse(cfg.isEmitSecurityEvents());
+ Assert.assertFalse(cfg.isEmitSystemEvents());
+ Assert.assertFalse(cfg.isCollectBuildLogs());
+ Assert.assertFalse(cfg.isRefreshDogstatsdClient());
+ Assert.assertFalse(cfg.isCacheBuildRuns());
+ Assert.assertFalse(cfg.isUseAwsInstanceHostname());
+ }
+
+ @Test
+ @ConfiguredWithCode("test-config-legacy.yml")
+ public void testLegacyConfigurationAsCodeCompatibility() {
+ DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
+
+ DatadogClientConfiguration datadogClientConfiguration = cfg.getDatadogClientConfiguration();
+ Assert.assertTrue(datadogClientConfiguration instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration apiConfiguration = (DatadogApiConfiguration) datadogClientConfiguration;
+
+ DatadogIntake intake = apiConfiguration.getIntake();
+ Assert.assertEquals("my-target-api-url", intake.getApiUrl());
+ Assert.assertEquals("my-target-log-intake-url", intake.getLogsUrl());
+ Assert.assertEquals("my-target-webhook-intake-url", intake.getWebhooksUrl());
+
+ assertTrue(apiConfiguration.getApiKey() instanceof DatadogCredentialsApiKey);
+ DatadogCredentialsApiKey credentialsApiKey = (DatadogCredentialsApiKey) apiConfiguration.getApiKey();
+ assertEquals("my-target-credentials-api-key", credentialsApiKey.getCredentialsId());
+
+ Assert.assertTrue(cfg.getEnableCiVisibility());
+ Assert.assertEquals("my-trace-service-name", cfg.getCiInstanceName());
+ Assert.assertEquals("my-blacklist", cfg.getExcluded());
+ Assert.assertEquals("my-whitelist", cfg.getIncluded());
+ Assert.assertEquals("my-hostname", cfg.getHostname());
+ Assert.assertEquals("my-global-tag-file", cfg.getGlobalTagFile());
+ Assert.assertEquals("my-global-tags", cfg.getGlobalTags());
+ Assert.assertEquals("my-global-job-tags", cfg.getGlobalJobTags());
+ Assert.assertEquals("my-include-events", cfg.getIncludeEvents());
+ Assert.assertEquals("my-exclude-events", cfg.getExcludeEvents());
+ Assert.assertFalse(cfg.isEmitSecurityEvents());
+ Assert.assertTrue(cfg.isEmitSystemEvents());
+ Assert.assertFalse(cfg.isCollectBuildLogs());
+ Assert.assertFalse(cfg.isRefreshDogstatsdClient());
+ Assert.assertTrue(cfg.isCacheBuildRuns());
+ Assert.assertFalse(cfg.isUseAwsInstanceHostname());
+ }
+
+ @Test
+ @ConfiguredWithCode("test-config-legacy-agent.yml")
+ public void testLegacyAgentConfigurationAsCodeCompatibility() {
+ DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
+ DatadogClientConfiguration datadogClientConfiguration = cfg.getDatadogClientConfiguration();
+ Assert.assertTrue(datadogClientConfiguration instanceof DatadogAgentConfiguration);
+
+ DatadogAgentConfiguration agentConfiguration = (DatadogAgentConfiguration) datadogClientConfiguration;
+ Assert.assertEquals("my-target-host", agentConfiguration.getAgentHost());
+ Assert.assertEquals((Integer) 1357, agentConfiguration.getAgentPort());
+ Assert.assertEquals((Integer) 2468, agentConfiguration.getAgentLogCollectionPort());
+ Assert.assertEquals((Integer) 3579, agentConfiguration.getAgentTraceCollectionPort());
+
+ Assert.assertFalse(cfg.getEnableCiVisibility());
+ Assert.assertEquals("my-trace-service-name", cfg.getCiInstanceName());
+ Assert.assertEquals("my-blacklist", cfg.getExcluded());
+ Assert.assertEquals("my-whitelist", cfg.getIncluded());
+ Assert.assertEquals("my-hostname", cfg.getHostname());
+ Assert.assertEquals("my-global-tag-file", cfg.getGlobalTagFile());
+ Assert.assertEquals("my-global-tags", cfg.getGlobalTags());
+ Assert.assertEquals("my-global-job-tags", cfg.getGlobalJobTags());
+ Assert.assertEquals("my-include-events", cfg.getIncludeEvents());
+ Assert.assertEquals("my-exclude-events", cfg.getExcludeEvents());
+ Assert.assertTrue(cfg.isEmitSecurityEvents());
+ Assert.assertFalse(cfg.isEmitSystemEvents());
+ Assert.assertTrue(cfg.isCollectBuildLogs());
+ Assert.assertTrue(cfg.isRefreshDogstatsdClient());
+ Assert.assertFalse(cfg.isCacheBuildRuns());
+ Assert.assertTrue(cfg.isUseAwsInstanceHostname());
+ }
+}
+
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationEnvVariablesTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationEnvVariablesTest.java
new file mode 100644
index 000000000..f904c5a78
--- /dev/null
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationEnvVariablesTest.java
@@ -0,0 +1,207 @@
+package org.datadog.jenkins.plugins.datadog;
+
+import com.github.stefanbirkner.systemlambda.SystemLambda;
+import org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration;
+import org.datadog.jenkins.plugins.datadog.configuration.DatadogApiConfiguration;
+import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntake;
+import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeSite;
+import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeUrls;
+import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogSite;
+import org.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogApiKey;
+import org.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogTextApiKey;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
+
+import static org.junit.Assert.*;
+
+public class DatadogGlobalConfigurationEnvVariablesTest {
+
+ @ClassRule
+ public static final JenkinsRule jenkinsRule = new JenkinsRule();
+
+ @Test
+ public void testDefaultValues() throws Exception {
+ DatadogGlobalConfiguration configuration = SystemLambda
+ .withEnvironmentVariable(DatadogGlobalConfiguration.REPORT_WITH_PROPERTY, null)
+ .and(DatadogIntakeSite.DATADOG_SITE_PROPERTY, null)
+ .and(DatadogIntakeUrls.TARGET_API_URL_PROPERTY, null)
+ .and(DatadogIntakeUrls.TARGET_WEBHOOK_INTAKE_URL_PROPERTY, null)
+ .and(DatadogIntakeUrls.TARGET_LOG_INTAKE_URL_PROPERTY, null)
+ .and(DatadogTextApiKey.TARGET_API_KEY_PROPERTY, null)
+ .execute(DatadogGlobalConfiguration::new);
+
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration datadogClientConfiguration = (DatadogApiConfiguration) configuration.getDatadogClientConfiguration();
+
+ DatadogIntake intake = datadogClientConfiguration.getIntake();
+ assertEquals("https://api.datadoghq.com/api/", intake.getApiUrl());
+ assertEquals("https://http-intake.logs.datadoghq.com/v1/input/", intake.getLogsUrl());
+ assertEquals("https://webhook-intake.datadoghq.com/api/v2/webhook/", intake.getWebhooksUrl());
+
+ DatadogApiKey apiKey = datadogClientConfiguration.getApiKey();
+ assertNull(apiKey.getKey());
+ }
+
+ @Test
+ public void testAgentDefaultValues() throws Exception {
+ DatadogGlobalConfiguration configuration = SystemLambda
+ .withEnvironmentVariable(DatadogGlobalConfiguration.REPORT_WITH_PROPERTY, "DSD")
+ .and(DatadogAgentConfiguration.TARGET_HOST_PROPERTY, null)
+ .and(DatadogAgentConfiguration.TARGET_PORT_PROPERTY, null)
+ .and(DatadogAgentConfiguration.TARGET_TRACE_COLLECTION_PORT_PROPERTY, null)
+ .and(DatadogAgentConfiguration.TARGET_LOG_COLLECTION_PORT_PROPERTY, null)
+ .and(DatadogAgentConfiguration.DD_AGENT_HOST, null)
+ .and(DatadogAgentConfiguration.DD_AGENT_PORT, null)
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_PORT, null)
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_URL, null)
+ .execute(DatadogGlobalConfiguration::new);
+
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogAgentConfiguration);
+ DatadogAgentConfiguration datadogClientConfiguration = (DatadogAgentConfiguration) configuration.getDatadogClientConfiguration();
+
+ assertEquals("localhost", datadogClientConfiguration.getAgentHost());
+ assertEquals((Integer) 8125, datadogClientConfiguration.getAgentPort());
+ assertEquals((Integer) 8126, datadogClientConfiguration.getAgentTraceCollectionPort());
+ assertEquals((Integer) null, datadogClientConfiguration.getAgentLogCollectionPort());
+ }
+
+ @Test
+ public void testIntakeConfiguration() throws Exception {
+ DatadogGlobalConfiguration configuration = SystemLambda
+ .withEnvironmentVariable(DatadogGlobalConfiguration.REPORT_WITH_PROPERTY, "HTTP")
+ .and(DatadogIntakeSite.DATADOG_SITE_PROPERTY, null)
+ .and(DatadogIntakeUrls.TARGET_API_URL_PROPERTY, "my-target-api-url")
+ .and(DatadogIntakeUrls.TARGET_WEBHOOK_INTAKE_URL_PROPERTY, "my-webhook-intake-url")
+ .and(DatadogIntakeUrls.TARGET_LOG_INTAKE_URL_PROPERTY, "my-log-intake-url")
+ .and(DatadogTextApiKey.TARGET_API_KEY_PROPERTY, "my-api-key")
+ .execute(DatadogGlobalConfiguration::new);
+
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration datadogClientConfiguration = (DatadogApiConfiguration) configuration.getDatadogClientConfiguration();
+
+ DatadogIntake intake = datadogClientConfiguration.getIntake();
+ assertEquals("my-target-api-url", intake.getApiUrl());
+ assertEquals("my-log-intake-url", intake.getLogsUrl());
+ assertEquals("my-webhook-intake-url", intake.getWebhooksUrl());
+
+ DatadogApiKey apiKey = datadogClientConfiguration.getApiKey();
+ assertEquals("my-api-key", apiKey.getKey().getPlainText());
+ }
+
+ @Test
+ public void testSiteConfiguration() throws Exception {
+ DatadogGlobalConfiguration configuration = SystemLambda
+ .withEnvironmentVariable(DatadogGlobalConfiguration.REPORT_WITH_PROPERTY, "HTTP")
+ .and(DatadogIntakeSite.DATADOG_SITE_PROPERTY, "US1")
+ .and(DatadogIntakeUrls.TARGET_API_URL_PROPERTY, null)
+ .and(DatadogIntakeUrls.TARGET_WEBHOOK_INTAKE_URL_PROPERTY, null)
+ .and(DatadogIntakeUrls.TARGET_LOG_INTAKE_URL_PROPERTY, null)
+ .and(DatadogTextApiKey.TARGET_API_KEY_PROPERTY, "my-api-key")
+ .execute(DatadogGlobalConfiguration::new);
+
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration datadogClientConfiguration = (DatadogApiConfiguration) configuration.getDatadogClientConfiguration();
+
+ DatadogIntake intake = datadogClientConfiguration.getIntake();
+ assertEquals(DatadogSite.US1.getApiUrl(), intake.getApiUrl());
+ assertEquals(DatadogSite.US1.getLogsUrl(), intake.getLogsUrl());
+ assertEquals(DatadogSite.US1.getWebhooksUrl(), intake.getWebhooksUrl());
+
+ DatadogApiKey apiKey = datadogClientConfiguration.getApiKey();
+ assertEquals("my-api-key", apiKey.getKey().getPlainText());
+ }
+
+ @Test
+ public void testAgentConfiguration() throws Exception {
+ DatadogGlobalConfiguration configuration = SystemLambda
+ .withEnvironmentVariable(DatadogGlobalConfiguration.REPORT_WITH_PROPERTY, "DSD")
+ .and(DatadogAgentConfiguration.TARGET_HOST_PROPERTY, "my-target-host")
+ .and(DatadogAgentConfiguration.TARGET_PORT_PROPERTY, "123")
+ .and(DatadogAgentConfiguration.TARGET_TRACE_COLLECTION_PORT_PROPERTY, "456")
+ .and(DatadogAgentConfiguration.TARGET_LOG_COLLECTION_PORT_PROPERTY, "789")
+ .and(DatadogAgentConfiguration.DD_AGENT_HOST, null)
+ .and(DatadogAgentConfiguration.DD_AGENT_PORT, null)
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_PORT, null)
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_URL, null)
+ .execute(DatadogGlobalConfiguration::new);
+
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogAgentConfiguration);
+ DatadogAgentConfiguration datadogClientConfiguration = (DatadogAgentConfiguration) configuration.getDatadogClientConfiguration();
+
+ assertEquals("my-target-host", datadogClientConfiguration.getAgentHost());
+ assertEquals((Integer) 123, datadogClientConfiguration.getAgentPort());
+ assertEquals((Integer) 456, datadogClientConfiguration.getAgentTraceCollectionPort());
+ assertEquals((Integer) 789, datadogClientConfiguration.getAgentLogCollectionPort());
+ }
+
+ @Test
+ public void testLegacyAgentConfiguration() throws Exception {
+ DatadogGlobalConfiguration configuration = SystemLambda
+ .withEnvironmentVariable(DatadogGlobalConfiguration.REPORT_WITH_PROPERTY, "DSD")
+ .and(DatadogAgentConfiguration.TARGET_HOST_PROPERTY, null)
+ .and(DatadogAgentConfiguration.TARGET_PORT_PROPERTY, null)
+ .and(DatadogAgentConfiguration.TARGET_TRACE_COLLECTION_PORT_PROPERTY, "456")
+ .and(DatadogAgentConfiguration.TARGET_LOG_COLLECTION_PORT_PROPERTY, "789")
+ .and(DatadogAgentConfiguration.DD_AGENT_HOST, "my-target-host")
+ .and(DatadogAgentConfiguration.DD_AGENT_PORT, "123")
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_PORT, null)
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_URL, null)
+ .execute(DatadogGlobalConfiguration::new);
+
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogAgentConfiguration);
+ DatadogAgentConfiguration datadogClientConfiguration = (DatadogAgentConfiguration) configuration.getDatadogClientConfiguration();
+
+ assertEquals("my-target-host", datadogClientConfiguration.getAgentHost());
+ assertEquals((Integer) 123, datadogClientConfiguration.getAgentPort());
+ assertEquals((Integer) 456, datadogClientConfiguration.getAgentTraceCollectionPort());
+ assertEquals((Integer) 789, datadogClientConfiguration.getAgentLogCollectionPort());
+ }
+
+ @Test
+ public void testLegacyAgentPortConfiguration() throws Exception {
+ DatadogGlobalConfiguration configuration = SystemLambda
+ .withEnvironmentVariable(DatadogGlobalConfiguration.REPORT_WITH_PROPERTY, "DSD")
+ .and(DatadogAgentConfiguration.TARGET_HOST_PROPERTY, null)
+ .and(DatadogAgentConfiguration.TARGET_PORT_PROPERTY, "123")
+ .and(DatadogAgentConfiguration.TARGET_TRACE_COLLECTION_PORT_PROPERTY, null)
+ .and(DatadogAgentConfiguration.TARGET_LOG_COLLECTION_PORT_PROPERTY, "789")
+ .and(DatadogAgentConfiguration.DD_AGENT_HOST, "my-target-host")
+ .and(DatadogAgentConfiguration.DD_AGENT_PORT, null)
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_PORT, "456")
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_URL, null)
+ .execute(DatadogGlobalConfiguration::new);
+
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogAgentConfiguration);
+ DatadogAgentConfiguration datadogClientConfiguration = (DatadogAgentConfiguration) configuration.getDatadogClientConfiguration();
+
+ assertEquals("my-target-host", datadogClientConfiguration.getAgentHost());
+ assertEquals((Integer) 123, datadogClientConfiguration.getAgentPort());
+ assertEquals((Integer) 456, datadogClientConfiguration.getAgentTraceCollectionPort());
+ assertEquals((Integer) 789, datadogClientConfiguration.getAgentLogCollectionPort());
+ }
+
+ @Test
+ public void testLegacyAgentUrlConfiguration() throws Exception {
+ DatadogGlobalConfiguration configuration = SystemLambda
+ .withEnvironmentVariable(DatadogGlobalConfiguration.REPORT_WITH_PROPERTY, "DSD")
+ .and(DatadogAgentConfiguration.TARGET_HOST_PROPERTY, null)
+ .and(DatadogAgentConfiguration.TARGET_PORT_PROPERTY, "123")
+ .and(DatadogAgentConfiguration.TARGET_TRACE_COLLECTION_PORT_PROPERTY, null)
+ .and(DatadogAgentConfiguration.TARGET_LOG_COLLECTION_PORT_PROPERTY, "789")
+ .and(DatadogAgentConfiguration.DD_AGENT_HOST, null)
+ .and(DatadogAgentConfiguration.DD_AGENT_PORT, null)
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_PORT, null)
+ .and(DatadogAgentConfiguration.DD_TRACE_AGENT_URL, "http://my-target-host:456")
+ .execute(DatadogGlobalConfiguration::new);
+
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogAgentConfiguration);
+ DatadogAgentConfiguration datadogClientConfiguration = (DatadogAgentConfiguration) configuration.getDatadogClientConfiguration();
+
+ assertEquals("my-target-host", datadogClientConfiguration.getAgentHost());
+ assertEquals((Integer) 123, datadogClientConfiguration.getAgentPort());
+ assertEquals((Integer) 456, datadogClientConfiguration.getAgentTraceCollectionPort());
+ assertEquals((Integer) 789, datadogClientConfiguration.getAgentLogCollectionPort());
+ }
+
+}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationSaveTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationSaveTest.java
new file mode 100644
index 000000000..46f435180
--- /dev/null
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationSaveTest.java
@@ -0,0 +1,97 @@
+package org.datadog.jenkins.plugins.datadog;
+
+import com.thoughtworks.xstream.XStream;
+import hudson.util.XStream2;
+import org.datadog.jenkins.plugins.datadog.configuration.DatadogApiConfiguration;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Verifies that configuration stays the same after being saved and then loaded
+ */
+@RunWith(Parameterized.class)
+public class DatadogGlobalConfigurationSaveTest {
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Collection parameters() {
+ return Arrays.asList(new Object[][] {
+ { "globalConfiguration.xml" },
+ { "globalConfigurationCredentialsKey.xml" },
+ { "globalConfigurationSite.xml" },
+ { "globalConfigurationAgent.xml" },
+ { "globalConfigurationLegacyFormat.xml" },
+ { "globalConfigurationLegacyFormatCredentialsKey.xml" },
+ { "globalConfigurationLegacyFormatAgent.xml" },
+ });
+ }
+
+ private final String configurationResource;
+
+ public DatadogGlobalConfigurationSaveTest(String configurationResource) {
+ this.configurationResource = configurationResource;
+ }
+
+ @Test
+ public void canSaveAndLoadGlobalConfiguration() {
+ DatadogGlobalConfiguration configuration = parseConfigurationFromResource(configurationResource);
+ DatadogGlobalConfiguration loadedConfiguration = parseConfigurationFromString(serializeConfiguration(configuration));
+
+ assertEquals(configuration.getDatadogClientConfiguration(), loadedConfiguration.getDatadogClientConfiguration());
+ assertEquals(configuration.getExcluded(), loadedConfiguration.getExcluded());
+ assertEquals(configuration.getIncluded(), loadedConfiguration.getIncluded());
+ assertEquals(configuration.getCiInstanceName(), loadedConfiguration.getCiInstanceName());
+ assertEquals(configuration.getHostname(), loadedConfiguration.getHostname());
+ assertEquals(configuration.getGlobalTagFile(), loadedConfiguration.getGlobalTagFile());
+ assertEquals(configuration.getGlobalTags(), loadedConfiguration.getGlobalTags());
+ assertEquals(configuration.getGlobalJobTags(), loadedConfiguration.getGlobalJobTags());
+ assertEquals(configuration.getIncludeEvents(), loadedConfiguration.getIncludeEvents());
+ assertEquals(configuration.getExcludeEvents(), loadedConfiguration.getExcludeEvents());
+ assertEquals(configuration.isEmitSecurityEvents(), loadedConfiguration.isEmitSecurityEvents());
+ assertEquals(configuration.isEmitSystemEvents(), loadedConfiguration.isEmitSystemEvents());
+ assertEquals(configuration.isCollectBuildLogs(), loadedConfiguration.isCollectBuildLogs());
+ assertEquals(configuration.getEnableCiVisibility(), loadedConfiguration.getEnableCiVisibility());
+ assertEquals(configuration.isRefreshDogstatsdClient(), loadedConfiguration.isRefreshDogstatsdClient());
+ assertEquals(configuration.isCacheBuildRuns(), loadedConfiguration.isCacheBuildRuns());
+ assertEquals(configuration.isUseAwsInstanceHostname(), loadedConfiguration.isUseAwsInstanceHostname());
+ assertEquals(configuration.getTraceServiceName(), loadedConfiguration.getTraceServiceName());
+ assertEquals(configuration.getBlacklist(), loadedConfiguration.getBlacklist());
+ assertEquals(configuration.getWhitelist(), loadedConfiguration.getWhitelist());
+ assertEquals(configuration.isCollectBuildTraces(), loadedConfiguration.isCollectBuildTraces());
+ assertEquals(configuration.getReportWith(), loadedConfiguration.getReportWith());
+ assertEquals(configuration.getTargetApiURL(), loadedConfiguration.getTargetApiURL());
+ assertEquals(configuration.getTargetLogIntakeURL(), loadedConfiguration.getTargetLogIntakeURL());
+ assertEquals(configuration.getTargetWebhookIntakeURL(), loadedConfiguration.getTargetWebhookIntakeURL());
+ assertEquals(configuration.getTargetApiKey(), loadedConfiguration.getTargetApiKey());
+ assertEquals(configuration.getTargetCredentialsApiKey(), loadedConfiguration.getTargetCredentialsApiKey());
+ assertEquals(configuration.getTargetHost(), loadedConfiguration.getTargetHost());
+ assertEquals(configuration.getTargetPort(), loadedConfiguration.getTargetPort());
+ assertEquals(configuration.getTargetLogCollectionPort(), loadedConfiguration.getTargetLogCollectionPort());
+ assertEquals(configuration.getTargetTraceCollectionPort(), loadedConfiguration.getTargetTraceCollectionPort());
+ }
+
+ private static final XStream XSTREAM = new XStream2(XStream2.getDefaultDriver());
+
+ static {
+ XSTREAM.processAnnotations(new Class[] { DatadogGlobalConfiguration.class, DatadogApiConfiguration.class });
+ }
+
+ private static DatadogGlobalConfiguration parseConfigurationFromResource(String resourceName) {
+ URL resource = DatadogGlobalConfigurationSaveTest.class.getResource(resourceName);
+ return (DatadogGlobalConfiguration) XSTREAM.fromXML(resource);
+ }
+
+ private static DatadogGlobalConfiguration parseConfigurationFromString(String serializedConfiguration) {
+ return (DatadogGlobalConfiguration) XSTREAM.fromXML(serializedConfiguration);
+ }
+
+ private static String serializeConfiguration(DatadogGlobalConfiguration configuration) {
+ return XSTREAM.toXML(configuration);
+ }
+}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java
index b3ef6783c..dcf3901e4 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java
@@ -1,83 +1,287 @@
package org.datadog.jenkins.plugins.datadog;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import com.thoughtworks.xstream.XStream;
+import hudson.util.Secret;
+import hudson.util.XStream2;
+import java.net.URL;
+import org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration;
+import org.datadog.jenkins.plugins.datadog.configuration.DatadogApiConfiguration;
+import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntake;
+import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogSite;
+import org.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogCredentialsApiKey;
+import org.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogTextApiKey;
import org.junit.Test;
-import org.jvnet.hudson.test.JenkinsRule;
+public class DatadogGlobalConfigurationTest {
-import hudson.util.Secret;
-import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
-import org.jenkinsci.plugins.plaincredentials.StringCredentials;
+ @Test
+ public void canLoadGlobalConfiguration() {
+ DatadogGlobalConfiguration configuration = parseConfigurationFromResource("globalConfiguration.xml");
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration datadogClientConfiguration = (DatadogApiConfiguration) configuration.getDatadogClientConfiguration();
-import com.cloudbees.plugins.credentials.CredentialsProvider;
-import com.cloudbees.plugins.credentials.CredentialsScope;
-import com.cloudbees.plugins.credentials.CredentialsStore;
-import com.cloudbees.plugins.credentials.domains.Domain;
+ DatadogIntake intake = datadogClientConfiguration.getIntake();
+ assertEquals("https://my-api-url.com/api/", intake.getApiUrl());
+ assertEquals("https://my-log-intake-url.com/v1/input/", intake.getLogsUrl());
+ assertEquals("https://my-webhook-intake-url.com/api/v2/webhook/", intake.getWebhooksUrl());
-import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
-import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
+ assertTrue(datadogClientConfiguration.getApiKey() instanceof DatadogTextApiKey);
+ DatadogTextApiKey textApiKey = (DatadogTextApiKey) datadogClientConfiguration.getApiKey();
+ assertEquals("{AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}", Secret.toString(textApiKey.getKey()));
-import java.io.IOException;
+ assertEquals("my-jenkins-service-name", configuration.getCiInstanceName());
+ assertEquals("my-hostname", configuration.getHostname());
+ assertEquals("my-blacklist", configuration.getExcluded());
+ assertEquals("my-whitelist", configuration.getIncluded());
+ assertEquals("my-global-tag-file", configuration.getGlobalTagFile());
+ assertEquals("my-global-tags", configuration.getGlobalTags());
+ assertEquals("my-global-job-tags", configuration.getGlobalJobTags());
+ assertEquals("my-include-events", configuration.getIncludeEvents());
+ assertEquals("my-exclude-evens", configuration.getExcludeEvents());
+ assertFalse(configuration.isEmitSecurityEvents());
+ assertFalse(configuration.isEmitSystemEvents());
+ assertTrue(configuration.isCollectBuildLogs());
+ assertTrue(configuration.getEnableCiVisibility());
+ assertTrue(configuration.isRefreshDogstatsdClient());
+ assertFalse(configuration.isCacheBuildRuns());
+ assertTrue(configuration.isUseAwsInstanceHostname());
+ }
-public class DatadogGlobalConfigurationTest {
+ @Test
+ public void canLoadGlobalConfigurationWithCredentialsApiKey() {
+ DatadogGlobalConfiguration configuration = parseConfigurationFromResource("globalConfigurationCredentialsKey.xml");
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration datadogClientConfiguration = (DatadogApiConfiguration) configuration.getDatadogClientConfiguration();
- @ClassRule
- public static JenkinsRule jenkinsRule;
+ DatadogIntake intake = datadogClientConfiguration.getIntake();
+ assertEquals("https://my-api-url.com/api/", intake.getApiUrl());
+ assertEquals("https://my-log-intake-url.com/v1/input/", intake.getLogsUrl());
+ assertEquals("https://my-webhook-intake-url.com/api/v2/webhook/", intake.getWebhooksUrl());
- static {
- jenkinsRule = new JenkinsRule();
- jenkinsRule.timeout = 600; // default value of 180 is too small for all the test cases in this class
+ assertTrue(datadogClientConfiguration.getApiKey() instanceof DatadogCredentialsApiKey);
+ DatadogCredentialsApiKey credentialsApiKey = (DatadogCredentialsApiKey) datadogClientConfiguration.getApiKey();
+ assertEquals("my-api-key-credentials-id", credentialsApiKey.getCredentialsId());
+
+ assertEquals("my-jenkins-service-name", configuration.getCiInstanceName());
+ assertEquals("my-hostname", configuration.getHostname());
+ assertEquals("my-blacklist", configuration.getExcluded());
+ assertEquals("my-whitelist", configuration.getIncluded());
+ assertEquals("my-global-tag-file", configuration.getGlobalTagFile());
+ assertEquals("my-global-tags", configuration.getGlobalTags());
+ assertEquals("my-global-job-tags", configuration.getGlobalJobTags());
+ assertEquals("my-include-events", configuration.getIncludeEvents());
+ assertEquals("my-exclude-evens", configuration.getExcludeEvents());
+ assertFalse(configuration.isEmitSecurityEvents());
+ assertFalse(configuration.isEmitSystemEvents());
+ assertTrue(configuration.isCollectBuildLogs());
+ assertTrue(configuration.getEnableCiVisibility());
+ assertTrue(configuration.isRefreshDogstatsdClient());
+ assertFalse(configuration.isCacheBuildRuns());
+ assertTrue(configuration.isUseAwsInstanceHostname());
+ }
+
+ @Test
+ public void canLoadGlobalConfigurationWithSite() {
+ DatadogGlobalConfiguration configuration = parseConfigurationFromResource("globalConfigurationSite.xml");
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration datadogClientConfiguration = (DatadogApiConfiguration) configuration.getDatadogClientConfiguration();
+
+ DatadogIntake intake = datadogClientConfiguration.getIntake();
+ assertEquals(DatadogSite.US3.getApiUrl(), intake.getApiUrl());
+ assertEquals(DatadogSite.US3.getLogsUrl(), intake.getLogsUrl());
+ assertEquals(DatadogSite.US3.getWebhooksUrl(), intake.getWebhooksUrl());
+
+ assertTrue(datadogClientConfiguration.getApiKey() instanceof DatadogCredentialsApiKey);
+ DatadogCredentialsApiKey credentialsApiKey = (DatadogCredentialsApiKey) datadogClientConfiguration.getApiKey();
+ assertEquals("my-api-key-credentials-id", credentialsApiKey.getCredentialsId());
+
+ assertEquals("my-jenkins-service-name", configuration.getCiInstanceName());
+ assertEquals("my-hostname", configuration.getHostname());
+ assertEquals("my-blacklist", configuration.getExcluded());
+ assertEquals("my-whitelist", configuration.getIncluded());
+ assertEquals("my-global-tag-file", configuration.getGlobalTagFile());
+ assertEquals("my-global-tags", configuration.getGlobalTags());
+ assertEquals("my-global-job-tags", configuration.getGlobalJobTags());
+ assertEquals("my-include-events", configuration.getIncludeEvents());
+ assertEquals("my-exclude-evens", configuration.getExcludeEvents());
+ assertFalse(configuration.isEmitSecurityEvents());
+ assertFalse(configuration.isEmitSystemEvents());
+ assertTrue(configuration.isCollectBuildLogs());
+ assertTrue(configuration.getEnableCiVisibility());
+ assertTrue(configuration.isRefreshDogstatsdClient());
+ assertFalse(configuration.isCacheBuildRuns());
+ assertTrue(configuration.isUseAwsInstanceHostname());
}
- @Rule public JenkinsConfiguredWithCodeRule r = new JenkinsConfiguredWithCodeRule();
+ @Test
+ public void canLoadGlobalConfigurationReportingToAgent() {
+ DatadogGlobalConfiguration configuration = parseConfigurationFromResource("globalConfigurationAgent.xml");
+
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogAgentConfiguration);
+ DatadogAgentConfiguration datadogAgentConfiguration = (DatadogAgentConfiguration) configuration.getDatadogClientConfiguration();
+ assertEquals("my-agent-host", datadogAgentConfiguration.getAgentHost());
+ assertEquals((Integer) 9876, datadogAgentConfiguration.getAgentPort());
+ assertEquals((Integer) 8765, datadogAgentConfiguration.getAgentLogCollectionPort());
+ assertEquals((Integer) 7654, datadogAgentConfiguration.getAgentTraceCollectionPort());
+
+ assertEquals("my-jenkins-service-name", configuration.getCiInstanceName());
+ assertEquals("my-hostname", configuration.getHostname());
+ assertEquals("my-blacklist", configuration.getExcluded());
+ assertEquals("my-whitelist", configuration.getIncluded());
+ assertEquals("my-global-tag-file", configuration.getGlobalTagFile());
+ assertEquals("my-global-tags", configuration.getGlobalTags());
+ assertEquals("my-global-job-tags", configuration.getGlobalJobTags());
+ assertEquals("my-include-events", configuration.getIncludeEvents());
+ assertEquals("my-exclude-evens", configuration.getExcludeEvents());
+ assertTrue(configuration.isEmitSecurityEvents());
+ assertTrue(configuration.isEmitSystemEvents());
+ assertTrue(configuration.isCollectBuildLogs());
+ assertTrue(configuration.getEnableCiVisibility());
+ assertTrue(configuration.isRefreshDogstatsdClient());
+ assertTrue(configuration.isCacheBuildRuns());
+ assertTrue(configuration.isUseAwsInstanceHostname());
+ }
@Test
- @ConfiguredWithCode("test-config.yml")
- public void TestConfigurationAsCodeCompatibility() throws Exception {
- DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
- Assert.assertTrue(cfg.isEmitConfigChangeEvents());
+ public void canLoadGlobalConfigurationFromLegacyFormat() {
+ DatadogGlobalConfiguration configuration = parseConfigurationFromResource("globalConfigurationLegacyFormat.xml");
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration datadogClientConfiguration = (DatadogApiConfiguration) configuration.getDatadogClientConfiguration();
+
+ DatadogIntake intake = datadogClientConfiguration.getIntake();
+ assertEquals("my-target-api-url", intake.getApiUrl());
+ assertEquals("my-target-log-intake-url", intake.getLogsUrl());
+ assertEquals("my-target-webhook-intake-url", intake.getWebhooksUrl());
+
+ assertTrue(datadogClientConfiguration.getApiKey() instanceof DatadogTextApiKey);
+ DatadogTextApiKey textApiKey = (DatadogTextApiKey) datadogClientConfiguration.getApiKey();
+ assertEquals("{AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}", Secret.toString(textApiKey.getKey()));
+
+ assertEquals("my-jenkins-service-name", configuration.getCiInstanceName());
+ assertEquals("my-hostname", configuration.getHostname());
+ assertEquals("my-blacklist", configuration.getExcluded());
+ assertEquals("my-whitelist", configuration.getIncluded());
+ assertEquals("my-global-tag-file", configuration.getGlobalTagFile());
+ assertEquals("my-global-tags", configuration.getGlobalTags());
+ assertEquals("my-global-job-tags", configuration.getGlobalJobTags());
+ assertEquals("my-include-events", configuration.getIncludeEvents());
+ assertEquals("my-exclude-evens", configuration.getExcludeEvents());
+ assertFalse(configuration.isEmitSecurityEvents());
+ assertFalse(configuration.isEmitSystemEvents());
+ assertTrue(configuration.isCollectBuildLogs());
+ assertTrue(configuration.getEnableCiVisibility());
+ assertTrue(configuration.isRefreshDogstatsdClient());
+ assertFalse(configuration.isCacheBuildRuns());
+ assertTrue(configuration.isUseAwsInstanceHostname());
}
@Test
- public void testCanGetCredentialFromId() throws IOException {
- CredentialsStore credentialsStore = CredentialsProvider.lookupStores(jenkinsRule).iterator().next();
+ public void canLoadGlobalConfigurationFromLegacyFormatWithCredentialsApiKey() {
+ DatadogGlobalConfiguration configuration = parseConfigurationFromResource("globalConfigurationLegacyFormatCredentialsKey.xml");
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration datadogClientConfiguration = (DatadogApiConfiguration) configuration.getDatadogClientConfiguration();
+
+ DatadogIntake intake = datadogClientConfiguration.getIntake();
+ assertEquals("my-target-api-url", intake.getApiUrl());
+ assertEquals("my-target-log-intake-url", intake.getLogsUrl());
+ assertEquals("my-target-webhook-intake-url", intake.getWebhooksUrl());
- StringCredentials credential1 = new StringCredentialsImpl(CredentialsScope.SYSTEM, "string-cred-id", "description", Secret.fromString("api-key"));
- credentialsStore.addCredentials(Domain.global(), credential1);
- DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
- Assert.assertTrue(cfg.getCredentialFromId("string-cred-id").equals(credential1));
+ assertTrue(datadogClientConfiguration.getApiKey() instanceof DatadogCredentialsApiKey);
+ DatadogCredentialsApiKey credentialsApiKey = (DatadogCredentialsApiKey) datadogClientConfiguration.getApiKey();
+ assertEquals("target-credentials-api-key", credentialsApiKey.getCredentialsId());
- StringCredentials credential2 = new StringCredentialsImpl(CredentialsScope.SYSTEM, "string-cred-id2", "description", Secret.fromString("api-key"));
- credentialsStore.addCredentials(Domain.global(), credential2);
- Assert.assertTrue(cfg.getCredentialFromId("string-cred-id").equals(credential1));
- Assert.assertTrue(cfg.getCredentialFromId("string-cred-id2").equals(credential2));
+ assertEquals("my-jenkins-service-name", configuration.getCiInstanceName());
+ assertEquals("my-hostname", configuration.getHostname());
+ assertEquals("my-blacklist", configuration.getExcluded());
+ assertEquals("my-whitelist", configuration.getIncluded());
+ assertEquals("my-global-tag-file", configuration.getGlobalTagFile());
+ assertEquals("my-global-tags", configuration.getGlobalTags());
+ assertEquals("my-global-job-tags", configuration.getGlobalJobTags());
+ assertEquals("my-include-events", configuration.getIncludeEvents());
+ assertEquals("my-exclude-evens", configuration.getExcludeEvents());
+ assertFalse(configuration.isEmitSecurityEvents());
+ assertFalse(configuration.isEmitSystemEvents());
+ assertTrue(configuration.isCollectBuildLogs());
+ assertTrue(configuration.getEnableCiVisibility());
+ assertTrue(configuration.isRefreshDogstatsdClient());
+ assertFalse(configuration.isCacheBuildRuns());
+ assertTrue(configuration.isUseAwsInstanceHostname());
+ }
+
+ @Test
+ public void canLoadGlobalConfigurationFromLegacyFormatReportingToAgent() {
+ DatadogGlobalConfiguration configuration = parseConfigurationFromResource("globalConfigurationLegacyFormatAgent.xml");
- Assert.assertNull(cfg.getCredentialFromId("string-cred-id-fake"));
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogAgentConfiguration);
+ DatadogAgentConfiguration datadogAgentConfiguration = (DatadogAgentConfiguration) configuration.getDatadogClientConfiguration();
+ assertEquals("datadog", datadogAgentConfiguration.getAgentHost());
+ assertEquals((Integer) 1357, datadogAgentConfiguration.getAgentPort());
+ assertEquals((Integer) 2468, datadogAgentConfiguration.getAgentLogCollectionPort());
+ assertEquals((Integer) 3579, datadogAgentConfiguration.getAgentTraceCollectionPort());
+ assertEquals("my-jenkins-service-name", configuration.getCiInstanceName());
+ assertEquals("my-hostname", configuration.getHostname());
+ assertEquals("my-blacklist", configuration.getExcluded());
+ assertEquals("my-whitelist", configuration.getIncluded());
+ assertEquals("my-global-tag-file", configuration.getGlobalTagFile());
+ assertEquals("my-global-tags", configuration.getGlobalTags());
+ assertEquals("my-global-job-tags", configuration.getGlobalJobTags());
+ assertEquals("my-include-events", configuration.getIncludeEvents());
+ assertEquals("my-exclude-evens", configuration.getExcludeEvents());
+ assertTrue(configuration.isEmitSecurityEvents());
+ assertTrue(configuration.isEmitSystemEvents());
+ assertFalse(configuration.isCollectBuildLogs());
+ assertFalse(configuration.getEnableCiVisibility());
+ assertFalse(configuration.isRefreshDogstatsdClient());
+ assertTrue(configuration.isCacheBuildRuns());
+ assertFalse(configuration.isUseAwsInstanceHostname());
}
@Test
- public void testFindSecret() throws IOException {
- CredentialsStore credentialsStore = CredentialsProvider.lookupStores(jenkinsRule).iterator().next();
+ public void canLoadGlobalConfigurationFromLegacyFormatWithEmptyCredentialsKey() {
+ DatadogGlobalConfiguration configuration = parseConfigurationFromResource("globalConfigurationLegacyFormatCredentialsKeyEmpty.xml");
+ assertTrue(configuration.getDatadogClientConfiguration() instanceof DatadogApiConfiguration);
+ DatadogApiConfiguration datadogClientConfiguration = (DatadogApiConfiguration) configuration.getDatadogClientConfiguration();
+
+ DatadogIntake intake = datadogClientConfiguration.getIntake();
+ assertEquals("my-target-api-url", intake.getApiUrl());
+ assertEquals("my-target-log-intake-url", intake.getLogsUrl());
+ assertEquals("my-target-webhook-intake-url", intake.getWebhooksUrl());
- StringCredentials credential1 = new StringCredentialsImpl(CredentialsScope.SYSTEM, "string-cred-id", "description", Secret.fromString("api-key"));
- credentialsStore.addCredentials(Domain.global(), credential1);
+ assertTrue(datadogClientConfiguration.getApiKey() instanceof DatadogTextApiKey);
+ DatadogTextApiKey textApiKey = (DatadogTextApiKey) datadogClientConfiguration.getApiKey();
+ assertEquals("{AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}", Secret.toString(textApiKey.getKey()));
- StringCredentials credential2 = new StringCredentialsImpl(CredentialsScope.SYSTEM, "string-cred-id2", "description", Secret.fromString("api-key-2"));
- credentialsStore.addCredentials(Domain.global(), credential2);
+ assertEquals("my-jenkins-service-name", configuration.getCiInstanceName());
+ assertEquals("my-hostname", configuration.getHostname());
+ assertEquals("my-blacklist", configuration.getExcluded());
+ assertEquals("my-whitelist", configuration.getIncluded());
+ assertEquals("my-global-tag-file", configuration.getGlobalTagFile());
+ assertEquals("my-global-tags", configuration.getGlobalTags());
+ assertEquals("my-global-job-tags", configuration.getGlobalJobTags());
+ assertEquals("my-include-events", configuration.getIncludeEvents());
+ assertEquals("my-exclude-evens", configuration.getExcludeEvents());
+ assertFalse(configuration.isEmitSecurityEvents());
+ assertFalse(configuration.isEmitSystemEvents());
+ assertTrue(configuration.isCollectBuildLogs());
+ assertTrue(configuration.getEnableCiVisibility());
+ assertTrue(configuration.isRefreshDogstatsdClient());
+ assertFalse(configuration.isCacheBuildRuns());
+ assertTrue(configuration.isUseAwsInstanceHostname());
+ }
- DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
- Assert.assertTrue(cfg.findSecret("api-test", "string-cred-id").getPlainText().equals("api-key"));
- Assert.assertTrue(cfg.findSecret("api-test", "string-cred-id2").getPlainText().equals("api-key-2"));
+ private static final XStream XSTREAM = new XStream2(XStream2.getDefaultDriver());
- Assert.assertTrue(cfg.findSecret("api-test", "").getPlainText().equals("api-test"));
- Assert.assertTrue(cfg.findSecret("api-test", null).getPlainText().equals("api-test"));
- Assert.assertTrue(cfg.findSecret("", null).getPlainText().equals(""));
+ static {
+ XSTREAM.processAnnotations(new Class[] { DatadogGlobalConfiguration.class, DatadogApiConfiguration.class });
+ }
- Assert.assertTrue(cfg.findSecret(null, "").getPlainText().equals(""));
+ private static DatadogGlobalConfiguration parseConfigurationFromResource(String resourceName) {
+ URL resource = DatadogGlobalConfigurationTest.class.getResource(resourceName);
+ return (DatadogGlobalConfiguration) XSTREAM.fromXML(resource);
}
}
-
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/apm/TracerInjectionIT.java b/src/test/java/org/datadog/jenkins/plugins/datadog/apm/TracerInjectionIT.java
index 4f1ecf4b2..174a7f74d 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/apm/TracerInjectionIT.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/apm/TracerInjectionIT.java
@@ -1,5 +1,10 @@
package org.datadog.jenkins.plugins.datadog.apm;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentHost;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentLogCollectionPort;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentPort;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentTraceCollectionPort;
+
import hudson.FilePath;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
@@ -20,6 +25,7 @@
import org.apache.commons.io.IOUtils;
import org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration;
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
+import org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
@@ -45,7 +51,10 @@ public class TracerInjectionIT {
@BeforeClass
public static void suiteSetUp() throws Exception {
DatadogGlobalConfiguration datadogConfig = DatadogUtilities.getDatadogGlobalDescriptor();
- datadogConfig.setReportWith("DSD");
+ // There is no agent and the injected tracers will fail to actually send anything,
+ // but for the purposes of this test this is enough, since it is only asserted that the tracer initialisation was reported in the logs
+ datadogConfig.setDatadogClientConfiguration(new DatadogAgentConfiguration(
+ getDefaultAgentHost(), getDefaultAgentPort(), getDefaultAgentLogCollectionPort(), getDefaultAgentTraceCollectionPort()));
agentNode = jenkinsRule.createOnlineSlave();
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientTest.java
deleted file mode 100644
index 2bd1c1865..000000000
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientTest.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
-The MIT License
-
-Copyright (c) 2015-Present Datadog, Inc
-All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
- */
-
-package org.datadog.jenkins.plugins.datadog.clients;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration;
-import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
-import org.datadog.jenkins.plugins.datadog.metrics.MetricKey;
-import org.datadog.jenkins.plugins.datadog.metrics.Metrics;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.jvnet.hudson.test.JenkinsRule;
-import org.mockito.Mockito;
-
-public class DatadogClientTest {
-
- @ClassRule
- public static JenkinsRule j = new JenkinsRule();
-
- @Test
- public void testHttpClientGetInstanceApiKey() {
- //validateConfiguration throws an error when given an invalid API key when the urls are valid
- Exception exception = Assert.assertThrows(IllegalArgumentException.class, () -> new DatadogApiClient("http", "test", "test", null));
-
- String expectedMessage = "Datadog API Key is not set properly";
- String actualMessage = exception.getMessage();
- Assert.assertEquals(actualMessage, expectedMessage);
- }
-
- @Test
- public void testHttpClientGetInstanceApiUrl() {
- // validateConfiguration throws an error when given an invalid url
- Exception exception = Assert.assertThrows(IllegalArgumentException.class, () -> new DatadogApiClient("", null, null, null));
- String expectedMessage = "Datadog Target URL is not set properly";
- String actualMessage = exception.getMessage();
- Assert.assertEquals(actualMessage, expectedMessage);
- }
-
-
- @Test
- public void testHttpClientGetInstanceEnableValidations() {
- Assert.assertThrows(IllegalArgumentException.class, () -> new DatadogApiClient("https", null, null, null));
- }
-
- @Test
- public void testDogstatsDClientGetInstanceTargetPort() {
- // validateConfiguration throws an error when given an invalid port
- Exception exception = Assert.assertThrows(IllegalArgumentException.class, () -> new DatadogAgentClient("test", null, null, null));
-
- String expectedMessage = "Datadog Target Port is not set properly";
- String actualMessage = exception.getMessage();
- Assert.assertEquals(actualMessage, expectedMessage);
- }
-
- @Test
- public void testDogstatsDClientGetInstanceEnableValidations() {
- // calling getInstance with invalid data returns null
- Assert.assertThrows(IllegalArgumentException.class, () -> new DatadogAgentClient("https", null, null, null));
- }
-
- @Test
- public void testEvpProxyEnabled() {
- DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
- cfg.setEnableCiVisibility(true);
- DatadogAgentClient client = Mockito.spy(new DatadogAgentClient("test", 1234, 1235, 1236, 1_000));
- Mockito.doReturn(new HashSet<>(Collections.singletonList("/evp_proxy/v3/"))).when(client).fetchAgentSupportedEndpoints();
- Assert.assertTrue(client.isEvpProxySupported());
- }
-
- @Test
- public void testEvpProxyDisabled() {
- DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
- cfg.setEnableCiVisibility(true);
- DatadogAgentClient client = Mockito.spy(new DatadogAgentClient("test", 1234, 1235, 1236, 1_000));
- Mockito.doReturn(new HashSet()).when(client).fetchAgentSupportedEndpoints();
- Assert.assertFalse(client.isEvpProxySupported());
- }
-
- @Test
- public void testEmptyAgentSupportedEndpointsWithNoAgent() {
- DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
- cfg.setEnableCiVisibility(true);
- DatadogAgentClient client = new DatadogAgentClient("test", 1234, 1235, 1236, 1_000);
- Assert.assertTrue(client.fetchAgentSupportedEndpoints().isEmpty());
- }
-
- @Test
- public void testIncrementCountAndFlush() {
- Map> tags1 = new HashMap<>();
- DatadogClientStub.addTagToMap(tags1, "tag1", "value");
- DatadogClientStub.addTagToMap(tags1, "tag2", "value");
- Metrics.getInstance().incrementCounter("metric1", "host1", tags1);
- Metrics.getInstance().incrementCounter("metric1", "host1", tags1);
-
- Map> tags2 = new HashMap<>();
- DatadogClientStub.addTagToMap(tags2, "tag1", "value");
- DatadogClientStub.addTagToMap(tags2, "tag2", "value");
- DatadogClientStub.addTagToMap(tags2, "tag3", "value");
- Metrics.getInstance().incrementCounter("metric1", "host1", tags2);
-
- Metrics.getInstance().incrementCounter("metric1", "host2", tags2);
- Metrics.getInstance().incrementCounter("metric1", "host2", tags2);
-
- Metrics.getInstance().incrementCounter("metric2", "host2", tags2);
-
- // The following code should be the same as in the flushCounters method
- Map counters = Metrics.getInstance().getAndResetCounters();
-
- // Check counter is reset as expected
- Map countersEmpty = Metrics.getInstance().getAndResetCounters();
- Assert.assertEquals("size = " + countersEmpty.size(), 0, countersEmpty.size());
-
- // Check that metrics to submit are correct
- boolean check1 = false, check2 = false, check3 = false, check4 = false;
- Assert.assertEquals("counters = " + counters.size(), 4, counters.size());
- for (MetricKey counterMetric: counters.keySet()) {
- int count = counters.get(counterMetric);
- if (counterMetric.getMetricName().equals("metric1") && counterMetric.getHostname().equals("host1")
- && counterMetric.getTags().size() == 2) {
- Assert.assertEquals("count = " + count, 2, count);
- check1 = true;
- } else if (counterMetric.getMetricName().equals("metric1") && counterMetric.getHostname().equals("host1")
- && counterMetric.getTags().size() == 3) {
- Assert.assertEquals("count = " + count, 1, count);
- check2 = true;
- } else if (counterMetric.getMetricName().equals("metric1") && counterMetric.getHostname().equals("host2")
- && counterMetric.getTags().size() == 3) {
- Assert.assertEquals("count = " + count, 2, count);
- check3 = true;
- } else if (counterMetric.getMetricName().equals("metric2") && counterMetric.getHostname().equals("host2")
- && counterMetric.getTags().size() == 3) {
- Assert.assertEquals("count = " + count, 1, count);
- check4 = true;
- }
- }
- Assert.assertTrue(check1 + " " + check2 + " " + check3 + " " + check4,
- check1 && check2 && check3 && check4);
- }
-}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/MetricsTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/MetricsTest.java
index f85eb80a8..fcd379bc7 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/MetricsTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/MetricsTest.java
@@ -16,6 +16,59 @@
public class MetricsTest {
+ @Test
+ public void testIncrementCountAndFlush() {
+ Map> tags1 = new HashMap<>();
+ DatadogClientStub.addTagToMap(tags1, "tag1", "value");
+ DatadogClientStub.addTagToMap(tags1, "tag2", "value");
+ Metrics.getInstance().incrementCounter("metric1", "host1", tags1);
+ Metrics.getInstance().incrementCounter("metric1", "host1", tags1);
+
+ Map> tags2 = new HashMap<>();
+ DatadogClientStub.addTagToMap(tags2, "tag1", "value");
+ DatadogClientStub.addTagToMap(tags2, "tag2", "value");
+ DatadogClientStub.addTagToMap(tags2, "tag3", "value");
+ Metrics.getInstance().incrementCounter("metric1", "host1", tags2);
+
+ Metrics.getInstance().incrementCounter("metric1", "host2", tags2);
+ Metrics.getInstance().incrementCounter("metric1", "host2", tags2);
+
+ Metrics.getInstance().incrementCounter("metric2", "host2", tags2);
+
+ // The following code should be the same as in the flushCounters method
+ Map counters = Metrics.getInstance().getAndResetCounters();
+
+ // Check counter is reset as expected
+ Map countersEmpty = Metrics.getInstance().getAndResetCounters();
+ Assert.assertEquals("size = " + countersEmpty.size(), 0, countersEmpty.size());
+
+ // Check that metrics to submit are correct
+ boolean check1 = false, check2 = false, check3 = false, check4 = false;
+ Assert.assertEquals("counters = " + counters.size(), 4, counters.size());
+ for (MetricKey counterMetric: counters.keySet()) {
+ int count = counters.get(counterMetric);
+ if (counterMetric.getMetricName().equals("metric1") && counterMetric.getHostname().equals("host1")
+ && counterMetric.getTags().size() == 2) {
+ Assert.assertEquals("count = " + count, 2, count);
+ check1 = true;
+ } else if (counterMetric.getMetricName().equals("metric1") && counterMetric.getHostname().equals("host1")
+ && counterMetric.getTags().size() == 3) {
+ Assert.assertEquals("count = " + count, 1, count);
+ check2 = true;
+ } else if (counterMetric.getMetricName().equals("metric1") && counterMetric.getHostname().equals("host2")
+ && counterMetric.getTags().size() == 3) {
+ Assert.assertEquals("count = " + count, 2, count);
+ check3 = true;
+ } else if (counterMetric.getMetricName().equals("metric2") && counterMetric.getHostname().equals("host2")
+ && counterMetric.getTags().size() == 3) {
+ Assert.assertEquals("count = " + count, 1, count);
+ check4 = true;
+ }
+ }
+ Assert.assertTrue(check1 + " " + check2 + " " + check3 + " " + check4,
+ check1 && check2 && check3 && check4);
+ }
+
@Test
public void testIncrementCountAndFlushThreadedEnv() {
ExecutorService executor = Executors.newFixedThreadPool(2);
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfigurationTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfigurationTest.java
new file mode 100644
index 000000000..6da02c0cf
--- /dev/null
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfigurationTest.java
@@ -0,0 +1,101 @@
+package org.datadog.jenkins.plugins.datadog.configuration;
+
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DD_AGENT_HOST;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DD_AGENT_PORT;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DD_TRACE_AGENT_PORT;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DD_TRACE_AGENT_URL;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DEFAULT_AGENT_HOST_VALUE;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DEFAULT_AGENT_PORT_VALUE;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DEFAULT_LOG_COLLECTION_PORT_VALUE;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DEFAULT_TRACE_COLLECTION_PORT_VALUE;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.TARGET_HOST_PROPERTY;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.TARGET_LOG_COLLECTION_PORT_PROPERTY;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.TARGET_PORT_PROPERTY;
+import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.TARGET_TRACE_COLLECTION_PORT_PROPERTY;
+import static org.junit.Assert.assertEquals;
+
+import com.github.stefanbirkner.systemlambda.SystemLambda;
+import org.junit.Test;
+
+public class DatadogAgentConfigurationTest {
+
+ @Test
+ public void testGetDefaultAgentHost() throws Exception {
+ // check default value
+ assertEquals(DEFAULT_AGENT_HOST_VALUE, DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentHost());
+ // check environment property overrides
+ assertEquals("target-host", SystemLambda
+ .withEnvironmentVariable(TARGET_HOST_PROPERTY, "target-host")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentHost));
+ assertEquals("agent-host", SystemLambda
+ .withEnvironmentVariable(DD_TRACE_AGENT_URL, "http://agent-host:1234")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentHost));
+ assertEquals("dd-agent-host", SystemLambda
+ .withEnvironmentVariable(DD_AGENT_HOST, "dd-agent-host")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentHost));
+ // check environment property priorities
+ assertEquals("target-host", SystemLambda
+ .withEnvironmentVariable(TARGET_HOST_PROPERTY, "target-host")
+ .and(DD_TRACE_AGENT_URL, "http://agent-host:1234")
+ .and(DD_AGENT_HOST, "dd-agent-host")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentHost));
+ assertEquals("agent-host", SystemLambda
+ .withEnvironmentVariable(DD_TRACE_AGENT_URL, "http://agent-host:1234")
+ .and(DD_AGENT_HOST, "dd-agent-host")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentHost));
+ }
+
+ @Test
+ public void testGetDefaultAgentPort() throws Exception {
+ // check default value
+ assertEquals(DEFAULT_AGENT_PORT_VALUE, DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentPort());
+ // check environment property overrides
+ assertEquals((Integer) 1234, SystemLambda
+ .withEnvironmentVariable(TARGET_PORT_PROPERTY, "1234")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentPort));
+ assertEquals((Integer) 5678, SystemLambda
+ .withEnvironmentVariable(DD_AGENT_PORT, "5678")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentPort));
+ // check environment property priorities
+ assertEquals((Integer) 1234, SystemLambda
+ .withEnvironmentVariable(TARGET_PORT_PROPERTY, "1234")
+ .and(DD_AGENT_PORT, "5678")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentPort));
+ }
+
+ @Test
+ public void testGetDefaultAgentLogCollectionPort() throws Exception {
+ // check default value
+ assertEquals(DEFAULT_LOG_COLLECTION_PORT_VALUE, DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentLogCollectionPort());
+ // check environment property overrides
+ assertEquals((Integer) 1234, SystemLambda
+ .withEnvironmentVariable(TARGET_LOG_COLLECTION_PORT_PROPERTY, "1234")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentLogCollectionPort));
+ }
+
+ @Test
+ public void testGetDefaultAgentTraceCollectionPort() throws Exception {
+ // check default value
+ assertEquals(DEFAULT_TRACE_COLLECTION_PORT_VALUE, DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentTraceCollectionPort());
+ // check environment property overrides
+ assertEquals((Integer) 1234, SystemLambda
+ .withEnvironmentVariable(TARGET_TRACE_COLLECTION_PORT_PROPERTY, "1234")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentTraceCollectionPort));
+ assertEquals((Integer) 2468, SystemLambda
+ .withEnvironmentVariable(DD_TRACE_AGENT_URL, "http://agent-host:2468")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentTraceCollectionPort));
+ assertEquals((Integer) 5678, SystemLambda
+ .withEnvironmentVariable(DD_TRACE_AGENT_PORT, "5678")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentTraceCollectionPort));
+ // check environment property priorities
+ assertEquals((Integer) 1234, SystemLambda
+ .withEnvironmentVariable(TARGET_TRACE_COLLECTION_PORT_PROPERTY, "1234")
+ .and(DD_TRACE_AGENT_URL, "http://agent-host:2468")
+ .and(DD_TRACE_AGENT_PORT, "5678")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentTraceCollectionPort));
+ assertEquals((Integer) 2468, SystemLambda
+ .withEnvironmentVariable(DD_TRACE_AGENT_URL, "http://agent-host:2468")
+ .and(DD_TRACE_AGENT_PORT, "5678")
+ .execute(DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor::getDefaultAgentTraceCollectionPort));
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrlsTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrlsTest.java
new file mode 100644
index 000000000..ede3d8fbb
--- /dev/null
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrlsTest.java
@@ -0,0 +1,53 @@
+package org.datadog.jenkins.plugins.datadog.configuration.api.intake;
+
+import static org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeUrls.DEFAULT_API_URL_VALUE;
+import static org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeUrls.DEFAULT_LOG_INTAKE_URL_VALUE;
+import static org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeUrls.DEFAULT_WEBHOOK_INTAKE_URL_VALUE;
+import static org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeUrls.TARGET_API_URL_PROPERTY;
+import static org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeUrls.TARGET_LOG_INTAKE_URL_PROPERTY;
+import static org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeUrls.TARGET_WEBHOOK_INTAKE_URL_PROPERTY;
+import static org.junit.Assert.assertEquals;
+
+import com.github.stefanbirkner.systemlambda.SystemLambda;
+import org.junit.Test;
+
+public class DatadogIntakeUrlsTest {
+
+ @Test
+ public void testGetSiteName() {
+ for (DatadogSite site : DatadogSite.values()) {
+ DatadogIntakeUrls intakeUrls = new DatadogIntakeUrls(site.getApiUrl(), site.getLogsUrl(), site.getWebhooksUrl());
+ assertEquals(site.getSiteName(), intakeUrls.getSiteName());
+ }
+ }
+
+ @Test
+ public void testGetDefaultApiUrl() throws Exception {
+ // check default value
+ assertEquals(DEFAULT_API_URL_VALUE, DatadogIntakeUrls.DatadogIntakeUrlsDescriptor.getDefaultApiUrl());
+ // check environment property overrides
+ assertEquals("overridden-url", SystemLambda
+ .withEnvironmentVariable(TARGET_API_URL_PROPERTY, "overridden-url")
+ .execute(DatadogIntakeUrls.DatadogIntakeUrlsDescriptor::getDefaultApiUrl));
+ }
+
+ @Test
+ public void testGetDefaultLogIntakeUrl() throws Exception {
+ // check default value
+ assertEquals(DEFAULT_LOG_INTAKE_URL_VALUE, DatadogIntakeUrls.DatadogIntakeUrlsDescriptor.getDefaultLogsUrl());
+ // check environment property overrides
+ assertEquals("overridden-url", SystemLambda
+ .withEnvironmentVariable(TARGET_LOG_INTAKE_URL_PROPERTY, "overridden-url")
+ .execute(DatadogIntakeUrls.DatadogIntakeUrlsDescriptor::getDefaultLogsUrl));
+ }
+
+ @Test
+ public void testGetDefaultWebhookIntakeUrl() throws Exception {
+ // check default value
+ assertEquals(DEFAULT_WEBHOOK_INTAKE_URL_VALUE, DatadogIntakeUrls.DatadogIntakeUrlsDescriptor.getDefaultWebhooksUrl());
+ // check environment property overrides
+ assertEquals("overridden-url", SystemLambda
+ .withEnvironmentVariable(TARGET_WEBHOOK_INTAKE_URL_PROPERTY, "overridden-url")
+ .execute(DatadogIntakeUrls.DatadogIntakeUrlsDescriptor::getDefaultWebhooksUrl));
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKeyTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKeyTest.java
new file mode 100644
index 000000000..a7026e02e
--- /dev/null
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKeyTest.java
@@ -0,0 +1,43 @@
+package org.datadog.jenkins.plugins.datadog.configuration.api.key;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import com.cloudbees.plugins.credentials.CredentialsProvider;
+import com.cloudbees.plugins.credentials.CredentialsScope;
+import com.cloudbees.plugins.credentials.CredentialsStore;
+import com.cloudbees.plugins.credentials.domains.Domain;
+import hudson.util.Secret;
+import org.jenkinsci.plugins.plaincredentials.StringCredentials;
+import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
+
+public class DatadogCredentialsApiKeyTest {
+
+ @ClassRule
+ public static JenkinsRule jenkinsRule;
+
+ static {
+ jenkinsRule = new JenkinsRule();
+ jenkinsRule.timeout = 300; // default value of 180 is too small for all the test cases in this class
+ }
+
+ @Test
+ public void testCanGetCredentialFromId() throws Exception {
+ CredentialsStore credentialsStore = CredentialsProvider.lookupStores(jenkinsRule).iterator().next();
+
+ StringCredentials credential1 = new StringCredentialsImpl(CredentialsScope.SYSTEM, "string-cred-id", "description", Secret.fromString("api-key"));
+ credentialsStore.addCredentials(Domain.global(), credential1);
+ assertEquals(credential1, DatadogCredentialsApiKey.getCredentialFromId("string-cred-id"));
+
+ StringCredentials credential2 = new StringCredentialsImpl(CredentialsScope.SYSTEM, "string-cred-id2", "description", Secret.fromString("api-key"));
+ credentialsStore.addCredentials(Domain.global(), credential2);
+ assertEquals(credential1, DatadogCredentialsApiKey.getCredentialFromId("string-cred-id"));
+ assertEquals(credential2, DatadogCredentialsApiKey.getCredentialFromId("string-cred-id2"));
+
+ assertNull(DatadogCredentialsApiKey.getCredentialFromId("string-cred-id-fake"));
+ }
+
+}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKeyTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKeyTest.java
new file mode 100644
index 000000000..74c2ccdc9
--- /dev/null
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKeyTest.java
@@ -0,0 +1,22 @@
+package org.datadog.jenkins.plugins.datadog.configuration.api.key;
+
+import static org.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogTextApiKey.TARGET_API_KEY_PROPERTY;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import com.github.stefanbirkner.systemlambda.SystemLambda;
+import hudson.util.Secret;
+import org.junit.Test;
+
+public class DatadogTextApiKeyTest {
+
+ @Test
+ public void testGetDefaultApiKey() throws Exception {
+ // check default value
+ assertNull(DatadogTextApiKey.DatadogTextApiKeyDescriptor.getDefaultKey());
+ // check environment property overrides
+ assertEquals(Secret.fromString("an-api-key"), SystemLambda
+ .withEnvironmentVariable(TARGET_API_KEY_PROPERTY, "an-api-key")
+ .execute(DatadogTextApiKey.DatadogTextApiKeyDescriptor::getDefaultKey));
+ }
+}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/util/config/DatadogAgentConfigurationTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/util/config/DatadogAgentConfigurationTest.java
deleted file mode 100644
index 6569e7fa3..000000000
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/util/config/DatadogAgentConfigurationTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package org.datadog.jenkins.plugins.datadog.util.config;
-
-import static org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration.DD_AGENT_HOST;
-import static org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration.DD_AGENT_PORT;
-import static org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration.DD_TRACE_AGENT_PORT;
-import static org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration.DD_TRACE_AGENT_URL;
-import static org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration.TARGET_HOST_PROPERTY;
-import static org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration.TARGET_PORT_PROPERTY;
-import static org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration.TARGET_TRACE_COLLECTION_PORT_PROPERTY;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class DatadogAgentConfigurationTest {
-
- @Test
- public void testResolveEmptyConfig() {
- final DatadogAgentConfiguration config = DatadogAgentConfiguration.resolve(new HashMap<>());
- assertNull(config.getHost());
- assertNull(config.getPort());
- assertNull(config.getTracesPort());
- }
-
- @Test
- public void testResolveGenericEnvVars() {
- final Map envVars = new HashMap<>();
- envVars.put(DD_AGENT_HOST, "localhost");
- envVars.put(DD_AGENT_PORT, "8125");
- envVars.put(DD_TRACE_AGENT_PORT, "8126");
- final DatadogAgentConfiguration config = DatadogAgentConfiguration.resolve(envVars);
- assertEquals("localhost", config.getHost());
- assertEquals(Integer.valueOf(8125), config.getPort());
- assertEquals(Integer.valueOf(8126), config.getTracesPort());
- }
-
- @Test
- public void testResolveUsingTraceUrl() {
- final Map usingTraceUrl = new HashMap<>();
- usingTraceUrl.put(DD_TRACE_AGENT_URL, "http://localhost:8126");
- usingTraceUrl.put(DD_AGENT_PORT, "8125");
-
- final DatadogAgentConfiguration config = DatadogAgentConfiguration.resolve(usingTraceUrl);
- assertEquals("localhost", config.getHost());
- assertEquals(Integer.valueOf(8125), config.getPort());
- assertEquals(Integer.valueOf(8126), config.getTracesPort());
- }
-
- @Test
- public void testResolveSpecificEnvVars() {
- final Map envVars = new HashMap<>();
- envVars.put(TARGET_HOST_PROPERTY, "localhost");
- envVars.put(TARGET_PORT_PROPERTY, "8125");
- envVars.put(TARGET_TRACE_COLLECTION_PORT_PROPERTY, "8126");
-
- final DatadogAgentConfiguration config = DatadogAgentConfiguration.resolve(envVars);
- assertEquals("localhost", config.getHost());
- assertEquals(Integer.valueOf(8125), config.getPort());
- assertEquals(Integer.valueOf(8126), config.getTracesPort());
- }
-
- @Test
- public void testPrevalenceSpecificEnvVars() {
- final Map envVars = new HashMap<>();
- envVars.put(DD_AGENT_HOST, "some-host");
- envVars.put(DD_AGENT_PORT, "1111");
- envVars.put(DD_TRACE_AGENT_PORT, "1112");
- envVars.put(TARGET_HOST_PROPERTY, "localhost");
- envVars.put(TARGET_PORT_PROPERTY, "8125");
- envVars.put(TARGET_TRACE_COLLECTION_PORT_PROPERTY, "8126");
-
- final DatadogAgentConfiguration config = DatadogAgentConfiguration.resolve(envVars);
- assertEquals("localhost", config.getHost());
- assertEquals(Integer.valueOf(8125), config.getPort());
- assertEquals(Integer.valueOf(8126), config.getTracesPort());
- }
-
- @Test
- public void testPrevalenceTraceUrlEnvVars() {
- final Map envVars = new HashMap<>();
- envVars.put(DD_TRACE_AGENT_URL, "http://localhost:8126");
- envVars.put(DD_AGENT_PORT, "8125");
- envVars.put(DD_TRACE_AGENT_PORT, "1112");
-
- final DatadogAgentConfiguration config = DatadogAgentConfiguration.resolve(envVars);
- assertEquals("localhost", config.getHost());
- assertEquals(Integer.valueOf(8125), config.getPort());
- assertEquals(Integer.valueOf(8126), config.getTracesPort());
- }
-
-}
\ No newline at end of file
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/util/conversion/DatadogActionConverterTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/util/conversion/DatadogActionConverterTest.java
index 9ae1ad01c..48e0ddfc0 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/util/conversion/DatadogActionConverterTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/util/conversion/DatadogActionConverterTest.java
@@ -1,5 +1,6 @@
package org.datadog.jenkins.plugins.datadog.util.conversion;
+import static org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter.ignoreOldData;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -73,9 +74,9 @@ private static final class MyClass {
private int deserializedWithVersion;
}
- private static final class MyConverter extends DatadogActionConverter {
+ private static final class MyConverter extends DatadogConverter {
public MyConverter() {
- super(new MyVersionedConverter(1), new MyVersionedConverter(2), new MyVersionedConverter(3));
+ super(ignoreOldData(), new MyVersionedConverter(1), new MyVersionedConverter(2), new MyVersionedConverter(3));
}
}
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfiguration.xml b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfiguration.xml
new file mode 100644
index 000000000..04d843885
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfiguration.xml
@@ -0,0 +1,30 @@
+
+
+
+
+ https://my-api-url.com/api/
+ https://my-log-intake-url.com/v1/input/
+ https://my-webhook-intake-url.com/api/v2/webhook/
+
+
+ {AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}
+
+
+ my-jenkins-service-name
+ my-hostname
+ my-blacklist
+ my-whitelist
+ my-global-tag-file
+ my-global-tags
+ my-global-job-tags
+ my-include-events
+ my-exclude-evens
+ false
+ false
+ true
+ true
+ false
+ true
+ false
+ true
+
\ No newline at end of file
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationAgent.xml b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationAgent.xml
new file mode 100644
index 000000000..d75bfd322
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationAgent.xml
@@ -0,0 +1,26 @@
+
+
+
+ my-agent-host
+ 9876
+ 8765
+ 7654
+
+ my-jenkins-service-name
+ my-hostname
+ my-blacklist
+ my-whitelist
+ my-global-tag-file
+ my-global-tags
+ my-global-job-tags
+ my-include-events
+ my-exclude-evens
+ true
+ true
+ true
+ true
+ true
+ true
+ true
+ true
+
\ No newline at end of file
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationCredentialsKey.xml b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationCredentialsKey.xml
new file mode 100644
index 000000000..8b2b22f6e
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationCredentialsKey.xml
@@ -0,0 +1,30 @@
+
+
+
+
+ https://my-api-url.com/api/
+ https://my-log-intake-url.com/v1/input/
+ https://my-webhook-intake-url.com/api/v2/webhook/
+
+
+ my-api-key-credentials-id
+
+
+ my-jenkins-service-name
+ my-hostname
+ my-blacklist
+ my-whitelist
+ my-global-tag-file
+ my-global-tags
+ my-global-job-tags
+ my-include-events
+ my-exclude-evens
+ false
+ false
+ true
+ true
+ false
+ true
+ false
+ true
+
\ No newline at end of file
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormat.xml b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormat.xml
new file mode 100644
index 000000000..6fd220dbd
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormat.xml
@@ -0,0 +1,31 @@
+
+
+ HTTP
+ my-target-api-url
+ my-target-log-intake-url
+ my-target-webhook-intake-url
+ {AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}
+ {AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}
+ datadog
+ 1357
+ 2468
+ 3579
+ my-jenkins-service-name
+ my-hostname
+ my-blacklist
+ my-whitelist
+ my-global-tag-file
+ my-global-tags
+ my-global-job-tags
+ my-include-events
+ my-exclude-evens
+ false
+ false
+ true
+ true
+ true
+ false
+ true
+ false
+ true
+
\ No newline at end of file
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormatAgent.xml b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormatAgent.xml
new file mode 100644
index 000000000..ec7e20d3a
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormatAgent.xml
@@ -0,0 +1,32 @@
+
+
+ DSD
+ my-target-api-url
+ my-target-log-intake-url
+ my-target-webhook-intake-url
+ {AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}
+ target-credentials-api-key
+ {AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}
+ datadog
+ 1357
+ 2468
+ 3579
+ my-jenkins-service-name
+ my-hostname
+ my-blacklist
+ my-whitelist
+ my-global-tag-file
+ my-global-tags
+ my-global-job-tags
+ my-include-events
+ my-exclude-evens
+ true
+ true
+ false
+ false
+ false
+ true
+ false
+ true
+ false
+
\ No newline at end of file
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormatCredentialsKey.xml b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormatCredentialsKey.xml
new file mode 100644
index 000000000..785c89c84
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormatCredentialsKey.xml
@@ -0,0 +1,32 @@
+
+
+ HTTP
+ my-target-api-url
+ my-target-log-intake-url
+ my-target-webhook-intake-url
+ {AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}
+ target-credentials-api-key
+ {AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}
+ datadog
+ 1357
+ 2468
+ 3579
+ my-jenkins-service-name
+ my-hostname
+ my-blacklist
+ my-whitelist
+ my-global-tag-file
+ my-global-tags
+ my-global-job-tags
+ my-include-events
+ my-exclude-evens
+ false
+ false
+ true
+ true
+ true
+ false
+ true
+ false
+ true
+
\ No newline at end of file
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormatCredentialsKeyEmpty.xml b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormatCredentialsKeyEmpty.xml
new file mode 100644
index 000000000..d5b3437fc
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationLegacyFormatCredentialsKeyEmpty.xml
@@ -0,0 +1,32 @@
+
+
+ HTTP
+ my-target-api-url
+ my-target-log-intake-url
+ my-target-webhook-intake-url
+ {AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}
+
+ {AQAAABAAAAAwB78atDHwzelG9W0Fw5FRNq0ZUaLh1BwpQPKhvs2u84lxkRPDqeUNoVZel+MKwfyTOjuetnituHYGMdvE9bc3kg==}
+ datadog
+ 1357
+ 2468
+ 3579
+ my-jenkins-service-name
+ my-hostname
+ my-blacklist
+ my-whitelist
+ my-global-tag-file
+ my-global-tags
+ my-global-job-tags
+ my-include-events
+ my-exclude-evens
+ false
+ false
+ true
+ true
+ true
+ false
+ true
+ false
+ true
+
\ No newline at end of file
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationSite.xml b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationSite.xml
new file mode 100644
index 000000000..d16f6a64f
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/globalConfigurationSite.xml
@@ -0,0 +1,28 @@
+
+
+
+
+ US3
+
+
+ my-api-key-credentials-id
+
+
+ my-jenkins-service-name
+ my-hostname
+ my-blacklist
+ my-whitelist
+ my-global-tag-file
+ my-global-tags
+ my-global-job-tags
+ my-include-events
+ my-exclude-evens
+ false
+ false
+ true
+ true
+ false
+ true
+ false
+ true
+
\ No newline at end of file
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-agent.yml b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-agent.yml
new file mode 100644
index 000000000..9262bf2e8
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-agent.yml
@@ -0,0 +1,27 @@
+jenkins:
+ systemMessage: "Example of configuring datadog in Jenkins"
+
+unclassified:
+ datadogGlobalConfiguration:
+ datadogClientConfiguration:
+ datadogAgentConfiguration:
+ agentHost: 'my-agent-host'
+ agentPort: 1357
+ agentLogCollectionPort: 2468
+ agentTraceCollectionPort: 3579
+ enableCiVisibility: true
+ ciInstanceName: 'my-ci-instance-name'
+ excluded: 'my-excluded'
+ included: 'my-included'
+ hostname: 'my-hostname'
+ globalTagFile: 'my-global-tag-file'
+ globalTags: 'my-global-tags'
+ globalJobTags: 'my-global-job-tags'
+ includeEvents: 'my-include-events'
+ excludeEvents: 'my-exclude-events'
+ emitSecurityEvents: false
+ emitSystemEvents: false
+ collectBuildLogs: false
+ refreshDogstatsdClient: false
+ cacheBuildRuns: false
+ useAwsInstanceHostname: false
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-legacy-agent.yml b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-legacy-agent.yml
new file mode 100644
index 000000000..b40a88907
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-legacy-agent.yml
@@ -0,0 +1,27 @@
+jenkins:
+ systemMessage: "Example of configuring datadog in Jenkins"
+
+unclassified:
+ datadogGlobalConfiguration:
+ reportWith: 'DSD'
+ targetHost: 'my-target-host'
+ targetPort: 1357
+ targetLogCollectionPort: 2468
+ targetTraceCollectionPort: 3579
+ collectBuildTraces: false
+ traceServiceName: 'my-trace-service-name'
+ blacklist: 'my-blacklist'
+ whitelist: 'my-whitelist'
+ hostname: 'my-hostname'
+ globalTagFile: 'my-global-tag-file'
+ globalTags: 'my-global-tags'
+ globalJobTags: 'my-global-job-tags'
+ includeEvents: 'my-include-events'
+ excludeEvents: 'my-exclude-events'
+ emitConfigChangeEvents: false
+ emitSecurityEvents: true
+ emitSystemEvents: false
+ collectBuildLogs: true
+ refreshDogstatsdClient: true
+ cacheBuildRuns: false
+ useAwsInstanceHostname: true
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-legacy.yml b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-legacy.yml
new file mode 100644
index 000000000..4d54cb26d
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-legacy.yml
@@ -0,0 +1,30 @@
+jenkins:
+ systemMessage: "Example of configuring datadog in Jenkins"
+
+unclassified:
+ datadogGlobalConfiguration:
+ reportWith: 'HTTP'
+ targetCredentialsApiKey: 'my-target-credentials-api-key'
+ targetApiURL: 'my-target-api-url'
+ targetLogIntakeURL: 'my-target-log-intake-url'
+ targetWebhookIntakeURL: 'my-target-webhook-intake-url'
+ collectBuildTraces: true
+ traceServiceName: 'my-trace-service-name'
+ blacklist: 'my-blacklist'
+ whitelist: 'my-whitelist'
+ hostname: 'my-hostname'
+ globalTagFile: 'my-global-tag-file'
+ globalTags: 'my-global-tags'
+ globalJobTags: 'my-global-job-tags'
+ includeEvents: 'my-include-events'
+ excludeEvents: 'my-exclude-events'
+ emitConfigChangeEvents: true
+ emitSecurityEvents: false
+ emitSystemEvents: true
+ collectBuildLogs: false
+ refreshDogstatsdClient: false
+ cacheBuildRuns: true
+ useAwsInstanceHostname: false
+
+
+
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-site.yml b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-site.yml
new file mode 100644
index 000000000..067fbbe2d
--- /dev/null
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config-site.yml
@@ -0,0 +1,29 @@
+jenkins:
+ systemMessage: "Example of configuring datadog in Jenkins"
+
+unclassified:
+ datadogGlobalConfiguration:
+ datadogClientConfiguration:
+ datadogApiConfiguration:
+ intake:
+ datadogIntakeSite:
+ site: 'US3'
+ apiKey:
+ datadogCredentialsApiKey:
+ credentialsId: 'my-api-key-credentials-id'
+ enableCiVisibility: true
+ ciInstanceName: 'my-ci-instance-name'
+ excluded: 'my-excluded'
+ included: 'my-included'
+ hostname: 'my-hostname'
+ globalTagFile: 'my-global-tag-file'
+ globalTags: 'my-global-tags'
+ globalJobTags: 'my-global-job-tags'
+ includeEvents: 'my-include-events'
+ excludeEvents: 'my-exclude-events'
+ emitSecurityEvents: true
+ emitSystemEvents: true
+ collectBuildLogs: true
+ refreshDogstatsdClient: true
+ cacheBuildRuns: true
+ useAwsInstanceHostname: true
diff --git a/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config.yml b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config.yml
index c27db3948..f399472c6 100644
--- a/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config.yml
+++ b/src/test/resources/org/datadog/jenkins/plugins/datadog/test-config.yml
@@ -2,7 +2,30 @@ jenkins:
systemMessage: "Example of configuring datadog in Jenkins"
unclassified:
- datadogGlobalConfiguration:
- reportWith: 'HTTP'
- targetApiKey: 'test'
- emitConfigChangeEvents: true
+ datadogGlobalConfiguration:
+ datadogClientConfiguration:
+ datadogApiConfiguration:
+ intake:
+ datadogIntakeUrls:
+ apiUrl: 'my-api-url'
+ logsUrl: 'my-log-intake-url'
+ webhooksUrl: 'my-webhook-intake-url'
+ apiKey:
+ datadogCredentialsApiKey:
+ credentialsId: 'my-api-key-credentials-id'
+ enableCiVisibility: true
+ ciInstanceName: 'my-ci-instance-name'
+ excluded: 'my-excluded'
+ included: 'my-included'
+ hostname: 'my-hostname'
+ globalTagFile: 'my-global-tag-file'
+ globalTags: 'my-global-tags'
+ globalJobTags: 'my-global-job-tags'
+ includeEvents: 'my-include-events'
+ excludeEvents: 'my-exclude-events'
+ emitSecurityEvents: true
+ emitSystemEvents: true
+ collectBuildLogs: true
+ refreshDogstatsdClient: true
+ cacheBuildRuns: true
+ useAwsInstanceHostname: true