Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a MeterSharedState class that includes the InstrumentationLibraryinfo #901

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -75,8 +74,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 @@ -86,8 +85,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 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 @@ -75,8 +74,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 @@ -86,8 +85,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 @@ -100,7 +99,7 @@ public DoubleMeasure build() {
return new DoubleMeasureSdk(
getInstrumentDescriptor(),
getMeterProviderSharedState(),
getInstrumentationLibraryInfo(),
getMeterSharedState(),
isAbsolute());
}
}
Expand Down
Loading