Search in sources :

Example 1 with LineDelimitedDataSubmissionTask

use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask 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 2 with LineDelimitedDataSubmissionTask

use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask in project java by wavefrontHQ.

the class InMemorySubmissionQueueTest method scenarios.

@Parameterized.Parameters
public static Collection<Object[]> scenarios() {
    Collection<Object[]> scenarios = new ArrayList<>();
    for (TaskConverter.CompressionType type : TaskConverter.CompressionType.values()) {
        RetryTaskConverter<LineDelimitedDataSubmissionTask> converter = new RetryTaskConverter<>("2878", type);
        LineDelimitedDataSubmissionTask task = converter.fromBytes("WF\u0001\u0001{\"__CLASS\":\"com.wavefront.agent.data.LineDelimitedDataSubmissionTask\",\"enqueuedTimeMillis\":77777,\"attempts\":0,\"serverErrors\":0,\"handle\":\"2878\",\"entityType\":\"POINT\",\"format\":\"wavefront\",\"payload\":[\"java.util.ArrayList\",[\"item1\",\"item2\",\"item3\"]],\"enqueuedMillis\":77777}".getBytes());
        scenarios.add(new Object[] { type, task });
    }
    for (TaskConverter.CompressionType type : TaskConverter.CompressionType.values()) {
        RetryTaskConverter<EventDataSubmissionTask> converter = new RetryTaskConverter<>("2878", type);
        EventDataSubmissionTask task = converter.fromBytes("WF\u0001\u0001{\"__CLASS\":\"com.wavefront.agent.data.EventDataSubmissionTask\",\"enqueuedTimeMillis\":77777,\"attempts\":0,\"serverErrors\":0,\"handle\":\"2878\",\"entityType\":\"EVENT\",\"events\":[\"java.util.ArrayList\",[{\"name\":\"Event name for testing\",\"startTime\":77777000,\"endTime\":77777001,\"annotations\":[\"java.util.HashMap\",{\"severity\":\"INFO\"}],\"dimensions\":[\"java.util.HashMap\",{\"multi\":[\"java.util.ArrayList\",[\"bar\",\"baz\"]]}],\"hosts\":[\"java.util.ArrayList\",[\"host1\",\"host2\"]],\"tags\":[\"java.util.ArrayList\",[\"tag1\"]]}]],\"enqueuedMillis\":77777}".getBytes());
        scenarios.add(new Object[] { type, task });
    }
    for (TaskConverter.CompressionType type : TaskConverter.CompressionType.values()) {
        RetryTaskConverter<SourceTagSubmissionTask> converter = new RetryTaskConverter<>("2878", type);
        SourceTagSubmissionTask task = converter.fromBytes("WF\u0001\u0001{\"__CLASS\":\"com.wavefront.agent.data.SourceTagSubmissionTask\",\"enqueuedTimeMillis\":77777,\"attempts\":0,\"serverErrors\":0,\"handle\":\"2878\",\"entityType\":\"SOURCE_TAG\",\"limitRetries\":true,\"sourceTag\":{\"operation\":\"SOURCE_TAG\",\"action\":\"SAVE\",\"source\":\"testSource\",\"annotations\":[\"java.util.ArrayList\",[\"newtag1\",\"newtag2\"]]},\"enqueuedMillis\":77777}\n".getBytes());
        scenarios.add(new Object[] { type, task });
    }
    return scenarios;
}
Also used : SourceTagSubmissionTask(com.wavefront.agent.data.SourceTagSubmissionTask) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) ArrayList(java.util.ArrayList) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask)

Example 3 with LineDelimitedDataSubmissionTask

