Search in sources :

Example 36 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile 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)

Example 37 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class GraphRequestHandler method logServerWarnings.

private void logServerWarnings(GraphStatement<?> statement, List<String> warnings) {
    DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
    // use the RequestLogFormatter to format the query
    StringBuilder statementString = new StringBuilder();
    context.getRequestLogFormatter().appendRequest(statement, executionProfile.getInt(DefaultDriverOption.REQUEST_LOGGER_MAX_QUERY_LENGTH, RequestLogger.DEFAULT_REQUEST_LOGGER_MAX_QUERY_LENGTH), executionProfile.getBoolean(DefaultDriverOption.REQUEST_LOGGER_VALUES, RequestLogger.DEFAULT_REQUEST_LOGGER_SHOW_VALUES), executionProfile.getInt(DefaultDriverOption.REQUEST_LOGGER_MAX_VALUES, RequestLogger.DEFAULT_REQUEST_LOGGER_MAX_VALUES), executionProfile.getInt(DefaultDriverOption.REQUEST_LOGGER_MAX_VALUE_LENGTH, RequestLogger.DEFAULT_REQUEST_LOGGER_MAX_VALUE_LENGTH), statementString);
    // log each warning separately
    warnings.forEach((warning) -> LOG.warn("Query '{}' generated server side warning(s): {}", statementString, warning));
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile)

Example 38 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class GraphRequestHandler method setFinalResult.

private void setFinalResult(Result resultMessage, Frame responseFrame, NodeResponseCallback callback) {
    try {
        ExecutionInfo executionInfo = buildExecutionInfo(callback, responseFrame);
        DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(callback.statement, context);
        GraphProtocol subProtocol = GraphConversions.resolveGraphSubProtocol(callback.statement, graphSupportChecker, context);
        Queue<GraphNode> graphNodes = new ArrayDeque<>();
        for (List<ByteBuffer> row : ((Rows) resultMessage).getData()) {
            if (subProtocol.isGraphBinary()) {
                graphNodes.offer(GraphConversions.createGraphBinaryGraphNode(row, GraphRequestHandler.this.graphBinaryModule));
            } else {
                graphNodes.offer(GraphSONUtils.createGraphNode(row, subProtocol));
            }
        }
        DefaultAsyncGraphResultSet resultSet = new DefaultAsyncGraphResultSet(executionInfo, graphNodes, subProtocol);
        if (result.complete(resultSet)) {
            cancelScheduledTasks();
            throttler.signalSuccess(this);
            // Only call nanoTime() if we're actually going to use it
            long completionTimeNanos = NANOTIME_NOT_MEASURED_YET, totalLatencyNanos = NANOTIME_NOT_MEASURED_YET;
            if (!(requestTracker instanceof NoopRequestTracker)) {
                completionTimeNanos = System.nanoTime();
                totalLatencyNanos = completionTimeNanos - startTimeNanos;
                long nodeLatencyNanos = completionTimeNanos - callback.nodeStartTimeNanos;
                requestTracker.onNodeSuccess(callback.statement, nodeLatencyNanos, executionProfile, callback.node, logPrefix);
                requestTracker.onSuccess(callback.statement, totalLatencyNanos, executionProfile, callback.node, logPrefix);
            }
            if (sessionMetricUpdater.isEnabled(DseSessionMetric.GRAPH_REQUESTS, executionProfile.getName())) {
                if (completionTimeNanos == NANOTIME_NOT_MEASURED_YET) {
                    completionTimeNanos = System.nanoTime();
                    totalLatencyNanos = completionTimeNanos - startTimeNanos;
                }
                sessionMetricUpdater.updateTimer(DseSessionMetric.GRAPH_REQUESTS, executionProfile.getName(), totalLatencyNanos, TimeUnit.NANOSECONDS);
            }
        }
        // log the warnings if they have NOT been disabled
        if (!executionInfo.getWarnings().isEmpty() && executionProfile.getBoolean(DefaultDriverOption.REQUEST_LOG_WARNINGS) && LOG.isWarnEnabled()) {
            logServerWarnings(callback.statement, executionInfo.getWarnings());
        }
    } catch (Throwable error) {
        setFinalError(callback.statement, error, callback.node, NO_SUCCESSFUL_EXECUTION);
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DefaultExecutionInfo(com.datastax.oss.driver.internal.core.cql.DefaultExecutionInfo) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) ByteBuffer(java.nio.ByteBuffer) ArrayDeque(java.util.ArrayDeque) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) Rows(com.datastax.oss.protocol.internal.response.result.Rows)

