From 3ddb1fc99b22eaf7d7475d7db2dfad0bd9031955 Mon Sep 17 00:00:00 2001 From: Shivansh Dhar Date: Fri, 5 Oct 2018 10:58:30 -0700 Subject: [PATCH] config(Datadog): Add custom Datadog tags option (#1049) --- docs/commands.md | 5 +++- .../deploy/ha/EchoHaServiceCommand.java | 2 +- .../datadog/EditDatadogCommand.java | 29 +++++++++++++++++++ .../v1/metricStores/datadog/DatadogStore.java | 6 ++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 1286ad83cb..8723a64d6e 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -3150,7 +3150,7 @@ hal config deploy ha clouddriver enable [parameters] --- ## hal config deploy ha echo -Manage and view Spinnaker configuration for the echo high availability service Manage and view Spinnaker configuration for the echo high availability service. When echo high availability is enabled, Halyard will deploy echo as two separate services in order to increase availability: echo-scheduler and echo-worker. The echo-scheduler service only handles Spinnaker cron-jobs and is isolated from the rest of Spinnaker.. The echo-worker handles everything else. +Manage and view Spinnaker configuration for the echo high availability service Manage and view Spinnaker configuration for the echo high availability service. When echo high availability is enabled, Halyard will deploy echo as two separate services in order to increase availability: echo-scheduler and echo-worker. The echo-scheduler service only handles Spinnaker cron-jobs and is isolated from the rest of Spinnaker. The echo-worker handles everything else. #### Usage ``` @@ -3347,10 +3347,13 @@ hal config metric-stores datadog edit [parameters] ``` #### Parameters + * `--add-tag`: Add this tag to the list of Datadog tags. * `--api-key`: Your datadog API key. * `--app-key`: Your datadog app key. This is only required if you want Spinnaker to push pre-configured Spinnaker dashboards to your Datadog account. * `--deployment`: If supplied, use this Halyard deployment. This will _not_ create a new deployment. * `--no-validate`: (*Default*: `false`) Skip validation. + * `--remove-tag`: Remove this tag from the list of Datadog tags. + * `--tags`: (*Default*: `[]`) Your datadog custom tags. Please delimit the KVP with colons i.e. --tags app:test env:dev --- diff --git a/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/deploy/ha/EchoHaServiceCommand.java b/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/deploy/ha/EchoHaServiceCommand.java index 5594d8cabe..5d254ecb1c 100644 --- a/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/deploy/ha/EchoHaServiceCommand.java +++ b/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/deploy/ha/EchoHaServiceCommand.java @@ -34,6 +34,6 @@ public class EchoHaServiceCommand extends AbstractNamedHaServiceCommand { "When echo high availability is enabled, Halyard will deploy echo as two", "separate services in order to increase availability: echo-scheduler and echo-worker.", "The echo-scheduler service only handles Spinnaker cron-jobs and is isolated from", - "the rest of Spinnaker.. The echo-worker handles everything else." + "the rest of Spinnaker. The echo-worker handles everything else." ); } diff --git a/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/metricStores/datadog/EditDatadogCommand.java b/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/metricStores/datadog/EditDatadogCommand.java index 6e463de5a4..5ff409051b 100644 --- a/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/metricStores/datadog/EditDatadogCommand.java +++ b/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/metricStores/datadog/EditDatadogCommand.java @@ -24,6 +24,9 @@ import com.netflix.spinnaker.halyard.config.model.v1.node.MetricStore; import com.netflix.spinnaker.halyard.config.model.v1.node.MetricStores; +import java.util.ArrayList; +import java.util.List; + @Parameters(separators = "=") public class EditDatadogCommand extends AbstractEditMetricStoreCommand { public MetricStores.MetricStoreType getMetricStoreType() { @@ -42,11 +45,37 @@ public MetricStores.MetricStoreType getMetricStoreType() { ) private String appKey; + @Parameter( + names = "--tags", + variableArity = true, + description = "Your datadog custom tags. Please delimit the KVP with colons i.e. --tags app:test env:dev" + ) + private List tags = new ArrayList<>(); + + @Parameter( + names = "--add-tag", + description = "Add this tag to the list of Datadog tags." + ) + private String addTag; + + @Parameter( + names = "--remove-tag", + description = "Remove this tag from the list of Datadog tags." + ) + private String removeTag; + @Override protected MetricStore editMetricStore(DatadogStore datadogStore) { datadogStore.setApiKey(isSet(apiKey) ? apiKey : datadogStore.getApiKey()); datadogStore.setAppKey(isSet(appKey) ? appKey : datadogStore.getAppKey()); + try { + datadogStore.setTags( + updateStringList(datadogStore.getTags(), tags, addTag, removeTag)); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("Set either --tags or --[add/remove]-tag"); + } + return datadogStore; } } diff --git a/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/metricStores/datadog/DatadogStore.java b/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/metricStores/datadog/DatadogStore.java index af9502285e..219cf8dabf 100644 --- a/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/metricStores/datadog/DatadogStore.java +++ b/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/metricStores/datadog/DatadogStore.java @@ -24,6 +24,9 @@ import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.ArrayList; +import java.util.List; + @EqualsAndHashCode(callSuper = true) @Data public class DatadogStore extends MetricStore { @@ -40,4 +43,7 @@ public String getNodeName() { @JsonProperty("app_key") private String appKey; + + @JsonProperty("tags") + private List tags = new ArrayList<>(); }