storage_service: Fix getToppartitions to always return both reads and writes
In line with the previous API, the getToppartitions function returned results for one specified sampler (reads OR writes). This forced the user to call the function once for each sampler, which is suboptimal. This commit changes the signature so that results for both samplers are returned and the user can then pick whichever they need.
This commit is contained in:
parent
440313eb72
commit
a7c4c39dd0
@ -28,6 +28,7 @@ import java.io.IOException;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -93,6 +94,8 @@ public class StorageService extends MetricsMBean implements StorageServiceMBean,
|
|||||||
private static final CompositeType COUNTER_COMPOSITE_TYPE;
|
private static final CompositeType COUNTER_COMPOSITE_TYPE;
|
||||||
private static final TabularType COUNTER_TYPE;
|
private static final TabularType COUNTER_TYPE;
|
||||||
|
|
||||||
|
private static final String[] OPERATION_NAMES = new String[]{"read", "write"};
|
||||||
|
|
||||||
private static final String[] SAMPLER_NAMES = new String[]{"cardinality", "partitions"};
|
private static final String[] SAMPLER_NAMES = new String[]{"cardinality", "partitions"};
|
||||||
private static final String[] SAMPLER_DESCS = new String[]
|
private static final String[] SAMPLER_DESCS = new String[]
|
||||||
{ "cardinality of partitions",
|
{ "cardinality of partitions",
|
||||||
@ -1799,6 +1802,11 @@ public class StorageService extends MetricsMBean implements StorageServiceMBean,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompositeData getToppartitions(String sampler, List<String> keyspaceFilters, List<String> tableFilters, int duration, int capacity, int count) throws OpenDataException {
|
public CompositeData getToppartitions(String sampler, List<String> keyspaceFilters, List<String> tableFilters, int duration, int capacity, int count) throws OpenDataException {
|
||||||
|
return getToppartitions(Arrays.asList(sampler), keyspaceFilters, tableFilters, duration, capacity, count).get(sampler.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, CompositeData> getToppartitions(List<String> samplers, List<String> keyspaceFilters, List<String> tableFilters, int duration, int capacity, int count) throws OpenDataException {
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
APIClient.set_query_param(queryParams, "duration", Integer.toString(duration));
|
APIClient.set_query_param(queryParams, "duration", Integer.toString(duration));
|
||||||
APIClient.set_query_param(queryParams, "capacity", Integer.toString(capacity));
|
APIClient.set_query_param(queryParams, "capacity", Integer.toString(capacity));
|
||||||
@ -1806,23 +1814,29 @@ public class StorageService extends MetricsMBean implements StorageServiceMBean,
|
|||||||
APIClient.set_query_param(queryParams, "table_filters", tableFilters != null ? APIClient.join(tableFilters.toArray(new String[0])) : null);
|
APIClient.set_query_param(queryParams, "table_filters", tableFilters != null ? APIClient.join(tableFilters.toArray(new String[0])) : null);
|
||||||
JsonObject result = client.getJsonObj("/storage_service/toppartitions", queryParams);
|
JsonObject result = client.getJsonObj("/storage_service/toppartitions", queryParams);
|
||||||
|
|
||||||
JsonArray counters = result.getJsonArray((sampler.equalsIgnoreCase("reads")) ? "read" : "write");
|
Map<String, CompositeData> resultsMap = new HashMap<>();
|
||||||
long cardinality = result.getJsonNumber((sampler.equalsIgnoreCase("reads")) ? "read_cardinality" : "write_cardinality").longValue();
|
|
||||||
long size = 0;
|
|
||||||
TabularDataSupport tabularResult = new TabularDataSupport(COUNTER_TYPE);
|
|
||||||
|
|
||||||
if (counters != null) {
|
for (String operation : OPERATION_NAMES) {
|
||||||
size = (count > counters.size()) ? counters.size() : count;
|
JsonArray counters = result.getJsonArray(operation);
|
||||||
for (int i = 0; i < size; i++) {
|
long cardinality = result.getJsonNumber(operation + "_cardinality").longValue();
|
||||||
JsonObject counter = counters.getJsonObject(i);
|
long size = 0;
|
||||||
tabularResult.put(new CompositeDataSupport(COUNTER_COMPOSITE_TYPE, COUNTER_NAMES,
|
TabularDataSupport tabularResult = new TabularDataSupport(COUNTER_TYPE);
|
||||||
new Object[] { counter.getString("partition"), // raw
|
|
||||||
counter.getJsonNumber("count").longValue(), // count
|
if (counters != null) {
|
||||||
counter.getJsonNumber("error").longValue(), // error
|
size = (count > counters.size()) ? counters.size() : count;
|
||||||
counter.getString("partition") })); // string
|
for (int i = 0; i < size; i++) {
|
||||||
|
JsonObject counter = counters.getJsonObject(i);
|
||||||
|
tabularResult.put(new CompositeDataSupport(COUNTER_COMPOSITE_TYPE, COUNTER_NAMES,
|
||||||
|
new Object[] { counter.getString("partition"), // raw
|
||||||
|
counter.getJsonNumber("count").longValue(), // count
|
||||||
|
counter.getJsonNumber("error").longValue(), // error
|
||||||
|
counter.getString("partition") })); // string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resultsMap.put(operation + "s", new CompositeDataSupport(SAMPLING_RESULT, SAMPLER_NAMES, new Object[] { cardinality, tabularResult }));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CompositeDataSupport(SAMPLING_RESULT, SAMPLER_NAMES, new Object[] { cardinality, tabularResult });
|
return resultsMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -890,4 +890,6 @@ public interface StorageServiceMBean extends NotificationEmitter {
|
|||||||
public long getUptime();
|
public long getUptime();
|
||||||
|
|
||||||
public CompositeData getToppartitions(String sampler, List<String> keyspaceFilters, List<String> tableFilters, int duration, int capacity, int count) throws OpenDataException;
|
public CompositeData getToppartitions(String sampler, List<String> keyspaceFilters, List<String> tableFilters, int duration, int capacity, int count) throws OpenDataException;
|
||||||
|
|
||||||
|
public Map<String, CompositeData> getToppartitions(List<String> samplers, List<String> keyspaceFilters, List<String> tableFilters, int duration, int capacity, int count) throws OpenDataException;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user