Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes Exception to a Reaper Exception #1273

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/server/src/main/java/io/cassandrareaper/jmx/ClusterFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ExecutionError;
import org.apache.commons.lang3.tuple.Pair;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static io.cassandrareaper.jmx.MetricsProxy.convertToGenericMetrics;
import static io.cassandrareaper.jmx.MetricsProxy.updateGenericMetricAttribute;


public final class ClusterFacade {

Expand Down Expand Up @@ -279,6 +283,12 @@ public Map<List<String>, List<String>> getRangeToEndpointMap(
() -> getRangeToEndpointMapImpl(cluster, keyspace));
} catch (ExecutionException ex) {
throw new ReaperException(ex);
} catch (ExecutionError ex) {
if ((ex.getCause() instanceof AssertionError)) {
throw new ReaperException(String.valueOf(ex));
} else {
throw ex;
}
}
}

Expand Down Expand Up @@ -541,7 +551,7 @@ public List<MetricsHistogram> getClientRequestLatencies(Node node) throws Reaper
if (nodeIsAccessibleThroughJmx(nodeDc, node.getHostname())) {
MetricsProxy metricsProxy = MetricsProxy.create(connect(node));
return convertToMetricsHistogram(
MetricsProxy.convertToGenericMetrics(metricsProxy.collectLatencyMetrics(), node));
convertToGenericMetrics(metricsProxy.collectLatencyMetrics(), node));
} else {
// We look for metrics in the last two time based partitions to make sure we get a result
return convertToMetricsHistogram(((IDistributedStorage)context.storage)
Expand Down Expand Up @@ -570,7 +580,7 @@ public List<DroppedMessages> getDroppedMessages(Node node) throws ReaperExceptio
String nodeDc = getDatacenter(node.getCluster().get(), node.getHostname());
if (nodeIsAccessibleThroughJmx(nodeDc, node.getHostname())) {
MetricsProxy proxy = MetricsProxy.create(connect(node));
return convertToDroppedMessages(MetricsProxy.convertToGenericMetrics(proxy.collectDroppedMessages(), node));
return convertToDroppedMessages(convertToGenericMetrics(proxy.collectDroppedMessages(), node));
} else {
return convertToDroppedMessages(((IDistributedStorage)context.storage)
.getMetrics(
Expand All @@ -594,7 +604,7 @@ public List<DroppedMessages> convertToDroppedMessages(List<GenericMetric> metric
for (Entry<String, List<GenericMetric>> pool : metricsByScope.entrySet()) {
DroppedMessages.Builder builder = DroppedMessages.builder().withName(pool.getKey());
for (GenericMetric stat : pool.getValue()) {
builder = MetricsProxy.updateGenericMetricAttribute(stat, builder);
builder = updateGenericMetricAttribute(stat, builder);
}
droppedMessages.add(builder.build());
}
Expand All @@ -613,7 +623,7 @@ public List<ThreadPoolStat> getTpStats(Node node) throws ReaperException {
String nodeDc = getDatacenter(node.getCluster().get(), node.getHostname());
if (nodeIsAccessibleThroughJmx(nodeDc, node.getHostname())) {
MetricsProxy proxy = MetricsProxy.create(connect(node));
return convertToThreadPoolStats(MetricsProxy.convertToGenericMetrics(proxy.collectTpStats(), node));
return convertToThreadPoolStats(convertToGenericMetrics(proxy.collectTpStats(), node));
} else {
return convertToThreadPoolStats(((IDistributedStorage)context.storage)
.getMetrics(
Expand All @@ -637,7 +647,7 @@ public List<ThreadPoolStat> convertToThreadPoolStats(List<GenericMetric> metrics
for (Entry<String, List<GenericMetric>> pool : metricsByScope.entrySet()) {
ThreadPoolStat.Builder builder = ThreadPoolStat.builder().withName(pool.getKey());
for (GenericMetric stat : pool.getValue()) {
builder = MetricsProxy.updateGenericMetricAttribute(stat, builder);
builder = updateGenericMetricAttribute(stat, builder);
}
tpstats.add(builder.build());
}
Expand All @@ -664,7 +674,7 @@ public List<MetricsHistogram> convertToMetricsHistogram(List<GenericMetric> metr
.withName(metricByScope.getKey())
.withType(metricByName.getKey());
for (GenericMetric stat : metricByName.getValue()) {
builder = MetricsProxy.updateGenericMetricAttribute(stat, builder);
builder = updateGenericMetricAttribute(stat, builder);
}
histograms.add(builder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@
import io.cassandrareaper.ReaperApplicationConfiguration;
import io.cassandrareaper.ReaperApplicationConfiguration.DatacenterAvailability;
import io.cassandrareaper.ReaperException;
import io.cassandrareaper.core.Cluster;
import io.cassandrareaper.core.Compaction;
import io.cassandrareaper.core.CompactionStats;
import io.cassandrareaper.core.JmxCredentials;
import io.cassandrareaper.core.StreamSession;

import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
Expand All @@ -46,6 +50,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -191,4 +197,29 @@ public void endpointCleanupScylla() {
}
}

@Test(expected = ReaperException.class)
public void getRangeToEndpointMapArgumentExceptionTest() throws ReaperException {
final AppContext cxt = new AppContext();
cxt.config = new ReaperApplicationConfiguration();
AppContext contextSpy = Mockito.spy(cxt);
Mockito.doReturn("127.0.0.1").when(contextSpy).getLocalNodeAddress();

contextSpy.config.setDatacenterAvailability(DatacenterAvailability.SIDECAR);
JmxConnectionFactory jmxConnectionFactory = mock(JmxConnectionFactory.class);
JmxProxy mockProxy = mock(JmxProxy.class);
when(jmxConnectionFactory.connectAny(any(Collection.class))).thenReturn(mockProxy);
contextSpy.jmxConnectionFactory = jmxConnectionFactory;
final ClusterFacade cf = ClusterFacade.create(contextSpy);
JmxCredentials jmxCredentials = JmxCredentials.builder().withUsername("test").withPassword("testPwd").build();
Set<String> seedHosts = new HashSet<>();
seedHosts.add("127.0.0.1");
Cluster.Builder builder = Cluster.builder();
builder.withName("testCluster");
builder.withJmxCredentials(jmxCredentials);
builder.withSeedHosts(seedHosts);
Cluster mockCluster = builder.build();
when(mockProxy.getRangeToEndpointMap(eq("fake-ks"))).thenThrow(new AssertionError(""));
cf.getRangeToEndpointMap(mockCluster, "fake-ks");
}

}