Skip to content

Commit

Permalink
Plugin Resource, LibraryInfo and instrument types (#859)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Cristian Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Feb 13, 2020
1 parent 3f2ad43 commit 84f4443
Show file tree
Hide file tree
Showing 17 changed files with 302 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.metrics.Counter;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;

abstract class AbstractCounterBuilder<B extends Counter.Builder<B, V>, V>
extends AbstractInstrumentBuilder<B, V> implements Counter.Builder<B, V> {
private boolean monotonic = true;

AbstractCounterBuilder(String name, MeterSharedState sharedState) {
super(name, sharedState);
AbstractCounterBuilder(
String name,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, sharedState, instrumentationLibraryInfo);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.metrics.Instrument;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentType;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import java.util.List;
import java.util.Map;

Expand All @@ -28,6 +31,7 @@ abstract class AbstractInstrument implements Instrument {
private final Map<String, String> constantLabels;
private final List<String> labelKeys;
private final MeterSharedState meterSharedState;
private final InstrumentationLibraryInfo instrumentationLibraryInfo;

// All arguments cannot be null because they are checked in the abstract builder classes.
AbstractInstrument(
Expand All @@ -36,13 +40,17 @@ abstract class AbstractInstrument implements Instrument {
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
MeterSharedState meterSharedState) {
InstrumentType instrumentType,
InstrumentValueType instrumentValueType,
MeterSharedState meterSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
this.name = name;
this.description = description;
this.unit = unit;
this.constantLabels = constantLabels;
this.labelKeys = labelKeys;
this.meterSharedState = meterSharedState;
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
}

final String getName() {
Expand All @@ -69,6 +77,10 @@ final MeterSharedState getMeterSharedState() {
return meterSharedState;
}

final InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
return instrumentationLibraryInfo;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -96,4 +108,16 @@ public int hashCode() {
result = 31 * result + labelKeys.hashCode();
return result;
}

static InstrumentType getCounterInstrumentType(boolean monotonic) {
return monotonic ? InstrumentType.COUNTER_MONOTONIC : InstrumentType.COUNTER_NON_MONOTONIC;
}

static InstrumentType getMeasureInstrumentType(boolean absolute) {
return absolute ? InstrumentType.MEASURE_ABSOLUTE : InstrumentType.MEASURE_NON_ABSOLUTE;
}

static InstrumentType getObserverInstrumentType(boolean monotonic) {
return monotonic ? InstrumentType.OBSERVER_MONOTONIC : InstrumentType.OBSERVER_NON_MONOTONIC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.opentelemetry.internal.StringUtils;
import io.opentelemetry.internal.Utils;
import io.opentelemetry.metrics.Instrument;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -35,18 +36,23 @@ abstract class AbstractInstrumentBuilder<B extends Instrument.Builder<B, V>, V>

private final String name;
private final MeterSharedState meterSharedState;
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
private String description = "";
private String unit = "1";
private List<String> labelKeys = Collections.emptyList();
private Map<String, String> constantLabels = Collections.emptyMap();

AbstractInstrumentBuilder(String name, MeterSharedState meterSharedState) {
AbstractInstrumentBuilder(
String name,
MeterSharedState meterSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
Utils.checkNotNull(name, "name");
Utils.checkArgument(
StringUtils.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH,
ERROR_MESSAGE_INVALID_NAME);
this.name = name;
this.meterSharedState = meterSharedState;
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
}

@Override
Expand Down Expand Up @@ -84,6 +90,10 @@ final MeterSharedState getMeterSharedState() {
return meterSharedState;
}

final InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
return instrumentationLibraryInfo;
}

final String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.metrics.Measure;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;

abstract class AbstractMeasureBuilder<B extends Measure.Builder<B, V>, V>
extends AbstractInstrumentBuilder<B, V> implements Measure.Builder<B, V> {
private boolean absolute = true;

AbstractMeasureBuilder(String name, MeterSharedState sharedState) {
super(name, sharedState);
AbstractMeasureBuilder(
String name,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, sharedState, instrumentationLibraryInfo);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.metrics.Observer;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;

abstract class AbstractObserverBuilder<B extends Observer.Builder<B, V>, V>
extends AbstractInstrumentBuilder<B, V> implements Observer.Builder<B, V> {
private boolean monotonic = false;

AbstractObserverBuilder(String name, MeterSharedState sharedState) {
super(name, sharedState);
AbstractObserverBuilder(
String name,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, sharedState, instrumentationLibraryInfo);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import io.opentelemetry.metrics.DoubleCounter;
import io.opentelemetry.metrics.LabelSet;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import java.util.List;
import java.util.Map;

Expand All @@ -31,9 +33,19 @@ private DoubleCounterSdk(
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
boolean monotonic,
MeterSharedState sharedState,
boolean monotonic) {
super(name, description, unit, constantLabels, labelKeys, sharedState);
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(
name,
description,
unit,
constantLabels,
labelKeys,
getCounterInstrumentType(monotonic),
InstrumentValueType.DOUBLE,
sharedState,
instrumentationLibraryInfo);
this.monotonic = monotonic;
}

Expand Down Expand Up @@ -91,16 +103,22 @@ public void add(double delta) {
}
}

static DoubleCounter.Builder builder(String name, MeterSharedState sharedState) {
return new Builder(name, sharedState);
static DoubleCounter.Builder builder(
String name,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
return new Builder(name, sharedState, instrumentationLibraryInfo);
}

private static final class Builder
extends AbstractCounterBuilder<DoubleCounter.Builder, DoubleCounter>
implements DoubleCounter.Builder {

private Builder(String name, MeterSharedState sharedState) {
super(name, sharedState);
private Builder(
String name,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, sharedState, instrumentationLibraryInfo);
}

@Override
Expand All @@ -116,8 +134,9 @@ public DoubleCounter build() {
getUnit(),
getConstantLabels(),
getLabelKeys(),
isMonotonic(),
getMeterSharedState(),
isMonotonic());
getInstrumentationLibraryInfo());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import io.opentelemetry.metrics.DoubleMeasure;
import io.opentelemetry.metrics.LabelSet;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import java.util.List;
import java.util.Map;

Expand All @@ -32,8 +34,18 @@ private DoubleMeasureSdk(
Map<String, String> constantLabels,
List<String> labelKeys,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
boolean absolute) {
super(name, description, unit, constantLabels, labelKeys, sharedState);
super(
name,
description,
unit,
constantLabels,
labelKeys,
getMeasureInstrumentType(absolute),
InstrumentValueType.DOUBLE,
sharedState,
instrumentationLibraryInfo);
this.absolute = absolute;
}

Expand Down Expand Up @@ -91,16 +103,22 @@ public void record(double value) {
}
}

static DoubleMeasure.Builder builder(String name, MeterSharedState sharedState) {
return new Builder(name, sharedState);
static DoubleMeasure.Builder builder(
String name,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
return new Builder(name, sharedState, instrumentationLibraryInfo);
}

private static final class Builder
extends AbstractMeasureBuilder<DoubleMeasure.Builder, DoubleMeasure>
implements DoubleMeasure.Builder {

private Builder(String name, MeterSharedState sharedState) {
super(name, sharedState);
private Builder(
String name,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, sharedState, instrumentationLibraryInfo);
}

@Override
Expand All @@ -117,6 +135,7 @@ public DoubleMeasure build() {
getConstantLabels(),
getLabelKeys(),
getMeterSharedState(),
getInstrumentationLibraryInfo(),
isAbsolute());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.metrics.DoubleObserver;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import java.util.List;
import java.util.Map;

Expand All @@ -30,8 +32,18 @@ final class DoubleObserverSdk extends AbstractInstrument implements DoubleObserv
Map<String, String> constantLabels,
List<String> labelKeys,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
boolean monotonic) {
super(name, description, unit, constantLabels, labelKeys, sharedState);
super(
name,
description,
unit,
constantLabels,
labelKeys,
getObserverInstrumentType(monotonic),
InstrumentValueType.LONG,
sharedState,
instrumentationLibraryInfo);
this.monotonic = monotonic;
}

Expand Down Expand Up @@ -64,16 +76,22 @@ public int hashCode() {
return result;
}

static DoubleObserver.Builder builder(String name, MeterSharedState sharedState) {
return new Builder(name, sharedState);
static DoubleObserver.Builder builder(
String name,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
return new Builder(name, sharedState, instrumentationLibraryInfo);
}

private static final class Builder
extends AbstractObserverBuilder<DoubleObserver.Builder, DoubleObserver>
implements DoubleObserver.Builder {

private Builder(String name, MeterSharedState sharedState) {
super(name, sharedState);
private Builder(
String name,
MeterSharedState sharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, sharedState, instrumentationLibraryInfo);
}

@Override
Expand All @@ -90,6 +108,7 @@ public DoubleObserver build() {
getConstantLabels(),
getLabelKeys(),
getMeterSharedState(),
getInstrumentationLibraryInfo(),
isMonotonic());
}
}
Expand Down
Loading

0 comments on commit 84f4443

Please sign in to comment.