- 
                Notifications
    You must be signed in to change notification settings 
- Fork 24
Add setting to exclude certain indices from insight query #308
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
Add setting to exclude certain indices from insight query #308
Conversation
        
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/settings/QueryInsightsSettings.java
          
            Show resolved
            Hide resolved
        
      4c0b18b    to
    0ec43d2      
    Compare
  
    0ec43d2    to
    374929f      
    Compare
  
            
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/test/java/org/opensearch/plugin/insights/core/service/QueryInsightsServiceTests.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/test/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListenerTests.java
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | private boolean groupingFieldNameEnabled; | ||
| private boolean groupingFieldTypeEnabled; | ||
| private final QueryShapeGenerator queryShapeGenerator; | ||
| private Set<String> excludedIndicesHashSet; | 
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.
We should precompute the excluded index regex patterns. Can you change excludedIndicesHashSet from Set<String> to Set<Pattern>? Will need to update the logic where excludedIndicesHashSet  is used:
    for (Pattern indexPattern : excludedIndexPatterns) {
        if (indexPattern.matcher(indexName).matches()) {
            return true;
        }
    }
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.
Precomputation would be inside the setter right? and the purpose of this is to create the regex pattern beforehands, so this won't be executed for every request, is it
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.
And one more thing is that if we convert to Pattern then I have to adding dot in front of the wildcard * to make it work or is there any other way to do it
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.
Let's go with the Pattern approach and substitute the wildcards.
I did a quick benchmark on Regex.simpleMatch vs precompiled pattern .matcher(testString).matches(). The Regex method has a high initial cost, then benefits from some caching. However the Pattern option is still more efficient on average.
  1> [2568-04-25T00:39:55,920][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Timing results for Regex.simpleMatch:
  1> [2568-04-25T00:39:55,923][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 1: 2.062202 ms
  1> [2568-04-25T00:39:55,923][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 2: 0.002459 ms
  1> [2568-04-25T00:39:55,923][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 3: 0.003216 ms
  1> [2568-04-25T00:39:55,924][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 4: 0.002384 ms
  1> [2568-04-25T00:39:55,924][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 5: 0.003177 ms
  1> [2568-04-25T00:39:55,924][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 6: 0.002605 ms
  1> [2568-04-25T00:39:55,924][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 7: 0.002438 ms
  1> [2568-04-25T00:39:55,925][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 8: 0.002981 ms
  1> [2568-04-25T00:39:55,925][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 9: 0.002324 ms
  1> [2568-04-25T00:39:55,925][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 10: 0.003247 ms
  1> [2568-04-25T00:39:55,926][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Timing results for Precompiled Pattern match:
  1> [2568-04-25T00:39:55,926][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 1: 0.013073 ms
  1> [2568-04-25T00:39:55,926][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 2: 0.00164 ms
  1> [2568-04-25T00:39:55,927][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 3: 0.002374 ms
  1> [2568-04-25T00:39:55,927][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 4: 0.00258 ms
  1> [2568-04-25T00:39:55,927][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 5: 0.001796 ms
  1> [2568-04-25T00:39:55,927][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 6: 0.001598 ms
  1> [2568-04-25T00:39:55,928][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 7: 0.001615 ms
  1> [2568-04-25T00:39:55,928][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 8: 0.001556 ms
  1> [2568-04-25T00:39:55,928][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 9: 0.001392 ms
  1> [2568-04-25T00:39:55,928][INFO ][o.o.p.i.c.r.MultiIndexDateRangeIT] [testPerf] Run 10: 0.001359 ms
        
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
          
            Show resolved
            Hide resolved
        
      | @quangdutran Build failing can you please take a look. Thanks! | 
| Thanks @quangdutran. The code looks good to me. Could you lastly add testing steps & output in the PR description to demonstrate the feature. | 
| Testing1. Start Query Insights ./gradlew run & create test data on three different indices named:  Response: 3. Perform search on  Top queries: 
 Top queries: 5. Set the excluded indices to  6. Perform search on index  Top queries: 7. Set the excluded indices to null to reset the setting 8. Perform search on any index and check top queries  | 
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.
The overall logic looks pretty good to me, @quangdutran thanks for the change!!
Left several comments. Also, could you add an integration test for this change? - We don't have integ tests for our settings endpoints, but I believe this is an important feature we should have integ test coverage. You can look at TopQueriesRestIT for reference.
        
          
                src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java
          
            Show resolved
            Hide resolved
        
      |  | ||
| private void setExcludedIndices(List<String> excludedIndices) { | ||
| this.excludedIndicesPattern = excludedIndices.stream() | ||
| .map(index -> index.contains("*") ? index.replace("*", ".*") : index) | 
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.
This is a little bit hacky, can we use org.opensearch.common.Strings.simpleMatch? It is designed for this type of matching.
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.
Hi @ansjcy I could not find any method with simpleMatch or pattern inside org.opensearch.core.common.Strings
| * @param excludedIndices list of index to validate | ||
| */ | ||
| public void validateExcludedIndices(@NonNull List<String> excludedIndices) { | ||
| for (String index : excludedIndices) { | 
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.
We should use org.opensearch.common.Strings.isSimpleMatchPattern to validate the pattern
| Hi @ansjcy integration has been added, could you take a look? Thanks, and please check the  | 
| @quangdutran Builds failing and code hygiene checks failing. Can you please take a look and fix. | 
| 
 The failing is caused by security plugin not ready in 3.1. I believe it is ready now. We can do a rebase on main and the pipeline should pass. | 
| @quangdutran my bad, it should be Regex.simpleMatch, see: Will this function satisfy your need? | 
| @ansjcy We were originally using Regex.simpleMatch, but there is some extra latency with this option. Every time simpleMatch is called, the provided index pattern string is converted to a pattern object. Instead of storing the index patterns as  Previous thread and small benchmark here -> #308 (comment) | 
Signed-off-by: Du Tran <quangdutran809@gmail.com>
…tor UT Signed-off-by: Du Tran <quangdutran809@gmail.com>
…tor UT Signed-off-by: Du Tran <quangdutran809@gmail.com>
… case Signed-off-by: Du Tran <quangdutran809@gmail.com>
ed9077b    to
    d642a6f      
    Compare
  
    d642a6f    to
    175de8e      
    Compare
  
    | @dzane17 Hi David, could you pls suggest me the solution for this: | 
| 
 Oh! Sorry I missed that. It makes sense to me now. 
 @quangdutran If we disable and reenable all the features before your test is run, ideally you can get a clean env without other tests runs, see below for references: Line 30 in 16be187 
 query-insights/src/test/java/org/opensearch/plugin/insights/QueryInsightsRestTestCase.java Line 198 in 16be187 
 Another better option is, instead of asserting the number of top queries after the exclude settings, you can check that the returned SearchQueryRecord includes/ doesn't include the record with your included/excluded indices. | 
175de8e    to
    94cfdb5      
    Compare
  
    Signed-off-by: Du Tran <quangdutran809@gmail.com>
94cfdb5    to
    b17ac8d      
    Compare
  
    Signed-off-by: Du Tran <quangdutran809@gmail.com> (cherry picked from commit aea9b41) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
(cherry picked from commit aea9b41) Signed-off-by: Du Tran <quangdutran809@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>
Signed-off-by: Du Tran quangdutran809@gmail.com
Description
Add setting
excluded_indicesto let user exclude certain indices from insight queryIssues Resolved
#260
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.