Skip to content

Commit 0d51bcd

Browse files
authored
ESQL: Fix metrics for took between 1 and 10 hours (#139257)
We build a little histogram of the `took` time of queries so we can plan our future work. When I built it I typoed the metric for questions between one hour and ten hours. Instead I reported the ten minute to one hour bucket. This fixes that metric.
1 parent 3508148 commit 0d51bcd

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

docs/changelog/139257.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 139257
2+
summary: Fix metrics for took between 1 and 10 hours
3+
area: ES|QL
4+
type: bug
5+
issues: []

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/telemetry/TookMetrics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void counters(String prefix, Counters counters) {
7979
counters.inc(prefix + "lt_1m", lessThan1m.count());
8080
counters.inc(prefix + "lt_10m", lessThan10m.count());
8181
counters.inc(prefix + "lt_1h", lessThan1h.count());
82-
counters.inc(prefix + "lt_10h", lessThan1h.count());
82+
counters.inc(prefix + "lt_10h", lessThan10h.count());
8383
counters.inc(prefix + "lt_1d", lessThan1d.count());
8484
counters.inc(prefix + "gt_1d", greaterThan1d.count());
8585
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.telemetry;
9+
10+
import org.elasticsearch.test.ESTestCase;
11+
import org.elasticsearch.xpack.core.watcher.common.stats.Counters;
12+
13+
import static org.elasticsearch.test.MapMatcher.assertMap;
14+
import static org.elasticsearch.test.MapMatcher.matchesMap;
15+
16+
public class TookMetricsTests extends ESTestCase {
17+
public void testCounters() {
18+
Counters counters = new Counters();
19+
TookMetrics metrics = new TookMetrics();
20+
long[] boundaries = new long[] {
21+
10,
22+
100,
23+
TookMetrics.ONE_SECOND,
24+
TookMetrics.TEN_SECONDS,
25+
TookMetrics.ONE_MINUTE,
26+
TookMetrics.TEN_MINUTES,
27+
TookMetrics.ONE_HOUR,
28+
TookMetrics.TEN_HOURS,
29+
TookMetrics.ONE_DAY };
30+
for (int i = 0; i <= boundaries.length; i++) {
31+
long min = i == 0 ? 0 : boundaries[i - 1];
32+
long max = i == boundaries.length ? Long.MAX_VALUE : boundaries[i];
33+
for (int count = 0; count < i + 10; count++) {
34+
metrics.count(randomLongBetween(min, max - 1));
35+
}
36+
}
37+
metrics.counters("took.", counters);
38+
assertMap(
39+
counters.toNestedMap(),
40+
matchesMap().entry(
41+
"took",
42+
matchesMap().entry("lt_10ms", 10L)
43+
.entry("lt_100ms", 11L)
44+
.entry("lt_1s", 12L)
45+
.entry("lt_10s", 13L)
46+
.entry("lt_1m", 14L)
47+
.entry("lt_10m", 15L)
48+
.entry("lt_1h", 16L)
49+
.entry("lt_10h", 17L)
50+
.entry("lt_1d", 18L)
51+
.entry("gt_1d", 19L)
52+
)
53+
);
54+
}
55+
}

0 commit comments

Comments
 (0)