Skip to content

Commit

Permalink
Add a MeterSharedState class that includes the InstrumentationLibrary…
Browse files Browse the repository at this point in the history
…Info (open-telemetry#901)

Signed-off-by: Bogdan Cristian Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored and DotSpy committed Feb 21, 2020
1 parent 71f2456 commit 678628f
Show file tree
Hide file tree
Showing 23 changed files with 204 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import javax.annotation.Nullable;

/**
* Base class for all the registry classes (Tracer, Meter, etc.).
* Base class for all the provider classes (TracerProvider, MeterProvider, etc.).
*
* @param <V> the type of the registered value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.metrics.Counter;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentType;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
Expand All @@ -33,19 +32,19 @@ abstract class AbstractCounter<B extends AbstractBoundInstrument>
InstrumentDescriptor descriptor,
InstrumentValueType instrumentValueType,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
MeterSharedState meterSharedState,
boolean monotonic) {
super(
descriptor,
meterProviderSharedState,
instrumentationLibraryInfo,
meterSharedState,
new ActiveBatcher(
getDefaultBatcher(
descriptor,
getCounterInstrumentType(monotonic),
instrumentValueType,
meterProviderSharedState,
instrumentationLibraryInfo)));
meterSharedState)));
this.monotonic = monotonic;
this.instrumentValueType = instrumentValueType;
}
Expand Down Expand Up @@ -86,8 +85,8 @@ abstract static class Builder<B extends Counter.Builder<B, V>, V>
Builder(
String name,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, meterProviderSharedState, instrumentationLibraryInfo);
MeterSharedState meterSharedState) {
super(name, meterProviderSharedState, meterSharedState);
}

@Override
Expand All @@ -110,13 +109,13 @@ private static Batcher getDefaultBatcher(
InstrumentType instrumentType,
InstrumentValueType instrumentValueType,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
MeterSharedState meterSharedState) {
Aggregation defaultAggregation = Aggregations.sum();
return Batchers.getCumulativeAllLabels(
getDefaultMetricDescriptor(
descriptor, instrumentType, instrumentValueType, defaultAggregation),
meterProviderSharedState.getResource(),
instrumentationLibraryInfo,
meterSharedState.getInstrumentationLibraryInfo(),
defaultAggregation.getAggregatorFactory(instrumentValueType),
meterProviderSharedState.getClock());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.opentelemetry.internal.StringUtils;
import io.opentelemetry.internal.Utils;
import io.opentelemetry.metrics.Instrument;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.data.MetricData;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -31,18 +30,18 @@ abstract class AbstractInstrument implements Instrument {

private final InstrumentDescriptor descriptor;
private final MeterProviderSharedState meterProviderSharedState;
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
private final MeterSharedState meterSharedState;
private final ActiveBatcher activeBatcher;

// All arguments cannot be null because they are checked in the abstract builder classes.
AbstractInstrument(
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
MeterSharedState meterSharedState,
ActiveBatcher activeBatcher) {
this.descriptor = descriptor;
this.meterProviderSharedState = meterProviderSharedState;
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
this.meterSharedState = meterSharedState;
this.activeBatcher = activeBatcher;
}

Expand All @@ -54,8 +53,8 @@ final MeterProviderSharedState getMeterProviderSharedState() {
return meterProviderSharedState;
}

final InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
return instrumentationLibraryInfo;
final MeterSharedState getMeterSharedState() {
return meterSharedState;
}

final ActiveBatcher getActiveBatcher() {
Expand Down Expand Up @@ -93,7 +92,7 @@ abstract static class Builder<B extends Instrument.Builder<B, V>, V>

private final String name;
private final MeterProviderSharedState meterProviderSharedState;
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
private final MeterSharedState meterSharedState;
private String description = "";
private String unit = "1";
private List<String> labelKeys = Collections.emptyList();
Expand All @@ -102,14 +101,14 @@ abstract static class Builder<B extends Instrument.Builder<B, V>, V>
Builder(
String name,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
MeterSharedState meterSharedState) {
Utils.checkNotNull(name, "name");
Utils.checkArgument(
StringUtils.isValidMetricName(name) && name.length() <= NAME_MAX_LENGTH,
ERROR_MESSAGE_INVALID_NAME);
this.name = name;
this.meterProviderSharedState = meterProviderSharedState;
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
this.meterSharedState = meterSharedState;
}

@Override
Expand Down Expand Up @@ -143,8 +142,8 @@ final MeterProviderSharedState getMeterProviderSharedState() {
return meterProviderSharedState;
}

final InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
return instrumentationLibraryInfo;
final MeterSharedState getMeterSharedState() {
return meterSharedState;
}

final InstrumentDescriptor getInstrumentDescriptor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.metrics.LabelSet;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.data.MetricData;
import java.util.List;
import java.util.Map;
Expand All @@ -32,9 +31,9 @@ abstract class AbstractInstrumentWithBinding<B extends AbstractBoundInstrument>
AbstractInstrumentWithBinding(
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
MeterSharedState meterSharedState,
ActiveBatcher activeBatcher) {
super(descriptor, meterProviderSharedState, instrumentationLibraryInfo, activeBatcher);
super(descriptor, meterProviderSharedState, meterSharedState, activeBatcher);
boundLabels = new ConcurrentHashMap<>();
collectLock = new ReentrantLock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package io.opentelemetry.sdk.metrics;

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

abstract class AbstractMeasure<B extends AbstractBoundInstrument>
Expand All @@ -30,12 +28,12 @@ abstract class AbstractMeasure<B extends AbstractBoundInstrument>
InstrumentDescriptor descriptor,
InstrumentValueType instrumentValueType,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
MeterSharedState meterSharedState,
boolean absolute) {
super(
descriptor,
meterProviderSharedState,
instrumentationLibraryInfo,
meterSharedState,
new ActiveBatcher(Batchers.getNoop()));
this.absolute = absolute;
this.instrumentValueType = instrumentValueType;
Expand Down Expand Up @@ -77,8 +75,8 @@ abstract static class Builder<B extends Measure.Builder<B, V>, V>
Builder(
String name,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, meterProviderSharedState, instrumentationLibraryInfo);
MeterSharedState meterSharedState) {
super(name, meterProviderSharedState, meterSharedState);
}

@Override
Expand All @@ -91,8 +89,4 @@ final boolean isAbsolute() {
return this.absolute;
}
}

static InstrumentType getInstrumentType(boolean absolute) {
return absolute ? InstrumentType.MEASURE_ABSOLUTE : InstrumentType.MEASURE_NON_ABSOLUTE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.metrics.Observer;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentType;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import io.opentelemetry.sdk.metrics.data.MetricData;
import java.util.Collections;
Expand All @@ -32,12 +30,12 @@ class AbstractObserver extends AbstractInstrument {
InstrumentDescriptor descriptor,
InstrumentValueType instrumentValueType,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
MeterSharedState meterSharedState,
boolean monotonic) {
super(
descriptor,
meterProviderSharedState,
instrumentationLibraryInfo,
meterSharedState,
new ActiveBatcher(Batchers.getNoop()));
this.monotonic = monotonic;
this.instrumentValueType = instrumentValueType;
Expand Down Expand Up @@ -85,8 +83,8 @@ abstract static class Builder<B extends Observer.Builder<B, V>, V>
Builder(
String name,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, meterProviderSharedState, instrumentationLibraryInfo);
MeterSharedState meterSharedState) {
super(name, meterProviderSharedState, meterSharedState);
}

@Override
Expand All @@ -99,9 +97,4 @@ final boolean isMonotonic() {
return this.monotonic;
}
}

// TODO: make this private
static InstrumentType getInstrumentType(boolean monotonic) {
return monotonic ? InstrumentType.OBSERVER_MONOTONIC : InstrumentType.OBSERVER_NON_MONOTONIC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import io.opentelemetry.metrics.DoubleCounter;
import io.opentelemetry.metrics.LabelSet;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.DoubleCounterSdk.BoundInstrument;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;

Expand All @@ -28,12 +27,12 @@ private DoubleCounterSdk(
InstrumentDescriptor descriptor,
boolean monotonic,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
MeterSharedState meterSharedState) {
super(
descriptor,
InstrumentValueType.DOUBLE,
meterProviderSharedState,
instrumentationLibraryInfo,
meterSharedState,
monotonic);
}

Expand Down Expand Up @@ -76,8 +75,8 @@ public void add(double delta) {
static DoubleCounter.Builder builder(
String name,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
return new Builder(name, meterProviderSharedState, instrumentationLibraryInfo);
MeterSharedState meterSharedState) {
return new Builder(name, meterProviderSharedState, meterSharedState);
}

private static final class Builder
Expand All @@ -87,8 +86,8 @@ private static final class Builder
private Builder(
String name,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, meterProviderSharedState, instrumentationLibraryInfo);
MeterSharedState meterSharedState) {
super(name, meterProviderSharedState, meterSharedState);
}

@Override
Expand All @@ -102,7 +101,7 @@ public DoubleCounter build() {
getInstrumentDescriptor(),
isMonotonic(),
getMeterProviderSharedState(),
getInstrumentationLibraryInfo());
getMeterSharedState());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import io.opentelemetry.metrics.DoubleMeasure;
import io.opentelemetry.metrics.LabelSet;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.DoubleMeasureSdk.BoundInstrument;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;

Expand All @@ -27,13 +26,13 @@ final class DoubleMeasureSdk extends AbstractMeasure<BoundInstrument> implements
private DoubleMeasureSdk(
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
MeterSharedState meterSharedState,
boolean absolute) {
super(
descriptor,
InstrumentValueType.DOUBLE,
meterProviderSharedState,
instrumentationLibraryInfo,
meterSharedState,
absolute);
}

Expand Down Expand Up @@ -76,8 +75,8 @@ public void record(double value) {
static DoubleMeasure.Builder builder(
String name,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
return new Builder(name, meterProviderSharedState, instrumentationLibraryInfo);
MeterSharedState meterSharedState) {
return new Builder(name, meterProviderSharedState, meterSharedState);
}

private static final class Builder
Expand All @@ -87,8 +86,8 @@ private static final class Builder
private Builder(
String name,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(name, meterProviderSharedState, instrumentationLibraryInfo);
MeterSharedState meterSharedState) {
super(name, meterProviderSharedState, meterSharedState);
}

@Override
Expand All @@ -101,7 +100,7 @@ public DoubleMeasure build() {
return new DoubleMeasureSdk(
getInstrumentDescriptor(),
getMeterProviderSharedState(),
getInstrumentationLibraryInfo(),
getMeterSharedState(),
isAbsolute());
}
}
Expand Down
Loading

0 comments on commit 678628f

Please sign in to comment.