-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add support for extended search usage telemetry #135306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kderusso
merged 32 commits into
elastic:main
from
kderusso:kderusso/add-extended-telemetry
Sep 26, 2025
Merged
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
43bdac7
Add extended telemetry
kderusso 6d8ef33
Cleanup
kderusso 7ba47b8
Update docs/changelog/135306.yaml
kderusso ee69131
[CI] Auto commit changes from spotless
e6521dc
[CI] Update transport version definitions
991b017
Fix serialization
kderusso d5ecba0
Add tests
kderusso 3ae7298
Merge branch 'main' into kderusso/add-extended-telemetry
kderusso 8dc43b8
Update transport
kderusso b6eeb4d
Tests
kderusso 3c1b802
[CI] Auto commit changes from spotless
9f4e40d
Yaml
kderusso 64dd905
Merge branch 'main' into kderusso/add-extended-telemetry
kderusso 2f3cc00
Merge branch 'main' into kderusso/add-extended-telemetry
kderusso 269cf37
Fix error in SearchUsageStatsTests due to randomization
kderusso 66020f8
Ensure mutation in serialization tests
kderusso 70150fa
[CI] Auto commit changes from spotless
89e911b
Revert "Yaml"
kderusso 9843a41
[CI] Update transport version definitions
ffdf860
Merge from main
kderusso c6da79e
Remove old debug breakpoint
kderusso 5290e09
PR feedback: Refactor extended stats into objects instead of forcing …
kderusso 636104e
Make ExtendedSeearchUsageMetric a NamedWriteable
kderusso 2f542b7
Merge from main
kderusso c6e03dd
Regenerate transport version
kderusso 788fe03
Fix serialization
kderusso 427df05
[CI] Auto commit changes from spotless
06b6c3f
PR Feedback
kderusso 18e663c
[CI] Auto commit changes from spotless
d3b7ecc
PR feedback
kderusso 61c2823
Merge update from main
kderusso 49e1ef8
Regenerate transport version
kderusso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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: 135306 | ||
| summary: Add support for extended search usage telemetry | ||
| area: Relevance | ||
| type: enhancement | ||
| issues: [] |
124 changes: 124 additions & 0 deletions
124
.../src/main/java/org/elasticsearch/action/admin/cluster/stats/ExtendedSearchUsageStats.java
This file contains hidden or 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,124 @@ | ||
| /* | ||
| * 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.action.admin.cluster.stats; | ||
|
|
||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.usage.SearchUsage; | ||
| import org.elasticsearch.xcontent.ToXContent; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Provides extended statistics for {@link SearchUsage} beyond the basic counts provided in {@link SearchUsageStats}. | ||
| */ | ||
| public class ExtendedSearchUsageStats implements Writeable, ToXContent { | ||
|
|
||
| /** | ||
| * A map of categories to extended data. Categories correspond to a high-level search usage statistic, | ||
| * e.g. `queries`, `rescorers`, `sections`, `retrievers`. | ||
| * | ||
| * Extended data is further segmented by name, for example collecting specific statistics for certain retrievers only. | ||
| * | ||
| * Finally, we have string:count pairs that track each individual metric we wish to track. | ||
| */ | ||
| private final Map<String, Map<String, Map<String, Long>>> categoriesToExtendedData; | ||
kderusso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public ExtendedSearchUsageStats() { | ||
| this.categoriesToExtendedData = new HashMap<>(); | ||
| } | ||
|
|
||
| public ExtendedSearchUsageStats(Map<String, Map<String, Map<String, Long>>> categoriesToExtendedData) { | ||
| this.categoriesToExtendedData = categoriesToExtendedData; | ||
| } | ||
|
|
||
| public ExtendedSearchUsageStats(StreamInput in) throws IOException { | ||
| this.categoriesToExtendedData = in.readMap( | ||
| StreamInput::readString, | ||
| i -> i.readMap(StreamInput::readString, j -> j.readMap(StreamInput::readString, StreamInput::readLong)) | ||
| ); | ||
| } | ||
|
|
||
| public Map<String, Map<String, Map<String, Long>>> getCategoriesToExtendedData() { | ||
| return Collections.unmodifiableMap(categoriesToExtendedData); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeMap( | ||
| categoriesToExtendedData, | ||
| StreamOutput::writeString, | ||
| (o, v) -> o.writeMap(v, StreamOutput::writeString, (p, q) -> p.writeMap(q, StreamOutput::writeString, StreamOutput::writeLong)) | ||
| ); | ||
| } | ||
|
|
||
| public void merge(ExtendedSearchUsageStats other) { | ||
| other.categoriesToExtendedData.forEach((key, otherMap) -> { | ||
| categoriesToExtendedData.merge(key, otherMap, (existingMap, newMap) -> { | ||
| Map<String, Map<String, Long>> mergedMap = new HashMap<>(existingMap); | ||
| newMap.forEach((innerKey, innerValue) -> { | ||
| mergedMap.merge(innerKey, innerValue, (existingInnerMap, newInnerMap) -> { | ||
| Map<String, Long> mergedInnerMap = new HashMap<>(existingInnerMap); | ||
| newInnerMap.forEach( | ||
| (propertyKey, propertyValue) -> { mergedInnerMap.merge(propertyKey, propertyValue, Long::sum); } | ||
| ); | ||
| return mergedInnerMap; | ||
| }); | ||
| }); | ||
| return mergedMap; | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
|
|
||
| builder.startObject(); | ||
| for (String category : categoriesToExtendedData.keySet()) { | ||
| builder.startObject(category); | ||
| Map<String, Map<String, Long>> names = categoriesToExtendedData.get(category); | ||
| for (String name : names.keySet()) { | ||
| builder.startObject(name); | ||
| for (String property : names.get(name).keySet()) { | ||
| builder.field(property, names.get(name).get(property)); | ||
| } | ||
| builder.endObject(); | ||
| } | ||
| builder.endObject(); | ||
| } | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| ExtendedSearchUsageStats that = (ExtendedSearchUsageStats) o; | ||
| return Objects.equals(categoriesToExtendedData, that.categoriesToExtendedData); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(categoriesToExtendedData); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return Strings.toString(this, true, true); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.