diff options
author | gjoranv <gv@verizonmedia.com> | 2020-02-27 14:48:04 +0100 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2020-02-27 15:46:50 +0100 |
commit | 3f75d479cc5040732340b48f8a8450a40561ba86 (patch) | |
tree | 86d4a41c59db1aa874673107aec428a69f86280f | |
parent | ccc613e98f3b2cd0f69cb48715646c7093da8134 (diff) |
Modify xml syntax for cloudwatch
- Group access+secret key in new element 'credentials'
- Move 'profile' into new element 'shared-credentials'
5 files changed, 37 insertions, 24 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/builder/xml/XmlHelper.java b/config-model/src/main/java/com/yahoo/config/model/builder/xml/XmlHelper.java index a9677d4b34c..4cd0c1815dd 100644 --- a/config-model/src/main/java/com/yahoo/config/model/builder/xml/XmlHelper.java +++ b/config-model/src/main/java/com/yahoo/config/model/builder/xml/XmlHelper.java @@ -133,6 +133,11 @@ public final class XmlHelper { return Optional.ofNullable(element.getAttribute(name)).filter(s -> !s.isEmpty()); } + public static Optional<Element> getOptionalChild(Element parent, String childName) { + return Optional.ofNullable(XML.getChild(parent, childName)); + + } + public static Optional<String> getOptionalChildValue(Element parent, String childName) { Element child = XML.getChild(parent, childName); if (child == null) return Optional.empty(); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/builder/xml/CloudWatchBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/builder/xml/CloudWatchBuilder.java index 4b9d5542aa9..74a389b0c9e 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/builder/xml/CloudWatchBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/builder/xml/CloudWatchBuilder.java @@ -5,7 +5,7 @@ import com.yahoo.vespa.model.admin.monitoring.CloudWatch.HostedAuth; import com.yahoo.vespa.model.admin.monitoring.MetricsConsumer; import org.w3c.dom.Element; -import static com.yahoo.config.model.builder.xml.XmlHelper.getOptionalChildValue; +import static com.yahoo.config.model.builder.xml.XmlHelper.getOptionalChild; /** * @author gjoranv @@ -14,22 +14,23 @@ public class CloudWatchBuilder { private static final String REGION_ATTRIBUTE = "region"; private static final String NAMESPACE_ATTRIBUTE = "namespace"; - private static final String ACCESS_KEY_ELEMENT = "access-key-name"; - private static final String SECRET_KEY_ELEMENT = "secret-key-name"; - private static final String PROFILE_ELEMENT = "profile"; + private static final String CREDENTIALS_ELEMENT = "credentials"; + private static final String ACCESS_KEY_ATTRIBUTE = "access-key-name"; + private static final String SECRET_KEY_ATTRIBUTE = "secret-key-name"; + private static final String SHARED_CREDENTIALS_ELEMENT = "shared-credentials"; + private static final String PROFILE_ATTRIBUTE = "profile"; public static CloudWatch buildCloudWatch(Element cloudwatchElement, MetricsConsumer consumer) { CloudWatch cloudWatch = new CloudWatch(cloudwatchElement.getAttribute(REGION_ATTRIBUTE), cloudwatchElement.getAttribute(NAMESPACE_ATTRIBUTE), consumer); - getOptionalChildValue(cloudwatchElement, PROFILE_ELEMENT).ifPresent(cloudWatch::setProfile); + getOptionalChild(cloudwatchElement, CREDENTIALS_ELEMENT) + .ifPresent(elem -> cloudWatch.setHostedAuth(new HostedAuth(elem.getAttribute(ACCESS_KEY_ATTRIBUTE), + elem.getAttribute(SECRET_KEY_ATTRIBUTE)))); + getOptionalChild(cloudwatchElement, SHARED_CREDENTIALS_ELEMENT) + .ifPresent(elem -> cloudWatch.setProfile(elem.getAttribute(PROFILE_ATTRIBUTE))); - getOptionalChildValue(cloudwatchElement, ACCESS_KEY_ELEMENT) - .ifPresent(accessKey -> cloudWatch.setHostedAuth( - new HostedAuth(accessKey, - getOptionalChildValue(cloudwatchElement, SECRET_KEY_ELEMENT) - .orElseThrow(() -> new IllegalArgumentException("Access key given without a secret key."))))); return cloudWatch; } diff --git a/config-model/src/main/resources/schema/admin.rnc b/config-model/src/main/resources/schema/admin.rnc index e3ba7dc500d..f4585b3cf3f 100644 --- a/config-model/src/main/resources/schema/admin.rnc +++ b/config-model/src/main/resources/schema/admin.rnc @@ -91,14 +91,16 @@ Cloudwatch = element cloudwatch { attribute region { xsd:Name } & attribute namespace { xsd:string { pattern = "[\w_\-/#:\.]+" } } & ( - ( - element access-key-name { xsd:Name } & - element secret-key-name { xsd:Name } - ) + element credentials { + attribute access-key-name { xsd:Name } & + attribute secret-key-name { xsd:Name } + } | - element profile { xsd:Name } + element shared-credentials { + attribute profile { xsd:Name } & + attribute file { string }? + } )? - } ClusterControllers = element cluster-controllers { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/TelegrafTest.java b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/TelegrafTest.java index dbcbad7bf49..9be94e4198e 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/TelegrafTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/TelegrafTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; /** * @author gjoranv @@ -53,6 +54,7 @@ public class TelegrafTest { String services = servicesWithCloudwatch(); VespaModel hostedModel = getModel(services, hosted); TelegrafConfig config = hostedModel.getConfig(TelegrafConfig.class, CLUSTER_CONFIG_ID); + assertTrue(config.isHostedVespa()); var cloudWatch0 = config.cloudWatch(0); assertEquals("cloudwatch-consumer", cloudWatch0.consumer()); @@ -72,8 +74,8 @@ public class TelegrafTest { " <consumer id='cloudwatch-consumer'>", " <metric id='my-metric'/>", " <cloudwatch region='us-east-1' namespace='my-namespace' >", - " <access-key-name>my-access-key</access-key-name>", - " <secret-key-name>my-secret-key</secret-key-name>", + " <credentials access-key-name='my-access-key' ", + " secret-key-name='my-secret-key' />", " </cloudwatch>", " </consumer>", " </metrics>", @@ -92,11 +94,11 @@ public class TelegrafTest { " <consumer id='cloudwatch-consumer'>", " <metric id='my-metric'/>", " <cloudwatch region='us-east-1' namespace='namespace-1' >", - " <access-key-name>access-key-1</access-key-name>", - " <secret-key-name>secret-key-1</secret-key-name>", + " <credentials access-key-name='access-key-1' ", + " secret-key-name='secret-key-1' />", " </cloudwatch>", " <cloudwatch region='us-east-1' namespace='namespace-2' >", - " <profile>profile-2</profile>", + " <shared-credentials profile='profile-2' />", " </cloudwatch>", " </consumer>", " </metrics>", diff --git a/config-model/src/test/schema-test-files/services.xml b/config-model/src/test/schema-test-files/services.xml index 604e2abbbae..0c395fedb96 100644 --- a/config-model/src/test/schema-test-files/services.xml +++ b/config-model/src/test/schema-test-files/services.xml @@ -15,26 +15,29 @@ <slobrok hostalias="rtc-1" /> </slobroks> <metrics> + <consumer id="cloudwatch-hosted"> <metric-set id="my-set" /> <metric id="my-metric"/> <metric id="my-metric2" display-name="my-metric3"/> <metric display-name="my-metric4" id="my-metric4.avg"/> <cloudwatch region="us-east1" namespace="my-namespace"> - <access-key-name>my-access-key</access-key-name> - <secret-key-name>my-secret-key</secret-key-name> + <credentials access-key-name="my-access-key" secret-key-name="my-secret-key" /> </cloudwatch> </consumer> + <consumer id="cloudwatch-self-hosted-with-default-auth"> <metric-set id="public" /> <cloudwatch region="us-east1" namespace="namespace_legal.chars:/#1" /> </consumer> + <consumer id="cloudwatch-self-hosted-with-profile"> <metric id="my-custom-metric" /> <cloudwatch region="us-east1" namespace="another-namespace"> - <profile>profile-in-credentials-file</profile> + <shared-credentials profile="profile-in-credentials-file" file="/user/.aws/credentials"/> </cloudwatch> </consumer> + </metrics> <logforwarding> <splunk deployment-server="foo:8989" client-name="foobar" splunk-home="/opt/splunk" phone-home-interval="900"/> |