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();
}
}
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);
}
}
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);
}
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));
}
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");
}
Aggregations