Skip to content

Commit

Permalink
Extract descriptor fields for Instrument and use autovalue
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Cristian Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Feb 19, 2020
1 parent 9e1882f commit b754143
Show file tree
Hide file tree
Showing 19 changed files with 286 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,18 @@
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 extends AbstractInstrument {
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);
super(descriptor, meterProviderSharedState, instrumentationLibraryInfo);
this.monotonic = monotonic;
this.instrumentValueType = instrumentValueType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,30 @@

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;

// 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) {
this.name = name;
this.description = description;
this.unit = unit;
this.constantLabels = constantLabels;
this.labelKeys = labelKeys;
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
InstrumentationLibraryInfo instrumentationLibraryInfo) {
this.descriptor = descriptor;
this.meterProviderSharedState = meterProviderSharedState;
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
}

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;
}

@Override
Expand All @@ -79,21 +65,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);
}

@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 @@ -152,10 +129,6 @@ public final B setConstantLabels(Map<String, String> constantLabels) {
return getThis();
}

final String getName() {
return name;
}

final MeterProviderSharedState getMeterProviderSharedState() {
return meterProviderSharedState;
}
Expand All @@ -164,20 +137,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 @@ -19,24 +19,18 @@
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 extends AbstractInstrument {
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);
super(descriptor, meterProviderSharedState, instrumentationLibraryInfo);
this.absolute = absolute;
this.instrumentValueType = instrumentValueType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,18 @@
import io.opentelemetry.metrics.Observer;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
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);
super(descriptor, meterProviderSharedState, instrumentationLibraryInfo);
this.monotonic = monotonic;
this.instrumentValueType = instrumentValueType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,16 @@
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;

final class DoubleCounterSdk extends AbstractCounter 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 @@ -102,11 +92,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 @@ -20,26 +20,16 @@
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;

final class DoubleMeasureSdk extends AbstractMeasure 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 @@ -102,11 +92,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2020, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.opentelemetry.sdk.metrics;

import com.google.auto.value.AutoValue;
import java.util.List;
import java.util.Map;
import javax.annotation.concurrent.Immutable;

@AutoValue
@Immutable
abstract class InstrumentDescriptor {
static InstrumentDescriptor create(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys) {
return new AutoValue_InstrumentDescriptor(name, description, unit, constantLabels, labelKeys);
}

abstract String getName();

abstract String getDescription();

abstract String getUnit();

abstract Map<String, String> getConstantLabels();

abstract List<String> getLabelKeys();
}
Loading

0 comments on commit b754143

Please sign in to comment.