diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-04-30 15:30:20 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-04-30 15:30:20 +0200 |
commit | 7fdcc1acdaae16f6eafcb1a4b5ddd74cb39693cf (patch) | |
tree | 93aa8f51c1702333e0099a348b03a2ed000d12b3 /container-core | |
parent | 6f50a746d955e65ffdfd743141b46f4924a93dab (diff) |
Add http protocol verison as dimension to request/response metrics
Diffstat (limited to 'container-core')
4 files changed, 53 insertions, 23 deletions
diff --git a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HttpResponseStatisticsCollector.java b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HttpResponseStatisticsCollector.java index 82c445c7ca9..ac4e743784b 100644 --- a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HttpResponseStatisticsCollector.java +++ b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HttpResponseStatisticsCollector.java @@ -49,6 +49,10 @@ public class HttpResponseStatisticsCollector extends HandlerWrapper implements G HTTP, HTTPS, OTHER } + public enum HttpProtocol { + HTTP1, HTTP2, OTHER + } + private static final String[] HTTP_RESPONSE_GROUPS = { MetricDefinitions.RESPONSES_1XX, MetricDefinitions.RESPONSES_2XX, @@ -60,19 +64,21 @@ public class HttpResponseStatisticsCollector extends HandlerWrapper implements G }; private final AtomicLong inFlight = new AtomicLong(); - private final LongAdder[][][][] statistics; + private final LongAdder[][][][][] statistics; // TODO Rewrite me to a smarter data structure public HttpResponseStatisticsCollector(List<String> monitoringHandlerPaths, List<String> searchHandlerPaths) { this.monitoringHandlerPaths = monitoringHandlerPaths; this.searchHandlerPaths = searchHandlerPaths; - statistics = new LongAdder[HttpScheme.values().length][HttpMethod.values().length][][]; - for (int scheme = 0; scheme < HttpScheme.values().length; ++scheme) { - for (int method = 0; method < HttpMethod.values().length; method++) { - statistics[scheme][method] = new LongAdder[HTTP_RESPONSE_GROUPS.length][]; - for (int group = 0; group < HTTP_RESPONSE_GROUPS.length; group++) { - statistics[scheme][method][group] = new LongAdder[HttpRequest.RequestType.values().length]; - for (int requestType = 0; requestType < HttpRequest.RequestType.values().length; requestType++) { - statistics[scheme][method][group][requestType] = new LongAdder(); + statistics = new LongAdder[HttpProtocol.values().length][HttpScheme.values().length][HttpMethod.values().length][][]; + for (int protocol = 0; protocol < HttpProtocol.values().length; protocol++) { + for (int scheme = 0; scheme < HttpScheme.values().length; ++scheme) { + for (int method = 0; method < HttpMethod.values().length; method++) { + statistics[protocol][scheme][method] = new LongAdder[HTTP_RESPONSE_GROUPS.length][]; + for (int group = 0; group < HTTP_RESPONSE_GROUPS.length; group++) { + statistics[protocol][scheme][method][group] = new LongAdder[HttpRequest.RequestType.values().length]; + for (int requestType = 0; requestType < HttpRequest.RequestType.values().length; requestType++) { + statistics[protocol][scheme][method][group][requestType] = new LongAdder(); + } } } } @@ -129,13 +135,14 @@ public class HttpResponseStatisticsCollector extends HandlerWrapper implements G private void observeEndOfRequest(Request request, HttpServletResponse flushableResponse) throws IOException { int group = groupIndex(request); if (group >= 0) { + HttpProtocol protocol = getProtocol(request); HttpScheme scheme = getScheme(request); HttpMethod method = getMethod(request); HttpRequest.RequestType requestType = getRequestType(request); - statistics[scheme.ordinal()][method.ordinal()][group][requestType.ordinal()].increment(); + statistics[protocol.ordinal()][scheme.ordinal()][method.ordinal()][group][requestType.ordinal()].increment(); if (group == 5 || group == 6) { // if 401/403, also increment 4xx - statistics[scheme.ordinal()][method.ordinal()][3][requestType.ordinal()].increment(); + statistics[protocol.ordinal()][scheme.ordinal()][method.ordinal()][3][requestType.ordinal()].increment(); } } @@ -161,7 +168,7 @@ public class HttpResponseStatisticsCollector extends HandlerWrapper implements G } index = index / 100 - 1; // 1xx = 0, 2xx = 1 etc. - if (index < 0 || index >= statistics[0].length) { + if (index < 0 || index >= statistics[0][0].length) { return -1; } else { return index; @@ -200,6 +207,20 @@ public class HttpResponseStatisticsCollector extends HandlerWrapper implements G } } + private HttpProtocol getProtocol(Request request) { + switch (request.getProtocol()) { + case "HTTP/1": + case "HTTP/1.0": + case "HTTP/1.1": + return HttpProtocol.HTTP1; + case "HTTP/2": + case "HTTP/2.0": + return HttpProtocol.HTTP2; + default: + return HttpProtocol.OTHER; + } + } + private HttpRequest.RequestType getRequestType(Request request) { HttpRequest.RequestType requestType = (HttpRequest.RequestType)request.getAttribute(requestTypeAttribute); if (requestType != null) return requestType; @@ -221,15 +242,18 @@ public class HttpResponseStatisticsCollector extends HandlerWrapper implements G public List<StatisticsEntry> takeStatistics() { var ret = new ArrayList<StatisticsEntry>(); - for (HttpScheme scheme : HttpScheme.values()) { - int schemeIndex = scheme.ordinal(); - for (HttpMethod method : HttpMethod.values()) { - int methodIndex = method.ordinal(); - for (int group = 0; group < HTTP_RESPONSE_GROUPS.length; group++) { - for (HttpRequest.RequestType type : HttpRequest.RequestType.values()) { - long value = statistics[schemeIndex][methodIndex][group][type.ordinal()].sumThenReset(); - if (value > 0) { - ret.add(new StatisticsEntry(scheme.name().toLowerCase(), method.name(), HTTP_RESPONSE_GROUPS[group], type.name().toLowerCase(), value)); + for (HttpProtocol protocol : HttpProtocol.values()) { + int protocolIndex = protocol.ordinal(); + for (HttpScheme scheme : HttpScheme.values()) { + int schemeIndex = scheme.ordinal(); + for (HttpMethod method : HttpMethod.values()) { + int methodIndex = method.ordinal(); + for (int group = 0; group < HTTP_RESPONSE_GROUPS.length; group++) { + for (HttpRequest.RequestType type : HttpRequest.RequestType.values()) { + long value = statistics[protocolIndex][schemeIndex][methodIndex][group][type.ordinal()].sumThenReset(); + if (value > 0) { + ret.add(new StatisticsEntry(protocol.name().toLowerCase(), scheme.name().toLowerCase(), method.name(), HTTP_RESPONSE_GROUPS[group], type.name().toLowerCase(), value)); + } } } } @@ -272,13 +296,15 @@ public class HttpResponseStatisticsCollector extends HandlerWrapper implements G public static class StatisticsEntry { + public final String protocol; public final String scheme; public final String method; public final String name; public final String requestType; public final long value; - public StatisticsEntry(String scheme, String method, String name, String requestType, long value) { + public StatisticsEntry(String protocol, String scheme, String method, String name, String requestType, long value) { + this.protocol = protocol; this.scheme = scheme; this.method = method; this.name = name; @@ -288,7 +314,8 @@ public class HttpResponseStatisticsCollector extends HandlerWrapper implements G @Override public String toString() { - return "scheme: " + scheme + + return "protocol: " + protocol + + ", scheme: " + scheme + ", method: " + method + ", name: " + name + ", requestType: " + requestType + diff --git a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JDiscServerConnector.java b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JDiscServerConnector.java index 99d0c5c8d8c..a355ca886c5 100644 --- a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JDiscServerConnector.java +++ b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JDiscServerConnector.java @@ -76,6 +76,7 @@ class JDiscServerConnector extends ServerConnector { dimensions.put(MetricDefinitions.METHOD_DIMENSION, method); dimensions.put(MetricDefinitions.SCHEME_DIMENSION, scheme); dimensions.put(MetricDefinitions.CLIENT_AUTHENTICATED_DIMENSION, Boolean.toString(clientAuthenticated)); + dimensions.put(MetricDefinitions.PROTOCOL_DIMENSION, request.getProtocol()); String serverName = Optional.ofNullable(request.getServerName()).orElse("unknown"); dimensions.put(MetricDefinitions.REQUEST_SERVER_NAME_DIMENSION, serverName); dimensions.putAll(extraDimensions); diff --git a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/MetricDefinitions.java b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/MetricDefinitions.java index 5e953179b53..b0b7ae14739 100644 --- a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/MetricDefinitions.java +++ b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/MetricDefinitions.java @@ -16,6 +16,7 @@ class MetricDefinitions { static final String CLIENT_AUTHENTICATED_DIMENSION = "clientAuthenticated"; static final String REQUEST_SERVER_NAME_DIMENSION = "requestServerName"; static final String FILTER_CHAIN_ID_DIMENSION = "chainId"; + static final String PROTOCOL_DIMENSION = "protocol"; static final String NUM_OPEN_CONNECTIONS = "serverNumOpenConnections"; static final String NUM_CONNECTIONS_OPEN_MAX = "serverConnectionsOpenMax"; diff --git a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/ServerMetricReporter.java b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/ServerMetricReporter.java index ba3694ffc2f..ea263350d0a 100644 --- a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/ServerMetricReporter.java +++ b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/ServerMetricReporter.java @@ -86,6 +86,7 @@ class ServerMetricReporter { dimensions.put(MetricDefinitions.METHOD_DIMENSION, metricEntry.method); dimensions.put(MetricDefinitions.SCHEME_DIMENSION, metricEntry.scheme); dimensions.put(MetricDefinitions.REQUEST_TYPE_DIMENSION, metricEntry.requestType); + dimensions.put(MetricDefinitions.PROTOCOL_DIMENSION, metricEntry.protocol); metric.add(metricEntry.name, metricEntry.value, metric.createContext(dimensions)); } } |