Search in sources :

Example 1 with MetricId

use of com.datastax.oss.driver.internal.core.metrics.MetricId in project java-driver by datastax.

the class DropwizardMetricsIT method assertMetricsPresent.

@Override
protected void assertMetricsPresent(CqlSession session) {
    MetricRegistry registry = (MetricRegistry) ((InternalDriverContext) session.getContext()).getMetricRegistry();
    assertThat(registry).isNotNull();
    assertThat(registry.getMetrics()).hasSize(ENABLED_SESSION_METRICS.size() + ENABLED_NODE_METRICS.size() * 3);
    MetricIdGenerator metricIdGenerator = ((InternalDriverContext) session.getContext()).getMetricIdGenerator();
    assertThat(session.getMetrics()).isPresent();
    Metrics metrics = session.getMetrics().get();
    for (DefaultSessionMetric metric : ENABLED_SESSION_METRICS) {
        MetricId id = metricIdGenerator.sessionMetricId(metric);
        Metric m = registry.getMetrics().get(id.getName());
        assertThat(m).isNotNull();
        // assert that the same metric is retrievable through the registry and through the driver API
        assertThat(metrics.getSessionMetric(metric)).isPresent().hasValueSatisfying(v -> assertThat(v).isSameAs(m));
        switch(metric) {
            case CONNECTED_NODES:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat((Integer) ((Gauge<?>) m).getValue()).isEqualTo(3);
                break;
            case CQL_REQUESTS:
                assertThat(m).isInstanceOf(Timer.class);
                await().untilAsserted(() -> assertThat(((Timer) m).getCount()).isEqualTo(30));
                break;
            case CQL_PREPARED_CACHE_SIZE:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat((Long) ((Gauge<?>) m).getValue()).isOne();
                break;
            case BYTES_SENT:
            case BYTES_RECEIVED:
                assertThat(m).isInstanceOf(Meter.class);
                assertThat(((Meter) m).getCount()).isGreaterThan(0);
                break;
            case CQL_CLIENT_TIMEOUTS:
            case THROTTLING_ERRORS:
                assertThat(m).isInstanceOf(Counter.class);
                assertThat(((Counter) m).getCount()).isZero();
                break;
            case THROTTLING_DELAY:
                assertThat(m).isInstanceOf(Timer.class);
                assertThat(((Timer) m).getCount()).isZero();
                break;
            case THROTTLING_QUEUE_SIZE:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat((Integer) ((Gauge<?>) m).getValue()).isZero();
                break;
        }
    }
    for (Node node : session.getMetadata().getNodes().values()) {
        for (DefaultNodeMetric metric : ENABLED_NODE_METRICS) {
            MetricId id = metricIdGenerator.nodeMetricId(node, metric);
            Metric m = registry.getMetrics().get(id.getName());
            assertThat(m).isNotNull();
            // assert that the same metric is retrievable through the registry and through the driver
            // API
            assertThat(metrics.getNodeMetric(node, metric)).isPresent().hasValueSatisfying(v -> assertThat(v).isSameAs(m));
            switch(metric) {
                case OPEN_CONNECTIONS:
                    assertThat(m).isInstanceOf(Gauge.class);
                    // control node has 2 connections
                    assertThat((Integer) ((Gauge<?>) m).getValue()).isBetween(1, 2);
                    break;
                case CQL_MESSAGES:
                    assertThat(m).isInstanceOf(Timer.class);
                    await().untilAsserted(() -> assertThat(((Timer) m).getCount()).isEqualTo(10));
                    break;
                case READ_TIMEOUTS:
                case WRITE_TIMEOUTS:
                case UNAVAILABLES:
                case OTHER_ERRORS:
                case ABORTED_REQUESTS:
                case UNSENT_REQUESTS:
                case RETRIES:
                case IGNORES:
                case RETRIES_ON_READ_TIMEOUT:
                case RETRIES_ON_WRITE_TIMEOUT:
                case RETRIES_ON_UNAVAILABLE:
                case RETRIES_ON_OTHER_ERROR:
                case RETRIES_ON_ABORTED:
                case IGNORES_ON_READ_TIMEOUT:
                case IGNORES_ON_WRITE_TIMEOUT:
                case IGNORES_ON_UNAVAILABLE:
                case IGNORES_ON_OTHER_ERROR:
                case IGNORES_ON_ABORTED:
                case SPECULATIVE_EXECUTIONS:
                case CONNECTION_INIT_ERRORS:
                case AUTHENTICATION_ERRORS:
                    assertThat(m).isInstanceOf(Counter.class);
                    assertThat(((Counter) m).getCount()).isZero();
                    break;
                case BYTES_SENT:
                case BYTES_RECEIVED:
                    assertThat(m).isInstanceOf(Meter.class);
                    assertThat(((Meter) m).getCount()).isGreaterThan(0L);
                    break;
                case AVAILABLE_STREAMS:
                case IN_FLIGHT:
                case ORPHANED_STREAMS:
                    assertThat(m).isInstanceOf(Gauge.class);
                    break;
            }
        }
    }
}
Also used : DefaultSessionMetric(com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric) Meter(com.codahale.metrics.Meter) MetricRegistry(com.codahale.metrics.MetricRegistry) Node(com.datastax.oss.driver.api.core.metadata.Node) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) MetricIdGenerator(com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator) Metrics(com.datastax.oss.driver.api.core.metrics.Metrics) MetricId(com.datastax.oss.driver.internal.core.metrics.MetricId) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) Metric(com.codahale.metrics.Metric) DefaultSessionMetric(com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext)

