Search in sources :

Example 36 with StatsTrack

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);
}
Also used : DataTree(org.apache.zookeeper.server.DataTree) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Example 37 with StatsTrack

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);
}
Also used : DataTree(org.apache.zookeeper.server.DataTree) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Example 38 with StatsTrack

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;
}
Also used : StatsTrack(org.apache.zookeeper.StatsTrack)

Example 39 with StatsTrack

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);
}
Also used : DataTree(org.apache.zookeeper.server.DataTree) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Example 40 with StatsTrack

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;
}
Also used : Stat(org.apache.zookeeper.data.Stat) StatsTrack(org.apache.zookeeper.StatsTrack) ArrayList(java.util.ArrayList)

Aggregations

StatsTrack (org.apache.zookeeper.StatsTrack)43 Test (org.junit.jupiter.api.Test)25 OldStatsTrack (org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack)19 QuotaExceededException (org.apache.zookeeper.KeeperException.QuotaExceededException)14 KeeperException (org.apache.zookeeper.KeeperException)9 Stat (org.apache.zookeeper.data.Stat)6 DataTree (org.apache.zookeeper.server.DataTree)3 Op (org.apache.zookeeper.Op)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1 MalformedPathException (org.apache.zookeeper.cli.MalformedPathException)1 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)1