Skip to content

Commit

Permalink
Fixes the re enabling of RTFCacheConfigMetricsCollector (#759)
Browse files Browse the repository at this point in the history
Signed-off-by: Gagan Juneja <[email protected]>
Co-authored-by: Gagan Juneja <[email protected]>
  • Loading branch information
Gaganjuneja and Gagan Juneja authored Nov 5, 2024
1 parent 6c5b932 commit cdd56a0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ private void closeOpenGaugeObservablesIfAny() {
requestCacheGauge = null;
}
}
if (metricsInitialised) {
metricsInitialised = false;
}
}

private double getRequestCacheMaxSizeStatus(IndicesService indicesService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.io.Closeable;
import java.io.IOException;
import org.junit.After;
import org.junit.Before;
Expand All @@ -31,6 +34,7 @@ public class RTFCacheConfigMetricsCollectorTests extends OpenSearchSingleNodeTes
private RTFCacheConfigMetricsCollector rtfCacheConfigMetricsCollector;
private static MetricsRegistry metricsRegistry;
private static MetricsRegistry metricsRegistry1;
PerformanceAnalyzerController mockController;
private long startTimeInMills = 1153721339;

@Before
Expand All @@ -43,7 +47,7 @@ public void init() {
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
OpenSearchResources.INSTANCE.setIndicesService(indicesService);
ConfigOverridesWrapper mockWrapper = mock(ConfigOverridesWrapper.class);
PerformanceAnalyzerController mockController = mock(PerformanceAnalyzerController.class);
mockController = mock(PerformanceAnalyzerController.class);
Mockito.when(mockController.isCollectorDisabled(any(), anyString())).thenReturn(false);
rtfCacheConfigMetricsCollector =
spy(new RTFCacheConfigMetricsCollector(mockController, mockWrapper));
Expand Down Expand Up @@ -74,4 +78,39 @@ public void testCollectMetricsRepeated() throws IOException {
verify(metricsRegistry1, never())
.createGauge(anyString(), anyString(), anyString(), any(), any());
}

@Test
public void testCollectMetricsDisableEnable() throws IOException {
createIndex(TEST_INDEX);
Closeable fieldCacheGaugeObservable = Mockito.mock(Closeable.class);
Closeable requestCacheGaugeObservable = Mockito.mock(Closeable.class);

Mockito.when(
metricsRegistry.createGauge(
anyString(), anyString(), anyString(), any(), any()))
.thenReturn(requestCacheGaugeObservable, fieldCacheGaugeObservable);
rtfCacheConfigMetricsCollector.collectMetrics(startTimeInMills);
verify(metricsRegistry, times(2))
.createGauge(anyString(), anyString(), anyString(), any(), any());

OpenSearchResources.INSTANCE.setMetricsRegistry(metricsRegistry1);
Mockito.when(
mockController.isCollectorDisabled(
any(), eq("RTFCacheConfigMetricsCollector")))
.thenReturn(true);
rtfCacheConfigMetricsCollector.collectMetrics(startTimeInMills);
verify(fieldCacheGaugeObservable, Mockito.only()).close();
verify(requestCacheGaugeObservable, Mockito.only()).close();
verify(metricsRegistry1, never())
.createGauge(anyString(), anyString(), anyString(), any(), any());

OpenSearchResources.INSTANCE.setMetricsRegistry(metricsRegistry1);
Mockito.when(
mockController.isCollectorDisabled(
any(), eq("RTFCacheConfigMetricsCollector")))
.thenReturn(false);
rtfCacheConfigMetricsCollector.collectMetrics(startTimeInMills);
verify(metricsRegistry1, times(2))
.createGauge(anyString(), anyString(), anyString(), any(), any());
}
}

0 comments on commit cdd56a0

Please sign in to comment.