use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtilsTest method convertSummaryMetricWithNullSum.
@Test
public void convertSummaryMetricWithNullSum() {
io.opencensus.metrics.export.MetricDescriptor expectedMetricDescriptor1 = io.opencensus.metrics.export.MetricDescriptor.create(METRIC_NAME + SUMMARY_SUFFIX_COUNT, METRIC_DESCRIPTION, METRIC_UNIT_2, Type.CUMULATIVE_INT64, LABEL_KEY);
List<LabelKey> labelKeys = new ArrayList<>(LABEL_KEY);
labelKeys.add(PERCENTILE_LABEL_KEY);
io.opencensus.metrics.export.MetricDescriptor expectedMetricDescriptor2 = io.opencensus.metrics.export.MetricDescriptor.create(METRIC_NAME + SNAPSHOT_SUFFIX_PERCENTILE, METRIC_DESCRIPTION, METRIC_UNIT, Type.GAUGE_DOUBLE, labelKeys);
List<io.opencensus.metrics.export.TimeSeries> expectedTimeSeries1 = Collections.singletonList(io.opencensus.metrics.export.TimeSeries.createWithOnePoint(LABEL_VALUE, Point.create(Value.longValue(22), TIMESTAMP), null));
LabelValue existingLabelValues = LABEL_VALUE.get(0);
List<io.opencensus.metrics.export.TimeSeries> expectedTimeSeries2 = Collections.singletonList(io.opencensus.metrics.export.TimeSeries.createWithOnePoint(Arrays.asList(existingLabelValues, LabelValue.create("50.0")), Point.create(Value.doubleValue(6), TIMESTAMP), null));
List<io.opencensus.metrics.export.Metric> metrics = StackdriverExportUtils.convertSummaryMetric(SUMMARY_METRIC_NULL_SUM);
assertThat(metrics).isNotEmpty();
assertThat(metrics.size()).isEqualTo(2);
assertThat(metrics.get(0).getMetricDescriptor()).isEqualTo(expectedMetricDescriptor1);
assertThat(metrics.get(0).getTimeSeriesList()).isNotEmpty();
assertThat(metrics.get(0).getTimeSeriesList().size()).isEqualTo(1);
assertThat(metrics.get(0).getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeries1);
assertThat(metrics.get(1).getTimeSeriesList()).isNotEmpty();
assertThat(metrics.get(1).getMetricDescriptor()).isEqualTo(expectedMetricDescriptor2);
assertThat(metrics.get(1).getTimeSeriesList().size()).isEqualTo(1);
assertThat(metrics.get(1).getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeries2);
}
use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtilsTest method createMetricDescriptor_WithCustomConstantLabels.
@Test
public void createMetricDescriptor_WithCustomConstantLabels() {
Map<LabelKey, LabelValue> constantLabels = Collections.singletonMap(LabelKey.create("my_key", "desc"), LabelValue.create("value"));
MetricDescriptor metricDescriptor = StackdriverExportUtils.createMetricDescriptor(METRIC_DESCRIPTOR, PROJECT_ID, "custom.googleapis.com/myorg/", "myorg/", constantLabels);
assertThat(metricDescriptor.getLabelsList()).containsExactly(LabelDescriptor.newBuilder().setKey(LABEL_KEY.get(0).getKey()).setDescription(LABEL_KEY.get(0).getDescription()).setValueType(ValueType.STRING).build(), LabelDescriptor.newBuilder().setKey("my_key").setDescription("desc").setValueType(ValueType.STRING).build());
}
use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class LongGaugeImplTest method setDefaultLabelValues.
@Test
public void setDefaultLabelValues() {
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
LongGaugeImpl longGauge = new LongGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS);
LongPoint defaultPoint = longGauge.getDefaultTimeSeries();
defaultPoint.set(-230);
Metric metric = longGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
assertThat(metric.getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(2);
assertThat(metric.getTimeSeriesList().get(0).getLabelValues().get(0)).isEqualTo(UNSET_VALUE);
assertThat(metric.getTimeSeriesList().get(0).getLabelValues().get(1)).isEqualTo(UNSET_VALUE);
}
use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class LongGaugeImplTest method testEquals.
@Test
public void testEquals() {
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
List<LabelValue> labelValues = Arrays.asList(LabelValue.create("value1"), LabelValue.create("value2"));
LongGaugeImpl longGauge = new LongGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS);
LongPoint defaultPoint1 = longGauge.getDefaultTimeSeries();
LongPoint defaultPoint2 = longGauge.getDefaultTimeSeries();
LongPoint longPoint1 = longGauge.getOrCreateTimeSeries(labelValues);
LongPoint longPoint2 = longGauge.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).testEquals();
longGauge.clear();
LongPoint newDefaultPointAfterClear = longGauge.getDefaultTimeSeries();
LongPoint newLongPointAfterClear = longGauge.getOrCreateTimeSeries(labelValues);
longGauge.removeTimeSeries(labelValues);
LongPoint newLongPointAfterRemove = longGauge.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).addEqualityGroup(newDefaultPointAfterClear).addEqualityGroup(newLongPointAfterClear).addEqualityGroup(newLongPointAfterRemove).testEquals();
}
use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtils method createMetricDescriptor.
// Convert a OpenCensus MetricDescriptor to a StackDriver MetricDescriptor
static MetricDescriptor createMetricDescriptor(io.opencensus.metrics.export.MetricDescriptor metricDescriptor, String projectId, String domain, String displayNamePrefix, Map<LabelKey, LabelValue> constantLabels) {
MetricDescriptor.Builder builder = MetricDescriptor.newBuilder();
String type = generateType(metricDescriptor.getName(), domain);
// Name format refers to
// cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors/create
builder.setName("projects/" + projectId + "/metricDescriptors/" + type);
builder.setType(type);
builder.setDescription(metricDescriptor.getDescription());
builder.setDisplayName(createDisplayName(metricDescriptor.getName(), displayNamePrefix));
for (LabelKey labelKey : metricDescriptor.getLabelKeys()) {
builder.addLabels(createLabelDescriptor(labelKey));
}
for (LabelKey labelKey : constantLabels.keySet()) {
builder.addLabels(createLabelDescriptor(labelKey));
}
builder.setUnit(metricDescriptor.getUnit());
builder.setMetricKind(createMetricKind(metricDescriptor.getType()));
builder.setValueType(createValueType(metricDescriptor.getType()));
return builder.build();
}
Aggregations