forked from opensearch-project/OpenSearch
    
        
        - 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Add tiered stats to request cache response #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
          
     Draft
      
      
            peteralfonsi
  wants to merge
  10
  commits into
  framework-serialized
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
update_node_stats
  
      
      
   
  
    
  
  
  
 
  
      
    base: framework-serialized
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c760594
              
                added test entries metric for on heap
              
              
                 0b2e506
              
                Merge branch 'framework-serialized' into update_node_stats
              
              
                 4680ea7
              
                Added check for new entries field in IT test, added permissions allow…
              
              
                 c300d8b
              
                Initial implementation for tiered node request cache stats
              
              
                 9d8d433
              
                Added version checks to streaming functions
              
              
                 7d03562
              
                Added UT for RequestCacheStats
              
              
                 c5099f1
              
                Added IT for disk tier stats, plus spotlessApply
              
              
                 64b4bb3
              
                cleaned up
              
              
                 157ca6e
              
                Addressed comments besides moving IT tests into IndicesRequestCacheIT…
              
              
                 81c038a
              
                Added/tested get time EWMA to non-heap tiers
              
              
                 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            113 changes: 113 additions & 0 deletions
          
          113 
        
  ...er/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheDiskTierIT.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|  | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|  | ||
| /* | ||
| * Modifications Copyright OpenSearch Contributors. See | ||
| * GitHub history for details. | ||
| */ | ||
|  | ||
| package org.opensearch.indices; | ||
|  | ||
| import org.opensearch.action.search.SearchResponse; | ||
| import org.opensearch.client.Client; | ||
| import org.opensearch.cluster.metadata.IndexMetadata; | ||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.core.common.unit.ByteSizeValue; | ||
| import org.opensearch.index.cache.request.RequestCacheStats; | ||
| import org.opensearch.index.query.QueryBuilders; | ||
| import org.opensearch.test.OpenSearchIntegTestCase; | ||
|  | ||
| import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
| import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse; | ||
|  | ||
| // This is a separate file from IndicesRequestCacheIT because we only want to run our test | ||
| // on a node with a maximum request cache size that we set. | ||
|  | ||
| @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
| public class IndicesRequestCacheDiskTierIT extends OpenSearchIntegTestCase { | ||
| public void testDiskTierStats() throws Exception { | ||
| int heapSizeBytes = 4729; | ||
| String node = internalCluster().startNode( | ||
| Settings.builder().put(IndicesRequestCache.INDICES_CACHE_QUERY_SIZE.getKey(), new ByteSizeValue(heapSizeBytes)) | ||
| ); | ||
| Client client = client(node); | ||
|  | ||
| Settings.Builder indicesSettingBuilder = Settings.builder() | ||
| .put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0); | ||
|  | ||
| assertAcked( | ||
| client.admin().indices().prepareCreate("index").setMapping("k", "type=keyword").setSettings(indicesSettingBuilder).get() | ||
| ); | ||
| indexRandom(true, client.prepareIndex("index").setSource("k", "hello")); | ||
| ensureSearchable("index"); | ||
| SearchResponse resp; | ||
|  | ||
| resp = client.prepareSearch("index").setRequestCache(true).setQuery(QueryBuilders.termQuery("k", "hello" + 0)).get(); | ||
| int requestSize = (int) getCacheSizeBytes(client, "index", TierType.ON_HEAP); | ||
| assertTrue(heapSizeBytes > requestSize); | ||
| // If this fails, increase heapSizeBytes! We can't adjust it after getting the size of one query | ||
| // as the cache size setting is not dynamic | ||
|  | ||
| int numOnDisk = 5; | ||
| int numRequests = heapSizeBytes / requestSize + numOnDisk; | ||
| for (int i = 1; i < numRequests; i++) { | ||
| resp = client.prepareSearch("index").setRequestCache(true).setQuery(QueryBuilders.termQuery("k", "hello" + i)).get(); | ||
| assertSearchResponse(resp); | ||
| IndicesRequestCacheIT.assertCacheState(client, "index", 0, i + 1, TierType.ON_HEAP, false); | ||
| IndicesRequestCacheIT.assertCacheState(client, "index", 0, i + 1, TierType.DISK, false); | ||
| assertPositiveEWMAForDisk(client, "index"); | ||
| } | ||
| // the first request, for "hello0", should have been evicted to the disk tier | ||
| resp = client.prepareSearch("index").setRequestCache(true).setQuery(QueryBuilders.termQuery("k", "hello0")).get(); | ||
| IndicesRequestCacheIT.assertCacheState(client, "index", 0, numRequests + 1, TierType.ON_HEAP, false); | ||
| IndicesRequestCacheIT.assertCacheState(client, "index", 1, numRequests, TierType.DISK, false); | ||
| } | ||
|  | ||
| private long getCacheSizeBytes(Client client, String index, TierType tierType) { | ||
| RequestCacheStats requestCacheStats = client.admin() | ||
| .indices() | ||
| .prepareStats(index) | ||
| .setRequestCache(true) | ||
| .get() | ||
| .getTotal() | ||
| .getRequestCache(); | ||
| return requestCacheStats.getMemorySizeInBytes(tierType); | ||
| } | ||
|  | ||
| private void assertPositiveEWMAForDisk(Client client, String index) { | ||
| RequestCacheStats requestCacheStats = client.admin() | ||
| .indices() | ||
| .prepareStats(index) | ||
| .setRequestCache(true) | ||
| .get() | ||
| .getTotal() | ||
| .getRequestCache(); | ||
| assertTrue(requestCacheStats.getTimeEWMA(TierType.DISK) > 0); | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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 ideally add these tests as part of IndicesRequestCacheIT. Lets check what is needed to do that.