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