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 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 GraphSupportChecker method isPagingEnabled.
/**
* Checks whether graph paging is available.
*
* <p>Graph paging is available if:
*
* <ol>
* <li>Continuous paging is generally available (this implies protocol version {@link
* com.datastax.dse.driver.api.core.DseProtocolVersion#DSE_V1 DSE_V1} or higher);
* <li>Graph paging is set to <code>ENABLED</code> or <code>AUTO</code> in the configuration
* with {@link DseDriverOption#GRAPH_PAGING_ENABLED};
* <li>If graph paging is set to <code>AUTO</code>, then a check will be performed to verify
* that all hosts are running DSE 6.8+; if that is the case, then graph paging will be
* assumed to be available.
* </ol>
*
* Note that the hosts check will be done only once, then memoized; if other hosts join the
* cluster later and do not support graph paging, the user has to manually disable graph paging.
*/
public boolean isPagingEnabled(@NonNull GraphStatement<?> graphStatement, @NonNull InternalDriverContext context) {
DriverExecutionProfile driverExecutionProfile = Conversions.resolveExecutionProfile(graphStatement, context);
PagingEnabledOptions pagingEnabledOptions = PagingEnabledOptions.valueOf(driverExecutionProfile.getString(DseDriverOption.GRAPH_PAGING_ENABLED));
if (LOG.isTraceEnabled()) {
LOG.trace("GRAPH_PAGING_ENABLED: {}", pagingEnabledOptions);
}
if (pagingEnabledOptions == PagingEnabledOptions.DISABLED) {
return false;
} else if (pagingEnabledOptions == PagingEnabledOptions.ENABLED) {
return true;
} else {
return isContextGraphPagingEnabled(context);
}
}
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 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));
}
Aggregations