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

[BUG] Top N API returns no results when only cpu or only memory is enabled #83

Closed
dzane17 opened this issue Aug 29, 2024 · 2 comments
Closed
Labels
bug Something isn't working v2.17.0 Issues targeting release v2.17.0

Comments

@dzane17
Copy link
Collaborator

dzane17 commented Aug 29, 2024

What is the bug?

Top N API returns no results when only cpu or only memory is enabled.

In RestTopQueriesAction we have a single check for MetricType.LATENCY which is causing this issue:
https://github.com/opensearch-project/query-insights/blob/main/src/main/java/org/opensearch/plugin/insights/rules/resthandler/top_queries/RestTopQueriesAction.java#L69

How can one reproduce the bug?

  1. Enable top N for cpu. Ensure latency, memory, and search.query.metrics.enabled are disabled.
curl -X PUT "localhost:9200/_cluster/settings?pretty&flat_settings" -H 'Content-Type: application/json' -d '{"transient" : {"search.insights.top_queries.cpu.enabled" : true}}'
  1. Index data and send some search requests
// Bulk
curl -X POST "localhost:9200/_bulk?pretty" -H 'Content-Type: application/json' -d'
{ "index" : { "_index" : "test2", "_id" : "1" } }
{ "field1" : "value1" }                          
{ "index" : { "_index" : "test2", "_id" : "2" } }
{ "field2" : "value2" }
{ "index" : { "_index" : "test2", "_id" : "3" } }
{ "field3" : "value3" }
{ "index" : { "_index" : "test2", "_id" : "4" } }
{ "field4" : "value4" }
'

// Match all
curl -X GET "http://localhost:9200/_search?pretty&phase_took" -H 'Content-Type: application/json' -d' 
{
  "query": {
    "match_all": {}
  }
}'
  1. Get Top N
% curl -X GET "localhost:9200/_insights/top_queries?pretty"

{
  "top_queries" : [ ]
}

API will return no results even though top N cpu is enabled

What is the expected behavior?

Top N should return results if any 1 or more metrics (latency, cpu, memory) are enabled.

@dzane17 dzane17 added bug Something isn't working untriaged v2.17.0 Issues targeting release v2.17.0 labels Aug 29, 2024
@dzane17
Copy link
Collaborator Author

dzane17 commented Aug 30, 2024

If user calls Top N api without any type param (ex GET /_insights/top_queries) we use type=latency by default. That is why no results are returned anytime latency is disabled but cpu and/or memory are enabled.

final String metricType = request.param("type", MetricType.LATENCY.toString());

Need to update documentation:
https://opensearch.org/docs/2.16/observing-your-data/query-insights/top-n-queries/#monitoring-the-top-n-queries

You can use the Insights API endpoint to obtain the top N queries for all metric types:

GET /_insights/top_queries

@ansjcy
Copy link
Member

ansjcy commented Sep 4, 2024

@dzane17 is right, I think this is a bug introduced when adding CPU and memory as additional metric types. IMO we should not set the default metric type subjectively. But in this case we should also update the API to disallow users to call the API without the type parameter.

@ansjcy ansjcy closed this as completed Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v2.17.0 Issues targeting release v2.17.0
Projects
None yet
Development

No branches or pull requests

2 participants