use of com.wavefront.dto.SourceTag in project java by wavefrontHQ.
the class QueueExporterTest method testQueueExporter.
@Test
public void testQueueExporter() 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", false, 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);
mockedWriter.write("item1");
mockedWriter.newLine();
mockedWriter.write("item2");
mockedWriter.newLine();
mockedWriter.write("item3");
mockedWriter.newLine();
mockedWriter.write("item4");
mockedWriter.newLine();
mockedWriter.write("item5");
mockedWriter.newLine();
TaskQueue<EventDataSubmissionTask> queue2 = taskQueueFactory.getTaskQueue(HandlerKey.of(ReportableEntityType.EVENT, "2888"), 0);
queue2.clear();
EventDataSubmissionTask eventTask = new EventDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue2, "2888", ImmutableList.of(new Event(ReportEvent.newBuilder().setStartTime(123456789L * 1000).setEndTime(123456789L * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).setAnnotations(ImmutableMap.of("severity", "INFO")).setTags(ImmutableList.of("tag1")).build()), new Event(ReportEvent.newBuilder().setStartTime(123456789L * 1000).setEndTime(123456789L * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setAnnotations(ImmutableMap.of("severity", "INFO")).build())), () -> 12345L);
eventTask.enqueue(QueueingReason.RETRY);
mockedWriter.write("@Event 123456789000 123456789001 \"Event name for testing\" " + "\"host\"=\"host1\" \"host\"=\"host2\" \"severity\"=\"INFO\" \"multi\"=\"bar\" " + "\"multi\"=\"baz\" \"tag\"=\"tag1\"");
mockedWriter.newLine();
mockedWriter.write("@Event 123456789000 123456789001 \"Event name for testing\" " + "\"host\"=\"host1\" \"host\"=\"host2\" \"severity\"=\"INFO\"");
mockedWriter.newLine();
TaskQueue<SourceTagSubmissionTask> queue3 = taskQueueFactory.getTaskQueue(HandlerKey.of(ReportableEntityType.SOURCE_TAG, "2898"), 0);
queue3.clear();
SourceTagSubmissionTask sourceTagTask = new SourceTagSubmissionTask(null, new DefaultEntityPropertiesForTesting(), queue3, "2898", new SourceTag(ReportSourceTag.newBuilder().setOperation(SourceOperationType.SOURCE_TAG).setAction(SourceTagAction.SAVE).setSource("testSource").setAnnotations(ImmutableList.of("newtag1", "newtag2")).build()), () -> 12345L);
sourceTagTask.enqueue(QueueingReason.RETRY);
mockedWriter.write("@SourceTag action=save source=\"testSource\" \"newtag1\" \"newtag2\"");
mockedWriter.newLine();
expectLastCall().once();
replay(mockedWriter);
assertEquals(2, queue.size());
qe.processQueue(queue, mockedWriter);
assertEquals(0, queue.size());
assertEquals(1, queue2.size());
qe.processQueue(queue2, mockedWriter);
assertEquals(0, queue2.size());
assertEquals(1, queue3.size());
qe.processQueue(queue3, mockedWriter);
assertEquals(0, queue3.size());
verify(mockedWriter);
List<String> files = ConcurrentShardedQueueFile.listFiles(bufferFile, ".spool").stream().map(x -> x.replace(bufferFile + ".", "")).collect(Collectors.toList());
assertEquals(3, files.size());
assertTrue(files.contains("points.2878.0.spool_0000"));
assertTrue(files.contains("events.2888.0.spool_0000"));
assertTrue(files.contains("sourceTags.2898.0.spool_0000"));
HandlerKey k1 = HandlerKey.of(ReportableEntityType.POINT, "2878");
HandlerKey k2 = HandlerKey.of(ReportableEntityType.EVENT, "2888");
HandlerKey k3 = HandlerKey.of(ReportableEntityType.SOURCE_TAG, "2898");
files = ConcurrentShardedQueueFile.listFiles(bufferFile, ".spool");
Set<HandlerKey> hk = QueueExporter.getValidHandlerKeys(files, "all");
assertEquals(3, hk.size());
assertTrue(hk.contains(k1));
assertTrue(hk.contains(k2));
assertTrue(hk.contains(k3));
hk = QueueExporter.getValidHandlerKeys(files, "2878, 2898");
assertEquals(2, hk.size());
assertTrue(hk.contains(k1));
assertTrue(hk.contains(k3));
hk = QueueExporter.getValidHandlerKeys(files, "2888");
assertEquals(1, hk.size());
assertTrue(hk.contains(k2));
}
use of com.wavefront.dto.SourceTag in project java by wavefrontHQ.
the class WavefrontPortUnificationHandler method processLine.
/**
* @param ctx ChannelHandler context (to retrieve remote client's IP in case of errors)
* @param message line being processed
*/
@Override
protected void processLine(final ChannelHandlerContext ctx, @Nonnull String message, @Nullable DataFormat format) {
DataFormat dataFormat = format == null ? DataFormat.autodetect(message) : format;
switch(dataFormat) {
case SOURCE_TAG:
ReportableEntityHandler<ReportSourceTag, SourceTag> sourceTagHandler = sourceTagHandlerSupplier.get();
if (sourceTagHandler == null || sourceTagDecoder == null) {
wavefrontHandler.reject(message, "Port is not configured to accept " + "sourceTag-formatted data!");
return;
}
List<ReportSourceTag> output = new ArrayList<>(1);
try {
sourceTagDecoder.decode(message, output, "dummy");
for (ReportSourceTag tag : output) {
sourceTagHandler.report(tag);
}
} catch (Exception e) {
sourceTagHandler.reject(message, formatErrorMessage("WF-300 Cannot parse sourceTag: \"" + message + "\"", e, ctx));
}
return;
case EVENT:
ReportableEntityHandler<ReportEvent, ReportEvent> eventHandler = eventHandlerSupplier.get();
if (eventHandler == null || eventDecoder == null) {
wavefrontHandler.reject(message, "Port is not configured to accept event data!");
return;
}
List<ReportEvent> events = new ArrayList<>(1);
try {
eventDecoder.decode(message, events, "dummy");
for (ReportEvent event : events) {
eventHandler.report(event);
}
} catch (Exception e) {
eventHandler.reject(message, formatErrorMessage("WF-300 Cannot parse event: \"" + message + "\"", e, ctx));
}
return;
case SPAN:
ReportableEntityHandler<Span, String> spanHandler = spanHandlerSupplier.get();
if (spanHandler == null || spanDecoder == null) {
wavefrontHandler.reject(message, "Port is not configured to accept " + "tracing data (spans)!");
return;
}
message = annotator == null ? message : annotator.apply(ctx, message);
receivedSpansTotal.get().inc();
preprocessAndHandleSpan(message, spanDecoder, spanHandler, spanHandler::report, preprocessorSupplier, ctx, span -> sampler.sample(span, discardedSpansBySampler.get()));
return;
case SPAN_LOG:
if (isFeatureDisabled(spanLogsDisabled, SPANLOGS_DISABLED, discardedSpanLogs.get()))
return;
ReportableEntityHandler<SpanLogs, String> spanLogsHandler = spanLogsHandlerSupplier.get();
if (spanLogsHandler == null || spanLogsDecoder == null || spanDecoder == null) {
wavefrontHandler.reject(message, "Port is not configured to accept " + "tracing data (span logs)!");
return;
}
handleSpanLogs(message, spanLogsDecoder, spanDecoder, spanLogsHandler, preprocessorSupplier, ctx, span -> sampler.sample(span, discardedSpanLogsBySampler.get()));
return;
case HISTOGRAM:
if (isFeatureDisabled(histogramDisabled, HISTO_DISABLED, discardedHistograms.get()))
return;
ReportableEntityHandler<ReportPoint, String> histogramHandler = histogramHandlerSupplier.get();
if (histogramHandler == null || histogramDecoder == null) {
wavefrontHandler.reject(message, "Port is not configured to accept " + "histogram-formatted data!");
return;
}
message = annotator == null ? message : annotator.apply(ctx, message);
preprocessAndHandlePoint(message, histogramDecoder, histogramHandler, preprocessorSupplier, ctx, "histogram");
return;
default:
message = annotator == null ? message : annotator.apply(ctx, message);
preprocessAndHandlePoint(message, wavefrontDecoder, wavefrontHandler, preprocessorSupplier, ctx, "metric");
}
}
use of com.wavefront.dto.SourceTag in project java by wavefrontHQ.
the class InstrumentedTaskQueueDelegateTest method testSourceTagTask.
@Test
public void testSourceTagTask() throws Exception {
for (RetryTaskConverter.CompressionType type : RetryTaskConverter.CompressionType.values()) {
System.out.println("SourceTag task, compression type: " + type);
File file = new File(File.createTempFile("proxyTestConverter", null).getPath() + ".queue");
file.deleteOnExit();
TaskQueue<SourceTagSubmissionTask> queue = getTaskQueue(file, type);
queue.clear();
SourceTagSubmissionTask task = new SourceTagSubmissionTask(null, new DefaultEntityPropertiesForTesting(), queue, "2878", new SourceTag(ReportSourceTag.newBuilder().setOperation(SourceOperationType.SOURCE_TAG).setAction(SourceTagAction.SAVE).setSource("testSource").setAnnotations(ImmutableList.of("newtag1", "newtag2")).build()), () -> 77777L);
task.enqueue(QueueingReason.RETRY);
queue.close();
TaskQueue<SourceTagSubmissionTask> readQueue = getTaskQueue(file, type);
SourceTagSubmissionTask readTask = readQueue.peek();
assertEquals(task.payload(), readTask.payload());
assertEquals(77777, readTask.getEnqueuedMillis());
}
}
use of com.wavefront.dto.SourceTag in project java by wavefrontHQ.
the class ReportSourceTagHandlerImpl method reportInternal.
@Override
protected void reportInternal(ReportSourceTag sourceTag) {
if (!annotationsAreValid(sourceTag)) {
throw new IllegalArgumentException("WF-401: SourceTag annotation key has illegal characters.");
}
getTask(sourceTag).add(new SourceTag(sourceTag));
getReceivedCounter().inc();
}
use of com.wavefront.dto.SourceTag in project java by wavefrontHQ.
the class SourceTagSenderTask method run.
@Override
public void run() {
long nextRunMillis = properties.getPushFlushInterval();
isSending = true;
try {
List<SourceTag> current = createBatch();
if (current.size() == 0)
return;
Iterator<SourceTag> iterator = current.iterator();
while (iterator.hasNext()) {
if (rateLimiter == null || rateLimiter.tryAcquire()) {
SourceTag tag = iterator.next();
SourceTagSubmissionTask task = new SourceTagSubmissionTask(proxyAPI, properties, backlog, handlerKey.getHandle(), tag, null);
TaskResult result = task.execute();
this.attemptedCounter.inc();
switch(result) {
case DELIVERED:
continue;
case PERSISTED:
case PERSISTED_RETRY:
if (rateLimiter != null)
rateLimiter.recyclePermits(1);
continue;
case RETRY_LATER:
final List<SourceTag> remainingItems = new ArrayList<>();
remainingItems.add(tag);
iterator.forEachRemaining(remainingItems::add);
undoBatch(remainingItems);
if (rateLimiter != null)
rateLimiter.recyclePermits(1);
return;
default:
}
} else {
final List<SourceTag> remainingItems = new ArrayList<>();
iterator.forEachRemaining(remainingItems::add);
undoBatch(remainingItems);
// if proxy rate limit exceeded, try again in 1/4..1/2 of flush interval
// to introduce some degree of fairness.
nextRunMillis = (int) (1 + Math.random()) * nextRunMillis / 4;
final long willRetryIn = nextRunMillis;
throttledLogger.log(Level.INFO, () -> "[" + handlerKey.getHandle() + " thread " + threadId + "]: WF-4 Proxy rate limiter " + "active (pending " + handlerKey.getEntityType() + ": " + datum.size() + "), will retry in " + willRetryIn + "ms");
return;
}
}
} catch (Throwable t) {
logger.log(Level.SEVERE, "Unexpected error in flush loop", t);
} finally {
isSending = false;
scheduler.schedule(this, nextRunMillis, TimeUnit.MILLISECONDS);
}
}
Aggregations