use of org.apache.gobblin.metrics.Metric in project incubator-gobblin by apache.
the class MetricReportReporter method report.
/**
* Serializes metrics and pushes the byte arrays to Kafka. Uses the serialize* methods in {@link MetricReportReporter}.
*
* @param gauges map of {@link com.codahale.metrics.Gauge} to report and their name.
* @param counters map of {@link com.codahale.metrics.Counter} to report and their name.
* @param histograms map of {@link com.codahale.metrics.Histogram} to report and their name.
* @param meters map of {@link com.codahale.metrics.Meter} to report and their name.
* @param timers map of {@link com.codahale.metrics.Timer} to report and their name.
*/
@Override
protected void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers, Map<String, Object> tags) {
List<Metric> metrics = Lists.newArrayList();
for (Map.Entry<String, Gauge> gauge : gauges.entrySet()) {
metrics.addAll(serializeGauge(gauge.getKey(), gauge.getValue()));
}
for (Map.Entry<String, Counter> counter : counters.entrySet()) {
metrics.addAll(serializeCounter(counter.getKey(), counter.getValue()));
}
for (Map.Entry<String, Histogram> histogram : histograms.entrySet()) {
metrics.addAll(serializeSnapshot(histogram.getKey(), histogram.getValue().getSnapshot()));
metrics.addAll(serializeCounter(histogram.getKey(), histogram.getValue()));
}
for (Map.Entry<String, Meter> meter : meters.entrySet()) {
metrics.addAll(serializeMetered(meter.getKey(), meter.getValue()));
}
for (Map.Entry<String, Timer> timer : timers.entrySet()) {
metrics.addAll(serializeSnapshot(timer.getKey(), timer.getValue().getSnapshot()));
metrics.addAll(serializeMetered(timer.getKey(), timer.getValue()));
metrics.addAll(serializeSingleValue(timer.getKey(), timer.getValue().getCount(), Measurements.COUNT.getName()));
}
Map<String, Object> allTags = Maps.newHashMap();
allTags.putAll(tags);
allTags.putAll(this.tags);
Map<String, String> allTagsString = Maps.transformValues(allTags, new Function<Object, String>() {
@Nullable
@Override
public String apply(Object input) {
return input.toString();
}
});
MetricReport report = new MetricReport(allTagsString, System.currentTimeMillis(), metrics);
emitReport(report);
}
use of org.apache.gobblin.metrics.Metric 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);
}
use of org.apache.gobblin.metrics.Metric in project incubator-gobblin by apache.
the class KafkaReporterTest method expectMetrics.
/**
* Expect a set of metric names. Will fail if not all of these metrics are received.
* @param report MetricReport
* @param expected set of expected metric names
* @param strict if set to true, will fail if receiving any metric that is not expected
* @throws IOException
*/
private void expectMetrics(MetricReport report, Set<String> expected, boolean strict) throws IOException {
List<Metric> metricIterator = report.getMetrics();
for (Metric metric : metricIterator) {
// System.out.println(String.format("expectedSet.add(\"%s\")", metric.name));
if (expected.contains(metric.getName())) {
expected.remove(metric.getName());
} else if (strict && !metric.getName().contains(MetricContext.GOBBLIN_METRICS_NOTIFICATIONS_TIMER_NAME)) {
Assert.assertTrue(false, "Metric present in report not expected: " + metric.toString());
}
}
Assert.assertTrue(expected.isEmpty());
}
use of org.apache.gobblin.metrics.Metric in project incubator-gobblin by apache.
the class KafkaReporterTest method expectMetricsWithValues.
/**
* Expect a list of metrics with specific values.
* Fail if not all metrics are received, or some metric has the wrong value.
* @param report MetricReport.
* @param expected map of expected metric names and their values
* @throws IOException
*/
private void expectMetricsWithValues(MetricReport report, Map<String, Double> expected) throws IOException {
List<Metric> metricIterator = report.getMetrics();
for (Metric metric : metricIterator) {
if (expected.containsKey(metric.getName())) {
Assert.assertEquals(expected.get(metric.getName()), metric.getValue());
expected.remove(metric.getName());
}
}
Assert.assertTrue(expected.isEmpty());
}
Aggregations