generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 104
Add stats tracking for semantic highlighting #1327
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
junqiu-lei
merged 3 commits into
opensearch-project:main
from
junqiu-lei:highlight-stats
May 20, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
113 changes: 113 additions & 0 deletions
113
src/test/java/org/opensearch/neuralsearch/stats/events/SemanticHighlightingStatsTests.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,113 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.opensearch.neuralsearch.stats.events; | ||
|
|
||
| import org.opensearch.test.OpenSearchTestCase; | ||
| import org.junit.Before; | ||
|
|
||
| import java.util.EnumSet; | ||
| import java.util.Locale; | ||
|
|
||
| public class SemanticHighlightingStatsTests extends OpenSearchTestCase { | ||
junqiu-lei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private static final EnumSet<EventStatName> SEMANTIC_HIGHLIGHTING_STATS = EnumSet.of( | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_REQUEST_COUNT, | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_ERROR_COUNT | ||
| ); | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| } | ||
|
|
||
| public void testSemanticHighlightingStatsExist() { | ||
| // Verify that both semantic highlighting stats exist in the enum | ||
| assertTrue( | ||
| "SEMANTIC_HIGHLIGHTING_REQUEST_COUNT should exist", | ||
| EnumSet.allOf(EventStatName.class).contains(EventStatName.SEMANTIC_HIGHLIGHTING_REQUEST_COUNT) | ||
| ); | ||
| assertTrue( | ||
| "SEMANTIC_HIGHLIGHTING_ERROR_COUNT should exist", | ||
| EnumSet.allOf(EventStatName.class).contains(EventStatName.SEMANTIC_HIGHLIGHTING_ERROR_COUNT) | ||
| ); | ||
| } | ||
|
|
||
| public void testSemanticHighlightingStatsPaths() { | ||
| // Verify that both stats have the correct path | ||
| assertEquals( | ||
| "SEMANTIC_HIGHLIGHTING_REQUEST_COUNT should have correct path", | ||
| "semantic_highlighting", | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_REQUEST_COUNT.getPath() | ||
| ); | ||
| assertEquals( | ||
| "SEMANTIC_HIGHLIGHTING_ERROR_COUNT should have correct path", | ||
| "semantic_highlighting", | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_ERROR_COUNT.getPath() | ||
| ); | ||
| } | ||
|
|
||
| public void testSemanticHighlightingStatsNames() { | ||
| // Verify that both stats have the correct name strings | ||
| assertEquals( | ||
| "SEMANTIC_HIGHLIGHTING_REQUEST_COUNT should have correct name", | ||
| "request_count", | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_REQUEST_COUNT.getNameString() | ||
| ); | ||
| assertEquals( | ||
| "SEMANTIC_HIGHLIGHTING_ERROR_COUNT should have correct name", | ||
| "error_count", | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_ERROR_COUNT.getNameString() | ||
| ); | ||
| } | ||
|
|
||
| public void testSemanticHighlightingStatsFullPaths() { | ||
| // Verify that both stats have the correct full paths | ||
| assertEquals( | ||
| "SEMANTIC_HIGHLIGHTING_REQUEST_COUNT should have correct full path", | ||
| "semantic_highlighting.request_count", | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_REQUEST_COUNT.getFullPath() | ||
| ); | ||
| assertEquals( | ||
| "SEMANTIC_HIGHLIGHTING_ERROR_COUNT should have correct full path", | ||
| "semantic_highlighting.error_count", | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_ERROR_COUNT.getFullPath() | ||
| ); | ||
| } | ||
|
|
||
| public void testSemanticHighlightingStatsTypes() { | ||
| // Verify that both stats have the correct type | ||
| for (EventStatName stat : SEMANTIC_HIGHLIGHTING_STATS) { | ||
| assertEquals("Stat should be of type TIMESTAMPED_EVENT_COUNTER", EventStatType.TIMESTAMPED_EVENT_COUNTER, stat.getStatType()); | ||
| } | ||
| } | ||
|
|
||
| public void testSemanticHighlightingStatsEventStats() { | ||
| // Verify that both stats have non-null event stats | ||
| for (EventStatName stat : SEMANTIC_HIGHLIGHTING_STATS) { | ||
| assertNotNull("Event stat should not be null", stat.getEventStat()); | ||
| assertTrue("Event stat should be instance of TimestampedEventStat", stat.getEventStat() instanceof TimestampedEventStat); | ||
| } | ||
| } | ||
|
|
||
| public void testSemanticHighlightingStatsFromString() { | ||
| // Test looking up stats by their name strings | ||
| assertEquals( | ||
| "Should find SEMANTIC_HIGHLIGHTING_REQUEST_COUNT by name", | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_REQUEST_COUNT, | ||
| EventStatName.from("request_count") | ||
| ); | ||
| assertEquals( | ||
| "Should find SEMANTIC_HIGHLIGHTING_ERROR_COUNT by name", | ||
| EventStatName.SEMANTIC_HIGHLIGHTING_ERROR_COUNT, | ||
| EventStatName.from("error_count") | ||
| ); | ||
|
|
||
| // Test invalid name | ||
| IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> EventStatName.from("invalid_stat_name")); | ||
| assertTrue( | ||
| "Error message should mention invalid stat name", | ||
| exception.getMessage().toLowerCase(Locale.ROOT).contains("event stat not found") | ||
| ); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename the stat names to
semantic_highlighting_request_countandsemantic_highlighting_error_count. The stat name is used as a unique identifier across all stats without the path. Maybe also shorten the path fromsemantic_highlighting->highlighting?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can make the full path redundant in naming.
The EventStatName class already has a getFullPath() method that combines the path and name with a dot (e.g., semantic_highlighting.request_count), which seems like a more robust way to handle uniqueness?
I prefer to keep using with
semantic_highlightingwhich is consistent with the origin feature name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offline talked with @q-andy, the stats filter is being used along with child stats name, like
semantic_highlighting_request_count, this function is introduced since 3.0.0 OpenSearch. To keep the function same and backward compatibility, we'll use namesemantic_highlighting_request_countandsemantic_highlighting_error_count.