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

Fixes the re enabling of RTFCacheConfigMetricsCollector #759

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading