From 4bc9bffb4d50d0e8b1a8070cf57ff429fbf013fa Mon Sep 17 00:00:00 2001 From: Andrei Stefan Date: Tue, 18 Dec 2018 13:29:49 +0200 Subject: [PATCH] SQL: Extend the ODBC metric by differentiating between 32 and 64bit platforms (#36753) * The "overall" ODBC metric will now track a total of requests between 32bit and 64bit ODBC metrics, being calculated passively, upon request. --- .../sql/qa/rest/RestSqlUsageTestCase.java | 14 ++++++++--- .../xpack/sql/proto/RequestInfo.java | 25 ++++++++++++++++--- .../xpack/sql/plugin/RestSqlQueryAction.java | 2 +- .../xpack/sql/stats/Metrics.java | 16 ++++++++++-- .../xpack/sql/stats/QueryMetric.java | 14 +++++++++-- 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlUsageTestCase.java b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlUsageTestCase.java index a8c45fedf2a..7573fe8abaa 100644 --- a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlUsageTestCase.java +++ b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlUsageTestCase.java @@ -38,7 +38,7 @@ public abstract class RestSqlUsageTestCase extends ESRestTestCase { ); private enum ClientType { - CANVAS, CLI, JDBC, ODBC, REST; + CANVAS, CLI, JDBC, ODBC, ODBC32, ODBC64, REST; @Override public String toString() { @@ -84,7 +84,7 @@ public abstract class RestSqlUsageTestCase extends ESRestTestCase { baseMetrics.put(metric.toString(), (Integer) featuresMetrics.get(metric.toString())); } - // initialize the "base" metric values with whatever values are already recorder on ES + // initialize the "base" metric values with whatever values are already recorded on ES baseClientTypeTotalQueries = ((Map) queriesMetrics.get(clientType)).get("total"); baseClientTypeFailedQueries = ((Map) queriesMetrics.get(clientType)).get("failed"); baseAllTotalQueries = ((Map) queriesMetrics.get("_all")).get("total"); @@ -252,8 +252,14 @@ public abstract class RestSqlUsageTestCase extends ESRestTestCase { } private void runSql(String sql) throws IOException { - String mode = (clientType.equals(ClientType.JDBC.toString()) || clientType.equals(ClientType.ODBC.toString())) ? - clientType.toString() : Mode.PLAIN.toString(); + String mode = Mode.PLAIN.toString(); + if (clientType.equals(ClientType.JDBC.toString())) { + mode = Mode.JDBC.toString(); + } + if (clientType.startsWith(ClientType.ODBC.toString())) { + mode = Mode.ODBC.toString(); + } + runSql(mode, clientType, sql); } diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/RequestInfo.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/RequestInfo.java index be1f1a58adb..b860832856a 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/RequestInfo.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/RequestInfo.java @@ -6,15 +6,34 @@ package org.elasticsearch.xpack.sql.proto; -import java.util.Arrays; -import java.util.List; +import java.util.Collections; +import java.util.HashSet; import java.util.Locale; import java.util.Objects; +import java.util.Set; public class RequestInfo { public static final String CLI = "cli"; private static final String CANVAS = "canvas"; - public static final List CLIENT_IDS = Arrays.asList(CLI, CANVAS); + public static final String ODBC_32 = "odbc32"; + private static final String ODBC_64 = "odbc64"; + public static final Set CLIENT_IDS; + public static final Set ODBC_CLIENT_IDS; + + static { + Set clientIds = new HashSet<>(4); + clientIds.add(CLI); + clientIds.add(CANVAS); + clientIds.add(ODBC_32); + clientIds.add(ODBC_64); + + Set odbcClientIds = new HashSet<>(2); + odbcClientIds.add(ODBC_32); + odbcClientIds.add(ODBC_64); + + CLIENT_IDS = Collections.unmodifiableSet(clientIds); + ODBC_CLIENT_IDS = Collections.unmodifiableSet(odbcClientIds); + } private Mode mode; private String clientId; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java index bd03715ee22..d4d4ce16fb8 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java @@ -56,7 +56,7 @@ public class RestSqlQueryAction extends BaseRestHandler { SqlQueryRequest sqlRequest; try (XContentParser parser = request.contentOrSourceParamParser()) { sqlRequest = SqlQueryRequest.fromXContent(parser); - } + } /* * Since we support {@link TextFormat} and diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/Metrics.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/Metrics.java index fc72c66834b..1f0b23f7067 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/Metrics.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/Metrics.java @@ -15,6 +15,9 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import static org.elasticsearch.xpack.sql.proto.RequestInfo.ODBC_CLIENT_IDS; +import static org.elasticsearch.xpack.sql.stats.QueryMetric.ODBC; + /** * Class encapsulating the metrics collected for ES SQL */ @@ -101,9 +104,18 @@ public class Metrics { // queries metrics for (Entry> entry : opsByTypeMetrics.entrySet()) { + String metricName = entry.getKey().toString(); + for (OperationType type : OperationType.values()) { - counters.inc(QPREFIX + entry.getKey().toString() + "." + type.toString(), entry.getValue().get(type).count()); - counters.inc(QPREFIX + "_all." + type.toString(), entry.getValue().get(type).count()); + long metricCounter = entry.getValue().get(type).count(); + String operationTypeName = type.toString(); + + counters.inc(QPREFIX + metricName + "." + operationTypeName, metricCounter); + counters.inc(QPREFIX + "_all." + operationTypeName, metricCounter); + // compute the ODBC total metric + if (ODBC_CLIENT_IDS.contains(metricName)) { + counters.inc(QPREFIX + ODBC.toString() + "." + operationTypeName, metricCounter); + } } } diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/QueryMetric.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/QueryMetric.java index d0649b61e67..c4612545584 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/QueryMetric.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/QueryMetric.java @@ -7,12 +7,14 @@ package org.elasticsearch.xpack.sql.stats; import org.elasticsearch.xpack.sql.proto.Mode; +import org.elasticsearch.xpack.sql.proto.RequestInfo; import java.util.Locale; +import static org.elasticsearch.xpack.sql.proto.RequestInfo.ODBC_CLIENT_IDS; public enum QueryMetric { - CANVAS, CLI, JDBC, ODBC, REST; - + CANVAS, CLI, JDBC, ODBC, ODBC32, ODBC64, REST; + public static QueryMetric fromString(String metric) { try { return QueryMetric.valueOf(metric.toUpperCase(Locale.ROOT)); @@ -27,6 +29,14 @@ public enum QueryMetric { } public static QueryMetric from(Mode mode, String clientId) { + if (mode == Mode.ODBC) { + // default to "odbc_32" if the client_id is not provided or it has a wrong value + if (clientId == null || false == ODBC_CLIENT_IDS.contains(clientId)) { + return fromString(RequestInfo.ODBC_32); + } else { + return fromString(clientId); + } + } return fromString(mode == Mode.PLAIN ? clientId : mode.toString()); } }