Example 2 with MetricId

use of com.datastax.oss.driver.internal.core.metrics.MetricId in project java-driver by datastax.

the class MicrometerMetricsIT method assertMetricsPresent.

@Override
protected void assertMetricsPresent(CqlSession session) {
    MeterRegistry registry = (MeterRegistry) ((InternalDriverContext) session.getContext()).getMetricRegistry();
    assertThat(registry).isNotNull();
    assertThat(registry.getMeters()).hasSize(ENABLED_SESSION_METRICS.size() + ENABLED_NODE_METRICS.size() * 3);
    MetricIdGenerator metricIdGenerator = ((InternalDriverContext) session.getContext()).getMetricIdGenerator();
    for (DefaultSessionMetric metric : ENABLED_SESSION_METRICS) {
        MetricId id = metricIdGenerator.sessionMetricId(metric);
        Iterable<Tag> tags = MicrometerTags.toMicrometerTags(id.getTags());
        Meter m = registry.find(id.getName()).tags(tags).meter();
        assertThat(m).isNotNull();
        switch(metric) {
            case CONNECTED_NODES:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat(((Gauge) m).value()).isEqualTo(3);
                break;
            case CQL_REQUESTS:
                assertThat(m).isInstanceOf(Timer.class);
                await().untilAsserted(() -> assertThat(((Timer) m).count()).isEqualTo(30));
                break;
            case CQL_PREPARED_CACHE_SIZE:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat(((Gauge) m).value()).isOne();
                break;
            case BYTES_SENT:
            case BYTES_RECEIVED:
                assertThat(m).isInstanceOf(Counter.class);
                assertThat(((Counter) m).count()).isGreaterThan(0);
                break;
            case CQL_CLIENT_TIMEOUTS:
            case THROTTLING_ERRORS:
                assertThat(m).isInstanceOf(Counter.class);
                assertThat(((Counter) m).count()).isZero();
                break;
            case THROTTLING_DELAY:
                assertThat(m).isInstanceOf(Timer.class);
                assertThat(((Timer) m).count()).isZero();
                break;
            case THROTTLING_QUEUE_SIZE:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat(((Gauge) m).value()).isZero();
                break;
        }
    }
    for (Node node : session.getMetadata().getNodes().values()) {
        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).isNotNull();
            switch(metric) {
                case OPEN_CONNECTIONS:
                    assertThat(m).isInstanceOf(Gauge.class);
                    // control node has 2 connections
                    assertThat(((Gauge) m).value()).isBetween(1.0, 2.0);
                    break;
                case CQL_MESSAGES:
                    assertThat(m).isInstanceOf(Timer.class);
                    await().untilAsserted(() -> assertThat(((Timer) m).count()).isEqualTo(10));
                    break;
                case READ_TIMEOUTS:
                case WRITE_TIMEOUTS:
                case UNAVAILABLES:
                case OTHER_ERRORS:
                case ABORTED_REQUESTS:
                case UNSENT_REQUESTS:
                case RETRIES:
                case IGNORES:
                case RETRIES_ON_READ_TIMEOUT:
                case RETRIES_ON_WRITE_TIMEOUT:
                case RETRIES_ON_UNAVAILABLE:
                case RETRIES_ON_OTHER_ERROR:
                case RETRIES_ON_ABORTED:
                case IGNORES_ON_READ_TIMEOUT:
                case IGNORES_ON_WRITE_TIMEOUT:
                case IGNORES_ON_UNAVAILABLE:
                case IGNORES_ON_OTHER_ERROR:
                case IGNORES_ON_ABORTED:
                case SPECULATIVE_EXECUTIONS:
                case CONNECTION_INIT_ERRORS:
                case AUTHENTICATION_ERRORS:
                    assertThat(m).isInstanceOf(Counter.class);
                    assertThat(((Counter) m).count()).isZero();
                    break;
                case BYTES_SENT:
                case BYTES_RECEIVED:
                    assertThat(m).isInstanceOf(Counter.class);
                    assertThat(((Counter) m).count()).isGreaterThan(0.0);
                    break;
                case AVAILABLE_STREAMS:
                case IN_FLIGHT:
                case ORPHANED_STREAMS:
                    assertThat(m).isInstanceOf(Gauge.class);
                    break;
            }
        }
    }
}
Also used : DefaultSessionMetric(com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric) Meter(io.micrometer.core.instrument.Meter) Node(com.datastax.oss.driver.api.core.metadata.Node) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Gauge(io.micrometer.core.instrument.Gauge) MetricIdGenerator(com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator) MetricId(com.datastax.oss.driver.internal.core.metrics.MetricId) Counter(io.micrometer.core.instrument.Counter) Timer(io.micrometer.core.instrument.Timer) Tag(io.micrometer.core.instrument.Tag) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext)

