Search in sources :

Example 21 with LabelValue

use of io.opencensus.metrics.LabelValue 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());
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) LabelValue(io.opencensus.metrics.LabelValue) LabelKey(io.opencensus.metrics.LabelKey) Test(org.junit.Test)

Example 22 with LabelValue

use of io.opencensus.metrics.LabelValue 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();
}
Also used : LabelValue(io.opencensus.metrics.LabelValue) EqualsTester(com.google.common.testing.EqualsTester) LabelKey(io.opencensus.metrics.LabelKey) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Aggregations

LabelValue (io.opencensus.metrics.LabelValue)22 LabelKey (io.opencensus.metrics.LabelKey)17 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)10 TimeSeries (io.opencensus.metrics.export.TimeSeries)10 Metric (io.opencensus.metrics.export.Metric)9 EqualsTester (com.google.common.testing.EqualsTester)4 Timestamp (io.opencensus.common.Timestamp)4 Metric (com.google.api.Metric)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 LongPoint (io.opencensus.metrics.LongGauge.LongPoint)3 TimeSeries (com.google.monitoring.v3.TimeSeries)2 DoublePoint (io.opencensus.metrics.DoubleCumulative.DoublePoint)2 DoublePoint (io.opencensus.metrics.DoubleGauge.DoublePoint)2 LongPoint (io.opencensus.metrics.LongCumulative.LongPoint)2 Type (io.opencensus.metrics.export.MetricDescriptor.Type)2 Value (io.opencensus.metrics.export.Value)2 List (java.util.List)2 Map (java.util.Map)2