From ac5d5e125e1d7e388edc2130d3a03ca5ba684de0 Mon Sep 17 00:00:00 2001 From: ektavarma10 Date: Tue, 14 Nov 2023 14:45:17 +0530 Subject: [PATCH] Add metric counter when authenticating a request from a service-account --- .../web/security/AtlasKeycloakAuthenticationProvider.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java index 367839b82a..40b9fba612 100644 --- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java +++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java @@ -16,6 +16,8 @@ */ package org.apache.atlas.web.security; +import io.micrometer.core.instrument.Counter; +import org.apache.atlas.service.metrics.MetricUtils; import org.apache.atlas.ApplicationProperties; import org.apache.commons.configuration.Configuration; import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider; @@ -66,6 +68,11 @@ public Authentication authenticate(Authentication authentication) { } } + if(authentication.getName().startsWith("service-account-apikey")) { + // Increment the counter when the authentication is for a service account. + Counter.builder("service_account_apikey_request_counter").register(MetricUtils.getMeterRegistry()).increment(); + } + return authentication; }