Skip to content

Commit

Permalink
Rename CoreNodeMetric to DefaultNodeMetric
Browse files Browse the repository at this point in the history
  • Loading branch information
olim7t committed Feb 12, 2018
1 parent 5ae220f commit 678f9ee
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 110 deletions.
Expand Up @@ -19,7 +19,7 @@
import java.util.Map;

/** See {@code reference.conf} for a description of each metric. */
public enum CoreNodeMetric implements NodeMetric {
public enum DefaultNodeMetric implements NodeMetric {
OPEN_CONNECTIONS("pool.open-connections"),
AVAILABLE_STREAMS("pool.available-streams"),
IN_FLIGHT("pool.in-flight"),
Expand Down Expand Up @@ -48,11 +48,11 @@ public enum CoreNodeMetric implements NodeMetric {
AUTHENTICATION_ERRORS("errors.connection.auth"),
;

private static final Map<String, CoreNodeMetric> BY_PATH = sortByPath();
private static final Map<String, DefaultNodeMetric> BY_PATH = sortByPath();

private final String path;

CoreNodeMetric(String path) {
DefaultNodeMetric(String path) {
this.path = path;
}

Expand All @@ -61,17 +61,17 @@ public String getPath() {
return path;
}

public static CoreNodeMetric fromPath(String path) {
CoreNodeMetric metric = BY_PATH.get(path);
public static DefaultNodeMetric fromPath(String path) {
DefaultNodeMetric metric = BY_PATH.get(path);
if (metric == null) {
throw new IllegalArgumentException("Unknown node metric path " + path);
}
return metric;
}

private static Map<String, CoreNodeMetric> sortByPath() {
ImmutableMap.Builder<String, CoreNodeMetric> result = ImmutableMap.builder();
for (CoreNodeMetric value : values()) {
private static Map<String, DefaultNodeMetric> sortByPath() {
ImmutableMap.Builder<String, DefaultNodeMetric> result = ImmutableMap.builder();
for (DefaultNodeMetric value : values()) {
result.put(value.getPath(), value);
}
return result.build();
Expand Down
Expand Up @@ -36,8 +36,8 @@
* Meter retriesMeter = session.getMetricRegistry().meter("s0.nodes.0:0:0:0:0:0:0:1_9042.retries.total");
* </pre>
*
* <p>All metrics exposed out of the box by the driver are instances of {@link CoreNodeMetric} (this
* interface only exists to allow custom metrics in driver extensions).
* <p>All metrics exposed out of the box by the driver are instances of {@link DefaultNodeMetric}
* (this interface only exists to allow custom metrics in driver extensions).
*
* @see SessionMetric
*/
Expand Down
Expand Up @@ -26,8 +26,8 @@
import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
import com.datastax.oss.driver.api.core.cql.Statement;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.metrics.CoreNodeMetric;
import com.datastax.oss.driver.api.core.metrics.CoreSessionMetric;
import com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric;
import com.datastax.oss.driver.api.core.retry.RetryDecision;
import com.datastax.oss.driver.api.core.retry.RetryPolicy;
import com.datastax.oss.driver.api.core.servererrors.BootstrappingException;
Expand Down Expand Up @@ -362,7 +362,9 @@ public void operationComplete(Future<java.lang.Void> future) throws Exception {
channel,
error);
recordError(node, error);
((DefaultNode) node).getMetricUpdater().incrementCounter(CoreNodeMetric.UNSENT_REQUESTS);
((DefaultNode) node)
.getMetricUpdater()
.incrementCounter(DefaultNodeMetric.UNSENT_REQUESTS);
sendRequest(null, execution, retryCount, scheduleNextExecution); // try next node
}
} else {
Expand Down Expand Up @@ -399,7 +401,7 @@ public void operationComplete(Future<java.lang.Void> future) throws Exception {
startedSpeculativeExecutionsCount.incrementAndGet();
((DefaultNode) node)
.getMetricUpdater()
.incrementCounter(CoreNodeMetric.SPECULATIVE_EXECUTIONS);
.incrementCounter(DefaultNodeMetric.SPECULATIVE_EXECUTIONS);
sendRequest(null, nextExecution, 0, true);
}
},
Expand All @@ -421,7 +423,7 @@ public void onResponse(Frame responseFrame) {
((DefaultNode) node)
.getMetricUpdater()
.updateTimer(
CoreNodeMetric.CQL_MESSAGES, System.nanoTime() - start, TimeUnit.NANOSECONDS);
DefaultNodeMetric.CQL_MESSAGES, System.nanoTime() - start, TimeUnit.NANOSECONDS);
inFlightCallbacks.remove(this);
if (result.isDone()) {
return;
Expand Down Expand Up @@ -519,7 +521,7 @@ private void processErrorResponse(Error errorMessage) {
|| error instanceof FunctionFailureException
|| error instanceof ProtocolError) {
LOG.debug("[{}] Unrecoverable error, rethrowing", logPrefix);
metricUpdater.incrementCounter(CoreNodeMetric.OTHER_ERRORS);
metricUpdater.incrementCounter(DefaultNodeMetric.OTHER_ERRORS);
setFinalError(error);
} else {
RetryDecision decision;
Expand All @@ -536,9 +538,9 @@ private void processErrorResponse(Error errorMessage) {
updateErrorMetrics(
metricUpdater,
decision,
CoreNodeMetric.READ_TIMEOUTS,
CoreNodeMetric.RETRIES_ON_READ_TIMEOUT,
CoreNodeMetric.IGNORES_ON_READ_TIMEOUT);
DefaultNodeMetric.READ_TIMEOUTS,
DefaultNodeMetric.RETRIES_ON_READ_TIMEOUT,
DefaultNodeMetric.IGNORES_ON_READ_TIMEOUT);
} else if (error instanceof WriteTimeoutException) {
WriteTimeoutException writeTimeout = (WriteTimeoutException) error;
decision =
Expand All @@ -554,9 +556,9 @@ private void processErrorResponse(Error errorMessage) {
updateErrorMetrics(
metricUpdater,
decision,
CoreNodeMetric.WRITE_TIMEOUTS,
CoreNodeMetric.RETRIES_ON_WRITE_TIMEOUT,
CoreNodeMetric.IGNORES_ON_WRITE_TIMEOUT);
DefaultNodeMetric.WRITE_TIMEOUTS,
DefaultNodeMetric.RETRIES_ON_WRITE_TIMEOUT,
DefaultNodeMetric.IGNORES_ON_WRITE_TIMEOUT);
} else if (error instanceof UnavailableException) {
UnavailableException unavailable = (UnavailableException) error;
decision =
Expand All @@ -569,9 +571,9 @@ private void processErrorResponse(Error errorMessage) {
updateErrorMetrics(
metricUpdater,
decision,
CoreNodeMetric.UNAVAILABLES,
CoreNodeMetric.RETRIES_ON_UNAVAILABLE,
CoreNodeMetric.IGNORES_ON_UNAVAILABLE);
DefaultNodeMetric.UNAVAILABLES,
DefaultNodeMetric.RETRIES_ON_UNAVAILABLE,
DefaultNodeMetric.IGNORES_ON_UNAVAILABLE);
} else {
decision =
isIdempotent
Expand All @@ -580,9 +582,9 @@ private void processErrorResponse(Error errorMessage) {
updateErrorMetrics(
metricUpdater,
decision,
CoreNodeMetric.OTHER_ERRORS,
CoreNodeMetric.RETRIES_ON_OTHER_ERROR,
CoreNodeMetric.IGNORES_ON_OTHER_ERROR);
DefaultNodeMetric.OTHER_ERRORS,
DefaultNodeMetric.RETRIES_ON_OTHER_ERROR,
DefaultNodeMetric.IGNORES_ON_OTHER_ERROR);
}
processRetryDecision(decision, error);
}
Expand Down Expand Up @@ -611,18 +613,18 @@ private void processRetryDecision(RetryDecision decision, Throwable error) {
private void updateErrorMetrics(
NodeMetricUpdater metricUpdater,
RetryDecision decision,
CoreNodeMetric error,
CoreNodeMetric retriesOnError,
CoreNodeMetric ignoresOnError) {
DefaultNodeMetric error,
DefaultNodeMetric retriesOnError,
DefaultNodeMetric ignoresOnError) {
metricUpdater.incrementCounter(error);
switch (decision) {
case RETRY_SAME:
case RETRY_NEXT:
metricUpdater.incrementCounter(CoreNodeMetric.RETRIES);
metricUpdater.incrementCounter(DefaultNodeMetric.RETRIES);
metricUpdater.incrementCounter(retriesOnError);
break;
case IGNORE:
metricUpdater.incrementCounter(CoreNodeMetric.IGNORES);
metricUpdater.incrementCounter(DefaultNodeMetric.IGNORES);
metricUpdater.incrementCounter(ignoresOnError);
break;
case RETHROW:
Expand All @@ -647,9 +649,9 @@ public void onFailure(Throwable error) {
updateErrorMetrics(
((DefaultNode) node).getMetricUpdater(),
decision,
CoreNodeMetric.ABORTED_REQUESTS,
CoreNodeMetric.RETRIES_ON_ABORTED,
CoreNodeMetric.IGNORES_ON_ABORTED);
DefaultNodeMetric.ABORTED_REQUESTS,
DefaultNodeMetric.RETRIES_ON_ABORTED,
DefaultNodeMetric.IGNORES_ON_ABORTED);
}

public void cancel() {
Expand Down
Expand Up @@ -18,8 +18,8 @@
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigProfile;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.metrics.CoreNodeMetric;
import com.datastax.oss.driver.api.core.metrics.CoreSessionMetric;
import com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric;
import com.datastax.oss.driver.api.core.metrics.NodeMetric;
import com.datastax.oss.driver.api.core.metrics.SessionMetric;
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
Expand Down Expand Up @@ -72,10 +72,10 @@ private Set<SessionMetric> parseSessionMetricPaths(List<String> paths) {
}

private Set<NodeMetric> parseNodeMetricPaths(List<String> paths) {
EnumSet<CoreNodeMetric> result = EnumSet.noneOf(CoreNodeMetric.class);
EnumSet<DefaultNodeMetric> result = EnumSet.noneOf(DefaultNodeMetric.class);
for (String path : paths) {
try {
result.add(CoreNodeMetric.fromPath(path));
result.add(DefaultNodeMetric.fromPath(path));
} catch (IllegalArgumentException e) {
LOG.warn("[{}] Unknown node metric {}, skipping", logPrefix, path);
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigProfile;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.metrics.CoreNodeMetric;
import com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric;
import com.datastax.oss.driver.api.core.metrics.NodeMetric;
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
import com.datastax.oss.driver.internal.core.pool.ChannelPool;
Expand All @@ -42,43 +42,43 @@ public DefaultNodeMetricUpdater(

DriverConfigProfile config = context.config().getDefaultProfile();

if (enabledMetrics.contains(CoreNodeMetric.OPEN_CONNECTIONS)) {
if (enabledMetrics.contains(DefaultNodeMetric.OPEN_CONNECTIONS)) {
metricRegistry.register(
buildFullName(CoreNodeMetric.OPEN_CONNECTIONS),
buildFullName(DefaultNodeMetric.OPEN_CONNECTIONS),
(Gauge<Integer>) node::getOpenConnections);
}
initializePoolGauge(
CoreNodeMetric.AVAILABLE_STREAMS, node, ChannelPool::getAvailableIds, context);
initializePoolGauge(CoreNodeMetric.IN_FLIGHT, node, ChannelPool::getInFlight, context);
DefaultNodeMetric.AVAILABLE_STREAMS, node, ChannelPool::getAvailableIds, context);
initializePoolGauge(DefaultNodeMetric.IN_FLIGHT, node, ChannelPool::getInFlight, context);
initializePoolGauge(
CoreNodeMetric.ORPHANED_STREAMS, node, ChannelPool::getOrphanedIds, context);
DefaultNodeMetric.ORPHANED_STREAMS, node, ChannelPool::getOrphanedIds, context);
initializeHdrTimer(
CoreNodeMetric.CQL_MESSAGES,
DefaultNodeMetric.CQL_MESSAGES,
config,
DefaultDriverOption.METRICS_NODE_CQL_MESSAGES_HIGHEST,
DefaultDriverOption.METRICS_NODE_CQL_MESSAGES_DIGITS,
DefaultDriverOption.METRICS_NODE_CQL_MESSAGES_INTERVAL);
initializeDefaultCounter(CoreNodeMetric.UNSENT_REQUESTS);
initializeDefaultCounter(CoreNodeMetric.ABORTED_REQUESTS);
initializeDefaultCounter(CoreNodeMetric.WRITE_TIMEOUTS);
initializeDefaultCounter(CoreNodeMetric.READ_TIMEOUTS);
initializeDefaultCounter(CoreNodeMetric.UNAVAILABLES);
initializeDefaultCounter(CoreNodeMetric.OTHER_ERRORS);
initializeDefaultCounter(CoreNodeMetric.RETRIES);
initializeDefaultCounter(CoreNodeMetric.RETRIES_ON_ABORTED);
initializeDefaultCounter(CoreNodeMetric.RETRIES_ON_READ_TIMEOUT);
initializeDefaultCounter(CoreNodeMetric.RETRIES_ON_WRITE_TIMEOUT);
initializeDefaultCounter(CoreNodeMetric.RETRIES_ON_UNAVAILABLE);
initializeDefaultCounter(CoreNodeMetric.RETRIES_ON_OTHER_ERROR);
initializeDefaultCounter(CoreNodeMetric.IGNORES);
initializeDefaultCounter(CoreNodeMetric.IGNORES_ON_ABORTED);
initializeDefaultCounter(CoreNodeMetric.IGNORES_ON_READ_TIMEOUT);
initializeDefaultCounter(CoreNodeMetric.IGNORES_ON_WRITE_TIMEOUT);
initializeDefaultCounter(CoreNodeMetric.IGNORES_ON_UNAVAILABLE);
initializeDefaultCounter(CoreNodeMetric.IGNORES_ON_OTHER_ERROR);
initializeDefaultCounter(CoreNodeMetric.SPECULATIVE_EXECUTIONS);
initializeDefaultCounter(CoreNodeMetric.CONNECTION_INIT_ERRORS);
initializeDefaultCounter(CoreNodeMetric.AUTHENTICATION_ERRORS);
initializeDefaultCounter(DefaultNodeMetric.UNSENT_REQUESTS);
initializeDefaultCounter(DefaultNodeMetric.ABORTED_REQUESTS);
initializeDefaultCounter(DefaultNodeMetric.WRITE_TIMEOUTS);
initializeDefaultCounter(DefaultNodeMetric.READ_TIMEOUTS);
initializeDefaultCounter(DefaultNodeMetric.UNAVAILABLES);
initializeDefaultCounter(DefaultNodeMetric.OTHER_ERRORS);
initializeDefaultCounter(DefaultNodeMetric.RETRIES);
initializeDefaultCounter(DefaultNodeMetric.RETRIES_ON_ABORTED);
initializeDefaultCounter(DefaultNodeMetric.RETRIES_ON_READ_TIMEOUT);
initializeDefaultCounter(DefaultNodeMetric.RETRIES_ON_WRITE_TIMEOUT);
initializeDefaultCounter(DefaultNodeMetric.RETRIES_ON_UNAVAILABLE);
initializeDefaultCounter(DefaultNodeMetric.RETRIES_ON_OTHER_ERROR);
initializeDefaultCounter(DefaultNodeMetric.IGNORES);
initializeDefaultCounter(DefaultNodeMetric.IGNORES_ON_ABORTED);
initializeDefaultCounter(DefaultNodeMetric.IGNORES_ON_READ_TIMEOUT);
initializeDefaultCounter(DefaultNodeMetric.IGNORES_ON_WRITE_TIMEOUT);
initializeDefaultCounter(DefaultNodeMetric.IGNORES_ON_UNAVAILABLE);
initializeDefaultCounter(DefaultNodeMetric.IGNORES_ON_OTHER_ERROR);
initializeDefaultCounter(DefaultNodeMetric.SPECULATIVE_EXECUTIONS);
initializeDefaultCounter(DefaultNodeMetric.CONNECTION_INIT_ERRORS);
initializeDefaultCounter(DefaultNodeMetric.AUTHENTICATION_ERRORS);
}

@Override
Expand Down
Expand Up @@ -24,7 +24,7 @@
import com.datastax.oss.driver.api.core.config.DriverConfig;
import com.datastax.oss.driver.api.core.loadbalancing.NodeDistance;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.metrics.CoreNodeMetric;
import com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric;
import com.datastax.oss.driver.internal.core.channel.ChannelEvent;
import com.datastax.oss.driver.internal.core.channel.ChannelFactory;
import com.datastax.oss.driver.internal.core.channel.ClusterNameMismatchException;
Expand Down Expand Up @@ -293,8 +293,8 @@ private boolean onAllConnected(@SuppressWarnings("unused") Void v) {
.getMetricUpdater()
.incrementCounter(
error instanceof AuthenticationException
? CoreNodeMetric.AUTHENTICATION_ERRORS
: CoreNodeMetric.CONNECTION_INIT_ERRORS);
? DefaultNodeMetric.AUTHENTICATION_ERRORS
: DefaultNodeMetric.CONNECTION_INIT_ERRORS);
if (error instanceof ClusterNameMismatchException
|| error instanceof UnsupportedProtocolVersionException) {
// This will likely be thrown by all channels, but finish the loop cleanly
Expand Down

0 comments on commit 678f9ee

Please sign in to comment.