use of com.amazonaws.xray.strategy.sampling.rule.CentralizedRule in project aws-xray-sdk-java by aws.
the class CentralizedManifest method rebuild.
LinkedHashMap<String, CentralizedRule> rebuild(Map<String, CentralizedRule> old, List<SamplingRule> inputs) {
List<CentralizedRule> rules = new ArrayList<>(inputs.size() - 1);
for (SamplingRule i : inputs) {
if (i.getRuleName().equals(CentralizedRule.DEFAULT_RULE_NAME)) {
continue;
}
CentralizedRule r = old.get(i.getRuleName());
if (r == null) {
r = new CentralizedRule(i, new RandImpl());
}
rules.add(r);
}
Collections.sort(rules);
LinkedHashMap<String, CentralizedRule> current = new LinkedHashMap<>(rules.size());
for (CentralizedRule r : rules) {
current.put(r.getName(), r);
}
return current;
}
use of com.amazonaws.xray.strategy.sampling.rule.CentralizedRule in project aws-xray-sdk-java by aws.
the class CentralizedManifestTest method testSnapshotsWithDefaultRule.
@Test
void testSnapshotsWithDefaultRule() {
Instant now = Instant.ofEpochSecond(1500000000);
CentralizedManifest m = new CentralizedManifest();
m.putRules(Arrays.asList(rule("r1"), rule("r2"), rule(CentralizedRule.DEFAULT_RULE_NAME)), now);
Map<String, CentralizedRule> rules = Whitebox.getInternalState(m, "rules", CentralizedManifest.class);
CentralizedRule defaultRule = Whitebox.getInternalState(m, "defaultRule", CentralizedManifest.class);
rules.forEach((key, r) -> r.sample(now));
defaultRule.sample(now);
List<SamplingStatisticsDocument> snapshots = m.snapshots(now);
Assertions.assertEquals(3, snapshots.size());
}
use of com.amazonaws.xray.strategy.sampling.rule.CentralizedRule in project aws-xray-sdk-java by aws.
the class CentralizedManifestTest method testRebuildOnPriorityChange.
@Test
void testRebuildOnPriorityChange() {
CentralizedManifest manifest = new CentralizedManifest();
manifest.putRules(Arrays.asList(rule("r1")), Instant.now());
Map<String, CentralizedRule> rules1 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class);
SamplingRule r = rule("r1").withPriority(200);
manifest.putRules(Arrays.asList(r), Instant.now());
Map<String, CentralizedRule> rules2 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class);
// The map of rules should be rebuilt, resulting in a new object
Assertions.assertFalse(rules1 == rules2);
Assertions.assertEquals(1, rules1.size());
Assertions.assertEquals(1, rules2.size());
}
use of com.amazonaws.xray.strategy.sampling.rule.CentralizedRule in project aws-xray-sdk-java by aws.
the class CentralizedManifestTest method testPutRulesWithoutRebuild.
@Test
void testPutRulesWithoutRebuild() {
CentralizedManifest manifest = new CentralizedManifest();
manifest.putRules(Arrays.asList(rule("r1")), Instant.now());
Map<String, CentralizedRule> rules1 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class);
SamplingRule r = rule("r1").withResourceARN("arn3");
manifest.putRules(Arrays.asList(r), Instant.now());
Map<String, CentralizedRule> rules2 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class);
// The map of rules should not have been rebuilt
Assertions.assertTrue(rules1 == rules2);
}
use of com.amazonaws.xray.strategy.sampling.rule.CentralizedRule in project aws-xray-sdk-java by aws.
the class CentralizedManifest method snapshots.
public List<SamplingStatisticsDocument> snapshots(Instant now) {
List<SamplingStatisticsDocument> snapshots = new ArrayList<>(rules.size() + 1);
Date date = Date.from(now);
for (CentralizedRule rule : rules.values()) {
if (!rule.isStale(now)) {
continue;
}
SamplingStatisticsDocument snapshot = rule.snapshot(date);
snapshot.withClientID(CentralizedSamplingStrategy.getClientID());
snapshots.add(snapshot);
}
if (defaultRule != null && defaultRule.isStale(now)) {
SamplingStatisticsDocument snapshot = defaultRule.snapshot(date);
snapshot.withClientID(CentralizedSamplingStrategy.getClientID());
snapshots.add(snapshot);
}
return snapshots;
}
Aggregations