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

Top n queries historical queries from local index and time range #84

Merged
merged 10 commits into from
Sep 5, 2024

Conversation

LilyCaroline17
Copy link
Contributor

@LilyCaroline17 LilyCaroline17 commented Aug 30, 2024

Description

When the local index exporter is enabled, historical top N queries data is stored there. Previously, obtaining these historical queries required manually searching through each index. To simplify this process for users, we've introduced two parameters: 'from' and 'to', to the top n queries request. This allows users to define the time range for retrieving historical data. Please ensure that from and to are in ISO format.

For example, you could make this following call to retrieve the top N queries from August 25, 2024, at 15:00 UTC to August 30, 2024, at 17:00 UTC.
curl -X GET "http://localhost:9200/_insights/top_queries?from=2024-08-25T15:00:00.000Z&to=2024-08-30T17:00:00.000Z"

Issues Resolved

Closes #12

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.

LilyCaroline17 and others added 4 commits August 22, 2024 16:50
Signed-off-by: Emily Guo <emilyguo@amazon.com>

Handle indexing errors and accurate search parsing

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Correctly filter in window queries when from and to exist

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Remove search requests from top n queries

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Removed comments

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Comments for new functions

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Comments for new functions

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Updated comments

Signed-off-by: Emily Guo <emilyguo@amazon.com>
Signed-off-by: Emily Guo <emilyguo@amazon.com>
Signed-off-by: Emily Guo <35637792+LilyCaroline17@users.noreply.github.com>
Signed-off-by: Emily Guo <35637792+LilyCaroline17@users.noreply.github.com>
@deshsidd
Copy link
Collaborator

Looks like one of the build is failing please take a look

Signed-off-by: Emily Guo <35637792+LilyCaroline17@users.noreply.github.com>
end = DateTime.now(DateTimeZone.UTC);
}
DateTime curr = start;
while (curr.compareTo(end.plusDays(1).withTimeAtStartOfDay()) < 0) {
Copy link
Member

@ansjcy ansjcy Sep 5, 2024

Choose a reason for hiding this comment

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

Note: We are making assumptions on the index pattern that it will rollover every day. We should add this assumption with a check in the configuration API as well. And we should not allow user to change this rollover period and only allow them to change the prefix pattern. In that case

MatchQueryBuilder excludeQuery = QueryBuilders.matchQuery("indices", "top_queries*");

would become something like

MatchQueryBuilder excludeQuery = QueryBuilders.matchQuery("indices", TOP_N_QUERIES_INDEX_PATTERN + "*");

return Arrays.stream(indices).noneMatch(index -> {
if (index instanceof String) {
String indexString = (String) index;
return indexString.contains("top_queries");
Copy link
Member

Choose a reason for hiding this comment

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

Also we are basically saying ignoring any requests made on the top_queries index. it might be worth discussing it further whether we want to do this.

LilyCaroline17 and others added 3 commits September 4, 2024 21:36
…ilters to historical, and rename functions

Signed-off-by: Emily Guo <LilyCaroline1717@gmail.com>
Signed-off-by: Emily Guo <35637792+LilyCaroline17@users.noreply.github.com>
Signed-off-by: Emily Guo <LilyCaroline1717@gmail.com>
@ansjcy ansjcy merged commit 4d896cc into opensearch-project:main Sep 5, 2024
16 checks passed
@ansjcy
Copy link
Member

ansjcy commented Sep 5, 2024

Thanks for making the changes!
Overall it looks good to me and I'm merging it now, but we still need to follow up one several things before 2.18 release:

  • Discuss further on whether we should ignore any requests made on the top_queries index.
  • Have more strict restriction on index pattern the user can use.

opensearch-trigger-bot bot pushed a commit that referenced this pull request Sep 5, 2024
* Added support for historical top n queries

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Handle indexing errors and accurate search parsing

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Correctly filter in window queries when from and to exist

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Remove search requests from top n queries

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Removed comments

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Comments for new functions

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Comments for new functions

Signed-off-by: Emily Guo <emilyguo@amazon.com>

Updated comments

Signed-off-by: Emily Guo <emilyguo@amazon.com>

* Added unit tests

Signed-off-by: Emily Guo <emilyguo@amazon.com>

* Update LocalIndexExporter.java

Signed-off-by: Emily Guo <35637792+LilyCaroline17@users.noreply.github.com>

* Update LocalIndexReaderTests.java

Signed-off-by: Emily Guo <35637792+LilyCaroline17@users.noreply.github.com>

* Update QueryInsightsReaderFactoryTests.java

Signed-off-by: Emily Guo <35637792+LilyCaroline17@users.noreply.github.com>

* Address comments, change getTimeRange into getFrom and getTo, apply filters to historical, and rename functions

Signed-off-by: Emily Guo <LilyCaroline1717@gmail.com>

* Fix test cases

Signed-off-by: Emily Guo <LilyCaroline1717@gmail.com>

---------

Signed-off-by: Emily Guo <emilyguo@amazon.com>
Signed-off-by: Emily Guo <35637792+LilyCaroline17@users.noreply.github.com>
Signed-off-by: Emily Guo <LilyCaroline1717@gmail.com>
(cherry picked from commit 4d896cc)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ansjcy pushed a commit that referenced this pull request Sep 5, 2024
#105)

* Added support for historical top n queries



Handle indexing errors and accurate search parsing



Correctly filter in window queries when from and to exist



Remove search requests from top n queries



Removed comments



Comments for new functions



Comments for new functions



Updated comments



* Added unit tests



* Update LocalIndexExporter.java



* Update LocalIndexReaderTests.java



* Update QueryInsightsReaderFactoryTests.java



* Address comments, change getTimeRange into getFrom and getTo, apply filters to historical, and rename functions



* Fix test cases



---------




(cherry picked from commit 4d896cc)

Signed-off-by: Emily Guo <emilyguo@amazon.com>
Signed-off-by: Emily Guo <35637792+LilyCaroline17@users.noreply.github.com>
Signed-off-by: Emily Guo <LilyCaroline1717@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Top N Queries API should be able to get historical data from index
3 participants