use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class PreprocessorRulesTest method testReportPointRules.
@Test
public void testReportPointRules() {
String pointLine = "\"Some Metric\" 10.0 1469751813 source=\"Host\" \"boo\"=\"Baz\" \"foo\"=\"bar\"";
ReportPoint point = parsePointLine(pointLine);
// lowercase a point tag value with no match - shouldn't change anything
new ReportPointForceLowercaseTransformer("boo", "nomatch.*", metrics).apply(point);
assertEquals(pointLine, referencePointToStringImpl(point));
// lowercase a point tag value - shouldn't affect metric name or source
new ReportPointForceLowercaseTransformer("boo", null, metrics).apply(point);
String expectedPoint1a = "\"Some Metric\" 10.0 1469751813 source=\"Host\" \"boo\"=\"baz\" \"foo\"=\"bar\"";
assertEquals(expectedPoint1a, referencePointToStringImpl(point));
// lowercase a metric name - shouldn't affect remaining source
new ReportPointForceLowercaseTransformer("metricName", null, metrics).apply(point);
String expectedPoint1b = "\"some metric\" 10.0 1469751813 source=\"Host\" \"boo\"=\"baz\" \"foo\"=\"bar\"";
assertEquals(expectedPoint1b, referencePointToStringImpl(point));
// lowercase source
new ReportPointForceLowercaseTransformer("sourceName", null, metrics).apply(point);
assertEquals(pointLine.toLowerCase(), referencePointToStringImpl(point));
// try to remove a point tag when value doesn't match the regex - shouldn't change
new ReportPointDropTagTransformer("foo", "bar(never|match)", metrics).apply(point);
assertEquals(pointLine.toLowerCase(), referencePointToStringImpl(point));
// try to remove a point tag when value does match the regex - should work
new ReportPointDropTagTransformer("foo", "ba.", metrics).apply(point);
String expectedPoint1 = "\"some metric\" 10.0 1469751813 source=\"host\" \"boo\"=\"baz\"";
assertEquals(expectedPoint1, referencePointToStringImpl(point));
// try to remove a point tag without a regex specified - should work
new ReportPointDropTagTransformer("boo", null, metrics).apply(point);
String expectedPoint2 = "\"some metric\" 10.0 1469751813 source=\"host\"";
assertEquals(expectedPoint2, referencePointToStringImpl(point));
// add a point tag back
new ReportPointAddTagTransformer("boo", "baz", metrics).apply(point);
String expectedPoint3 = "\"some metric\" 10.0 1469751813 source=\"host\" \"boo\"=\"baz\"";
assertEquals(expectedPoint3, referencePointToStringImpl(point));
// try to add a duplicate point tag - shouldn't change
new ReportPointAddTagIfNotExistsTransformer("boo", "bar", metrics).apply(point);
assertEquals(expectedPoint3, referencePointToStringImpl(point));
// add another point tag back - should work this time
new ReportPointAddTagIfNotExistsTransformer("foo", "bar", metrics).apply(point);
assertEquals(pointLine.toLowerCase(), referencePointToStringImpl(point));
// rename a point tag - should work
new ReportPointRenameTagTransformer("foo", "qux", null, metrics).apply(point);
String expectedPoint4 = "\"some metric\" 10.0 1469751813 source=\"host\" \"boo\"=\"baz\" \"qux\"=\"bar\"";
assertEquals(expectedPoint4, referencePointToStringImpl(point));
// rename a point tag matching the regex - should work
new ReportPointRenameTagTransformer("boo", "foo", "b[a-z]z", metrics).apply(point);
String expectedPoint5 = "\"some metric\" 10.0 1469751813 source=\"host\" \"foo\"=\"baz\" \"qux\"=\"bar\"";
assertEquals(expectedPoint5, referencePointToStringImpl(point));
// try to rename a point tag that doesn't match the regex - shouldn't change
new ReportPointRenameTagTransformer("foo", "boo", "wat", metrics).apply(point);
assertEquals(expectedPoint5, referencePointToStringImpl(point));
// add null metrics prefix - shouldn't change
new ReportPointAddPrefixTransformer(null).apply(point);
assertEquals(expectedPoint5, referencePointToStringImpl(point));
// add blank metrics prefix - shouldn't change
new ReportPointAddPrefixTransformer("").apply(point);
assertEquals(expectedPoint5, referencePointToStringImpl(point));
// add metrics prefix - should work
new ReportPointAddPrefixTransformer("prefix").apply(point);
String expectedPoint6 = "\"prefix.some metric\" 10.0 1469751813 source=\"host\" \"foo\"=\"baz\" \"qux\"=\"bar\"";
assertEquals(expectedPoint6, referencePointToStringImpl(point));
// replace regex in metric name, no matches - shouldn't change
new ReportPointReplaceRegexTransformer("metricName", "Z", "", null, null, metrics).apply(point);
assertEquals(expectedPoint6, referencePointToStringImpl(point));
// replace regex in metric name - shouldn't affect anything else
new ReportPointReplaceRegexTransformer("metricName", "o", "0", null, null, metrics).apply(point);
String expectedPoint7 = "\"prefix.s0me metric\" 10.0 1469751813 source=\"host\" \"foo\"=\"baz\" \"qux\"=\"bar\"";
assertEquals(expectedPoint7, referencePointToStringImpl(point));
// replace regex in source name - shouldn't affect anything else
new ReportPointReplaceRegexTransformer("sourceName", "o", "0", null, null, metrics).apply(point);
String expectedPoint8 = "\"prefix.s0me metric\" 10.0 1469751813 source=\"h0st\" \"foo\"=\"baz\" \"qux\"=\"bar\"";
assertEquals(expectedPoint8, referencePointToStringImpl(point));
// replace regex in a point tag value - shouldn't affect anything else
new ReportPointReplaceRegexTransformer("foo", "b", "z", null, null, metrics).apply(point);
String expectedPoint9 = "\"prefix.s0me metric\" 10.0 1469751813 source=\"h0st\" \"foo\"=\"zaz\" \"qux\"=\"bar\"";
assertEquals(expectedPoint9, referencePointToStringImpl(point));
// replace regex in a point tag value with matching groups
new ReportPointReplaceRegexTransformer("qux", "([a-c][a-c]).", "$1z", null, null, metrics).apply(point);
String expectedPoint10 = "\"prefix.s0me metric\" 10.0 1469751813 source=\"h0st\" \"foo\"=\"zaz\" \"qux\"=\"baz\"";
assertEquals(expectedPoint10, referencePointToStringImpl(point));
// replace regex in a point tag value with placeholders
// try to substitute sourceName, a point tag value and a non-existent point tag
new ReportPointReplaceRegexTransformer("qux", "az", "{{foo}}-{{no_match}}-g{{sourceName}}", null, null, metrics).apply(point);
String expectedPoint11 = "\"prefix.s0me metric\" 10.0 1469751813 source=\"h0st\" \"foo\"=\"zaz\" \"qux\"=\"bzaz-{{no_match}}-gh0st\"";
assertEquals(expectedPoint11, referencePointToStringImpl(point));
}
use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class PreprocessorRulesTest method testAgentPreprocessorForReportPoint.
@Test
public void testAgentPreprocessorForReportPoint() {
ReportPoint testPoint1 = parsePointLine("collectd.cpu.loadavg.1m 7 1459527231 source=hostname foo=bar boo=baz");
assertTrue(config.forPort("2878").forReportPoint().filter(testPoint1));
ReportPoint testPoint2 = parsePointLine("foo.collectd.cpu.loadavg.1m 7 1459527231 source=hostname foo=bar boo=baz");
assertFalse(config.forPort("2878").forReportPoint().filter(testPoint2));
ReportPoint testPoint3 = parsePointLine("collectd.cpu.loadavg.1m 7 1459527231 source=hostname foo=west123 boo=baz");
assertFalse(config.forPort("2878").forReportPoint().filter(testPoint3));
ReportPoint testPoint4 = parsePointLine("collectd.cpu.loadavg.1m 7 1459527231 source=bar123 foo=bar boo=baz");
assertFalse(config.forPort("2878").forReportPoint().filter(testPoint4));
// in this test we are confirming that the rule sets for different ports are in fact different
// on port 2878 we add "newtagkey=1", on port 4242 we don't
ReportPoint testPoint1a = parsePointLine("collectd.cpu.loadavg.1m 7 1459527231 source=hostname foo=bar boo=baz");
config.forPort("2878").forReportPoint().transform(testPoint1);
config.forPort("4242").forReportPoint().transform(testPoint1a);
String expectedPoint1 = "\"collectd.cpu.loadavg.1m\" 7.0 1459527231 " + "source=\"hostname\" \"baz\"=\"bar\" \"boo\"=\"baz\" \"newtagkey\"=\"1\"";
String expectedPoint1a = "\"collectd.cpu.loadavg.1m\" 7.0 1459527231 " + "source=\"hostname\" \"baz\"=\"bar\" \"boo\"=\"baz\"";
assertEquals(expectedPoint1, referencePointToStringImpl(testPoint1));
assertEquals(expectedPoint1a, referencePointToStringImpl(testPoint1a));
// in this test the following should happen:
// - rename foo tag to baz
// - "metrictest." prefix gets dropped from the metric name
// - replace dashes with dots in bar tag
String expectedPoint5 = "\"metric\" 7.0 1459527231 source=\"src\" " + "\"bar\"=\"baz.baz.baz\" \"baz\"=\"bar\" \"datacenter\"=\"az1\" \"newtagkey\"=\"1\" \"qux\"=\"123z\"";
assertEquals(expectedPoint5, applyAllTransformers("metrictest.metric 7 1459527231 source=src foo=bar datacenter=az1 bar=baz-baz-baz qux=123z", "2878"));
// in this test the following should happen:
// - rename tag foo to baz
// - add new tag newtagkey=1
// - drop dc1 tag
// - drop datacenter tag as it matches az[4-6]
// - rename qux tag to numericTag
String expectedPoint6 = "\"some.metric\" 7.0 1459527231 source=\"hostname\" " + "\"baz\"=\"bar\" \"newtagkey\"=\"1\" \"numericTag\"=\"12345\" \"prefix\"=\"some\"";
assertEquals(expectedPoint6, applyAllTransformers("some.metric 7 1459527231 source=hostname foo=bar dc1=baz datacenter=az4 qux=12345", "2878"));
}
use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class PointHandlerDispatcherTest method testBasicDispatch.
@Test
public void testBasicDispatch() {
in.put(keyA, digestA);
in.getResolveTask().run();
timeMillis.set(101L);
subject.run();
assertThat(pointOut).hasSize(1);
assertThat(debugLineOut).hasSize(1);
assertThat(blockedOut).hasSize(0);
assertThat(backingStore).isEmpty();
ReportPoint point = pointOut.get(0);
TestUtils.testKeyPointMatch(keyA, point);
}
use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class PointHandlerDispatcherTest method testOnlyRipeEntriesAreDispatched.
@Test
public void testOnlyRipeEntriesAreDispatched() {
in.put(keyA, digestA);
in.put(keyB, digestB);
in.getResolveTask().run();
timeMillis.set(101L);
subject.run();
in.getResolveTask().run();
assertThat(pointOut).hasSize(1);
assertThat(debugLineOut).hasSize(1);
assertThat(blockedOut).hasSize(0);
assertThat(backingStore).containsEntry(keyB, digestB);
ReportPoint point = pointOut.get(0);
TestUtils.testKeyPointMatch(keyA, point);
}
use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class TapeDispatcherTest method testBasicDispatch.
@Test
public void testBasicDispatch() {
in.put(keyA, digestA);
timeMillis.set(TimeUnit.MILLISECONDS.toNanos(101L));
subject.run();
assertThat(out.size()).isEqualTo(1);
assertThat(in).isEmpty();
ReportPoint point = out.peek();
TestUtils.testKeyPointMatch(keyA, point);
}
Aggregations