Skip to content

Commit

Permalink
Merge pull request #148 from ruromero/latency
Browse files Browse the repository at this point in the history
feat: expose histograms for incoming and outgoing requests
  • Loading branch information
ruromero authored Sep 12, 2023
2 parents 7892442 + c81d8fa commit 4837200
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 4 deletions.
30 changes: 27 additions & 3 deletions dashboards/grafana-dashboard-exhort.configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,38 @@ data:
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum(rate(http_server_requests_seconds_count{namespace=~\"$namespace\", job=\"exhort\", status!~\"5..\"}[7d]))\n/\nsum(rate(http_server_requests_seconds_count{namespace=~\"$namespace\", job=\"exhort\"}[7d]))",
"expr": "histogram_quantile(0.90, sum(rate(http_server_requests_seconds_bucket{ status!~\"5..\", uri=\"/api/v3/analysis\"}[2m])) by (le))",
"interval": "",
"legendFormat": "Latency",
"legendFormat": "0.90",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "histogram_quantile(0.95, sum(rate(http_server_requests_seconds_bucket{ status!~\"5..\", uri=\"/api/v3/analysis\"}[2m])) by (le))",
"interval": "",
"legendFormat": "0.95",
"range": true,
"refId": "B"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "histogram_quantile(0.99, sum(rate(http_server_requests_seconds_bucket{ status!~\"5..\", uri=\"/api/v3/analysis\"}[2m])) by (le))",
"interval": "",
"legendFormat": "0.99",
"range": true,
"refId": "C"
}
],
"title": "Latency (NOT READY)",
"title": "Latency",
"type": "timeseries"
},
{
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/com/redhat/exhort/config/metrics/CustomMetrics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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.
*/

package com.redhat.exhort.config.metrics;

import java.util.Collection;
import java.util.List;

import io.micrometer.core.instrument.Meter.Id;
import io.micrometer.core.instrument.config.MeterFilter;
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;

import jakarta.enterprise.inject.Produces;
import jakarta.inject.Singleton;

@Singleton
public class CustomMetrics {

private static final String HTTP_SERVER_REQUESTS_METRIC = "http.server.requests";
private static final String CAMEL_ROUTES_METRIC = "camel.route.policy";
private static final String ROUTE_ID_TAG = "routeId";

private static final Collection<String> MONITORED_ROUTES =
List.of(
"snykValidateToken",
"snykRequest",
"ossValidateCredentials",
"ossSplitReq",
"ossIndexRequest",
"gavRequest",
"vexRequest");

@Produces
@Singleton
public MeterFilter enableHistogram() {
return new MeterFilter() {
@Override
public DistributionStatisticConfig configure(Id id, DistributionStatisticConfig config) {
if (requiresHistogram(id)) {
return DistributionStatisticConfig.builder()
.percentiles(0.90, 0.95, 0.99)
.percentilesHistogram(Boolean.TRUE)
.build()
.merge(config);
}
return config;
}
};
}

private boolean requiresHistogram(Id id) {
if (HTTP_SERVER_REQUESTS_METRIC.equalsIgnoreCase(id.getName())) {
return true;
}
if (CAMEL_ROUTES_METRIC.equalsIgnoreCase(id.getName())) {
String routeTag = id.getTag(ROUTE_ID_TAG);
if (routeTag == null) {
return false;
}
return MONITORED_ROUTES.contains(routeTag);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void configure() {
.otherwise().setBody(constant(Collections.emptyMap()));

from(direct("vexRequest"))
.routeId("doVexRequest")
.routeId("vexRequest")
.marshal().json()
.to(vertxHttp("{{api.trustedContent.vex.host}}"))
.unmarshal(new ListJacksonDataFormat(VexResult.class));
Expand Down

0 comments on commit 4837200

Please sign in to comment.