List of usage examples for org.apache.hadoop.metrics2 MetricsTag description
@Override
public String description()
From source file:org.apache.phoenix.trace.PhoenixMetricsSink.java
License:Apache License
private void addDynamicEntry(List<String> keys, List<Object> values, List<String> variableValues, String family, MetricsTag tag, MetricInfo metric, int count) { // <family><.dynColumn><count> <VARCHAR> keys.add(getDynamicColumnName(family, metric.columnName, count) + " VARCHAR"); // build the annotation value String val = tag.description() + " - " + tag.value(); values.add(VARIABLE_VALUE);// w w w . jav a 2 s.com variableValues.add(val); }
From source file:org.apache.phoenix.trace.PhoenixMetricsWriterTest.java
License:Apache License
@Test public void testTranslation() throws Exception { // hook up a sink we can test MetricsWriter mockSink = Mockito.mock(MetricsWriter.class); // writer that will translate to the sink (specific to hadoop version used) PhoenixMetricsSink writer = new PhoenixMetricsSink(); writer.setWriterForTesting(mockSink); // create a simple metrics record final long traceid = 987654; MetricsInfo info = new ExposedMetricsInfoImpl(TracingCompat.getTraceMetricName(traceid), "Some generic trace"); // setup some metrics for the span long spanid = 10; AbstractMetric span = new ExposedMetricCounterLong( new ExposedMetricsInfoImpl(MetricInfo.SPAN.traceName, ""), spanid); long parentid = 11; AbstractMetric parent = new ExposedMetricCounterLong( new ExposedMetricsInfoImpl(MetricInfo.PARENT.traceName, ""), parentid); long startTime = 12; AbstractMetric start = new ExposedMetricCounterLong( new ExposedMetricsInfoImpl(MetricInfo.START.traceName, ""), startTime); long endTime = 13; AbstractMetric end = new ExposedMetricCounterLong(new ExposedMetricsInfoImpl(MetricInfo.END.traceName, ""), endTime);//from w w w . j a v a 2 s . c o m final List<AbstractMetric> metrics = Lists.newArrayList(span, parent, start, end); // create an annotation as well String annotation = "test annotation for a span"; MetricsTag tag = new MetricsTag(new ExposedMetricsInfoImpl(MetricInfo.ANNOTATION.traceName, "0"), annotation); String hostnameValue = "host-name.value"; MetricsTag hostname = new MetricsTag(new ExposedMetricsInfoImpl(MetricInfo.HOSTNAME.traceName, ""), hostnameValue); final List<MetricsTag> tags = Lists.newArrayList(hostname, tag); MetricsRecord record = new ExposedMetricsRecordImpl(info, System.currentTimeMillis(), tags, metrics); // setup the mocking/validation for the sink Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { PhoenixMetricsRecord record = (PhoenixMetricsRecord) invocation.getArguments()[0]; //validate that we got the right fields in the record assertEquals("phoenix.987654", record.name()); assertEquals("Some generic trace", record.description()); int count = 0; for (PhoenixAbstractMetric metric : record.metrics()) { count++; //find the matching metric in the list boolean found = false; for (AbstractMetric expected : metrics) { if (expected.name().equals(metric.getName())) { found = true; // make sure the rest of the info matches assertEquals("Metric value mismatch", expected.value(), metric.value()); } } assertTrue("Didn't find an expected metric to match " + metric, found); } assertEquals("Number of metrics is received is wrong", metrics.size(), count); count = 0; for (PhoenixMetricTag tag : record.tags()) { count++; // find the matching metric in the list boolean found = false; for (MetricsTag expected : tags) { if (expected.name().equals(tag.name())) { found = true; // make sure the rest of the info matches assertEquals("Tag value mismatch", expected.value(), tag.value()); assertEquals("Tag description mismatch", expected.description(), tag.description()); } } assertTrue("Didn't find an expected metric to match " + tag, found); } assertEquals("Number of tags is received is wrong", tags.size(), count); return null; } }).when(mockSink).addMetrics(Mockito.any(PhoenixMetricsRecord.class)); // actually do the update writer.putMetrics(record); writer.flush(); Mockito.verify(mockSink).addMetrics(Mockito.any(PhoenixMetricsRecord.class)); Mockito.verify(mockSink).flush(); }