-
Notifications
You must be signed in to change notification settings - Fork 8
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
Refactor Exporters and Readers #210
Refactor Exporters and Readers #210
Conversation
7f3d20d
to
851d174
Compare
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.
Added a few comments and went over this - looks good at a high level. Might need to give one more pass soon.
String currentDate = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ROOT) | ||
.format(Instant.now().atOffset(ZoneOffset.UTC).toLocalDate()); | ||
private boolean checkIndexExists(String indexName) { | ||
ClusterState clusterState = clusterService.state(); |
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.
Can there be a corner scenario where the cluster state does not have up to date information? Are we handling this?
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.
Yes, In theory the cluster state should be most up to date but there are scenarios when 2 threads are trying to create / delete the same index for the same time. If you look into the code I already handled with something like
Throwable cause = ExceptionsHelper.unwrapCause(e);
if (cause instanceof ResourceAlreadyExistsException) {
@@ -104,7 +116,7 @@ public List<SearchQueryRecord> read(final String from, final String to, String i | |||
while (curr.isBefore(end.plusDays(1).toLocalDate().atStartOfDay(end.getZone()))) { | |||
String indexName = buildLocalIndexName(curr); | |||
SearchRequest searchRequest = new SearchRequest(indexName); | |||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | |||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000); |
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.
Might want to add a constant so this does not get lost in the code in case we want to change this in the future
// This method is invoked when sink type is changed | ||
// Clear local indices if exporter is of type LocalIndexExporter | ||
if (topQueriesExporter != null && topQueriesExporter.getClass() == LocalIndexExporter.class) { | ||
deleteAllTopNIndices(client, indexMetadataMap, (LocalIndexExporter) topQueriesExporter); |
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.
If we toggle between exports and back to local index exporter do we want to lose all the older data in this scenario?
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.
Yes, that's the expectation for now. Disabling local index exporter will delete all historical data. It was originally implemented in #172
.execute(() -> ((LocalIndexExporter) exporter).deleteExpiredTopNIndices(indexMetadataMap)); | ||
} | ||
} | ||
public static boolean isTopQueriesIndex(String indexName, IndexMetadata indexMetadata) { |
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.
nit: Do we want to add this to a helper/util?
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.
I think it should belongs to TopQueriesService though since we are checking if an index belongs to top n queries.
* Prefix for top n queries by memory exporters | ||
*/ | ||
private static final String TOP_N_MEMORY_QUERIES_EXPORTER_PREFIX = TOP_N_MEMORY_QUERIES_PREFIX + ".exporter."; | ||
private static final String TOP_N_QUERIES_EXPORTER_PREFIX = TOP_N_QUERIES_SETTING_PREFIX + ".exporter"; |
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.
Self note: Will have to update the documentation since the current docs are now invalid.
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.
yes, I'll send a PR to update the document later.
verify(adminClient, times(3)).indices(); | ||
verify(indicesAdminClient, times(3)).delete(any(), any()); | ||
} | ||
// public void testDeleteExpiredTopNIndices() { |
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.
Why is this commented out?
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 is moved to queryInsightsTests.
verify(localIndexExporter, times(9)).deleteSingleIndex(any(), any()); | ||
} | ||
|
||
// TODO: comment out for now. Need to reenable this before mering |
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.
nit: Don't forget to resolve this
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.
Updated
Signed-off-by: Chenyang Ji <[email protected]>
Signed-off-by: Chenyang Ji <[email protected]>
Signed-off-by: Chenyang Ji <[email protected]>
Signed-off-by: Chenyang Ji <[email protected]>
Signed-off-by: Chenyang Ji <[email protected]>
851d174
to
9584b38
Compare
Signed-off-by: Chenyang Ji <[email protected]>
Signed-off-by: Chenyang Ji <[email protected]>
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.
LGTM overall with some minor comments.
@@ -22,4 +22,6 @@ public interface QueryInsightsExporter extends Closeable { | |||
* @param records list of {@link SearchQueryRecord} | |||
*/ | |||
void export(final List<SearchQueryRecord> records); | |||
|
|||
String getId(); |
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.
nit: good to add some comments here since this is an interface and the intent may get lost over time
.format(Instant.now().atOffset(ZoneOffset.UTC).toLocalDate()); | ||
private boolean checkIndexExists(String indexName) { | ||
ClusterState clusterState = clusterService.state(); | ||
return clusterState.getRoutingTable().hasIndex(indexName); |
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.
Hope we don't need to handle any potential errors here
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.
Good point.. I saw the same patter is used in multiple places in OpenSearch. I think we should be good.
https://github.com/opensearch-project/OpenSearch/blob/e6fc6008e408c41e2369ca308d5a763575ef8c89/server/src/main/java/org/opensearch/cluster/health/ClusterStateHealth.java#L211
} | ||
} else { | ||
// Disable exporter if exporter type is set to null | ||
try { |
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.
nit: Duplicated code few lines above, could refactor this out
} | ||
|
||
queryInsightsService.deleteAllTopNIndices(client, indexMetadataMap, localIndexExporter); | ||
// All 10 indices should be deleted |
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.
9 indices should be deleted?
@deshsidd Thanks for the review, I'll merge it for now to unblock the frontend, but we need to iterate from here to add missing doc/ refactor some code into util functions etc. |
* Move exporter config to query insights level Signed-off-by: Chenyang Ji <[email protected]> * use index mapping and define default index metadata for top n queries Signed-off-by: Chenyang Ji <[email protected]> * improve safegard for deleting top queries indices with index mapping Signed-off-by: Chenyang Ji <[email protected]> * fix unit tests Signed-off-by: Chenyang Ji <[email protected]> * fix bug on local index reader with generateLocalIndexDateHash Signed-off-by: Chenyang Ji <[email protected]> * fix exception in query grouper Signed-off-by: Chenyang Ji <[email protected]> * update PR based on comments and re-enable unit tests Signed-off-by: Chenyang Ji <[email protected]> --------- Signed-off-by: Chenyang Ji <[email protected]> (cherry picked from commit 2d14764) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
* Move exporter config to query insights level * use index mapping and define default index metadata for top n queries * improve safegard for deleting top queries indices with index mapping * fix unit tests * fix bug on local index reader with generateLocalIndexDateHash * fix exception in query grouper * update PR based on comments and re-enable unit tests --------- (cherry picked from commit 2d14764) Signed-off-by: Chenyang Ji <[email protected]> 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>
Description
There are multiple issues with the current exporter.
https://opensearch.org/docs/latest/observing-your-data/query-insights/top-n-queries/#configuring-a-local-index-exporter
This is not a good pattern since we don't have specific use cases when users enabled multiple top n metrics, but they only want to exporter certain of them. We need to move the exporter from
top queries service
level toquery insights service
level.Issues Resolved
TODO
tests
TODO
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.