|
4 | 4 | import com.uid2.shared.auth.IAuthorizable; |
5 | 5 | import com.uid2.shared.jmx.AdminApi; |
6 | 6 | import com.uid2.shared.middleware.AuthMiddleware; |
| 7 | +import com.uid2.shared.model.Site; |
| 8 | +import com.uid2.shared.store.ISiteStore; |
7 | 9 | import io.micrometer.core.instrument.Counter; |
8 | 10 | import io.micrometer.core.instrument.Metrics; |
9 | 11 | import io.vertx.core.Handler; |
@@ -32,11 +34,17 @@ public class RequestCapturingHandler implements Handler<RoutingContext> { |
32 | 34 | private Queue<String> _capturedRequests = null; |
33 | 35 | private final Map<String, Counter> _apiMetricCounters = new HashMap<>(); |
34 | 36 | private final Map<String, Counter> _clientAppVersionCounters = new HashMap<>(); |
| 37 | + private final ISiteStore siteStore; |
35 | 38 |
|
36 | 39 | private static String formatRFC1123DateTime(long time) { |
37 | 40 | return DateTimeFormatter.RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(time).atZone(ZONE_GMT)); |
38 | 41 | } |
39 | 42 |
|
| 43 | + public RequestCapturingHandler(ISiteStore siteStore) |
| 44 | + { |
| 45 | + this.siteStore = siteStore; |
| 46 | + } |
| 47 | + |
40 | 48 | @Override |
41 | 49 | public void handle(RoutingContext context) { |
42 | 50 | if (!AdminApi.instance.getCaptureRequests() && !AdminApi.instance.getPublishApiMetrics()) { |
@@ -105,7 +113,17 @@ private void capture(RoutingContext context, long timestamp, String remoteClient |
105 | 113 | } |
106 | 114 |
|
107 | 115 | final Integer siteId = getSiteId(context); |
108 | | - incrementMetricCounter(apiContact, siteId, host, status, method, path); |
| 116 | + |
| 117 | + String siteName = "unknown"; |
| 118 | + if (siteId != null) { |
| 119 | + Site site = siteStore.getSite(siteId); |
| 120 | + if (site != null) |
| 121 | + { |
| 122 | + siteName = site.getName(); |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + incrementMetricCounter(apiContact, siteId, siteName, host, status, method, path); |
109 | 127 |
|
110 | 128 | if (request.headers().contains(Const.Http.AppVersionHeader)) { |
111 | 129 | incrementAppVersionCounter(apiContact, request.headers().get(Const.Http.AppVersionHeader)); |
@@ -196,14 +214,16 @@ private static Integer getSiteId(RoutingContext context) { |
196 | 214 | return null; |
197 | 215 | } |
198 | 216 |
|
199 | | - private void incrementMetricCounter(String apiContact, Integer siteId, String host, int status, HttpMethod method, String path) { |
| 217 | + private void incrementMetricCounter(String apiContact, Integer siteId, String siteName, |
| 218 | + String host, int status, HttpMethod method, String path) { |
200 | 219 | assert apiContact != null; |
201 | | - String key = apiContact + "|" + siteId + "|" + host + "|" + status + "|" + method.name() + "|" + path; |
| 220 | + String key = apiContact + "|" + siteId + "|" + siteName + "|" + host + "|" + status + "|" + method.name() + "|" + path; |
202 | 221 | if (!_apiMetricCounters.containsKey(key)) { |
203 | 222 | Counter counter = Counter |
204 | 223 | .builder("uid2.http_requests") |
205 | 224 | .description("counter for how many http requests are processed per each api contact and status code") |
206 | | - .tags("api_contact", apiContact, "site_id", String.valueOf(siteId), "host", host, "status", String.valueOf(status), "method", method.name(), "path", path) |
| 225 | + .tags("api_contact", apiContact, "site_id", String.valueOf(siteId), "site_name", siteName, |
| 226 | + "host", host, "status", String.valueOf(status), "method", method.name(), "path", path) |
207 | 227 | .register(Metrics.globalRegistry); |
208 | 228 | _apiMetricCounters.put(key, counter); |
209 | 229 | } |
|
0 commit comments