Commit aa1c662
authored
Fix SearchStatsContributor to report per-shard fragment counts (opensearch-project#22291)
The analytics-engine SearchStatsContributor was reporting 1-per-query
(via queries.elapsed_ms.count), but Lucene's ShardSearchStats counts
1-per-shard via per-shard onPreQueryPhase / onQueryPhase callbacks.
Downstream consumers of _nodes/stats search counters were undercounting
analytics-engine traffic by the shard fan-out factor (e.g. ~50x on a
50-shard index, ~8x on 8 shards).
A secondary symptom: query_time_in_millis was reporting near-zero
because AnalyticsStatsCollector.recordExecution computes per-query
elapsed as (latestStageEnd - earliestStageStart) and skips recording
when either timestamp is 0, dropping most queries' latency entirely.
Fix: contribute from the fragments bucket (per-shard StageTasks)
instead of the per-query bucket. fragments.total is populated once
per shard execution with its own elapsed time, matching Lucene's
per-shard semantics for both count and time-in-millis.
Empirical confirmation on a 27-node OpenSearch 3.5 cluster:
50 PPL queries against a 50-shard index
- Observed: cluster-wide query_total delta = 36
- Expected (Lucene parity): 50 queries x 50 shards = 2500
- Per-node breakdown: only 3 of 27 nodes incremented (coordinators)
100 PPL queries against an 8-shard index
- Observed: cluster-wide query_total delta = 66
- Expected (Lucene parity): 100 queries x 8 shards = 800
The ratio of undercount scales with shard count, exactly as
shard-fan-out-vs-1-per-query predicts.
Also splits SearchStatsContributorIT into three tests:
- testQueryTotalScalesWithShardFanOut: 3-shard index, asserts
delta >= N*shards/2 (catches the 1-per-query bug)
- testQueryTimeIncrementsAfterAnalyticsQueries: asserts time
delta > 0 (catches the all-or-nothing-window latency bug)
- testQueryTotalIncrementsAtLeastOncePerQuery: asserts delta >= N
(catches a regression where the contributor stops firing)
Signed-off-by: Michael Oviedo <mikeovi@amazon.com>1 parent 64d6b50 commit aa1c662
2 files changed
Lines changed: 87 additions & 23 deletions
File tree
- sandbox
- plugins/analytics-engine/src/main/java/org/opensearch/analytics
- qa/analytics-engine-rest/src/test/java/org/opensearch/analytics/qa
Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
264 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
265 | 278 | | |
266 | 279 | | |
267 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
268 | 283 | | |
269 | 284 | | |
270 | 285 | | |
| |||
Lines changed: 69 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
32 | | - | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
36 | 44 | | |
37 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
38 | 52 | | |
39 | 53 | | |
40 | | - | |
41 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
42 | 57 | | |
43 | | - | |
44 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
45 | 108 | | |
46 | 109 | | |
47 | 110 | | |
48 | 111 | | |
49 | 112 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 113 | | |
65 | 114 | | |
66 | 115 | | |
| |||
0 commit comments