use of com.wavefront.agent.handlers.HandlerKey in project java by wavefrontHQ.
the class QueueExporter method getValidHandlerKeys.
@VisibleForTesting
static Set<HandlerKey> getValidHandlerKeys(@Nullable List<String> files, String portList) {
if (files == null) {
return Collections.emptySet();
}
Set<String> ports = new HashSet<>(Splitter.on(",").omitEmptyStrings().trimResults().splitToList(portList));
Set<HandlerKey> out = new HashSet<>();
files.forEach(x -> {
Matcher matcher = FILENAME.matcher(x);
if (matcher.matches()) {
ReportableEntityType type = ReportableEntityType.fromString(matcher.group(2));
String handle = matcher.group(3);
if (type != null && NumberUtils.isDigits(matcher.group(4)) && !handle.startsWith("_") && (portList.equalsIgnoreCase("all") || ports.contains(handle))) {
out.add(HandlerKey.of(type, handle));
}
}
});
return out;
}
use of com.wavefront.agent.handlers.HandlerKey in project java by wavefrontHQ.
the class QueueExporterTest method testQueueExporterWithRetainData.
@Test
public void testQueueExporterWithRetainData() throws Exception {
File file = new File(File.createTempFile("proxyTestConverter", null).getPath() + ".queue");
file.deleteOnExit();
String bufferFile = file.getAbsolutePath();
TaskQueueFactory taskQueueFactory = new TaskQueueFactoryImpl(bufferFile, false, false, 128);
EntityPropertiesFactory entityPropFactory = new DefaultEntityPropertiesFactoryForTesting();
QueueExporter qe = new QueueExporter(bufferFile, "2878", bufferFile + "-output", true, taskQueueFactory, entityPropFactory);
BufferedWriter mockedWriter = EasyMock.createMock(BufferedWriter.class);
reset(mockedWriter);
HandlerKey key = HandlerKey.of(ReportableEntityType.POINT, "2878");
TaskQueue<LineDelimitedDataSubmissionTask> queue = taskQueueFactory.getTaskQueue(key, 0);
queue.clear();
UUID proxyId = UUID.randomUUID();
LineDelimitedDataSubmissionTask task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), () -> 12345L);
task.enqueue(QueueingReason.RETRY);
LineDelimitedDataSubmissionTask task2 = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item4", "item5"), () -> 12345L);
task2.enqueue(QueueingReason.RETRY);
qe.export();
File outputTextFile = new File(file.getAbsolutePath() + "-output.points.2878.0.txt");
assertEquals(ImmutableList.of("item1", "item2", "item3", "item4", "item5"), Files.asCharSource(outputTextFile, Charsets.UTF_8).readLines());
assertEquals(2, taskQueueFactory.getTaskQueue(key, 0).size());
}
use of com.wavefront.agent.handlers.HandlerKey in project java by wavefrontHQ.
the class HttpEndToEndTest method testEndToEndHistograms.
@Test
public void testEndToEndHistograms() throws Exception {
AtomicInteger successfulSteps = new AtomicInteger(0);
AtomicInteger testCounter = new AtomicInteger(0);
long time = (Clock.now() / 1000) / 60 * 60 + 30;
AtomicLong digestTime = new AtomicLong(System.currentTimeMillis());
proxyPort = findAvailablePort(2898);
int histMinPort = findAvailablePort(40001);
int histHourPort = findAvailablePort(40002);
int histDayPort = findAvailablePort(40003);
int histDistPort = findAvailablePort(40000);
String buffer = File.createTempFile("proxyTestBuffer", null).getPath();
proxy = new PushAgent();
proxy.proxyConfig.server = "http://localhost:" + backendPort + "/api/";
proxy.proxyConfig.flushThreads = 1;
proxy.proxyConfig.histogramMinuteListenerPorts = String.valueOf(histMinPort);
proxy.proxyConfig.histogramHourListenerPorts = String.valueOf(histHourPort);
proxy.proxyConfig.histogramDayListenerPorts = String.valueOf(histDayPort);
proxy.proxyConfig.histogramDistListenerPorts = String.valueOf(histDistPort);
proxy.proxyConfig.histogramMinuteAccumulatorPersisted = false;
proxy.proxyConfig.histogramHourAccumulatorPersisted = false;
proxy.proxyConfig.histogramDayAccumulatorPersisted = false;
proxy.proxyConfig.histogramDistAccumulatorPersisted = false;
proxy.proxyConfig.histogramMinuteMemoryCache = false;
proxy.proxyConfig.histogramHourMemoryCache = false;
proxy.proxyConfig.histogramDayMemoryCache = false;
proxy.proxyConfig.histogramDistMemoryCache = false;
proxy.proxyConfig.histogramMinuteFlushSecs = 1;
proxy.proxyConfig.histogramHourFlushSecs = 1;
proxy.proxyConfig.histogramDayFlushSecs = 1;
proxy.proxyConfig.histogramDistFlushSecs = 1;
proxy.proxyConfig.histogramMinuteAccumulatorSize = 10L;
proxy.proxyConfig.histogramHourAccumulatorSize = 10L;
proxy.proxyConfig.histogramDayAccumulatorSize = 10L;
proxy.proxyConfig.histogramDistAccumulatorSize = 10L;
proxy.proxyConfig.histogramAccumulatorFlushInterval = 10000L;
proxy.proxyConfig.histogramAccumulatorResolveInterval = 10000L;
proxy.proxyConfig.splitPushWhenRateLimited = true;
proxy.proxyConfig.pushListenerPorts = String.valueOf(proxyPort);
proxy.proxyConfig.pushFlushInterval = 10000;
proxy.proxyConfig.bufferFile = buffer;
proxy.proxyConfig.timeProvider = digestTime::get;
proxy.start(new String[] {});
waitUntilListenerIsOnline(histDistPort);
if (!(proxy.senderTaskFactory instanceof SenderTaskFactoryImpl))
fail();
if (!(proxy.queueingFactory instanceof QueueingFactoryImpl))
fail();
String payloadHistograms = "metric.name 1 " + time + " source=metric.source tagk1=tagv1\n" + "metric.name 1 " + time + " source=metric.source tagk1=tagv1\n" + "metric.name 2 " + (time + 1) + " source=metric.source tagk1=tagv1\n" + "metric.name 2 " + (time + 2) + " source=metric.source tagk1=tagv1\n" + "metric.name 3 " + time + " source=metric.source tagk1=tagv2\n" + "metric.name 4 " + time + " source=metric.source tagk1=tagv2\n" + "metric.name 5 " + (time + 60) + " source=metric.source tagk1=tagv1\n" + "metric.name 6 " + (time + 60) + " source=metric.source tagk1=tagv1\n";
long minuteBin = time / 60 * 60;
long hourBin = time / 3600 * 3600;
long dayBin = time / 86400 * 86400;
Set<String> expectedHistograms = ImmutableSet.of("!M " + minuteBin + " #2 1.0 #2 2.0 \"metric.name\" " + "source=\"metric.source\" \"tagk1\"=\"tagv1\"", "!M " + minuteBin + " #1 3.0 #1 4.0 \"metric.name\" source=\"metric.source\" " + "\"tagk1\"=\"tagv2\"", "!M " + (minuteBin + 60) + " #1 5.0 #1 6.0 \"metric.name\" source=\"metric.source\" " + "\"tagk1\"=\"tagv1\"", "!H " + hourBin + " #2 1.0 #2 2.0 #1 5.0 #1 6.0 \"metric.name\" " + "source=\"metric.source\" \"tagk1\"=\"tagv1\"", "!H " + hourBin + " #1 3.0 #1 4.0 \"metric.name\" source=\"metric.source\" " + "\"tagk1\"=\"tagv2\"", "!D " + dayBin + " #1 3.0 #1 4.0 \"metric.name\" source=\"metric.source\" " + "\"tagk1\"=\"tagv2\"", "!D " + dayBin + " #2 1.0 #2 2.0 #1 5.0 #1 6.0 \"metric.name\" " + "source=\"metric.source\" \"tagk1\"=\"tagv1\"");
String distPayload = "!M " + minuteBin + " #1 1.0 #1 1.0 #1 2.0 #1 2.0 \"metric.name\" " + "source=\"metric.source\" \"tagk1\"=\"tagv1\"\n" + "!M " + minuteBin + " #1 1.0 #1 1.0 #1 2.0 #1 2.0 \"metric.name\" " + "source=\"metric.source\" \"tagk1\"=\"tagv1\"\n" + "!H " + minuteBin + " #1 1.0 #1 1.0 #1 2.0 #1 2.0 \"metric.name\" " + "source=\"metric.source\" \"tagk1\"=\"tagv1\"\n";
Set<String> expectedDists = ImmutableSet.of("!M " + minuteBin + " #4 1.0 #4 2.0 " + "\"metric.name\" source=\"metric.source\" \"tagk1\"=\"tagv1\"", "!H " + hourBin + " #2 1.0 #2 2.0 \"metric.name\" " + "source=\"metric.source\" \"tagk1\"=\"tagv1\"");
server.update(req -> {
String content = req.content().toString(CharsetUtil.UTF_8);
URI uri;
try {
uri = new URI(req.uri());
} catch (Exception e) {
throw new RuntimeException(e);
}
String path = uri.getPath();
assertEquals(HttpMethod.POST, req.method());
assertEquals("/api/v2/wfproxy/report", path);
logger.fine("Content received: " + content);
switch(testCounter.incrementAndGet()) {
case 1:
assertEquals(expectedHistograms, new HashSet<>(Arrays.asList(content.split("\n"))));
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
case 2:
assertEquals(expectedDists, new HashSet<>(Arrays.asList(content.split("\n"))));
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
}
return makeResponse(HttpResponseStatus.OK, "");
});
digestTime.set(System.currentTimeMillis() - 1001);
gzippedHttpPost("http://localhost:" + histMinPort + "/", payloadHistograms);
gzippedHttpPost("http://localhost:" + histHourPort + "/", payloadHistograms);
gzippedHttpPost("http://localhost:" + histDayPort + "/", payloadHistograms);
// should reject
gzippedHttpPost("http://localhost:" + histDistPort + "/", payloadHistograms);
digestTime.set(System.currentTimeMillis());
proxy.histogramFlushRunnables.forEach(Runnable::run);
HandlerKey key = HandlerKey.of(ReportableEntityType.HISTOGRAM, "histogram_ports");
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(key);
digestTime.set(System.currentTimeMillis() - 1001);
gzippedHttpPost("http://localhost:" + histDistPort + "/", distPayload);
digestTime.set(System.currentTimeMillis());
proxy.histogramFlushRunnables.forEach(Runnable::run);
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(key);
assertEquals(2, successfulSteps.getAndSet(0));
}
use of com.wavefront.agent.handlers.HandlerKey in project java by wavefrontHQ.
the class HttpEndToEndTest method testEndToEndSourceTags.
@Test
public void testEndToEndSourceTags() throws Exception {
AtomicInteger successfulSteps = new AtomicInteger(0);
AtomicInteger testCounter = new AtomicInteger(0);
proxyPort = findAvailablePort(2898);
String buffer = File.createTempFile("proxyTestBuffer", null).getPath();
proxy = new PushAgent();
proxy.proxyConfig.server = "http://localhost:" + backendPort + "/api/";
proxy.proxyConfig.flushThreads = 1;
proxy.proxyConfig.flushThreadsSourceTags = 1;
proxy.proxyConfig.splitPushWhenRateLimited = true;
proxy.proxyConfig.pushListenerPorts = String.valueOf(proxyPort);
proxy.proxyConfig.pushFlushInterval = 10000;
proxy.proxyConfig.pushRateLimitSourceTags = 100;
proxy.proxyConfig.bufferFile = buffer;
proxy.start(new String[] {});
waitUntilListenerIsOnline(proxyPort);
if (!(proxy.senderTaskFactory instanceof SenderTaskFactoryImpl))
fail();
if (!(proxy.queueingFactory instanceof QueueingFactoryImpl))
fail();
String payloadSourceTags = "@SourceTag action=add source=testSource addTag1 addTag2 addTag3\n" + "@SourceTag action=save source=testSource newtag1 newtag2\n" + "@SourceTag action=delete source=testSource deleteTag\n" + "@SourceDescription action=save source=testSource \"Long Description\"\n" + "@SourceDescription action=delete source=testSource";
server.update(req -> {
String content = req.content().toString(CharsetUtil.UTF_8);
URI uri;
try {
uri = new URI(req.uri());
} catch (Exception e) {
throw new RuntimeException(e);
}
String path = uri.getPath();
logger.fine("Content received: " + content);
switch(testCounter.incrementAndGet()) {
case 1:
assertEquals(HttpMethod.PUT, req.method());
assertEquals("/api/v2/source/testSource/tag/addTag1", path);
assertEquals("", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
case 2:
assertEquals(HttpMethod.PUT, req.method());
assertEquals("/api/v2/source/testSource/tag/addTag2", path);
assertEquals("", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
case 3:
assertEquals(HttpMethod.PUT, req.method());
assertEquals("/api/v2/source/testSource/tag/addTag3", path);
assertEquals("", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
case 4:
assertEquals(HttpMethod.POST, req.method());
assertEquals("/api/v2/source/testSource/tag", path);
assertEquals("[\"newtag1\",\"newtag2\"]", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, "");
case 5:
assertEquals(HttpMethod.DELETE, req.method());
assertEquals("/api/v2/source/testSource/tag/deleteTag", path);
assertEquals("", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
case 6:
assertEquals(HttpMethod.POST, req.method());
assertEquals("/api/v2/source/testSource/description", path);
assertEquals("Long Description", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.INTERNAL_SERVER_ERROR, "");
case 7:
assertEquals(HttpMethod.DELETE, req.method());
assertEquals("/api/v2/source/testSource/description", path);
assertEquals("", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.valueOf(407), "");
case 8:
assertEquals(HttpMethod.POST, req.method());
assertEquals("/api/v2/source/testSource/tag", path);
assertEquals("[\"newtag1\",\"newtag2\"]", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
case 9:
assertEquals(HttpMethod.POST, req.method());
assertEquals("/api/v2/source/testSource/description", path);
assertEquals("Long Description", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
case 10:
assertEquals(HttpMethod.DELETE, req.method());
assertEquals("/api/v2/source/testSource/description", path);
assertEquals("", content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
}
logger.warning("Too many requests");
// this will force the assert to fail
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
});
gzippedHttpPost("http://localhost:" + proxyPort + "/", payloadSourceTags);
HandlerKey key = HandlerKey.of(ReportableEntityType.SOURCE_TAG, String.valueOf(proxyPort));
for (int i = 0; i < 2; i++) ((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(key);
for (int i = 0; i < 4; i++) ((QueueingFactoryImpl) proxy.queueingFactory).flushNow(key);
assertEquals(10, successfulSteps.getAndSet(0));
}
use of com.wavefront.agent.handlers.HandlerKey in project java by wavefrontHQ.
the class HttpEndToEndTest method testEndToEndMetrics.
@Test
public void testEndToEndMetrics() throws Exception {
AtomicInteger successfulSteps = new AtomicInteger(0);
AtomicInteger testCounter = new AtomicInteger(0);
long time = Clock.now() / 1000;
proxyPort = findAvailablePort(2898);
String buffer = File.createTempFile("proxyTestBuffer", null).getPath();
proxy = new PushAgent();
proxy.proxyConfig.server = "http://localhost:" + backendPort + "/api/";
proxy.proxyConfig.flushThreads = 1;
proxy.proxyConfig.pushListenerPorts = String.valueOf(proxyPort);
proxy.proxyConfig.pushFlushInterval = 50;
proxy.proxyConfig.bufferFile = buffer;
proxy.proxyConfig.allowRegex = "^.*$";
proxy.proxyConfig.blockRegex = "^.*blocklist.*$";
proxy.proxyConfig.gzipCompression = false;
proxy.start(new String[] {});
waitUntilListenerIsOnline(proxyPort);
if (!(proxy.senderTaskFactory instanceof SenderTaskFactoryImpl))
fail();
if (!(proxy.queueingFactory instanceof QueueingFactoryImpl))
fail();
String payload = "metric.name 1 " + time + " source=metric.source tagk1=tagv1\n" + "metric.name 2 " + time + " source=metric.source tagk1=tagv2\n" + "metric.name 3 " + time + " source=metric.source tagk1=tagv3\n" + "metric.name 4 " + time + " source=metric.source tagk1=tagv4\n";
String expectedTest1part1 = "\"metric.name\" 1.0 " + time + " source=\"metric.source\" \"tagk1\"=\"tagv1\"\n" + "\"metric.name\" 2.0 " + time + " source=\"metric.source\" \"tagk1\"=\"tagv2\"";
String expectedTest1part2 = "\"metric.name\" 3.0 " + time + " source=\"metric.source\" \"tagk1\"=\"tagv3\"\n" + "\"metric.name\" 4.0 " + time + " source=\"metric.source\" \"tagk1\"=\"tagv4\"";
server.update(req -> {
String content = req.content().toString(CharsetUtil.UTF_8);
logger.fine("Content received: " + content);
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
});
gzippedHttpPost("http://localhost:" + proxyPort + "/", payload);
HandlerKey key = HandlerKey.of(ReportableEntityType.POINT, String.valueOf(proxyPort));
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(key);
assertEquals(1, successfulSteps.getAndSet(0));
AtomicBoolean part1 = new AtomicBoolean(false);
AtomicBoolean part2 = new AtomicBoolean(false);
server.update(req -> {
String content = req.content().toString(CharsetUtil.UTF_8);
logger.fine("Content received: " + content);
switch(testCounter.incrementAndGet()) {
case 1:
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.TOO_MANY_REQUESTS, "");
case 2:
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
case 3:
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.valueOf(407), "");
case 4:
assertEquals(expectedTest1part1 + "\n" + expectedTest1part2, content);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, "");
case 5:
case 6:
if (content.equals(expectedTest1part1))
part1.set(true);
if (content.equals(expectedTest1part2))
part2.set(true);
successfulSteps.incrementAndGet();
return makeResponse(HttpResponseStatus.OK, "");
}
throw new IllegalStateException();
});
gzippedHttpPost("http://localhost:" + proxyPort + "/", payload);
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(key);
((QueueingFactoryImpl) proxy.queueingFactory).flushNow(key);
gzippedHttpPost("http://localhost:" + proxyPort + "/", payload);
((SenderTaskFactoryImpl) proxy.senderTaskFactory).flushNow(key);
for (int i = 0; i < 3; i++) ((QueueingFactoryImpl) proxy.queueingFactory).flushNow(key);
assertEquals(6, successfulSteps.getAndSet(0));
assertTrue(part1.get());
assertTrue(part2.get());
}
Aggregations