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.
This commit is contained in:
parent
9087c98a5a
commit
4bc9bffb4d
|
@ -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<String,Integer>) queriesMetrics.get(clientType)).get("total");
|
||||
baseClientTypeFailedQueries = ((Map<String,Integer>) queriesMetrics.get(clientType)).get("failed");
|
||||
baseAllTotalQueries = ((Map<String,Integer>) 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> CLIENT_IDS = Arrays.asList(CLI, CANVAS);
|
||||
public static final String ODBC_32 = "odbc32";
|
||||
private static final String ODBC_64 = "odbc64";
|
||||
public static final Set<String> CLIENT_IDS;
|
||||
public static final Set<String> ODBC_CLIENT_IDS;
|
||||
|
||||
static {
|
||||
Set<String> clientIds = new HashSet<>(4);
|
||||
clientIds.add(CLI);
|
||||
clientIds.add(CANVAS);
|
||||
clientIds.add(ODBC_32);
|
||||
clientIds.add(ODBC_64);
|
||||
|
||||
Set<String> 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;
|
||||
|
|
|
@ -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} <strong>and</strong>
|
||||
|
|
|
@ -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<QueryMetric, Map<OperationType, CounterMetric>> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,13 @@
|
|||
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 {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue