use of wavefront.report.ReportSourceTag in project java by wavefrontHQ.
the class SourceTagSubmissionTaskTest method test404.
@Test
public void test404() throws Exception {
TaskQueue<SourceTagSubmissionTask> queue = createMock(TaskQueue.class);
reset(sourceTagAPI, queue);
ReportSourceTag sourceDescDelete = new ReportSourceTag(SourceOperationType.SOURCE_DESCRIPTION, SourceTagAction.DELETE, "dummy", ImmutableList.of());
ReportSourceTag sourceTagDelete = new ReportSourceTag(SourceOperationType.SOURCE_TAG, SourceTagAction.DELETE, "src", ImmutableList.of("tag"));
ReportSourceTag sourceTagAdd = new ReportSourceTag(SourceOperationType.SOURCE_TAG, SourceTagAction.ADD, "src", ImmutableList.of("tag"));
SourceTagSubmissionTask task = new SourceTagSubmissionTask(sourceTagAPI, props, queue, "2878", new SourceTag(sourceDescDelete), System::currentTimeMillis);
SourceTagSubmissionTask task2 = new SourceTagSubmissionTask(sourceTagAPI, props, queue, "2878", new SourceTag(sourceTagDelete), System::currentTimeMillis);
SourceTagSubmissionTask task3 = new SourceTagSubmissionTask(sourceTagAPI, props, queue, "2878", new SourceTag(sourceTagAdd), System::currentTimeMillis);
expect(sourceTagAPI.removeDescription("dummy")).andReturn(Response.status(404).build()).once();
expect(sourceTagAPI.removeTag("src", "tag")).andReturn(Response.status(404).build()).once();
expect(sourceTagAPI.appendTag("src", "tag")).andReturn(Response.status(404).build()).once();
queue.add(task3);
expectLastCall();
replay(sourceTagAPI, queue);
assertEquals(TaskResult.DELIVERED, task.execute());
assertEquals(TaskResult.DELIVERED, task2.execute());
assertEquals(TaskResult.PERSISTED, task3.execute());
verify(sourceTagAPI, queue);
}
use of wavefront.report.ReportSourceTag in project java by wavefrontHQ.
the class SourceTagSubmissionTaskTest method test500.
@Test
public void test500() throws Exception {
TaskQueue<SourceTagSubmissionTask> queue = createMock(TaskQueue.class);
reset(sourceTagAPI, queue);
ReportSourceTag sourceDescDelete = new ReportSourceTag(SourceOperationType.SOURCE_DESCRIPTION, SourceTagAction.DELETE, "dummy", ImmutableList.of());
ReportSourceTag sourceTagDelete = new ReportSourceTag(SourceOperationType.SOURCE_TAG, SourceTagAction.DELETE, "src", ImmutableList.of("tag"));
ReportSourceTag sourceTagAdd = new ReportSourceTag(SourceOperationType.SOURCE_TAG, SourceTagAction.ADD, "src", ImmutableList.of("tag"));
SourceTagSubmissionTask task = new SourceTagSubmissionTask(sourceTagAPI, props, queue, "2878", new SourceTag(sourceDescDelete), System::currentTimeMillis);
SourceTagSubmissionTask task2 = new SourceTagSubmissionTask(sourceTagAPI, props, queue, "2878", new SourceTag(sourceTagDelete), System::currentTimeMillis);
SourceTagSubmissionTask task3 = new SourceTagSubmissionTask(sourceTagAPI, props, queue, "2878", new SourceTag(sourceTagAdd), System::currentTimeMillis);
expect(sourceTagAPI.removeDescription("dummy")).andReturn(Response.status(500).build()).once();
expect(sourceTagAPI.removeTag("src", "tag")).andReturn(Response.status(500).build()).once();
expect(sourceTagAPI.appendTag("src", "tag")).andReturn(Response.status(500).build()).once();
queue.add(task);
queue.add(task2);
queue.add(task3);
expectLastCall();
replay(sourceTagAPI, queue);
assertEquals(TaskResult.PERSISTED, task.execute());
assertEquals(TaskResult.PERSISTED, task2.execute());
assertEquals(TaskResult.PERSISTED, task3.execute());
verify(sourceTagAPI, queue);
}
use of wavefront.report.ReportSourceTag 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 wavefront.report.ReportSourceTag in project java by wavefrontHQ.
the class ReportSourceTagIngesterFormatter method drive.
/**
* This method can be used to parse the input line into a ReportSourceTag object.
*
* @return The parsed ReportSourceTag object.
*/
@Override
public ReportSourceTag drive(String input, String defaultHostName, String customerId, List<String> customerSourceTags) {
Queue<Token> queue = getQueue(input);
ReportSourceTag sourceTag = new ReportSourceTag();
ReportSourceTagWrapper wrapper = new ReportSourceTagWrapper(sourceTag);
try {
for (FormatterElement element : elements) {
element.consume(queue, wrapper);
}
} catch (Exception ex) {
throw new RuntimeException("Could not parse: " + input, ex);
}
if (!queue.isEmpty()) {
throw new RuntimeException("Could not parse: " + input);
}
// verify the values - especially 'action' field
if (sourceTag.getSource() == null)
throw new RuntimeException("No source key was present in the input: " + input);
if (sourceTag.getAction() != null) {
// verify that only 'add' or 'delete' is present
String actionStr = sourceTag.getAction();
if (!actionStr.equals(ACTION_SAVE) && !actionStr.equals(ACTION_DELETE))
throw new RuntimeException("Action string did not match save/delete: " + input);
} else {
// no value was specified hence throw an exception
throw new RuntimeException("No action key was present in the input: " + input);
}
return ReportSourceTag.newBuilder(sourceTag).build();
}
use of wavefront.report.ReportSourceTag in project java by wavefrontHQ.
the class PostSourceTagTimedTask method createAgentPostBatch.
private List<ReportSourceTag> createAgentPostBatch() {
List<ReportSourceTag> current;
List<ReportSourceTag> currentBlockedSamples = null;
int blockSize;
synchronized (sourceTagMutex) {
blockSize = Math.min(sourceTags.size(), dataPerBatch);
current = sourceTags.subList(0, blockSize);
numIntervals += 1;
sourceTags = new ArrayList<>(sourceTags.subList(blockSize, sourceTags.size()));
}
if (((numIntervals % INTERVALS_PER_SUMMARY) == 0) && !blockedSamples.isEmpty()) {
synchronized (blockedSamplesMutex) {
// Copy this to a temp structure that we can iterate over for printing below
if ((!logLevel.equals(LOG_NONE))) {
currentBlockedSamples = new ArrayList<>(blockedSamples);
}
blockedSamples.clear();
}
}
if (logLevel.equals(LOG_DETAILED)) {
logger.warning("[" + port + "] (DETAILED): sending " + current.size() + " valid " + "sourceTags;" + " queue size:" + sourceTags.size() + "; total attempted sourceTags: " + getAttemptedSourceTags() + "; total blocked: " + this.sourceTagsBlocked.count());
}
if (((numIntervals % INTERVALS_PER_SUMMARY) == 0) && (!logLevel.equals(LOG_NONE))) {
logger.warning("[" + port + "] (SUMMARY): sourceTags attempted: " + getAttemptedSourceTags() + "; blocked: " + this.sourceTagsBlocked.count());
if (currentBlockedSamples != null) {
for (ReportSourceTag blockedLine : currentBlockedSamples) {
logger.warning("[" + port + "] blocked input: [" + blockedLine.toString() + "]");
}
}
}
return current;
}
Aggregations