Search in sources :

Example 1 with SourceTag

use of com.wavefront.dto.SourceTag in project java by wavefrontHQ.

the class ReportSourceTagHandlerTest method testSourceTagsTaskAffinity.

@Test
public void testSourceTagsTaskAffinity() {
    ReportSourceTag sourceTag1 = new ReportSourceTag(SourceOperationType.SOURCE_TAG, SourceTagAction.SAVE, "dummy", ImmutableList.of("tag1", "tag2"));
    ReportSourceTag sourceTag2 = new ReportSourceTag(SourceOperationType.SOURCE_TAG, SourceTagAction.SAVE, "dummy", ImmutableList.of("tag2", "tag3"));
    ReportSourceTag sourceTag3 = new ReportSourceTag(SourceOperationType.SOURCE_TAG, SourceTagAction.SAVE, "dummy-2", ImmutableList.of("tag3"));
    ReportSourceTag sourceTag4 = new ReportSourceTag(SourceOperationType.SOURCE_TAG, SourceTagAction.SAVE, "dummy", ImmutableList.of("tag1", "tag4", "tag5"));
    List<SenderTask<SourceTag>> tasks = new ArrayList<>();
    SourceTagSenderTask task1 = EasyMock.createMock(SourceTagSenderTask.class);
    SourceTagSenderTask task2 = EasyMock.createMock(SourceTagSenderTask.class);
    tasks.add(task1);
    tasks.add(task2);
    ReportSourceTagHandlerImpl sourceTagHandler = new ReportSourceTagHandlerImpl(HandlerKey.of(ReportableEntityType.SOURCE_TAG, "4878"), 10, tasks, null, blockedLogger);
    task1.add(new SourceTag(sourceTag1));
    EasyMock.expectLastCall();
    task1.add(new SourceTag(sourceTag2));
    EasyMock.expectLastCall();
    task2.add(new SourceTag(sourceTag3));
    EasyMock.expectLastCall();
    task1.add(new SourceTag(sourceTag4));
    EasyMock.expectLastCall();
    task1.add(new SourceTag(sourceTag4));
    EasyMock.expectLastCall();
    task2.add(new SourceTag(sourceTag3));
    EasyMock.expectLastCall();
    task1.add(new SourceTag(sourceTag2));
    EasyMock.expectLastCall();
    task1.add(new SourceTag(sourceTag1));
    EasyMock.expectLastCall();
    EasyMock.replay(task1);
    EasyMock.replay(task2);
    sourceTagHandler.report(sourceTag1);
    sourceTagHandler.report(sourceTag2);
    sourceTagHandler.report(sourceTag3);
    sourceTagHandler.report(sourceTag4);
    sourceTagHandler.report(sourceTag4);
    sourceTagHandler.report(sourceTag3);
    sourceTagHandler.report(sourceTag2);
    sourceTagHandler.report(sourceTag1);
    EasyMock.verify();
}
Also used : ArrayList(java.util.ArrayList) ReportSourceTag(wavefront.report.ReportSourceTag) SourceTag(com.wavefront.dto.SourceTag) ReportSourceTag(wavefront.report.ReportSourceTag) Test(org.junit.Test)

Example 2 with SourceTag

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");
    }
}
Also used : ArrayList(java.util.ArrayList) ReportSourceTag(wavefront.report.ReportSourceTag) SourceTag(com.wavefront.dto.SourceTag) SpanLogs(wavefront.report.SpanLogs) SpanUtils.handleSpanLogs(com.wavefront.agent.listeners.tracing.SpanUtils.handleSpanLogs) SpanUtils.preprocessAndHandleSpan(com.wavefront.agent.listeners.tracing.SpanUtils.preprocessAndHandleSpan) Span(wavefront.report.Span) ReportEvent(wavefront.report.ReportEvent) DataFormat(com.wavefront.agent.formatter.DataFormat) ReportSourceTag(wavefront.report.ReportSourceTag) ReportPoint(wavefront.report.ReportPoint)

Example 3 with SourceTag

use of com.wavefront.dto.SourceTag in project java by wavefrontHQ.

the class InMemorySubmissionQueueTest method testTaskRead.

