Skip to content

Commit f070620

Browse files
committed
Search query failure and search star-tree query failure stats
Signed-off-by: Sandesh Kumar <sandeshkr419@gmail.com>
1 parent a033cd1 commit f070620

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

server/src/main/java/org/opensearch/index/search/stats/SearchStats.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public static class Stats implements Writeable, ToXContentFragment {
142142
private long queryCount;
143143
private long queryTimeInMillis;
144144
private long queryCurrent;
145+
private long queryFailedCount;
145146

146147
private long concurrentQueryCount;
147148
private long concurrentQueryTimeInMillis;
@@ -169,6 +170,7 @@ public static class Stats implements Writeable, ToXContentFragment {
169170
private long starTreeQueryCount;
170171
private long starTreeQueryTimeInMillis;
171172
private long starTreeQueryCurrent;
173+
private long starTreeQueryFailed;
172174

173175
@Nullable
174176
private RequestStatsLongHolder requestStatsLongHolder;
@@ -191,6 +193,7 @@ private Stats(Builder builder) {
191193
this.queryCount = builder.queryCount;
192194
this.queryTimeInMillis = builder.queryTimeInMillis;
193195
this.queryCurrent = builder.queryCurrent;
196+
this.queryFailedCount = builder.queryFailedCount;
194197

195198
this.concurrentQueryCount = builder.concurrentQueryCount;
196199
this.concurrentQueryTimeInMillis = builder.concurrentQueryTimeInMillis;
@@ -218,6 +221,7 @@ private Stats(Builder builder) {
218221
this.starTreeQueryCount = builder.starTreeQueryCount;
219222
this.starTreeQueryTimeInMillis = builder.starTreeQueryTimeInMillis;
220223
this.starTreeQueryCurrent = builder.starTreeQueryCurrent;
224+
this.starTreeQueryFailed = builder.starTreeQueryFailed;
221225
}
222226

223227
/**
@@ -319,12 +323,18 @@ private Stats(StreamInput in) throws IOException {
319323
starTreeQueryTimeInMillis = in.readVLong();
320324
starTreeQueryCurrent = in.readVLong();
321325
}
326+
327+
if (in.getVersion().onOrAfter(Version.V_3_3_0)) {
328+
queryFailedCount = in.readVLong();
329+
starTreeQueryFailed = in.readVLong();
330+
}
322331
}
323332

324333
public void add(Stats stats) {
325334
queryCount += stats.queryCount;
326335
queryTimeInMillis += stats.queryTimeInMillis;
327336
queryCurrent += stats.queryCurrent;
337+
queryFailedCount += stats.queryFailedCount;
328338

329339
concurrentQueryCount += stats.concurrentQueryCount;
330340
concurrentQueryTimeInMillis += stats.concurrentQueryTimeInMillis;
@@ -352,11 +362,13 @@ public void add(Stats stats) {
352362
starTreeQueryCount += stats.starTreeQueryCount;
353363
starTreeQueryTimeInMillis += stats.starTreeQueryTimeInMillis;
354364
starTreeQueryCurrent += stats.starTreeQueryCurrent;
365+
starTreeQueryFailed += stats.starTreeQueryFailed;
355366
}
356367

357368
public void addForClosingShard(Stats stats) {
358369
queryCount += stats.queryCount;
359370
queryTimeInMillis += stats.queryTimeInMillis;
371+
queryFailedCount += stats.queryFailedCount;
360372

361373
concurrentQueryCount += stats.concurrentQueryCount;
362374
concurrentQueryTimeInMillis += stats.concurrentQueryTimeInMillis;
@@ -381,6 +393,7 @@ public void addForClosingShard(Stats stats) {
381393

382394
starTreeQueryCount += stats.starTreeQueryCount;
383395
starTreeQueryTimeInMillis += stats.starTreeQueryTimeInMillis;
396+
starTreeQueryFailed += stats.starTreeQueryFailed;
384397
}
385398

386399
public long getQueryCount() {
@@ -399,6 +412,10 @@ public long getQueryCurrent() {
399412
return queryCurrent;
400413
}
401414

415+
public long getQueryFailedCount() {
416+
return queryFailedCount;
417+
}
418+
402419
public long getConcurrentQueryCount() {
403420
return concurrentQueryCount;
404421
}
@@ -507,6 +524,10 @@ public long getStarTreeQueryCurrent() {
507524
return starTreeQueryCurrent;
508525
}
509526

527+
public long getStarTreeQueryFailed() {
528+
return starTreeQueryFailed;
529+
}
530+
510531
public static Stats readStats(StreamInput in) throws IOException {
511532
return new Stats(in);
512533
}
@@ -562,13 +583,19 @@ public void writeTo(StreamOutput out) throws IOException {
562583
out.writeVLong(starTreeQueryTimeInMillis);
563584
out.writeVLong(starTreeQueryCurrent);
564585
}
586+
587+
if (out.getVersion().onOrAfter(Version.V_3_3_0)) {
588+
out.writeVLong(queryFailedCount);
589+
out.writeVLong(starTreeQueryFailed);
590+
}
565591
}
566592

567593
@Override
568594
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
569595
builder.field(Fields.QUERY_TOTAL, queryCount);
570596
builder.humanReadableField(Fields.QUERY_TIME_IN_MILLIS, Fields.QUERY_TIME, getQueryTime());
571597
builder.field(Fields.QUERY_CURRENT, queryCurrent);
598+
builder.field(Fields.QUERY_FAILED_TOTAL, queryFailedCount);
572599

573600
builder.field(Fields.CONCURRENT_QUERY_TOTAL, concurrentQueryCount);
574601
builder.humanReadableField(Fields.CONCURRENT_QUERY_TIME_IN_MILLIS, Fields.CONCURRENT_QUERY_TIME, getConcurrentQueryTime());
@@ -578,6 +605,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
578605
builder.field(Fields.STARTREE_QUERY_TOTAL, starTreeQueryCount);
579606
builder.humanReadableField(Fields.STARTREE_QUERY_TIME_IN_MILLIS, Fields.STARTREE_QUERY_TIME, getStarTreeQueryTime());
580607
builder.field(Fields.STARTREE_QUERY_CURRENT, getStarTreeQueryCurrent());
608+
builder.field(Fields.STARTREE_QUERY_FAILED, getStarTreeQueryFailed());
581609

582610
builder.field(Fields.FETCH_TOTAL, fetchCount);
583611
builder.humanReadableField(Fields.FETCH_TIME_IN_MILLIS, Fields.FETCH_TIME, getFetchTime());
@@ -633,6 +661,7 @@ public static class Builder {
633661
private long queryCount = 0;
634662
private long queryTimeInMillis = 0;
635663
private long queryCurrent = 0;
664+
private long queryFailedCount = 0;
636665
private long concurrentQueryCount = 0;
637666
private long concurrentQueryTimeInMillis = 0;
638667
private long concurrentQueryCurrent = 0;
@@ -653,6 +682,7 @@ public static class Builder {
653682
private long starTreeQueryCount = 0;
654683
private long starTreeQueryTimeInMillis = 0;
655684
private long starTreeQueryCurrent = 0;
685+
private long starTreeQueryFailed = 0;
656686
@Nullable
657687
private RequestStatsLongHolder requestStatsLongHolder = null;
658688

@@ -673,6 +703,11 @@ public Builder queryCurrent(long current) {
673703
return this;
674704
}
675705

706+
public Builder queryFailed(long count) {
707+
this.queryFailedCount = count;
708+
return this;
709+
}
710+
676711
public Builder concurrentQueryCount(long count) {
677712
this.concurrentQueryCount = count;
678713
return this;
@@ -773,6 +808,11 @@ public Builder starTreeQueryCurrent(long current) {
773808
return this;
774809
}
775810

811+
public Builder starTreeQueryFailed(long count) {
812+
this.starTreeQueryFailed = count;
813+
return this;
814+
}
815+
776816
/**
777817
* Creates a {@link Stats} object from the builder's current state.
778818
* @return A new Stats instance.
@@ -916,6 +956,7 @@ static final class Fields {
916956
static final String QUERY_TIME = "query_time";
917957
static final String QUERY_TIME_IN_MILLIS = "query_time_in_millis";
918958
static final String QUERY_CURRENT = "query_current";
959+
static final String QUERY_FAILED_TOTAL = "query_failed";
919960
static final String CONCURRENT_QUERY_TOTAL = "concurrent_query_total";
920961
static final String CONCURRENT_QUERY_TIME = "concurrent_query_time";
921962
static final String CONCURRENT_QUERY_TIME_IN_MILLIS = "concurrent_query_time_in_millis";
@@ -925,6 +966,7 @@ static final class Fields {
925966
static final String STARTREE_QUERY_TIME = "startree_query_time";
926967
static final String STARTREE_QUERY_TIME_IN_MILLIS = "startree_query_time_in_millis";
927968
static final String STARTREE_QUERY_CURRENT = "startree_query_current";
969+
static final String STARTREE_QUERY_FAILED = "startree_query_failed";
928970
static final String FETCH_TOTAL = "fetch_total";
929971
static final String FETCH_TIME = "fetch_time";
930972
static final String FETCH_TIME_IN_MILLIS = "fetch_time_in_millis";

server/src/main/java/org/opensearch/index/search/stats/ShardSearchStats.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public void onPreQueryPhase(SearchContext searchContext) {
104104
@Override
105105
public void onFailedQueryPhase(SearchContext searchContext) {
106106
computeStats(searchContext, statsHolder -> {
107+
statsHolder.queryFailed.inc();
107108
if (searchContext.hasOnlySuggest()) {
108109
statsHolder.suggestCurrent.dec();
109110
assert statsHolder.suggestCurrent.count() >= 0;
@@ -115,6 +116,7 @@ public void onFailedQueryPhase(SearchContext searchContext) {
115116
assert statsHolder.concurrentQueryCurrent.count() >= 0;
116117
}
117118
if (searchContext.getQueryShardContext().getStarTreeQueryContext() != null) {
119+
statsHolder.starTreeQueryFailed.inc();
118120
statsHolder.starTreeCurrent.dec();
119121
assert statsHolder.starTreeCurrent.count() >= 0;
120122
}
@@ -237,6 +239,7 @@ public void onSearchIdleReactivation() {
237239
*/
238240
static final class StatsHolder {
239241
final MeanMetric queryMetric = new MeanMetric();
242+
final CounterMetric queryFailed = new CounterMetric();
240243
final MeanMetric concurrentQueryMetric = new MeanMetric();
241244
final CounterMetric queryConcurrencyMetric = new CounterMetric();
242245
final MeanMetric fetchMetric = new MeanMetric();
@@ -259,11 +262,13 @@ static final class StatsHolder {
259262
final CounterMetric searchIdleMetric = new CounterMetric();
260263
final MeanMetric starTreeQueryMetric = new MeanMetric();
261264
final CounterMetric starTreeCurrent = new CounterMetric();
265+
final CounterMetric starTreeQueryFailed = new CounterMetric();
262266

263267
SearchStats.Stats stats() {
264268
return new SearchStats.Stats.Builder().queryCount(queryMetric.count())
265269
.queryTimeInMillis(TimeUnit.NANOSECONDS.toMillis(queryMetric.sum()))
266270
.queryCurrent(queryCurrent.count())
271+
.queryFailed(queryFailed.count())
267272
.concurrentQueryCount(concurrentQueryMetric.count())
268273
.concurrentQueryTimeInMillis(TimeUnit.NANOSECONDS.toMillis(concurrentQueryMetric.sum()))
269274
.concurrentQueryCurrent(concurrentQueryCurrent.count())
@@ -284,6 +289,7 @@ SearchStats.Stats stats() {
284289
.starTreeQueryCount(starTreeQueryMetric.count())
285290
.starTreeQueryTimeInMillis(TimeUnit.NANOSECONDS.toMillis(starTreeQueryMetric.sum()))
286291
.starTreeQueryCurrent(starTreeCurrent.count())
292+
.starTreeQueryFailed(starTreeQueryFailed.count())
287293
.build();
288294
}
289295
}

server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,13 @@ protected Table getTableWithHeader(final RestRequest request, final PageToken pa
653653
"sibling:pri;alias:sqto,searchQueryTotal;default:false;text-align:right;desc:total query phase ops"
654654
);
655655
table.addCell("pri.search.query_total", "default:false;text-align:right;desc:total query phase ops");
656+
657+
table.addCell(
658+
"search.query_failed",
659+
"sibling:pri;alias:sqf,searchQueryFailed;default:false;text-align:right;desc:failed query phase ops"
660+
);
661+
table.addCell("pri.search.query_failed", "default:false;text-align:right;desc:failed query phase ops");
662+
656663
table.addCell(
657664
"search.concurrent_query_current",
658665
"sibling:pri;alias:scqc,searchConcurrentQueryCurrent;default:false;text-align:right;desc:current concurrent query phase ops"
@@ -1017,6 +1024,9 @@ protected Table buildTable(
10171024
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getQueryCount());
10181025
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getQueryCount());
10191026

1027+
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getQueryFailedCount());
1028+
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getQueryFailedCount());
1029+
10201030
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getConcurrentQueryCurrent());
10211031
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getConcurrentQueryCurrent());
10221032

server/src/main/java/org/opensearch/rest/action/cat/RestNodesAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ protected Table getTableWithHeader(final RestRequest request) {
304304
table.addCell("search.query_current", "alias:sqc,searchQueryCurrent;default:false;text-align:right;desc:current query phase ops");
305305
table.addCell("search.query_time", "alias:sqti,searchQueryTime;default:false;text-align:right;desc:time spent in query phase");
306306
table.addCell("search.query_total", "alias:sqto,searchQueryTotal;default:false;text-align:right;desc:total query phase ops");
307+
table.addCell("search.query_failed", "alias:sqf,searchQueryFailed;default:false;text-align:right;desc:total failed query phase ops");
307308
table.addCell(
308309
"search.concurrent_query_current",
309310
"alias:scqc,searchConcurrentQueryCurrent;default:false;text-align:right;desc:current concurrent query phase ops"
@@ -561,6 +562,7 @@ Table buildTable(
561562
table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCurrent());
562563
table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryTime());
563564
table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCount());
565+
table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryFailedCount());
564566
table.addCell(searchStats == null ? null : searchStats.getTotal().getConcurrentQueryCurrent());
565567
table.addCell(searchStats == null ? null : searchStats.getTotal().getConcurrentQueryTime());
566568
table.addCell(searchStats == null ? null : searchStats.getTotal().getConcurrentQueryCount());

server/src/main/java/org/opensearch/rest/action/cat/RestShardsAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ protected Table getTableWithHeader(final RestRequest request, final PageToken pa
233233
table.addCell("search.query_current", "alias:sqc,searchQueryCurrent;default:false;text-align:right;desc:current query phase ops");
234234
table.addCell("search.query_time", "alias:sqti,searchQueryTime;default:false;text-align:right;desc:time spent in query phase");
235235
table.addCell("search.query_total", "alias:sqto,searchQueryTotal;default:false;text-align:right;desc:total query phase ops");
236+
table.addCell("search.query_failed", "alias:sqf,searchQueryFailed;default:false;text-align:right;desc:failed query phase ops");
236237
table.addCell(
237238
"search.concurrent_query_current",
238239
"alias:scqc,searchConcurrentQueryCurrent;default:false;text-align:right;desc:current concurrent query phase ops"
@@ -458,6 +459,7 @@ Table buildTable(
458459
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryCurrent()));
459460
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryTime()));
460461
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryCount()));
462+
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryFailedCount()));
461463
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getConcurrentQueryCurrent()));
462464
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getConcurrentQueryTime()));
463465
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getConcurrentQueryCount()));

0 commit comments

Comments
 (0)