diff options
author | Morten Tokle <mortent@verizonmedia.com> | 2020-11-09 08:42:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-09 08:42:32 +0100 |
commit | 158549f21554108c93062536ab34ee12fa19905f (patch) | |
tree | c61c2b03c48a9d6cb0b2b55d972a97b70ec53423 /controller-server | |
parent | 434567d25d1ccecbabf193ce1692be718ca11ea0 (diff) | |
parent | b0dfbc33a0078ac6f34c299f5626f2a4a5f3e77a (diff) |
Merge pull request #15202 from vespa-engine/mortent/athenz-error-handler
Report metrics on athenz client errors
Diffstat (limited to 'controller-server')
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/athenz/impl/AthenzClientFactoryImpl.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/athenz/impl/AthenzClientFactoryImpl.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/athenz/impl/AthenzClientFactoryImpl.java index 173729c7472..323d49e4639 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/athenz/impl/AthenzClientFactoryImpl.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/athenz/impl/AthenzClientFactoryImpl.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.athenz.impl; import com.google.inject.Inject; +import com.yahoo.jdisc.Metric; import com.yahoo.vespa.athenz.api.AthenzIdentity; import com.yahoo.vespa.athenz.client.zms.DefaultZmsClient; import com.yahoo.vespa.athenz.client.zms.ZmsClient; @@ -10,21 +11,32 @@ import com.yahoo.vespa.athenz.client.zts.ZtsClient; import com.yahoo.vespa.athenz.identity.ServiceIdentityProvider; import com.yahoo.vespa.hosted.controller.api.integration.athenz.AthenzClientFactory; import com.yahoo.vespa.hosted.controller.athenz.config.AthenzConfig; +import org.apache.http.client.methods.HttpUriRequest; import java.net.URI; +import java.util.HashMap; +import java.util.Map; /** * @author bjorncs */ public class AthenzClientFactoryImpl implements AthenzClientFactory { + private static final String METRIC_NAME = "athenz.request.error"; + private static final String ATHENZ_SERVICE_DIMENSION = "athenzService"; + private static final String EXCEPTION_DIMENSION = "exception"; + private final AthenzConfig config; private final ServiceIdentityProvider identityProvider; + private final Metric metrics; + private final Map<String, Metric.Context> metricContexts; @Inject - public AthenzClientFactoryImpl(ServiceIdentityProvider identityProvider, AthenzConfig config) { + public AthenzClientFactoryImpl(ServiceIdentityProvider identityProvider, AthenzConfig config, Metric metrics) { this.identityProvider = identityProvider; this.config = config; + this.metrics = metrics; + this.metricContexts = new HashMap<>(); } @Override @@ -37,7 +49,7 @@ public class AthenzClientFactoryImpl implements AthenzClientFactory { */ @Override public ZmsClient createZmsClient() { - return new DefaultZmsClient(URI.create(config.zmsUrl()), identityProvider); + return new DefaultZmsClient(URI.create(config.zmsUrl()), identityProvider, this::reportMetricErrorHandler); } /** @@ -45,7 +57,7 @@ public class AthenzClientFactoryImpl implements AthenzClientFactory { */ @Override public ZtsClient createZtsClient() { - return new DefaultZtsClient(URI.create(config.ztsUrl()), identityProvider); + return new DefaultZtsClient.Builder(URI.create(config.ztsUrl())).withIdentityProvider(identityProvider).build(); } @Override @@ -53,4 +65,11 @@ public class AthenzClientFactoryImpl implements AthenzClientFactory { return true; } + private void reportMetricErrorHandler(HttpUriRequest request, Exception error) { + String hostname = request.getURI().getHost(); + Metric.Context context = metricContexts.computeIfAbsent(hostname, host -> metrics.createContext( + Map.of(ATHENZ_SERVICE_DIMENSION, host, + EXCEPTION_DIMENSION, error.getClass().getSimpleName()))); + metrics.add(METRIC_NAME, 1, context); + } } |