forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] Add Search Phase APM metrics (elastic#113194) (elastic#116751)
- Loading branch information
1 parent
2811a76
commit 161b7ef
Showing
17 changed files
with
371 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 113194 | ||
summary: Add Search Phase APM metrics | ||
area: Search | ||
type: enhancement | ||
issues: [] |
51 changes: 0 additions & 51 deletions
51
server/src/main/java/org/elasticsearch/action/search/SearchTransportAPMMetrics.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchPhaseAPMMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.search.stats; | ||
|
||
import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
import org.elasticsearch.index.shard.SearchOperationListener; | ||
import org.elasticsearch.search.internal.SearchContext; | ||
import org.elasticsearch.telemetry.metric.LongHistogram; | ||
import org.elasticsearch.telemetry.metric.MeterRegistry; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public final class ShardSearchPhaseAPMMetrics implements SearchOperationListener { | ||
|
||
public static final String QUERY_SEARCH_PHASE_METRIC = "es.search.shards.phases.query.duration.histogram"; | ||
public static final String FETCH_SEARCH_PHASE_METRIC = "es.search.shards.phases.fetch.duration.histogram"; | ||
|
||
public static final String SYSTEM_THREAD_ATTRIBUTE_NAME = "system_thread"; | ||
|
||
private final LongHistogram queryPhaseMetric; | ||
private final LongHistogram fetchPhaseMetric; | ||
|
||
// Avoid allocating objects in the search path and multithreading clashes | ||
private static final ThreadLocal<Map<String, Object>> THREAD_LOCAL_ATTRS = ThreadLocal.withInitial(() -> new HashMap<>(1)); | ||
|
||
public ShardSearchPhaseAPMMetrics(MeterRegistry meterRegistry) { | ||
this.queryPhaseMetric = meterRegistry.registerLongHistogram( | ||
QUERY_SEARCH_PHASE_METRIC, | ||
"Query search phase execution times at the shard level, expressed as a histogram", | ||
"ms" | ||
); | ||
this.fetchPhaseMetric = meterRegistry.registerLongHistogram( | ||
FETCH_SEARCH_PHASE_METRIC, | ||
"Fetch search phase execution times at the shard level, expressed as a histogram", | ||
"ms" | ||
); | ||
} | ||
|
||
@Override | ||
public void onQueryPhase(SearchContext searchContext, long tookInNanos) { | ||
recordPhaseLatency(queryPhaseMetric, tookInNanos); | ||
} | ||
|
||
@Override | ||
public void onFetchPhase(SearchContext searchContext, long tookInNanos) { | ||
recordPhaseLatency(fetchPhaseMetric, tookInNanos); | ||
} | ||
|
||
private static void recordPhaseLatency(LongHistogram histogramMetric, long tookInNanos) { | ||
Map<String, Object> attrs = ShardSearchPhaseAPMMetrics.THREAD_LOCAL_ATTRS.get(); | ||
boolean isSystem = ((EsExecutors.EsThread) Thread.currentThread()).isSystem(); | ||
attrs.put(SYSTEM_THREAD_ATTRIBUTE_NAME, isSystem); | ||
histogramMetric.record(TimeUnit.NANOSECONDS.toMillis(tookInNanos), attrs); | ||
} | ||
} |
Oops, something went wrong.