use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class QuotaMetricsUtilsTest method testQuotaMetrics_noUsage.
@Test
public void testQuotaMetrics_noUsage() throws Exception {
// register the metrics
final String nameSuffix = UUID.randomUUID().toString();
final DataTree dt = new DataTree();
registerQuotaMetrics(nameSuffix, dt);
// build the data tree
final String ns = UUID.randomUUID().toString();
final long countLimit = 20;
final long bytesLimit = 200;
final long countHardLimit = -1;
final long bytesHardLimit = -1;
// the node itself is always counted
final long countUsage = 1;
final long bytesUsage = 0;
final StatsTrack limitTrack = buildLimitStatsTrack(countLimit, bytesLimit, countHardLimit, bytesHardLimit);
final StatsTrack usageTrack = buildUsageStatsTrack(countUsage, bytesUsage);
buildDataTree("/" + ns, limitTrack, usageTrack, dt);
// validate the quota
validateQuotaMetrics(ns, countLimit, bytesLimit, countUsage, bytesUsage, nameSuffix);
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class QuotaMetricsUtilsTest method testQuotaMetrics_multipleQuotaSubtrees.
@Test
public void testQuotaMetrics_multipleQuotaSubtrees() throws Exception {
// register the metrics
final String nameSuffix = UUID.randomUUID().toString();
final DataTree dt = new DataTree();
registerQuotaMetrics(nameSuffix, dt);
// build the data tree
final String ns = UUID.randomUUID().toString();
final long countLimit1 = 10;
final long bytesLimit1 = 100;
final long countHardLimit1 = 5;
final long bytesHardLimit1 = 50;
final long countUsage1 = 5;
final long bytesUsage1 = 40;
final StatsTrack limitTrack1 = buildLimitStatsTrack(countLimit1, bytesLimit1, countHardLimit1, bytesHardLimit1);
final StatsTrack usageTrack1 = buildUsageStatsTrack(countUsage1, bytesUsage1);
buildDataTree("/" + ns + "/a/b", limitTrack1, usageTrack1, dt);
// validate the quota metrics
validateQuotaMetrics(ns, countHardLimit1, bytesHardLimit1, countUsage1, bytesUsage1, nameSuffix);
// update the data tree with another quota subtree
final long countLimit2 = 20;
final long bytesLimit2 = 200;
final long countHardLimit2 = 10;
final long bytesHardLimit2 = 100;
final long countUsage2 = 9;
final long bytesUsage2 = 80;
final StatsTrack limitTrack2 = buildLimitStatsTrack(countLimit2, bytesLimit2, countHardLimit2, bytesHardLimit2);
final StatsTrack usageTrack2 = buildUsageStatsTrack(countUsage2, bytesUsage2);
buildDataTree("/" + ns + "/a/c/d", limitTrack2, usageTrack2, dt);
// validate the quota metrics
validateQuotaMetrics(ns, countHardLimit1 + countHardLimit2, bytesHardLimit1 + bytesHardLimit2, countUsage1 + countUsage2, bytesUsage1 + bytesUsage2, nameSuffix);
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class QuotaMetricsUtilsTest method buildUsageStatsTrack.
private StatsTrack buildUsageStatsTrack(final long countUsage, final long bytesUsage) {
final StatsTrack usageTrack = new StatsTrack();
usageTrack.setCount(countUsage);
usageTrack.setBytes(bytesUsage);
return usageTrack;
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class QuotaMetricsUtilsTest method testQuotaMetrics_singleQuotaSubtree.
@Test
public void testQuotaMetrics_singleQuotaSubtree() throws Exception {
// register the metrics
final String nameSuffix = UUID.randomUUID().toString();
final DataTree dt = new DataTree();
registerQuotaMetrics(nameSuffix, dt);
// build the data tree
final String ns = UUID.randomUUID().toString();
final long countLimit = 10;
final long bytesLimit = 100;
final long countHardLimit = 5;
final long bytesHardLimit = 50;
final long countUsage = 5;
final long bytesUsage = 40;
final StatsTrack limitTrack = buildLimitStatsTrack(countLimit, bytesLimit, countHardLimit, bytesHardLimit);
final StatsTrack usageTrack = buildUsageStatsTrack(countUsage, bytesUsage);
buildDataTree("/" + ns, limitTrack, usageTrack, dt);
// validate the quota metrics
validateQuotaMetrics(ns, countHardLimit, bytesHardLimit, countUsage, bytesUsage, nameSuffix);
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ListQuotaCommand method listQuota.
// @VisibleForTesting
public static List<StatsTrack> listQuota(ZooKeeper zk, String path) throws KeeperException, InterruptedException {
List<StatsTrack> statsTracks = new ArrayList<>();
Stat stat = new Stat();
byte[] data = zk.getData(Quotas.limitPath(path), false, stat);
StatsTrack st = new StatsTrack(data);
statsTracks.add(st);
data = zk.getData(Quotas.statPath(path), false, stat);
st = new StatsTrack(data);
statsTracks.add(st);
return statsTracks;
}
Aggregations