use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask 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));
}
Also used : HandlerKey(com.wavefront.agent.handlers.HandlerKey) QueueingReason(com.wavefront.agent.data.QueueingReason) ReportSourceTag(wavefront.report.ReportSourceTag) ReportEvent(wavefront.report.ReportEvent) SourceOperationType(wavefront.report.SourceOperationType) ImmutableList(com.google.common.collect.ImmutableList) Event(com.wavefront.dto.Event) EasyMock.reset(org.easymock.EasyMock.reset) Files(com.google.common.io.Files) DefaultEntityPropertiesFactoryForTesting(com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting) SourceTagSubmissionTask(com.wavefront.agent.data.SourceTagSubmissionTask) HandlerKey(com.wavefront.agent.handlers.HandlerKey) EasyMock.replay(org.easymock.EasyMock.replay) Charsets(com.google.common.base.Charsets) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) ImmutableMap(com.google.common.collect.ImmutableMap) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) BufferedWriter(java.io.BufferedWriter) EntityPropertiesFactory(com.wavefront.agent.data.EntityPropertiesFactory) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) File(java.io.File) SourceTag(com.wavefront.dto.SourceTag) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) ReportableEntityType(com.wavefront.data.ReportableEntityType) List(java.util.List) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) EasyMock.verify(org.easymock.EasyMock.verify) Assert.assertEquals(org.junit.Assert.assertEquals) SourceTagAction(wavefront.report.SourceTagAction) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) ReportSourceTag(wavefront.report.ReportSourceTag) SourceTag(com.wavefront.dto.SourceTag) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) DefaultEntityPropertiesFactoryForTesting(com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting) EntityPropertiesFactory(com.wavefront.agent.data.EntityPropertiesFactory) BufferedWriter(java.io.BufferedWriter) SourceTagSubmissionTask(com.wavefront.agent.data.SourceTagSubmissionTask) ReportEvent(wavefront.report.ReportEvent) Event(com.wavefront.dto.Event) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) UUID(java.util.UUID) File(java.io.File) Test(org.junit.Test)

Example 4 with LineDelimitedDataSubmissionTask

use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask in project java by wavefrontHQ.

the class LineDelimitedSenderTask method flushSingleBatch.

@Override
void flushSingleBatch(List<String> batch, @Nullable QueueingReason reason) {
    LineDelimitedDataSubmissionTask task = new LineDelimitedDataSubmissionTask(proxyAPI, proxyId, properties, backlog, pushFormat, handlerKey.getEntityType(), handlerKey.getHandle(), batch, null);
    task.enqueue(reason);
}
Also used : LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask)

Example 5 with LineDelimitedDataSubmissionTask

use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask in project java by wavefrontHQ.

the class QueueExporter method processTask.

@VisibleForTesting
<T extends DataSubmissionTask<T>> void processTask(T task, BufferedWriter writer) throws IOException {
    if (task instanceof LineDelimitedDataSubmissionTask) {
        for (String line : ((LineDelimitedDataSubmissionTask) task).payload()) {
            writer.write(line);
            writer.newLine();
        }
    } else if (task instanceof SourceTagSubmissionTask) {
        writer.write(((SourceTagSubmissionTask) task).payload().toString());
        writer.newLine();
    } else if (task instanceof EventDataSubmissionTask) {
        for (Event event : ((EventDataSubmissionTask) task).payload()) {
            writer.write(event.toString());
            writer.newLine();
        }
    }
}
Also used : SourceTagSubmissionTask(com.wavefront.agent.data.SourceTagSubmissionTask) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) Event(com.wavefront.dto.Event) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

LineDelimitedDataSubmissionTask (com.wavefront.agent.data.LineDelimitedDataSubmissionTask)10 DefaultEntityPropertiesForTesting (com.wavefront.agent.data.DefaultEntityPropertiesForTesting)6 EventDataSubmissionTask (com.wavefront.agent.data.EventDataSubmissionTask)6 UUID (java.util.UUID)6 Test (org.junit.Test)6 SourceTagSubmissionTask (com.wavefront.agent.data.SourceTagSubmissionTask)4 Event (com.wavefront.dto.Event)4 File (java.io.File)3 ReportEvent (wavefront.report.ReportEvent)3 DefaultEntityPropertiesFactoryForTesting (com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting)2 EntityPropertiesFactory (com.wavefront.agent.data.EntityPropertiesFactory)2 HandlerKey (com.wavefront.agent.handlers.HandlerKey)2 SourceTag (com.wavefront.dto.SourceTag)2 BufferedWriter (java.io.BufferedWriter)2 ArrayList (java.util.ArrayList)2 ReportSourceTag (wavefront.report.ReportSourceTag)2 Message (com.amazonaws.services.sqs.model.Message)1 ReceiveMessageRequest (com.amazonaws.services.sqs.model.ReceiveMessageRequest)1 ReceiveMessageResult (com.amazonaws.services.sqs.model.ReceiveMessageResult)1 SendMessageRequest (com.amazonaws.services.sqs.model.SendMessageRequest)1