Example 3 with MetricId

use of com.datastax.oss.driver.internal.core.metrics.MetricId 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 4 with MetricId

use of com.datastax.oss.driver.internal.core.metrics.MetricId in project java-driver by datastax.

the class MicrometerMetricsIT method assertNodeMetricsNotEvicted.

@Override
protected void assertNodeMetricsNotEvicted(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).isNotNull();
    }
}
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 5 with MetricId

use of com.datastax.oss.driver.internal.core.metrics.MetricId in project java-driver by datastax.

the class MicroProfileMetricsIT method assertMetricsPresent.

@Override
protected void assertMetricsPresent(CqlSession session) {
    MetricRegistry registry = (MetricRegistry) ((InternalDriverContext) session.getContext()).getMetricRegistry();
    assertThat(registry).isNotNull();
    assertThat(registry.getMetrics()).hasSize(ENABLED_SESSION_METRICS.size() + ENABLED_NODE_METRICS.size() * 3);
    MetricIdGenerator metricIdGenerator = ((InternalDriverContext) session.getContext()).getMetricIdGenerator();
    for (DefaultSessionMetric metric : ENABLED_SESSION_METRICS) {
        MetricId metricId = metricIdGenerator.sessionMetricId(metric);
        Tag[] tags = MicroProfileTags.toMicroProfileTags(metricId.getTags());
        MetricID id = new MetricID(metricId.getName(), tags);
        Metric m = registry.getMetrics().get(id);
        assertThat(m).isNotNull();
        switch(metric) {
            case CONNECTED_NODES:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat((Integer) ((Gauge<?>) m).getValue()).isEqualTo(3);
                break;
            case CQL_REQUESTS:
                assertThat(m).isInstanceOf(Timer.class);
                await().untilAsserted(() -> assertThat(((Timer) m).getCount()).isEqualTo(30));
                break;
            case CQL_PREPARED_CACHE_SIZE:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat((Long) ((Gauge<?>) m).getValue()).isOne();
                break;
            case BYTES_SENT:
            case BYTES_RECEIVED:
                assertThat(m).isInstanceOf(Meter.class);
                assertThat(((Meter) m).getCount()).isGreaterThan(0);
                break;
            case CQL_CLIENT_TIMEOUTS:
            case THROTTLING_ERRORS:
                assertThat(m).isInstanceOf(Counter.class);
                assertThat(((Counter) m).getCount()).isZero();
                break;
            case THROTTLING_DELAY:
                assertThat(m).isInstanceOf(Timer.class);
                assertThat(((Timer) m).getCount()).isZero();
                break;
            case THROTTLING_QUEUE_SIZE:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat((Integer) ((Gauge<?>) m).getValue()).isZero();
                break;
        }
    }
    for (Node node : session.getMetadata().getNodes().values()) {
        for (DefaultNodeMetric metric : ENABLED_NODE_METRICS) {
            MetricId description = metricIdGenerator.nodeMetricId(node, metric);
            Tag[] tags = MicroProfileTags.toMicroProfileTags(description.getTags());
            MetricID id = new MetricID(description.getName(), tags);
            Metric m = registry.getMetrics().get(id);
            assertThat(m).isNotNull();
            switch(metric) {
                case OPEN_CONNECTIONS:
                    assertThat(m).isInstanceOf(Gauge.class);
                    // control node has 2 connections
                    assertThat((Integer) ((Gauge<?>) m).getValue()).isBetween(1, 2);
                    break;
                case CQL_MESSAGES:
                    assertThat(m).isInstanceOf(Timer.class);
                    await().untilAsserted(() -> assertThat(((Timer) m).getCount()).isEqualTo(10));
                    break;
                case READ_TIMEOUTS:
                case WRITE_TIMEOUTS:
                case UNAVAILABLES:
                case OTHER_ERRORS:
                case ABORTED_REQUESTS:
                case UNSENT_REQUESTS:
                case RETRIES:
                case IGNORES:
                case RETRIES_ON_READ_TIMEOUT:
                case RETRIES_ON_WRITE_TIMEOUT:
                case RETRIES_ON_UNAVAILABLE:
                case RETRIES_ON_OTHER_ERROR:
                case RETRIES_ON_ABORTED:
                case IGNORES_ON_READ_TIMEOUT:
                case IGNORES_ON_WRITE_TIMEOUT:
                case IGNORES_ON_UNAVAILABLE:
                case IGNORES_ON_OTHER_ERROR:
                case IGNORES_ON_ABORTED:
                case SPECULATIVE_EXECUTIONS:
                case CONNECTION_INIT_ERRORS:
                case AUTHENTICATION_ERRORS:
                    assertThat(m).isInstanceOf(Counter.class);
                    assertThat(((Counter) m).getCount()).isZero();
                    break;
                case BYTES_SENT:
                case BYTES_RECEIVED:
                    assertThat(m).isInstanceOf(Meter.class);
                    assertThat(((Meter) m).getCount()).isGreaterThan(0L);
                    break;
                case AVAILABLE_STREAMS:
                case IN_FLIGHT:
                case ORPHANED_STREAMS:
                    assertThat(m).isInstanceOf(Gauge.class);
                    break;
            }
        }
    }
}
Also used : DefaultSessionMetric(com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric) Meter(org.eclipse.microprofile.metrics.Meter) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Node(com.datastax.oss.driver.api.core.metadata.Node) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) MetricIdGenerator(com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator) MetricId(com.datastax.oss.driver.internal.core.metrics.MetricId) MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Timer(org.eclipse.microprofile.metrics.Timer) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) Metric(org.eclipse.microprofile.metrics.Metric) DefaultSessionMetric(com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric) Tag(org.eclipse.microprofile.metrics.Tag) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext)

Aggregations

MetricId (com.datastax.oss.driver.internal.core.metrics.MetricId)10 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)7 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)5 MetricIdGenerator (com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator)5 Tag (io.micrometer.core.instrument.Tag)4 Node (com.datastax.oss.driver.api.core.metadata.Node)3 DefaultSessionMetric (com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric)3 Meter (io.micrometer.core.instrument.Meter)3 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)3 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 MetricID (org.eclipse.microprofile.metrics.MetricID)3 Tag (org.eclipse.microprofile.metrics.Tag)3 ArrayList (java.util.ArrayList)2 Counter (com.codahale.metrics.Counter)1 Meter (com.codahale.metrics.Meter)1 Metric (com.codahale.metrics.Metric)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Timer (com.codahale.metrics.Timer)1 Metrics (com.datastax.oss.driver.api.core.metrics.Metrics)1 Counter (io.micrometer.core.instrument.Counter)1