diff options
author | roger yuan <roger.yuan@yoppworks.com> | 2021-05-19 10:02:03 -0600 |
---|---|---|
committer | roger yuan <roger.yuan@yoppworks.com> | 2021-05-19 12:22:31 -0600 |
commit | 6180838e24698c885091d65603c6ce19c54853f4 (patch) | |
tree | 6ae837a5f437403adfcbb1c52c37c53140117534 /aai-traversal/src/main | |
parent | 7b0b01a41e7eacd40ba296dda474b7fcbc54a1cd (diff) |
[AAI] Export relevant key metrics for monitoring in Prometheus
Make the key metrics available to the monitoring system by
instrumenting the code.
The Key metrics are available via
/actuator/prometheus
/actuator/info
/actuator/health
Issue-ID: AAI-3343
Signed-off-by: Roger Yuan <roger.yuan@yoppworks.com>
Change-Id: If72858484231d95a39c938bacfc1773430806e5a
Diffstat (limited to 'aai-traversal/src/main')
6 files changed, 80 insertions, 1 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/DslConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/DslConsumer.java index 41a3a3c..fefd2dc 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/DslConsumer.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/DslConsumer.java @@ -22,6 +22,7 @@ package org.onap.aai.rest; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import io.micrometer.core.annotation.Timed; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.janusgraph.core.SchemaViolationException; import org.onap.aai.concurrent.AaiCallable; @@ -58,6 +59,7 @@ import java.util.*; import java.util.stream.Collectors; @Path("{version: v[1-9][0-9]*|latest}/dsl") +@Timed public class DslConsumer extends TraversalConsumer { private HttpEntry traversalUriHttpEntry; diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java index affee3a..e015ec3 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java @@ -22,6 +22,7 @@ package org.onap.aai.rest; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import io.micrometer.core.annotation.Timed; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.onap.aai.concurrent.AaiCallable; @@ -62,6 +63,7 @@ import java.util.*; import java.util.stream.Collectors; @Path("{version: v[1-9][0-9]*|latest}/query") +@Timed public class QueryConsumer extends TraversalConsumer { private QueryProcessorType processorType = QueryProcessorType.LOCAL_GROOVY; diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/RecentAPIConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/RecentAPIConsumer.java index f2b88f3..7ec20bc 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/RecentAPIConsumer.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/RecentAPIConsumer.java @@ -19,6 +19,7 @@ */ package org.onap.aai.rest; +import io.micrometer.core.annotation.Timed; import org.onap.aai.concurrent.AaiCallable; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.ModelType; @@ -54,6 +55,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; @Path("/recents/{version: v[1-9][0-9]*|latest}") +@Timed public class RecentAPIConsumer extends RESTAPI { private static final String AAI_3021 = "AAI_3021"; diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java index 241cffd..1db2699 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java @@ -19,6 +19,7 @@ */ package org.onap.aai.rest.search; +import io.micrometer.core.annotation.Timed; import org.onap.aai.aailog.logs.AaiDBTraversalMetricLog; import org.onap.aai.concurrent.AaiCallable; import org.onap.aai.dbgraphmap.SearchGraph; @@ -59,6 +60,7 @@ import java.util.Optional; * X-TransactionId in the header. */ @Path("/{version: v[1-9][0-9]*|latest}/search") +@Timed public class SearchProvider extends RESTAPI { private static final Logger LOGGER = LoggerFactory.getLogger(SearchProvider.class); diff --git a/aai-traversal/src/main/java/org/onap/aai/web/MicrometerConfiguration.java b/aai-traversal/src/main/java/org/onap/aai/web/MicrometerConfiguration.java new file mode 100644 index 0000000..9b48dae --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/web/MicrometerConfiguration.java @@ -0,0 +1,60 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.web; +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Tags; +import io.micrometer.jersey2.server.JerseyTags; +import io.micrometer.jersey2.server.JerseyTagsProvider; +import org.glassfish.jersey.server.ContainerResponse; +import org.glassfish.jersey.server.monitoring.RequestEvent; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Configuration Class to add customized tags to http metrics scraped in /actuator/prometheus endpoint + */ +@Configuration +public class MicrometerConfiguration { + private static final String TAG_AAI_URI = "aai_uri"; + private static final String NOT_AVAILABLE = "NOT AVAILABLE"; + + @Bean + public JerseyTagsProvider jerseyTagsProvider() { + return new JerseyTagsProvider() { + @Override + public Iterable httpRequestTags(RequestEvent event) { + ContainerResponse response = event.getContainerResponse(); + return Tags.of(JerseyTags.method(event.getContainerRequest()), + JerseyTags.exception(event), JerseyTags.status(response), JerseyTags.outcome(response), getAaiUriTag(event)); + } + private Tag getAaiUriTag(RequestEvent event) { + String aai_uri = event.getUriInfo().getRequestUri().toString(); + if (aai_uri == null) { + aai_uri = NOT_AVAILABLE; + } + return Tag.of(TAG_AAI_URI, aai_uri); + } + @Override + public Iterable<Tag> httpLongRequestTags(RequestEvent event) { + return Tags.of(JerseyTags.method(event.getContainerRequest()), JerseyTags.uri(event)); + } + }; + } +} diff --git a/aai-traversal/src/main/resources/application.properties b/aai-traversal/src/main/resources/application.properties index a22f708..4ef501b 100644 --- a/aai-traversal/src/main/resources/application.properties +++ b/aai-traversal/src/main/resources/application.properties @@ -13,7 +13,8 @@ spring.autoconfigure.exclude=\ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ org.keycloak.adapters.springboot.KeycloakAutoConfiguration,\ - org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration + org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration, \ + org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration spring.jersey.application-path=${schema.uri.base.path} @@ -112,3 +113,13 @@ aaf.cadi.file=${server.local.startpath}/cadi.properties history.enabled=false; history.truncate.window.days=365 + +#To Expose the Prometheus scraping endpoint +management.server.port=8448 +#To Enable Actuator Endpoint, you can override this to True in OOM charts +management.endpoints.enabled-by-default=false +#To Enable Actuator Endpoint, you can override this in OOM Charts +#management.endpoints.web.exposure.include=info, health, prometheus +management.metrics.web.server.auto-time-requests=false +management.metrics.tags.group_id=aai +management.metrics.tags.app_id=${info.build.artifact} |