Skip to content
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

78 collect stats for usage and health #79

Conversation

JohannesDaniel
Copy link
Collaborator

Description

Collecting stats about requests in total, requests with errors and cache usage.

Issues Resolved

#78

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…s and caches into query implementations

Signed-off-by: Johannes Peter <[email protected]>
@JohannesDaniel JohannesDaniel force-pushed the 78-collect-stats-for-usage-and-health branch from 8a1ea9a to 7b5ac91 Compare December 3, 2024 17:46
@JohannesDaniel
Copy link
Collaborator Author

@ylwu-amzn
@jngz-es

src/main/java/com/o19s/es/explore/ExplorerQuery.java Outdated Show resolved Hide resolved
src/main/java/com/o19s/es/ltr/stats/LTRStats.java Outdated Show resolved Hide resolved
src/main/java/org/opensearch/ltr/stats/StatName.java Outdated Show resolved Hide resolved
@Override
public Map<String, Map<String, Object>> get() {
Map<String, Map<String, Object>> values = new HashMap<>();
values.put("feature", getCacheStats(caches.featureCache()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using an enum for cache types instead of hardcoded strings?

Then we can refactor this method as

@Override
public Map<String, Map<String, Object>> get() {
    Map<String, Map<String, Object>> values = new HashMap<>();
    for (CacheType type : CacheType.values()) {
        values.put(type.getValue(), getCacheStats(getCacheForType(type)));
    }
    return Collections.unmodifiableMap(values);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the way the caching is implemented as of now, I do not see the benefit of having an enum here, as this will still require a direct mapping between the enum and the method called to get the corresponding metrics, so the code is not going to be simplified/generified:

caches.featureCache()
caches.featureSetCache()
caches.modelCache()

However, I will pull the hard-coded strings out of the method and refactor them to static class variables.

src/main/java/org/opensearch/ltr/stats/LTRStats.java Outdated Show resolved Hide resolved
src/main/java/org/opensearch/ltr/stats/LTRStat.java Outdated Show resolved Hide resolved
return _doToQuery(context);
} catch (Exception e) {
ltrStats.getStat(StatName.LTR_REQUEST_ERROR_COUNT.getName()).increment();
throw e;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log error before throwing ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a wrapper to collect stats about exceptions but does not initiate or handle the exceptions. I would expect them to be logged where they are initiated or handled, otherwise this might lead to redundant logging.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, sounds good if upper layer already have logging for such case

src/main/java/com/o19s/es/ltr/query/RankerQuery.java Outdated Show resolved Hide resolved
return _createWeight(searcher, scoreMode, boost);
} catch (Exception e) {
ltrStats.getStat(StatName.LTR_REQUEST_ERROR_COUNT.getName()).increment();
throw e;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log error before throwing ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

@sstults sstults merged commit c19e3a3 into opensearch-project:main Dec 5, 2024
5 checks passed
sstults pushed a commit to sstults/opensearch-learning-to-rank-base that referenced this pull request Dec 19, 2024
Signed-off-by: Johannes Peter <[email protected]>
(cherry picked from commit c19e3a3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants