Search in sources :

Example 1 with Metrics

use of com.datastax.oss.driver.api.core.metrics.Metrics in project zipkin by openzipkin.

the class CassandraStorageExtension method poolInFlight.

// Use metrics to wait for in-flight requests to settle per
// https://groups.google.com/a/lists.datastax.com/g/java-driver-user/c/5um_yGNynow/m/cInH5I5jBgAJ
static boolean poolInFlight(CqlSession session) {
    Collection<Node> nodes = session.getMetadata().getNodes().values();
    Optional<Metrics> metrics = session.getMetrics();
    for (Node node : nodes) {
        int inFlight = metrics.flatMap(m -> m.getNodeMetric(node, DefaultNodeMetric.IN_FLIGHT)).map(m -> ((Gauge<Integer>) m).getValue()).orElse(0);
        if (inFlight > 0)
            return true;
    }
    return false;
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) Metrics(com.datastax.oss.driver.api.core.metrics.Metrics) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ArrayList(java.util.ArrayList) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) SEARCH_TABLES(zipkin2.storage.cassandra.ITCassandraStorage.SEARCH_TABLES) TABLE_SPAN(zipkin2.storage.cassandra.Schema.TABLE_SPAN) GenericContainer(org.testcontainers.containers.GenericContainer) InvalidQueryException(com.datastax.oss.driver.api.core.servererrors.InvalidQueryException) Call.propagateIfFatal(zipkin2.Call.propagateIfFatal) DockerImageName.parse(org.testcontainers.utility.DockerImageName.parse) Wait(org.testcontainers.containers.wait.strategy.Wait) TABLE_DEPENDENCY(zipkin2.storage.cassandra.Schema.TABLE_DEPENDENCY) Logger(org.slf4j.Logger) Collection(java.util.Collection) TestAbortedException(org.opentest4j.TestAbortedException) List(java.util.List) BeforeAllCallback(org.junit.jupiter.api.extension.BeforeAllCallback) AfterAllCallback(org.junit.jupiter.api.extension.AfterAllCallback) Optional(java.util.Optional) Gauge(com.codahale.metrics.Gauge) Metrics(com.datastax.oss.driver.api.core.metrics.Metrics) Node(com.datastax.oss.driver.api.core.metadata.Node) Gauge(com.codahale.metrics.Gauge)

Aggregations

Gauge (com.codahale.metrics.Gauge)1 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 Node (com.datastax.oss.driver.api.core.metadata.Node)1 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)1 Metrics (com.datastax.oss.driver.api.core.metrics.Metrics)1 InvalidQueryException (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assumptions.assumeTrue (org.junit.jupiter.api.Assumptions.assumeTrue)1 AfterAllCallback (org.junit.jupiter.api.extension.AfterAllCallback)1 BeforeAllCallback (org.junit.jupiter.api.extension.BeforeAllCallback)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 TestAbortedException (org.opentest4j.TestAbortedException)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 GenericContainer (org.testcontainers.containers.GenericContainer)1 Slf4jLogConsumer (org.testcontainers.containers.output.Slf4jLogConsumer)1