Skip to content

Commit 4bc9bff

Browse files
authored
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.
1 parent 9087c98 commit 4bc9bff

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlUsageTestCase.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class RestSqlUsageTestCase extends ESRestTestCase {
3838
);
3939

4040
private enum ClientType {
41-
CANVAS, CLI, JDBC, ODBC, REST;
41+
CANVAS, CLI, JDBC, ODBC, ODBC32, ODBC64, REST;
4242

4343
@Override
4444
public String toString() {
@@ -84,7 +84,7 @@ private void getBaseMetrics() throws UnsupportedOperationException, IOException
8484
baseMetrics.put(metric.toString(), (Integer) featuresMetrics.get(metric.toString()));
8585
}
8686

87-
// initialize the "base" metric values with whatever values are already recorder on ES
87+
// initialize the "base" metric values with whatever values are already recorded on ES
8888
baseClientTypeTotalQueries = ((Map<String,Integer>) queriesMetrics.get(clientType)).get("total");
8989
baseClientTypeFailedQueries = ((Map<String,Integer>) queriesMetrics.get(clientType)).get("failed");
9090
baseAllTotalQueries = ((Map<String,Integer>) queriesMetrics.get("_all")).get("total");
@@ -252,8 +252,14 @@ private void runTranslate(String sql) throws IOException {
252252
}
253253

254254
private void runSql(String sql) throws IOException {
255-
String mode = (clientType.equals(ClientType.JDBC.toString()) || clientType.equals(ClientType.ODBC.toString())) ?
256-
clientType.toString() : Mode.PLAIN.toString();
255+
String mode = Mode.PLAIN.toString();
256+
if (clientType.equals(ClientType.JDBC.toString())) {
257+
mode = Mode.JDBC.toString();
258+
}
259+
if (clientType.startsWith(ClientType.ODBC.toString())) {
260+
mode = Mode.ODBC.toString();
261+
}
262+
257263
runSql(mode, clientType, sql);
258264
}
259265

x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/RequestInfo.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,34 @@
66

77
package org.elasticsearch.xpack.sql.proto;
88

9-
import java.util.Arrays;
10-
import java.util.List;
9+
import java.util.Collections;
10+
import java.util.HashSet;
1111
import java.util.Locale;
1212
import java.util.Objects;
13+
import java.util.Set;
1314

1415
public class RequestInfo {
1516
public static final String CLI = "cli";
1617
private static final String CANVAS = "canvas";
17-
public static final List<String> CLIENT_IDS = Arrays.asList(CLI, CANVAS);
18+
public static final String ODBC_32 = "odbc32";
19+
private static final String ODBC_64 = "odbc64";
20+
public static final Set<String> CLIENT_IDS;
21+
public static final Set<String> ODBC_CLIENT_IDS;
22+
23+
static {
24+
Set<String> clientIds = new HashSet<>(4);
25+
clientIds.add(CLI);
26+
clientIds.add(CANVAS);
27+
clientIds.add(ODBC_32);
28+
clientIds.add(ODBC_64);
29+
30+
Set<String> odbcClientIds = new HashSet<>(2);
31+
odbcClientIds.add(ODBC_32);
32+
odbcClientIds.add(ODBC_64);
33+
34+
CLIENT_IDS = Collections.unmodifiableSet(clientIds);
35+
ODBC_CLIENT_IDS = Collections.unmodifiableSet(odbcClientIds);
36+
}
1837

1938
private Mode mode;
2039
private String clientId;

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
5656
SqlQueryRequest sqlRequest;
5757
try (XContentParser parser = request.contentOrSourceParamParser()) {
5858
sqlRequest = SqlQueryRequest.fromXContent(parser);
59-
}
59+
}
6060

6161
/*
6262
* Since we support {@link TextFormat} <strong>and</strong>

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/Metrics.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import java.util.Map;
1616
import java.util.Map.Entry;
1717

18+
import static org.elasticsearch.xpack.sql.proto.RequestInfo.ODBC_CLIENT_IDS;
19+
import static org.elasticsearch.xpack.sql.stats.QueryMetric.ODBC;
20+
1821
/**
1922
* Class encapsulating the metrics collected for ES SQL
2023
*/
@@ -101,9 +104,18 @@ public Counters stats() {
101104

102105
// queries metrics
103106
for (Entry<QueryMetric, Map<OperationType, CounterMetric>> entry : opsByTypeMetrics.entrySet()) {
107+
String metricName = entry.getKey().toString();
108+
104109
for (OperationType type : OperationType.values()) {
105-
counters.inc(QPREFIX + entry.getKey().toString() + "." + type.toString(), entry.getValue().get(type).count());
106-
counters.inc(QPREFIX + "_all." + type.toString(), entry.getValue().get(type).count());
110+
long metricCounter = entry.getValue().get(type).count();
111+
String operationTypeName = type.toString();
112+
113+
counters.inc(QPREFIX + metricName + "." + operationTypeName, metricCounter);
114+
counters.inc(QPREFIX + "_all." + operationTypeName, metricCounter);
115+
// compute the ODBC total metric
116+
if (ODBC_CLIENT_IDS.contains(metricName)) {
117+
counters.inc(QPREFIX + ODBC.toString() + "." + operationTypeName, metricCounter);
118+
}
107119
}
108120
}
109121

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/stats/QueryMetric.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
package org.elasticsearch.xpack.sql.stats;
88

99
import org.elasticsearch.xpack.sql.proto.Mode;
10+
import org.elasticsearch.xpack.sql.proto.RequestInfo;
1011

1112
import java.util.Locale;
13+
import static org.elasticsearch.xpack.sql.proto.RequestInfo.ODBC_CLIENT_IDS;
1214

1315
public enum QueryMetric {
14-
CANVAS, CLI, JDBC, ODBC, REST;
15-
16+
CANVAS, CLI, JDBC, ODBC, ODBC32, ODBC64, REST;
17+
1618
public static QueryMetric fromString(String metric) {
1719
try {
1820
return QueryMetric.valueOf(metric.toUpperCase(Locale.ROOT));
@@ -27,6 +29,14 @@ public String toString() {
2729
}
2830

2931
public static QueryMetric from(Mode mode, String clientId) {
32+
if (mode == Mode.ODBC) {
33+
// default to "odbc_32" if the client_id is not provided or it has a wrong value
34+
if (clientId == null || false == ODBC_CLIENT_IDS.contains(clientId)) {
35+
return fromString(RequestInfo.ODBC_32);
36+
} else {
37+
return fromString(clientId);
38+
}
39+
}
3040
return fromString(mode == Mode.PLAIN ? clientId : mode.toString());
3141
}
3242
}

0 commit comments

Comments
 (0)