Search in sources :

Example 1 with MetricsRegistryImpl

use of io.smallrye.metrics.MetricsRegistryImpl in project java-driver by datastax.

the class MicroProfileNodeMetricsUpdaterTest method should_not_log_warning_when_provided_eviction_time_setting_is_acceptable.

@Test
@UseDataProvider(value = "acceptableEvictionTimes")
public void should_not_log_warning_when_provided_eviction_time_setting_is_acceptable(Duration expireAfter) {
    // given
    LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(AbstractMetricUpdater.class, Level.WARN);
    Node node = mock(Node.class);
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
    DriverConfig config = mock(DriverConfig.class);
    Set<NodeMetric> enabledMetrics = Collections.singleton(DefaultNodeMetric.CQL_MESSAGES);
    // when
    when(context.getSessionName()).thenReturn("prefix");
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(profile);
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(expireAfter);
    MicroProfileNodeMetricUpdater updater = new MicroProfileNodeMetricUpdater(node, context, enabledMetrics, new MetricsRegistryImpl()) {

        @Override
        protected void initializeGauge(NodeMetric metric, DriverExecutionProfile profile, Gauge<Number> supplier) {
        // do nothing
        }

        @Override
        protected void initializeCounter(NodeMetric metric, DriverExecutionProfile profile) {
        // do nothing
        }

        @Override
        protected void initializeTimer(NodeMetric metric, DriverExecutionProfile profile) {
        // do nothing
        }
    };
    // then
    assertThat(updater.getExpireAfter()).isEqualTo(expireAfter);
    verify(logger.appender, timeout(500).times(0)).doAppend(logger.loggingEventCaptor.capture());
}
Also used : DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) NodeMetric(com.datastax.oss.driver.api.core.metrics.NodeMetric) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Node(com.datastax.oss.driver.api.core.metadata.Node) MetricsRegistryImpl(io.smallrye.metrics.MetricsRegistryImpl) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Gauge(org.eclipse.microprofile.metrics.Gauge) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 2 with MetricsRegistryImpl

use of io.smallrye.metrics.MetricsRegistryImpl in project java-driver by datastax.

the class MicroProfileNodeMetricsUpdaterTest method should_log_warning_when_provided_eviction_time_setting_is_too_low.

@Test
public void should_log_warning_when_provided_eviction_time_setting_is_too_low() {
    // given
    LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(AbstractMetricUpdater.class, Level.WARN);
    Node node = mock(Node.class);
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
    DriverConfig config = mock(DriverConfig.class);
    Set<NodeMetric> enabledMetrics = Collections.singleton(DefaultNodeMetric.CQL_MESSAGES);
    Duration expireAfter = AbstractMetricUpdater.MIN_EXPIRE_AFTER.minusMinutes(1);
    // when
    when(context.getSessionName()).thenReturn("prefix");
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(profile);
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(expireAfter);
    MicroProfileNodeMetricUpdater updater = new MicroProfileNodeMetricUpdater(node, context, enabledMetrics, new MetricsRegistryImpl()) {

        @Override
        protected void initializeGauge(NodeMetric metric, DriverExecutionProfile profile, Gauge<Number> supplier) {
        // do nothing
        }

        @Override
        protected void initializeCounter(NodeMetric metric, DriverExecutionProfile profile) {
        // do nothing
        }

        @Override
        protected void initializeTimer(NodeMetric metric, DriverExecutionProfile profile) {
        // do nothing
        }
    };
    // then
    assertThat(updater.getExpireAfter()).isEqualTo(AbstractMetricUpdater.MIN_EXPIRE_AFTER);
    verify(logger.appender, timeout(500).times(1)).doAppend(logger.loggingEventCaptor.capture());
    assertThat(logger.loggingEventCaptor.getValue().getMessage()).isNotNull();
    assertThat(logger.loggingEventCaptor.getValue().getFormattedMessage()).contains(String.format("[prefix] Value too low for %s: %s. Forcing to %s instead.", DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER.getPath(), expireAfter, AbstractMetricUpdater.MIN_EXPIRE_AFTER));
}
Also used : DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) NodeMetric(com.datastax.oss.driver.api.core.metrics.NodeMetric) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Node(com.datastax.oss.driver.api.core.metadata.Node) MetricsRegistryImpl(io.smallrye.metrics.MetricsRegistryImpl) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Duration(java.time.Duration) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Gauge(org.eclipse.microprofile.metrics.Gauge) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test)

Aggregations

DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)2 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)2 Node (com.datastax.oss.driver.api.core.metadata.Node)2 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)2 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)2 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)2 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)2 MetricsRegistryImpl (io.smallrye.metrics.MetricsRegistryImpl)2 Gauge (org.eclipse.microprofile.metrics.Gauge)2 Test (org.junit.Test)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Duration (java.time.Duration)1