Example 39 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class GraphRequestHandler method onThrottleFailure.

@Override
public void onThrottleFailure(@NonNull RequestThrottlingException error) {
    DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(initialStatement, context);
    sessionMetricUpdater.incrementCounter(DefaultSessionMetric.THROTTLING_ERRORS, executionProfile.getName());
    setFinalError(initialStatement, error, null, NO_SUCCESSFUL_EXECUTION);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile)

Example 40 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class DefaultSchemaQueriesFactory method newInstance.

protected SchemaQueries newInstance(Node node, DriverChannel channel) {
    DriverExecutionProfile config = context.getConfig().getDefaultProfile();
    Version dseVersion = (Version) node.getExtras().get(DseNodeProperties.DSE_VERSION);
    if (dseVersion != null) {
        dseVersion = dseVersion.nextStable();
        LOG.debug("[{}] Sending schema queries to {} with DSE version {}", logPrefix, node, dseVersion);
        // 4.8 is the oldest version supported, which uses C* 2.1 schema
        if (dseVersion.compareTo(Version.V5_0_0) < 0) {
            return new Cassandra21SchemaQueries(channel, node, config, logPrefix);
        } else if (dseVersion.compareTo(Version.V6_7_0) < 0) {
            // 5.0 - 6.7 uses C* 3.0 schema
            return new Cassandra3SchemaQueries(channel, node, config, logPrefix);
        } else if (dseVersion.compareTo(Version.V6_8_0) < 0) {
            // 6.7 uses C* 4.0 schema
            return new Cassandra4SchemaQueries(channel, node, config, logPrefix);
        } else {
            // 6.8+ uses DSE 6.8 schema (C* 4.0 schema with graph metadata) (JAVA-1898)
            return new Dse68SchemaQueries(channel, node, config, logPrefix);
        }
    } else {
        Version cassandraVersion = node.getCassandraVersion();
        if (cassandraVersion == null) {
            LOG.warn("[{}] Cassandra version missing for {}, defaulting to {}", logPrefix, node, Version.V3_0_0);
            cassandraVersion = Version.V3_0_0;
        } else {
            cassandraVersion = cassandraVersion.nextStable();
        }
        LOG.debug("[{}] Sending schema queries to {} with version {}", logPrefix, node, cassandraVersion);
        if (cassandraVersion.compareTo(Version.V2_2_0) < 0) {
            return new Cassandra21SchemaQueries(channel, node, config, logPrefix);
        } else if (cassandraVersion.compareTo(Version.V3_0_0) < 0) {
            return new Cassandra22SchemaQueries(channel, node, config, logPrefix);
        } else if (cassandraVersion.compareTo(Version.V4_0_0) < 0) {
            return new Cassandra3SchemaQueries(channel, node, config, logPrefix);
        } else {
            return new Cassandra4SchemaQueries(channel, node, config, logPrefix);
        }
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Version(com.datastax.oss.driver.api.core.Version)

Aggregations

DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)152 Test (org.junit.Test)81 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)29 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)21 CqlSession (com.datastax.oss.driver.api.core.CqlSession)20 Test (org.junit.jupiter.api.Test)19 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)17 Node (com.datastax.oss.driver.api.core.metadata.Node)16 ByteBuffer (java.nio.ByteBuffer)13 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)12 Duration (java.time.Duration)11 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)10 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)10 Row (com.datastax.oss.driver.api.core.cql.Row)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)7 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 Message (com.datastax.oss.protocol.internal.Message)7 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)6 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)6