Search in sources :

Example 1 with GobblinTrackingEvent

use of org.apache.gobblin.metrics.GobblinTrackingEvent in project incubator-gobblin by apache.

the class KafkaAvroEventReporterWithSchemaRegistryTest method test.

@Test
public void test() throws Exception {
    MetricContext context = MetricContext.builder("context").build();
    MockKafkaPusher pusher = new MockKafkaPusher();
    KafkaAvroSchemaRegistry registry = Mockito.mock(KafkaAvroSchemaRegistry.class);
    Mockito.when(registry.register(Mockito.any(Schema.class))).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return register((Schema) invocation.getArguments()[0]);
        }
    });
    Mockito.when(registry.register(Mockito.any(Schema.class), Mockito.anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return register((Schema) invocation.getArguments()[0]);
        }
    });
    KafkaEventReporter kafkaReporter = KafkaAvroEventReporter.forContext(context).withKafkaPusher(pusher).withSchemaRegistry(registry).build("localhost:0000", "topic");
    GobblinTrackingEvent event = new GobblinTrackingEvent(0l, "namespace", "name", Maps.<String, String>newHashMap());
    context.submitEvent(event);
    try {
        Thread.sleep(100);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    kafkaReporter.report();
    try {
        Thread.sleep(100);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    byte[] nextMessage = pusher.messageIterator().next();
    DataInputStream is = new DataInputStream(new ByteArrayInputStream(nextMessage));
    Assert.assertEquals(is.readByte(), KafkaAvroSchemaRegistry.MAGIC_BYTE);
    byte[] readId = new byte[20];
    Assert.assertEquals(is.read(readId), 20);
    String readStringId = Hex.encodeHexString(readId);
    Assert.assertTrue(this.schemas.containsKey(readStringId));
    Schema schema = this.schemas.get(readStringId);
    Assert.assertFalse(schema.toString().contains("avro.java.string"));
    is.close();
}
Also used : Schema(org.apache.avro.Schema) KafkaEventReporter(org.apache.gobblin.metrics.kafka.KafkaEventReporter) DataInputStream(java.io.DataInputStream) GobblinTrackingEvent(org.apache.gobblin.metrics.GobblinTrackingEvent) MetricContext(org.apache.gobblin.metrics.MetricContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) KafkaAvroSchemaRegistry(org.apache.gobblin.metrics.kafka.KafkaAvroSchemaRegistry) Test(org.testng.annotations.Test)

Example 2 with GobblinTrackingEvent

use of org.apache.gobblin.metrics.GobblinTrackingEvent in project incubator-gobblin by apache.

the class R2RestResponseHandler method handleResponse.

@Override
public R2ResponseStatus handleResponse(Request<RestRequest> request, RestResponse response) {
    R2ResponseStatus status = new R2ResponseStatus(StatusType.OK);
    int statusCode = response.getStatus();
    status.setStatusCode(statusCode);
    HttpUtils.updateStatusType(status, statusCode, errorCodeWhitelist);
    if (status.getType() == StatusType.OK) {
        status.setContent(response.getEntity());
        status.setContentType(response.getHeader(CONTENT_TYPE_HEADER));
    } else {
        log.info("Receive an unsuccessful response with status code: " + statusCode);
        Map<String, String> metadata = Maps.newHashMap();
        metadata.put(HttpConstants.STATUS_CODE, String.valueOf(statusCode));
        metadata.put(HttpConstants.REQUEST, request.toString());
        if (status.getType() != StatusType.CONTINUE) {
            FailureEventBuilder failureEvent = new FailureEventBuilder(R2_FAILED_REQUEST_EVENT);
            failureEvent.addAdditionalMetadata(metadata);
            failureEvent.submit(metricsContext);
        } else {
            GobblinTrackingEvent event = new GobblinTrackingEvent(0L, R2_RESPONSE_EVENT_NAMESPACE, R2_FAILED_REQUEST_EVENT, metadata);
            metricsContext.submitEvent(event);
        }
    }
    return status;
}
Also used : GobblinTrackingEvent(org.apache.gobblin.metrics.GobblinTrackingEvent) FailureEventBuilder(org.apache.gobblin.metrics.event.FailureEventBuilder)

Example 3 with GobblinTrackingEvent

use of org.apache.gobblin.metrics.GobblinTrackingEvent in project incubator-gobblin by apache.

the class KafkaEventReporterTest method testTagInjection.

@Test
public void testTagInjection() throws IOException {
    String tag1 = "tag1";
    String value1 = "value1";
    String metadataValue1 = "metadata1";
    String tag2 = "tag2";
    String value2 = "value2";
    MetricContext context = MetricContext.builder("context").addTag(new Tag<String>(tag1, value1)).addTag(new Tag<String>(tag2, value2)).build();
    MockKafkaPusher pusher = new MockKafkaPusher();
    KafkaEventReporter kafkaReporter = getBuilder(context, pusher).build("localhost:0000", "topic");
    String namespace = "gobblin.metrics.test";
    String eventName = "testEvent";
    GobblinTrackingEvent event = new GobblinTrackingEvent();
    event.setName(eventName);
    event.setNamespace(namespace);
    Map<String, String> metadata = Maps.newHashMap();
    metadata.put(tag1, metadataValue1);
    event.setMetadata(metadata);
    context.submitEvent(event);
    try {
        Thread.sleep(100);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    kafkaReporter.report();
    try {
        Thread.sleep(100);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    GobblinTrackingEvent retrievedEvent = nextEvent(pusher.messageIterator());
    Assert.assertEquals(retrievedEvent.getNamespace(), namespace);
    Assert.assertEquals(retrievedEvent.getName(), eventName);
    Assert.assertEquals(retrievedEvent.getMetadata().size(), 4);
    Assert.assertEquals(retrievedEvent.getMetadata().get(tag1), metadataValue1);
    Assert.assertEquals(retrievedEvent.getMetadata().get(tag2), value2);
}
Also used : GobblinTrackingEvent(org.apache.gobblin.metrics.GobblinTrackingEvent) MetricContext(org.apache.gobblin.metrics.MetricContext) KafkaEventReporter(org.apache.gobblin.metrics.kafka.KafkaEventReporter) Tag(org.apache.gobblin.metrics.Tag) Test(org.testng.annotations.Test)

Example 4 with GobblinTrackingEvent

use of org.apache.gobblin.metrics.GobblinTrackingEvent in project incubator-gobblin by apache.

the class KafkaEventReporter method reportEventQueue.

@Override
public void reportEventQueue(Queue<GobblinTrackingEvent> queue) {
    GobblinTrackingEvent nextEvent;
    List<byte[]> events = Lists.newArrayList();
    while (null != (nextEvent = queue.poll())) {
        events.add(this.serializer.serializeRecord(nextEvent));
    }
    if (!events.isEmpty()) {
        this.kafkaPusher.pushMessages(events);
    }
}
Also used : GobblinTrackingEvent(org.apache.gobblin.metrics.GobblinTrackingEvent)

Example 5 with GobblinTrackingEvent

use of org.apache.gobblin.metrics.GobblinTrackingEvent in project incubator-gobblin by apache.

the class KafkaAvroJobMonitorTest method testWrongSchemaVersionWriter.

@Test
public void testWrongSchemaVersionWriter() throws Exception {
    TestKafkaAvroJobMonitor monitor = new TestKafkaAvroJobMonitor(GobblinTrackingEvent.SCHEMA$, new NoopSchemaVersionWriter());
    monitor.buildMetricsContextAndMetrics();
    AvroSerializer<GobblinTrackingEvent> serializer = new AvroBinarySerializer<>(GobblinTrackingEvent.SCHEMA$, new FixedSchemaVersionWriter());
    GobblinTrackingEvent event = new GobblinTrackingEvent(0L, "namespace", "event", Maps.<String, String>newHashMap());
    Collection<Either<JobSpec, URI>> results = monitor.parseJobSpec(serializer.serializeRecord(event));
    Assert.assertEquals(results.size(), 0);
    Assert.assertEquals(monitor.events.size(), 0);
    Assert.assertEquals(monitor.getMessageParseFailures().getCount(), 1);
    monitor.shutdownMetrics();
}
Also used : GobblinTrackingEvent(org.apache.gobblin.metrics.GobblinTrackingEvent) FixedSchemaVersionWriter(org.apache.gobblin.metrics.reporter.util.FixedSchemaVersionWriter) Either(org.apache.gobblin.util.Either) NoopSchemaVersionWriter(org.apache.gobblin.metrics.reporter.util.NoopSchemaVersionWriter) AvroBinarySerializer(org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer) HighLevelConsumerTest(org.apache.gobblin.runtime.kafka.HighLevelConsumerTest) Test(org.testng.annotations.Test)

Aggregations

GobblinTrackingEvent (org.apache.gobblin.metrics.GobblinTrackingEvent)15 Test (org.testng.annotations.Test)10 HighLevelConsumerTest (org.apache.gobblin.runtime.kafka.HighLevelConsumerTest)6 Either (org.apache.gobblin.util.Either)6 NoopSchemaVersionWriter (org.apache.gobblin.metrics.reporter.util.NoopSchemaVersionWriter)5 MetricContext (org.apache.gobblin.metrics.MetricContext)4 URI (java.net.URI)3 KafkaEventReporter (org.apache.gobblin.metrics.kafka.KafkaEventReporter)3 AvroBinarySerializer (org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer)3 FailureEventBuilder (org.apache.gobblin.metrics.event.FailureEventBuilder)2 FixedSchemaVersionWriter (org.apache.gobblin.metrics.reporter.util.FixedSchemaVersionWriter)2 Config (com.typesafe.config.Config)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Properties (java.util.Properties)1 Schema (org.apache.avro.Schema)1 Tag (org.apache.gobblin.metrics.Tag)1 KafkaAvroSchemaRegistry (org.apache.gobblin.metrics.kafka.KafkaAvroSchemaRegistry)1