Search in sources :

Example 1 with AvroBinarySerializer

use of org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer in project incubator-gobblin by apache.

the class GobblinMetricsPinotFlattenerConverterTest method test.

@Test
public void test() throws Exception {
    MetricReport metricReport = new MetricReport();
    metricReport.setTags(ImmutableMap.of("tag", "value", "tag2", "value2"));
    metricReport.setTimestamp(10L);
    metricReport.setMetrics(Lists.newArrayList(new Metric("metric", 1.0), new Metric("metric2", 2.0)));
    AvroSerializer<MetricReport> serializer = new AvroBinarySerializer<>(MetricReport.SCHEMA$, new NoopSchemaVersionWriter());
    serializer.serializeRecord(metricReport);
    Schema metricReportUtf8 = new Schema.Parser().parse(this.getClass().getClassLoader().getResourceAsStream("MetricReport.avsc"));
    GenericRecord genericRecordMetric = AvroUtils.slowDeserializeGenericRecord(serializer.serializeRecord(metricReport), metricReportUtf8);
    GobblinMetricsPinotFlattenerConverter converter = new GobblinMetricsPinotFlattenerConverter();
    Schema outputSchema = converter.convertSchema(MetricReport.SCHEMA$, new WorkUnitState());
    Iterable<GenericRecord> converted = converter.convertRecord(outputSchema, genericRecordMetric, new WorkUnitState());
    List<GenericRecord> convertedList = Lists.newArrayList(converted);
    Assert.assertEquals(convertedList.size(), 2);
    Assert.assertEquals(Sets.newHashSet((List<Utf8>) convertedList.get(0).get("tags")), Sets.newHashSet("tag:value", "tag2:value2"));
    Assert.assertEquals(convertedList.get(0).get("timestamp"), 10L);
    Assert.assertEquals(convertedList.get(0).get("metricName").toString(), "metric");
    Assert.assertEquals(convertedList.get(0).get("metricValue"), 1.0);
    Assert.assertEquals(Sets.newHashSet((List<Utf8>) convertedList.get(1).get("tags")), Sets.newHashSet("tag:value", "tag2:value2"));
    Assert.assertEquals(convertedList.get(1).get("timestamp"), 10L);
    Assert.assertEquals(convertedList.get(1).get("metricName").toString(), "metric2");
    Assert.assertEquals(convertedList.get(1).get("metricValue"), 2.0);
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) NoopSchemaVersionWriter(org.apache.gobblin.metrics.reporter.util.NoopSchemaVersionWriter) AvroBinarySerializer(org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer) Metric(org.apache.gobblin.metrics.Metric) List(java.util.List) MetricReport(org.apache.gobblin.metrics.MetricReport) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.testng.annotations.Test)

Example 2 with AvroBinarySerializer

use of org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer in project incubator-gobblin by apache.

the class KafkaAvroJobMonitorTest method testWrongSchema.

@Test
public void testWrongSchema() throws Exception {
    TestKafkaAvroJobMonitor monitor = new TestKafkaAvroJobMonitor(GobblinTrackingEvent.SCHEMA$, new NoopSchemaVersionWriter());
    monitor.buildMetricsContextAndMetrics();
    AvroSerializer<MetricReport> serializer = new AvroBinarySerializer<>(MetricReport.SCHEMA$, new NoopSchemaVersionWriter());
    MetricReport event = new MetricReport(Maps.<String, String>newHashMap(), 0L, Lists.<Metric>newArrayList());
    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 : Either(org.apache.gobblin.util.Either) MetricReport(org.apache.gobblin.metrics.MetricReport) 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)

Example 3 with AvroBinarySerializer

use of org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer 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)

Example 4 with AvroBinarySerializer

use of org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer in project incubator-gobblin by apache.

the class KafkaAvroJobMonitorTest method testUsingSchemaVersion.

@Test
public void testUsingSchemaVersion() throws Exception {
    TestKafkaAvroJobMonitor monitor = new TestKafkaAvroJobMonitor(GobblinTrackingEvent.SCHEMA$, new FixedSchemaVersionWriter());
    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(), 1);
    Assert.assertEquals(monitor.events.size(), 1);
    Assert.assertEquals(monitor.events.get(0), event);
    monitor.shutdownMetrics();
}
Also used : GobblinTrackingEvent(org.apache.gobblin.metrics.GobblinTrackingEvent) FixedSchemaVersionWriter(org.apache.gobblin.metrics.reporter.util.FixedSchemaVersionWriter) Either(org.apache.gobblin.util.Either) AvroBinarySerializer(org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer) HighLevelConsumerTest(org.apache.gobblin.runtime.kafka.HighLevelConsumerTest) Test(org.testng.annotations.Test)

Example 5 with AvroBinarySerializer

use of org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer in project incubator-gobblin by apache.

the class KafkaAvroJobMonitorTest method testSimple.

@Test
public void testSimple() throws Exception {
    TestKafkaAvroJobMonitor monitor = new TestKafkaAvroJobMonitor(GobblinTrackingEvent.SCHEMA$, new NoopSchemaVersionWriter());
    monitor.buildMetricsContextAndMetrics();
    AvroSerializer<GobblinTrackingEvent> serializer = new AvroBinarySerializer<>(GobblinTrackingEvent.SCHEMA$, new NoopSchemaVersionWriter());
    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(), 1);
    Assert.assertEquals(monitor.events.size(), 1);
    Assert.assertEquals(monitor.events.get(0), event);
    monitor.shutdownMetrics();
}
Also used : GobblinTrackingEvent(org.apache.gobblin.metrics.GobblinTrackingEvent) 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

AvroBinarySerializer (org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer)5 Test (org.testng.annotations.Test)5 NoopSchemaVersionWriter (org.apache.gobblin.metrics.reporter.util.NoopSchemaVersionWriter)4 HighLevelConsumerTest (org.apache.gobblin.runtime.kafka.HighLevelConsumerTest)4 Either (org.apache.gobblin.util.Either)4 GobblinTrackingEvent (org.apache.gobblin.metrics.GobblinTrackingEvent)3 MetricReport (org.apache.gobblin.metrics.MetricReport)2 FixedSchemaVersionWriter (org.apache.gobblin.metrics.reporter.util.FixedSchemaVersionWriter)2 List (java.util.List)1 Schema (org.apache.avro.Schema)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)1 Metric (org.apache.gobblin.metrics.Metric)1