use of io.opentelemetry.sdk.metrics.common.InstrumentType in project opentelemetry-java by open-telemetry.
the class ViewConfig method toInstrumentSelector.
// Visible for testing
static InstrumentSelector toInstrumentSelector(SelectorSpecification selectorSpec) {
InstrumentSelectorBuilder builder = InstrumentSelector.builder();
String instrumentName = selectorSpec.getInstrumentName();
if (instrumentName != null) {
builder.setName(instrumentName);
}
InstrumentType instrumentType = selectorSpec.getInstrumentType();
if (instrumentType != null) {
builder.setType(instrumentType);
}
String meterName = selectorSpec.getMeterName();
if (meterName != null) {
builder.setMeterName(meterName);
}
String meterVersion = selectorSpec.getMeterVersion();
if (meterVersion != null) {
builder.setMeterVersion(meterVersion);
}
String meterSchemaUrl = selectorSpec.getMeterSchemaUrl();
if (meterSchemaUrl != null) {
builder.setMeterSchemaUrl(meterSchemaUrl);
}
return builder.build();
}
use of io.opentelemetry.sdk.metrics.common.InstrumentType in project opentelemetry-java by open-telemetry.
the class ViewConfig method loadViewConfig.
// Visible for testing
@SuppressWarnings("unchecked")
static List<ViewConfigSpecification> loadViewConfig(InputStream inputStream) {
Yaml yaml = new Yaml();
try {
List<ViewConfigSpecification> result = new ArrayList<>();
List<Map<String, Object>> viewConfigs = yaml.load(inputStream);
for (Map<String, Object> viewConfigSpecMap : viewConfigs) {
Map<String, Object> selectorSpecMap = requireNonNull(getAsType(viewConfigSpecMap, "selector", Map.class), "selector is required");
Map<String, Object> viewSpecMap = requireNonNull(getAsType(viewConfigSpecMap, "view", Map.class), "view is required");
InstrumentType instrumentType = Optional.ofNullable(getAsType(selectorSpecMap, "instrument_type", String.class)).map(InstrumentType::valueOf).orElse(null);
List<String> attributeKeys = Optional.ofNullable(((List<Object>) getAsType(viewSpecMap, "attribute_keys", List.class))).map(objects -> objects.stream().map(String::valueOf).collect(toList())).orElse(null);
result.add(ViewConfigSpecification.builder().selectorSpecification(SelectorSpecification.builder().instrumentName(getAsType(selectorSpecMap, "instrument_name", String.class)).instrumentType(instrumentType).meterName(getAsType(selectorSpecMap, "meter_name", String.class)).meterVersion(getAsType(selectorSpecMap, "meter_version", String.class)).meterSchemaUrl(getAsType(selectorSpecMap, "meter_schema_url", String.class)).build()).viewSpecification(ViewSpecification.builder().name(getAsType(viewSpecMap, "name", String.class)).description(getAsType(viewSpecMap, "description", String.class)).aggregation(getAsType(viewSpecMap, "aggregation", String.class)).attributeKeys(attributeKeys).build()).build());
}
return result;
} catch (RuntimeException e) {
throw new ConfigurationException("Failed to parse view config", e);
}
}
use of io.opentelemetry.sdk.metrics.common.InstrumentType in project opentelemetry-java by open-telemetry.
the class DoubleSumAggregatorTest method mergeAndDiff.
@Test
void mergeAndDiff() {
Attributes attributes = Attributes.builder().put("test", "value").build();
ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
List<ExemplarData> exemplars = Collections.singletonList(exemplar);
List<ExemplarData> previousExemplars = Collections.singletonList(DoubleExemplarData.create(attributes, 1L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 2));
for (InstrumentType instrumentType : InstrumentType.values()) {
for (AggregationTemporality temporality : AggregationTemporality.values()) {
DoubleSumAggregator aggregator = new DoubleSumAggregator(InstrumentDescriptor.create("name", "description", "unit", instrumentType, InstrumentValueType.LONG), ExemplarReservoir::noSamples);
DoubleAccumulation merged = aggregator.merge(DoubleAccumulation.create(1.0d, previousExemplars), DoubleAccumulation.create(2.0d, exemplars));
assertThat(merged.getValue()).withFailMessage("Invalid merge result for instrumentType %s, temporality %s: %s", instrumentType, temporality, merged).isEqualTo(3.0d);
assertThat(merged.getExemplars()).containsExactly(exemplar);
DoubleAccumulation diffed = aggregator.diff(DoubleAccumulation.create(1d), DoubleAccumulation.create(2d, exemplars));
assertThat(diffed.getValue()).withFailMessage("Invalid diff result for instrumentType %s, temporality %s: %s", instrumentType, temporality, merged).isEqualTo(1d);
assertThat(diffed.getExemplars()).containsExactly(exemplar);
}
}
}
use of io.opentelemetry.sdk.metrics.common.InstrumentType in project opentelemetry-java by open-telemetry.
the class LongSumAggregatorTest method mergeAndDiff.
@Test
void mergeAndDiff() {
ExemplarData exemplar = DoubleExemplarData.create(Attributes.empty(), 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
List<ExemplarData> exemplars = Collections.singletonList(exemplar);
for (InstrumentType instrumentType : InstrumentType.values()) {
for (AggregationTemporality temporality : AggregationTemporality.values()) {
LongSumAggregator aggregator = new LongSumAggregator(InstrumentDescriptor.create("name", "description", "unit", instrumentType, InstrumentValueType.LONG), ExemplarReservoir::noSamples);
LongAccumulation merged = aggregator.merge(LongAccumulation.create(1L), LongAccumulation.create(2L, exemplars));
assertThat(merged.getValue()).withFailMessage("Invalid merge result for instrumentType %s, temporality %s: %s", instrumentType, temporality, merged).isEqualTo(3);
assertThat(merged.getExemplars()).containsExactly(exemplar);
LongAccumulation diffed = aggregator.diff(LongAccumulation.create(1L), LongAccumulation.create(2L, exemplars));
assertThat(diffed.getValue()).withFailMessage("Invalid diff result for instrumentType %s, temporality %s: %s", instrumentType, temporality, merged).isEqualTo(1);
assertThat(diffed.getExemplars()).containsExactly(exemplar);
}
}
}
Aggregations