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

integ tests for exporter n reader #267

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

KishoreKicha14
Copy link
Contributor

Description

This PR improves the QueryInsightsExporterIT test by adding the following updates:

  1. Create Document
  2. Configure Top Queries Exporter
  3. Perform Search
  4. Set Latency Window Size
  5. Check the local index creation
  6. Disable and Re-enable Exporter
  7. Set Exporter to Debug Mode

Issues Resolved

Closes [#233]

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.

Kishore Kumaar Natarajan added 2 commits March 13, 2025 03:53
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
@ansjcy
Copy link
Member

ansjcy commented Mar 17, 2025

Thanks! These cases make the exporter tests much more complete. I have several suggestions:

  • In checkLocalIndices, Can we actually check the content of the indices?
  • Since we introduced the default index template in Add default index template for query insights local index #254, can we also test if the index template is successfully created?
  • Can we also test get the historical data from reader? i.e. Call the top queries API with from and end to see if you can get the same data.

Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
@KishoreKicha14 KishoreKicha14 force-pushed the Feat-integ-tests-for-exporter-n-reader branch from ccfd35f to 2a56543 Compare March 20, 2025 20:51
Kishore Kumaar Natarajan added 2 commits March 20, 2025 17:12
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
@KishoreKicha14
Copy link
Contributor Author

Thanks! These cases make the exporter tests much more complete. I have several suggestions:

  • In checkLocalIndices, Can we actually check the content of the indices?
  • Since we introduced the default index template in Add default index template for query insights local index #254, can we also test if the index template is successfully created?
  • Can we also test get the historical data from reader? i.e. Call the top queries API with from and end to see if you can get the same data.

Added these changes and also added a step to check topqueries-* is green

Kishore Kumaar Natarajan added 5 commits March 24, 2025 23:05
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
@KishoreKicha14 KishoreKicha14 force-pushed the Feat-integ-tests-for-exporter-n-reader branch from 7930dcc to 779bb3f Compare March 25, 2025 09:17
Kishore Kumaar Natarajan added 12 commits March 25, 2025 02:20
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Kishore Kumaar Natarajan added 14 commits April 1, 2025 14:48
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
@deshsidd
Copy link
Collaborator

deshsidd commented Apr 2, 2025

Triggering the tests again to make sure they are not flaky

}

private void createIndexTemplate() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to create an index template here? Index template should be created by the exporter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Response response = client().performRequest(request);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
setLatencyWindowSize("1m");
createIndexTemplate();
waitForWindowToPass(10);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this waitForWindowToPass(10);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added because giving some time to create the document

checkQueryInsightsIndexTemplate();
disableLocalIndexExporter();
reEnableLocalIndexExporter();
setLocalIndexToDebug();
Copy link
Member

Choose a reason for hiding this comment

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

What's the usage of this function? For debugging only?

Copy link
Contributor Author

@KishoreKicha14 KishoreKicha14 Apr 7, 2025

Choose a reason for hiding this comment

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

To check whether it is able to change from local to debug

import org.junit.Assert;
import org.opensearch.client.Request;
import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.plugin.insights.QueryInsightsRestTestCase;

/** Rest Action tests for query */
/** Rest Action tests for query */
public class QueryInsightsExporterIT extends QueryInsightsRestTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

Overall, both of the tests only check the "happy path", but we also need to check for example:

  • Edge cases with invalid date parameters
  • Error handling with malformed requests
  • Filtering functionality with the id parameter (which exists in LocalIndexReader.java)
  • Other filtering and types.
  • Detailed Response structure validation

Copy link
Member

@ansjcy ansjcy Apr 2, 2025

Choose a reason for hiding this comment

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

Also:

  • Date ranges spanning multiple indices
  • Very large date ranges

waitForWindowToPass(10);
performSearch();

waitForWindowToPass(70);
Copy link
Member

Choose a reason for hiding this comment

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

These hardcoded sleep values make the test potentially flaky. Why 10 seconds? Why 70 seconds? Can we add some explainations for future debugging?

Copy link
Contributor Author

@KishoreKicha14 KishoreKicha14 Apr 7, 2025

Choose a reason for hiding this comment

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

Added Explanation

assertTrue("Expected search results for title='Test Document'", responseContent.contains("\"Test Document\""));
}

private void createDocument() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

A lot of these functions are duplicated between Exporter tests and Reader tests, can we make combine them into one to reduce code duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move all common utility methods into QueryInsightsRestTestCase


try {
client().performRequest(new Request("DELETE", "/top_queries"));
} catch (ResponseException ignored) {}
Copy link
Member

Choose a reason for hiding this comment

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

We should at least log something here instead of silently ignoring the errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added Logger

}

private void cleanup(String fullIndexName) throws IOException, InterruptedException {
Thread.sleep(10000);
Copy link
Member

Choose a reason for hiding this comment

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

In exporter it sleeps 3 seconds but in here it's 10 seconds, why's the difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think 10 seconds is needed for reader otherwise it is not able to find the Local Index (only for Reader)

String fetchResponseContent = new String(fetchResponse.getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8);
assertTrue(
"Expected title field with value 'Test Document' in query insights data in local Indices",
fetchResponseContent.contains("\"Test Document\"")
Copy link
Member

Choose a reason for hiding this comment

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

Can you check more detailed content/fields instead of this simple contains?
Maybe parse it to JSON format first to validate the structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the code

import org.opensearch.plugin.insights.QueryInsightsRestTestCase;

public class QueryInsightsReaderIT extends QueryInsightsRestTestCase {
public void testQueryInsightsReaderSettings() throws IOException, InterruptedException {
Copy link
Member

Choose a reason for hiding this comment

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

This function doesn't do what the name suggest. We should rename it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to testQueryInsightsHistoricalTopQueriesRead

Kishore Kumaar Natarajan added 2 commits April 7, 2025 13:27
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
@KishoreKicha14 KishoreKicha14 force-pushed the Feat-integ-tests-for-exporter-n-reader branch from 67582ac to f96251f Compare April 7, 2025 20:27
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.

3 participants