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

Extract descriptor fields for Instrument and use autovalue #865

Merged
merged 1 commit into from
Feb 19, 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 @@ -19,26 +19,23 @@
import io.opentelemetry.metrics.Counter;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import java.util.List;
import java.util.Map;

abstract class AbstractCounter<B extends AbstractBoundInstrument>
extends AbstractInstrumentWithBinding<B> {
private final boolean monotonic;
private final InstrumentValueType instrumentValueType;

AbstractCounter(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
InstrumentDescriptor descriptor,
InstrumentValueType instrumentValueType,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
boolean monotonic) {
super(
name, description, unit, constantLabels, labelKeys, new ActiveBatcher(Batchers.getNoop()));
descriptor,
meterProviderSharedState,
instrumentationLibraryInfo,
new ActiveBatcher(Batchers.getNoop()));
this.monotonic = monotonic;
this.instrumentValueType = instrumentValueType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,33 @@

abstract class AbstractInstrument implements Instrument {

private final String name;
private final String description;
private final String unit;
private final Map<String, String> constantLabels;
private final List<String> labelKeys;
private final InstrumentDescriptor descriptor;
private final MeterProviderSharedState meterProviderSharedState;
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
private final ActiveBatcher activeBatcher;

// All arguments cannot be null because they are checked in the abstract builder classes.
AbstractInstrument(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
ActiveBatcher activeBatcher) {
this.name = name;
this.description = description;
this.unit = unit;
this.constantLabels = constantLabels;
this.labelKeys = labelKeys;
// TODO: Allow to install views from config instead of always installing the default View.
this.descriptor = descriptor;
this.meterProviderSharedState = meterProviderSharedState;
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
this.activeBatcher = activeBatcher;
}

final String getName() {
return name;
final InstrumentDescriptor getDescriptor() {
return descriptor;
}

final String getDescription() {
return description;
final MeterProviderSharedState getMeterProviderSharedState() {
return meterProviderSharedState;
}

final String getUnit() {
return unit;
}

final Map<String, String> getConstantLabels() {
return constantLabels;
}

final List<String> getLabelKeys() {
return labelKeys;
final InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
return instrumentationLibraryInfo;
}

final ActiveBatcher getActiveBatcher() {
Expand All @@ -90,21 +75,12 @@ public boolean equals(Object o) {

AbstractInstrument that = (AbstractInstrument) o;

return name.equals(that.name)
&& description.equals(that.description)
&& unit.equals(that.unit)
&& constantLabels.equals(that.constantLabels)
&& labelKeys.equals(that.labelKeys);
return descriptor.equals(that.descriptor);
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + description.hashCode();
result = 31 * result + unit.hashCode();
result = 31 * result + constantLabels.hashCode();
result = 31 * result + labelKeys.hashCode();
return result;
return descriptor.hashCode();
}

abstract static class Builder<B extends Instrument.Builder<B, V>, V>
Expand Down Expand Up @@ -163,10 +139,6 @@ public final B setConstantLabels(Map<String, String> constantLabels) {
return getThis();
}

final String getName() {
return name;
}

final MeterProviderSharedState getMeterProviderSharedState() {
return meterProviderSharedState;
}
Expand All @@ -175,20 +147,8 @@ final InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
return instrumentationLibraryInfo;
}

final String getDescription() {
return description;
}

final String getUnit() {
return unit;
}

final List<String> getLabelKeys() {
return labelKeys;
}

final Map<String, String> getConstantLabels() {
return constantLabels;
final InstrumentDescriptor getInstrumentDescriptor() {
return InstrumentDescriptor.create(name, description, unit, constantLabels, labelKeys);
}

abstract B getThis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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 @@ -29,13 +30,11 @@ abstract class AbstractInstrumentWithBinding<B extends AbstractBoundInstrument>
private final ReentrantLock collectLock;

AbstractInstrumentWithBinding(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
ActiveBatcher activeBatcher) {
super(name, description, unit, constantLabels, labelKeys, activeBatcher);
super(descriptor, meterProviderSharedState, instrumentationLibraryInfo, activeBatcher);
boundLabels = new ConcurrentHashMap<>();
collectLock = new ReentrantLock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@
import io.opentelemetry.metrics.Measure;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import java.util.List;
import java.util.Map;

abstract class AbstractMeasure<B extends AbstractBoundInstrument>
extends AbstractInstrumentWithBinding<B> {
private final boolean absolute;
private final InstrumentValueType instrumentValueType;

AbstractMeasure(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
InstrumentDescriptor descriptor,
InstrumentValueType instrumentValueType,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
boolean absolute) {
super(
name, description, unit, constantLabels, labelKeys, new ActiveBatcher(Batchers.getNoop()));
descriptor,
meterProviderSharedState,
instrumentationLibraryInfo,
new ActiveBatcher(Batchers.getNoop()));
this.absolute = absolute;
this.instrumentValueType = instrumentValueType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import java.util.Collections;
import java.util.List;
import java.util.Map;

class AbstractObserver extends AbstractInstrument {
private final boolean monotonic;
private final InstrumentValueType instrumentValueType;

AbstractObserver(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
InstrumentDescriptor descriptor,
InstrumentValueType instrumentValueType,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
boolean monotonic) {
super(name, description, unit, constantLabels, labelKeys, null);
super(
descriptor,
meterProviderSharedState,
instrumentationLibraryInfo,
new ActiveBatcher(Batchers.getNoop()));
this.monotonic = monotonic;
this.instrumentValueType = instrumentValueType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,16 @@
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.DoubleCounterSdk.BoundInstrument;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import java.util.List;
import java.util.Map;

final class DoubleCounterSdk extends AbstractCounter<BoundInstrument> implements DoubleCounter {

private DoubleCounterSdk(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
InstrumentDescriptor descriptor,
boolean monotonic,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
super(
name,
description,
unit,
constantLabels,
labelKeys,
descriptor,
InstrumentValueType.DOUBLE,
meterProviderSharedState,
instrumentationLibraryInfo,
Expand Down Expand Up @@ -108,11 +98,7 @@ Builder getThis() {
@Override
public DoubleCounter build() {
return new DoubleCounterSdk(
getName(),
getDescription(),
getUnit(),
getConstantLabels(),
getLabelKeys(),
getInstrumentDescriptor(),
isMonotonic(),
getMeterProviderSharedState(),
getInstrumentationLibraryInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,16 @@
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.DoubleMeasureSdk.BoundInstrument;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import java.util.List;
import java.util.Map;

final class DoubleMeasureSdk extends AbstractMeasure<BoundInstrument> implements DoubleMeasure {

private DoubleMeasureSdk(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
boolean absolute) {
super(
name,
description,
unit,
constantLabels,
labelKeys,
descriptor,
InstrumentValueType.DOUBLE,
meterProviderSharedState,
instrumentationLibraryInfo,
Expand Down Expand Up @@ -108,11 +98,7 @@ Builder getThis() {
@Override
public DoubleMeasure build() {
return new DoubleMeasureSdk(
getName(),
getDescription(),
getUnit(),
getConstantLabels(),
getLabelKeys(),
getInstrumentDescriptor(),
getMeterProviderSharedState(),
getInstrumentationLibraryInfo(),
isAbsolute());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,16 @@
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;

final class DoubleObserverSdk extends AbstractObserver implements DoubleObserver {
DoubleObserverSdk(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo,
boolean monotonic) {
super(
name,
description,
unit,
constantLabels,
labelKeys,
InstrumentValueType.DOUBLE,
descriptor,
InstrumentValueType.LONG,
meterProviderSharedState,
instrumentationLibraryInfo,
monotonic);
Expand Down Expand Up @@ -75,11 +65,7 @@ Builder getThis() {
@Override
public DoubleObserver build() {
return new DoubleObserverSdk(
getName(),
getDescription(),
getUnit(),
getConstantLabels(),
getLabelKeys(),
getInstrumentDescriptor(),
getMeterProviderSharedState(),
getInstrumentationLibraryInfo(),
isMonotonic());
Expand Down
Loading