Search in sources :

Example 6 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class MicrometerMetricsIT method assertNodeMetricsEvicted.

@Override
protected void assertNodeMetricsEvicted(CqlSession session, Node node) {
    InternalDriverContext context = (InternalDriverContext) session.getContext();
    MetricIdGenerator metricIdGenerator = context.getMetricIdGenerator();
    MeterRegistry registry = (MeterRegistry) context.getMetricRegistry();
    assertThat(registry).isNotNull();
    for (DefaultNodeMetric metric : ENABLED_NODE_METRICS) {
        MetricId id = metricIdGenerator.nodeMetricId(node, metric);
        Iterable<Tag> tags = MicrometerTags.toMicrometerTags(id.getTags());
        Meter m = registry.find(id.getName()).tags(tags).meter();
        assertThat(m).isNull();
    }
}
Also used : MetricIdGenerator(com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator) MetricId(com.datastax.oss.driver.internal.core.metrics.MetricId) Meter(io.micrometer.core.instrument.Meter) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) Tag(io.micrometer.core.instrument.Tag) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 7 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class NodeMetadataIT method should_expose_node_metadata.

@Test
public void should_expose_node_metadata() {
    try (CqlSession session = SessionUtils.newSession(ccmRule)) {
        Node node = getUniqueNode(session);
        // Run a few basic checks given what we know about our test environment:
        assertThat(node.getEndPoint()).isNotNull();
        InetSocketAddress connectAddress = (InetSocketAddress) node.getEndPoint().resolve();
        node.getBroadcastAddress().ifPresent(broadcastAddress -> assertThat(broadcastAddress.getAddress()).isEqualTo(connectAddress.getAddress()));
        assertThat(node.getListenAddress().get().getAddress()).isEqualTo(connectAddress.getAddress());
        assertThat(node.getDatacenter()).isEqualTo("dc1");
        assertThat(node.getRack()).isEqualTo("r1");
        if (!CcmBridge.DSE_ENABLEMENT) {
            // CcmBridge does not report accurate C* versions for DSE, only approximated values
            assertThat(node.getCassandraVersion()).isEqualTo(ccmRule.getCassandraVersion());
        }
        assertThat(node.getState()).isSameAs(NodeState.UP);
        assertThat(node.getDistance()).isSameAs(NodeDistance.LOCAL);
        assertThat(node.getHostId()).isNotNull();
        assertThat(node.getSchemaVersion()).isNotNull();
        long upTime1 = node.getUpSinceMillis();
        assertThat(upTime1).isGreaterThan(-1);
        // Note: open connections and reconnection status are covered in NodeStateIT
        // Force the node down and back up to check that upSinceMillis gets updated
        EventBus eventBus = ((InternalDriverContext) session.getContext()).getEventBus();
        eventBus.fire(TopologyEvent.forceDown(node.getBroadcastRpcAddress().get()));
        await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> node.getState() == NodeState.FORCED_DOWN);
        assertThat(node.getUpSinceMillis()).isEqualTo(-1);
        eventBus.fire(TopologyEvent.forceUp(node.getBroadcastRpcAddress().get()));
        await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> node.getState() == NodeState.UP);
        assertThat(node.getUpSinceMillis()).isGreaterThan(upTime1);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Node(com.datastax.oss.driver.api.core.metadata.Node) EventBus(com.datastax.oss.driver.internal.core.context.EventBus) CqlSession(com.datastax.oss.driver.api.core.CqlSession) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) Test(org.junit.Test)

Example 8 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class DefaultSchemaQueriesFactoryTest method buildFactory.

private DefaultSchemaQueriesFactory buildFactory() {
    final DriverExecutionProfile mockProfile = mock(DriverExecutionProfile.class);
    final DriverConfig mockConfig = mock(DriverConfig.class);
    when(mockConfig.getDefaultProfile()).thenReturn(mockProfile);
    final InternalDriverContext mockInternalCtx = mock(InternalDriverContext.class);
    when(mockInternalCtx.getConfig()).thenReturn(mockConfig);
    return new DefaultSchemaQueriesFactory(mockInternalCtx);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext)

Example 9 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class DropwizardNodeMetricUpdaterTest 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);
    DropwizardNodeMetricUpdater updater = new DropwizardNodeMetricUpdater(node, context, enabledMetrics, new MetricRegistry()) {

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

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

        @Override
        protected void initializeHdrTimer(NodeMetric metric, DriverExecutionProfile profile, DriverOption highestLatency, DriverOption significantDigits, DriverOption interval) {
        // 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 : DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) DriverOption(com.datastax.oss.driver.api.core.config.DriverOption) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Node(com.datastax.oss.driver.api.core.metadata.Node) MetricRegistry(com.codahale.metrics.MetricRegistry) Duration(java.time.Duration) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) NodeMetric(com.datastax.oss.driver.api.core.metrics.NodeMetric) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Supplier(java.util.function.Supplier) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test)

Example 10 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class NoopMetricsFactoryTest method should_log_warning_when_metrics_enabled.

@Test
public void should_log_warning_when_metrics_enabled() {
    // given
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverConfig config = mock(DriverConfig.class);
    DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
    when(context.getSessionName()).thenReturn("MockSession");
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(profile);
    when(profile.getStringList(DefaultDriverOption.METRICS_SESSION_ENABLED)).thenReturn(Collections.singletonList(DefaultSessionMetric.CQL_REQUESTS.getPath()));
    LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(NoopMetricsFactory.class, Level.WARN);
    // when
    new NoopMetricsFactory(context);
    // then
    verify(logger.appender, times(1)).doAppend(logger.loggingEventCaptor.capture());
    assertThat(logger.loggingEventCaptor.getValue().getMessage()).isNotNull();
    assertThat(logger.loggingEventCaptor.getValue().getFormattedMessage()).contains("[MockSession] Some session-level or node-level metrics were enabled");
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) 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) Test(org.junit.Test) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest)

Aggregations

InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)45 Test (org.junit.Test)29 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)16 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)15 Node (com.datastax.oss.driver.api.core.metadata.Node)13 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)13 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)12 MetricIdGenerator (com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 MetricRegistry (com.codahale.metrics.MetricRegistry)5 CqlSession (com.datastax.oss.driver.api.core.CqlSession)5 MetricId (com.datastax.oss.driver.internal.core.metrics.MetricId)5 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)4 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)4 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)4 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)4 DefaultSessionMetric (com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric)4 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)4