Skip to content

Commit

Permalink
add metric to cat api
Browse files Browse the repository at this point in the history
  • Loading branch information
ruai0511 committed Mar 21, 2024
1 parent 8533d40 commit ef646c6
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static class Stats implements Writeable, ToXContentFragment {
private long pitTimeInMillis;
private long pitCurrent;

private long searchIdleWakenUpCount;
private long searchIdleReactivateCount;

@Nullable
private RequestStatsLongHolder requestStatsLongHolder;
Expand Down Expand Up @@ -196,7 +196,7 @@ public Stats(
long suggestCount,
long suggestTimeInMillis,
long suggestCurrent,
long searchIdleWakenUpCount
long searchIdleReactivateCount
) {
this.requestStatsLongHolder = new RequestStatsLongHolder();
this.queryCount = queryCount;
Expand Down Expand Up @@ -224,7 +224,7 @@ public Stats(
this.pitTimeInMillis = pitTimeInMillis;
this.pitCurrent = pitCurrent;

this.searchIdleWakenUpCount = searchIdleWakenUpCount;
this.searchIdleReactivateCount = searchIdleReactivateCount;
}

private Stats(StreamInput in) throws IOException {
Expand Down Expand Up @@ -262,7 +262,7 @@ private Stats(StreamInput in) throws IOException {
}

if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
searchIdleWakenUpCount = in.readVLong();
searchIdleReactivateCount = in.readVLong();
}
}

Expand Down Expand Up @@ -292,7 +292,7 @@ public void add(Stats stats) {
pitTimeInMillis += stats.pitTimeInMillis;
pitCurrent += stats.pitCurrent;

searchIdleWakenUpCount += stats.searchIdleWakenUpCount;
searchIdleReactivateCount += stats.searchIdleReactivateCount;
}

public void addForClosingShard(Stats stats) {
Expand All @@ -318,7 +318,7 @@ public void addForClosingShard(Stats stats) {
pitCurrent += stats.pitCurrent;
queryConcurrency += stats.queryConcurrency;

searchIdleWakenUpCount += stats.searchIdleWakenUpCount;
searchIdleReactivateCount += stats.searchIdleReactivateCount;
}

public long getQueryCount() {
Expand Down Expand Up @@ -425,8 +425,8 @@ public long getSuggestCurrent() {
return suggestCurrent;
}

public long getSearchIdleWakenUpCount() {
return searchIdleWakenUpCount;
public long getSearchIdleReactivateCount() {
return searchIdleReactivateCount;
}

public static Stats readStats(StreamInput in) throws IOException {
Expand Down Expand Up @@ -476,7 +476,7 @@ public void writeTo(StreamOutput out) throws IOException {
}

if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
out.writeVLong(searchIdleWakenUpCount);
out.writeVLong(searchIdleReactivateCount);
}
}

Expand Down Expand Up @@ -507,7 +507,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.humanReadableField(Fields.SUGGEST_TIME_IN_MILLIS, Fields.SUGGEST_TIME, getSuggestTime());
builder.field(Fields.SUGGEST_CURRENT, suggestCurrent);

builder.field(Fields.SEARCH_IDLE_WAKEN_UP_TOTAL, searchIdleWakenUpCount);
builder.field(Fields.SEARCH_IDLE_REACTIVATE_COUNT_TOTAL, searchIdleReactivateCount);

if (requestStatsLongHolder != null) {
builder.startObject(Fields.REQUEST);
Expand Down Expand Up @@ -677,7 +677,7 @@ static final class Fields {
static final String TIME = "time";
static final String CURRENT = "current";
static final String TOTAL = "total";
static final String SEARCH_IDLE_WAKEN_UP_TOTAL = "search_idle_waken_up_total";
static final String SEARCH_IDLE_REACTIVATE_COUNT_TOTAL = "search_idle_reactivate_count_total";

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void onFreePitContext(ReaderContext readerContext) {
}

@Override
public void onNewSearchIdleWakenUp() {
public void onSearchIdleReactivation() {
totalStats.searchIdleMetric.inc();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ public Engine.Searcher acquireSearcher(String source) {
private void markSearcherAccessed() {
if (isSearchIdle()) {
SearchOperationListener searchOperationListener = getSearchOperationListener();
searchOperationListener.onNewSearchIdleWakenUp();
searchOperationListener.onSearchIdleReactivation();
}
lastSearcherAccess.lazySet(threadPool.relativeTimeInMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ default void onFreePitContext(ReaderContext readerContext) {}
/**
* Executed when a shard goes from idle to non-idle state
*/
default void onNewSearchIdleWakenUp() {}
default void onSearchIdleReactivation() {}

/**
* A Composite listener that multiplexes calls to each of the listeners methods.
Expand Down Expand Up @@ -317,12 +317,12 @@ public void onFreePitContext(ReaderContext readerContext) {
}

@Override
public void onNewSearchIdleWakenUp() {
public void onSearchIdleReactivation() {
for (SearchOperationListener listener : listeners) {
try {
listener.onNewSearchIdleWakenUp();
listener.onSearchIdleReactivation();
} catch (Exception e) {
logger.warn(() -> new ParameterizedMessage("onNewSearchIdleWakenUp listener [{}] failed", listener), e);
logger.warn(() -> new ParameterizedMessage("onNewSearchIdleReactivation listener [{}] failed", listener), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,15 @@ protected Table getTableWithHeader(final RestRequest request) {
);
table.addCell("pri.search.point_in_time_total", "default:false;text-align:right;desc:completed point in time contexts");

table.addCell(
"search.search_idle_reactivate_count_total",
"sibling:pri;alias:ssirct,searchSearchIdleReactivateCountTotal;default:false;text-align:right;desc:number of times a shard reactivated"
);
table.addCell(
"pri.search.search_idle_reactivate_count_total",
"default:false;text-align:right;desc:number of times a shard reactivated"
);

table.addCell("segments.count", "sibling:pri;alias:sc,segmentsCount;default:false;text-align:right;desc:number of segments");
table.addCell("pri.segments.count", "default:false;text-align:right;desc:number of segments");

Expand Down Expand Up @@ -943,6 +952,9 @@ Table buildTable(
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getPitCount());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getPitCount());

table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getSearchIdleReactivateCount());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getSearchIdleReactivateCount());

table.addCell(totalStats.getSegments() == null ? null : totalStats.getSegments().getCount());
table.addCell(primaryStats.getSegments() == null ? null : primaryStats.getSegments().getCount());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ protected Table getTableWithHeader(final RestRequest request) {
"search.point_in_time_total",
"alias:scto,searchPointInTimeTotal;default:false;text-align:right;desc:completed point in time contexts"
);
table.addCell(
"search.search_idle_reactivate_count_total",
"alias:ssirct,searchSearchIdleReactivateCountTotal;default:false;text-align:right;desc:number of times a shard reactivated"
);

table.addCell("segments.count", "alias:sc,segmentsCount;default:false;text-align:right;desc:number of segments");
table.addCell("segments.memory", "alias:sm,segmentsMemory;default:false;text-align:right;desc:memory used by segments");
Expand Down Expand Up @@ -555,6 +559,7 @@ Table buildTable(
table.addCell(searchStats == null ? null : searchStats.getTotal().getPitCurrent());
table.addCell(searchStats == null ? null : searchStats.getTotal().getPitTime());
table.addCell(searchStats == null ? null : searchStats.getTotal().getPitCount());
table.addCell(searchStats == null ? null : searchStats.getTotal().getSearchIdleReactivateCount());

SegmentsStats segmentsStats = indicesStats == null ? null : indicesStats.getSegments();
table.addCell(segmentsStats == null ? null : segmentsStats.getCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ protected Table getTableWithHeader(final RestRequest request) {
"search.point_in_time_total",
"alias:spto,searchPointInTimeTotal;default:false;text-align:right;desc:completed point in time contexts"
);
table.addCell(
"search.search_idle_reactivate_count_total",
"alias:ssirct,searchSearchIdleReactivateCountTotal;default:false;text-align:right;desc:number of times a shard reactivated"
);

table.addCell("segments.count", "alias:sc,segmentsCount;default:false;text-align:right;desc:number of segments");
table.addCell("segments.memory", "alias:sm,segmentsMemory;default:false;text-align:right;desc:memory used by segments");
Expand Down Expand Up @@ -427,6 +431,7 @@ Table buildTable(RestRequest request, ClusterStateResponse state, IndicesStatsRe
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getPitCurrent()));
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getPitTime()));
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getPitCount()));
table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getSearchIdleReactivateCount()));

table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getCount));
table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getZeroMemory));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void assertStats(Stats stats, long equalTo) {
assertEquals(equalTo, stats.getSuggestCount());
assertEquals(equalTo, stats.getSuggestTimeInMillis());
assertEquals(equalTo, stats.getSuggestCurrent());
assertEquals(equalTo, stats.getSearchIdleWakenUpCount());
assertEquals(equalTo, stats.getSearchIdleReactivateCount());
// avg_concurrency is not summed up across stats
assertEquals(1, stats.getConcurrentAvgSliceCount(), 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testListenersAreExecuted() {
AtomicInteger newScrollContext = new AtomicInteger();
AtomicInteger freeScrollContext = new AtomicInteger();
AtomicInteger validateSearchContext = new AtomicInteger();
AtomicInteger searchIdleWakenUp = new AtomicInteger();
AtomicInteger searchIdleReactivateCount = new AtomicInteger();
AtomicInteger timeInNanos = new AtomicInteger(randomIntBetween(0, 10));
SearchOperationListener listener = new SearchOperationListener() {
@Override
Expand Down Expand Up @@ -136,8 +136,8 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest
}

@Override
public void onNewSearchIdleWakenUp() {
searchIdleWakenUp.incrementAndGet();
public void onSearchIdleReactivation() {
searchIdleReactivateCount.incrementAndGet();
}
};

Expand Down Expand Up @@ -175,7 +175,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(0, newScrollContext.get());
assertEquals(0, freeContext.get());
assertEquals(0, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onFetchPhase(ctx, timeInNanos.get());
Expand All @@ -189,7 +189,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(0, newScrollContext.get());
assertEquals(0, freeContext.get());
assertEquals(0, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onPreQueryPhase(ctx);
Expand All @@ -203,7 +203,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(0, newScrollContext.get());
assertEquals(0, freeContext.get());
assertEquals(0, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onPreFetchPhase(ctx);
Expand All @@ -217,7 +217,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(0, newScrollContext.get());
assertEquals(0, freeContext.get());
assertEquals(0, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onFailedFetchPhase(ctx);
Expand All @@ -231,7 +231,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(0, newScrollContext.get());
assertEquals(0, freeContext.get());
assertEquals(0, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onFailedQueryPhase(ctx);
Expand All @@ -245,7 +245,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(0, newScrollContext.get());
assertEquals(0, freeContext.get());
assertEquals(0, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onNewReaderContext(mock(ReaderContext.class));
Expand All @@ -259,7 +259,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(0, newScrollContext.get());
assertEquals(0, freeContext.get());
assertEquals(0, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onNewScrollContext(mock(ReaderContext.class));
Expand All @@ -273,7 +273,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(2, newScrollContext.get());
assertEquals(0, freeContext.get());
assertEquals(0, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onFreeReaderContext(mock(ReaderContext.class));
Expand All @@ -287,7 +287,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(2, newScrollContext.get());
assertEquals(2, freeContext.get());
assertEquals(0, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onFreeScrollContext(mock(ReaderContext.class));
Expand All @@ -301,10 +301,10 @@ public void onNewSearchIdleWakenUp() {
assertEquals(2, newScrollContext.get());
assertEquals(2, freeContext.get());
assertEquals(2, freeScrollContext.get());
assertEquals(0, searchIdleWakenUp.get());
assertEquals(0, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

compositeListener.onNewSearchIdleWakenUp();
compositeListener.onSearchIdleReactivation();
assertEquals(2, preFetch.get());
assertEquals(2, preQuery.get());
assertEquals(2, failedFetch.get());
Expand All @@ -315,7 +315,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(2, newScrollContext.get());
assertEquals(2, freeContext.get());
assertEquals(2, freeScrollContext.get());
assertEquals(2, searchIdleWakenUp.get());
assertEquals(2, searchIdleReactivateCount.get());
assertEquals(0, validateSearchContext.get());

if (throwingListeners == 0) {
Expand All @@ -341,7 +341,7 @@ public void onNewSearchIdleWakenUp() {
assertEquals(2, newScrollContext.get());
assertEquals(2, freeContext.get());
assertEquals(2, freeScrollContext.get());
assertEquals(2, searchIdleWakenUp.get());
assertEquals(2, searchIdleReactivateCount.get());
assertEquals(2, validateSearchContext.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void testBuildTable() {
assertThat(headers.get(6).value, equalTo("ip"));
assertThat(headers.get(7).value, equalTo("id"));
assertThat(headers.get(8).value, equalTo("node"));
assertThat(headers.get(78).value, equalTo("docs.deleted"));
assertThat(headers.get(79).value, equalTo("docs.deleted"));

final List<List<Table.Cell>> rows = table.getRows();
assertThat(rows.size(), equalTo(numShards));
Expand All @@ -141,9 +141,9 @@ public void testBuildTable() {
assertThat(row.get(4).value, equalTo(shardStats.getStats().getDocs().getCount()));
assertThat(row.get(6).value, equalTo(localNode.getHostAddress()));
assertThat(row.get(7).value, equalTo(localNode.getId()));
assertThat(row.get(76).value, equalTo(shardStats.getDataPath()));
assertThat(row.get(77).value, equalTo(shardStats.getStatePath()));
assertThat(row.get(78).value, equalTo(shardStats.getStats().getDocs().getDeleted()));
assertThat(row.get(77).value, equalTo(shardStats.getDataPath()));
assertThat(row.get(78).value, equalTo(shardStats.getStatePath()));
assertThat(row.get(79).value, equalTo(shardStats.getStats().getDocs().getDeleted()));
}
}
}

0 comments on commit ef646c6

Please sign in to comment.