@Test
public void testTaskRead() {
    TaskQueue queue = new InMemorySubmissionQueue<>();
    UUID proxyId = UUID.randomUUID();
    DataSubmissionTask<? extends DataSubmissionTask<?>> task = null;
    if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
        task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), time::get);
    } else if (this.expectedTask instanceof EventDataSubmissionTask) {
        task = new EventDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "2878", ImmutableList.of(new Event(ReportEvent.newBuilder().setStartTime(time.get() * 1000).setEndTime(time.get() * 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())), time::get);
    } else if (this.expectedTask instanceof 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()), time::get);
    }
    assertNotNull(task);
    task.enqueue(QueueingReason.RETRY);
    if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
        LineDelimitedDataSubmissionTask readTask = (LineDelimitedDataSubmissionTask) queue.peek();
        assertNotNull(readTask);
        assertEquals(((LineDelimitedDataSubmissionTask) task).payload(), readTask.payload());
        assertEquals(((LineDelimitedDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
        assertEquals(77777, readTask.getEnqueuedMillis());
    }
    if (this.expectedTask instanceof EventDataSubmissionTask) {
        EventDataSubmissionTask readTask = (EventDataSubmissionTask) queue.peek();
        assertNotNull(readTask);
        assertEquals(((EventDataSubmissionTask) task).payload(), readTask.payload());
        assertEquals(((EventDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
        assertEquals(77777, readTask.getEnqueuedMillis());
    }
    if (this.expectedTask instanceof SourceTagSubmissionTask) {
        SourceTagSubmissionTask readTask = (SourceTagSubmissionTask) queue.peek();
        assertNotNull(readTask);
        assertEquals(((SourceTagSubmissionTask) task).payload(), readTask.payload());
        assertEquals(((SourceTagSubmissionTask) this.expectedTask).payload(), readTask.payload());
        assertEquals(77777, readTask.getEnqueuedMillis());
    }
}
Also used : SourceTagSubmissionTask(com.wavefront.agent.data.SourceTagSubmissionTask) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) ReportEvent(wavefront.report.ReportEvent) Event(com.wavefront.dto.Event) ReportSourceTag(wavefront.report.ReportSourceTag) SourceTag(com.wavefront.dto.SourceTag) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with SourceTag

use of com.wavefront.dto.SourceTag in project java by wavefrontHQ.

the class SourceTagSubmissionTaskTest method test200.

@Test
public void test200() {
    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(200).build()).once();
    expect(sourceTagAPI.removeTag("src", "tag")).andReturn(Response.status(200).build()).once();
    expect(sourceTagAPI.appendTag("src", "tag")).andReturn(Response.status(200).build()).once();
    replay(sourceTagAPI, queue);
    assertEquals(TaskResult.DELIVERED, task.execute());
    assertEquals(TaskResult.DELIVERED, task2.execute());
    assertEquals(TaskResult.DELIVERED, task3.execute());
    verify(sourceTagAPI, queue);
}
Also used : ReportSourceTag(wavefront.report.ReportSourceTag) SourceTag(com.wavefront.dto.SourceTag) ReportSourceTag(wavefront.report.ReportSourceTag) Test(org.junit.Test)

Example 5 with SourceTag

use of com.wavefront.dto.SourceTag 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);
}
Also used : ReportSourceTag(wavefront.report.ReportSourceTag) SourceTag(com.wavefront.dto.SourceTag) ReportSourceTag(wavefront.report.ReportSourceTag) Test(org.junit.Test)

Aggregations

SourceTag (com.wavefront.dto.SourceTag)11 ReportSourceTag (wavefront.report.ReportSourceTag)9 Test (org.junit.Test)7 SourceTagSubmissionTask (com.wavefront.agent.data.SourceTagSubmissionTask)5 DefaultEntityPropertiesForTesting (com.wavefront.agent.data.DefaultEntityPropertiesForTesting)3 ArrayList (java.util.ArrayList)3 ReportEvent (wavefront.report.ReportEvent)3 EventDataSubmissionTask (com.wavefront.agent.data.EventDataSubmissionTask)2 LineDelimitedDataSubmissionTask (com.wavefront.agent.data.LineDelimitedDataSubmissionTask)2 Event (com.wavefront.dto.Event)2 File (java.io.File)2 UUID (java.util.UUID)2 Charsets (com.google.common.base.Charsets)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Files (com.google.common.io.Files)1 QueueFile (com.squareup.tape2.QueueFile)1 DefaultEntityPropertiesFactoryForTesting (com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting)1 EntityPropertiesFactory (com.wavefront.agent.data.EntityPropertiesFactory)1 QueueingReason (com.wavefront.agent.data.QueueingReason)1