Skip to content

Commit

Permalink
Add unit to BaseInstrument (#829)
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 6, 2020
1 parent 10b975b commit e9a44a2
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 29 deletions.
35 changes: 18 additions & 17 deletions sdk/src/main/java/io/opentelemetry/sdk/metrics/BaseInstrument.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ abstract class BaseInstrument 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;

// All arguments cannot be null because they are checked in the abstract builder classes.
BaseInstrument(
String name, String description, Map<String, String> constantLabels, List<String> labelKeys) {
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;
}
Expand All @@ -46,26 +53,20 @@ public boolean equals(Object o) {

BaseInstrument that = (BaseInstrument) o;

if (name != null ? !name.equals(that.name) : that.name != null) {
return false;
}
if (description != null ? !description.equals(that.description) : that.description != null) {
return false;
}
if (constantLabels != null
? !constantLabels.equals(that.constantLabels)
: that.constantLabels != null) {
return false;
}
return labelKeys != null ? labelKeys.equals(that.labelKeys) : that.labelKeys == null;
return name.equals(that.name)
&& description.equals(that.description)
&& unit.equals(that.unit)
&& constantLabels.equals(that.constantLabels)
&& labelKeys.equals(that.labelKeys);
}

@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (constantLabels != null ? constantLabels.hashCode() : 0);
result = 31 * result + (labelKeys != null ? labelKeys.hashCode() : 0);
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ final class DoubleCounterSdk extends BaseInstrument implements DoubleCounter {
private DoubleCounterSdk(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
boolean monotonic) {
super(name, description, constantLabels, labelKeys);
super(name, description, unit, constantLabels, labelKeys);
this.monotonic = monotonic;
}

Expand Down Expand Up @@ -113,7 +114,12 @@ Builder getThis() {
@Override
public DoubleCounter build() {
return new DoubleCounterSdk(
getName(), getDescription(), getConstantLabels(), getLabelKeys(), isMonotonic());
getName(),
getDescription(),
getUnit(),
getConstantLabels(),
getLabelKeys(),
isMonotonic());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ final class DoubleMeasureSdk extends BaseInstrument implements DoubleMeasure {
private DoubleMeasureSdk(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
boolean absolute) {
super(name, description, constantLabels, labelKeys);
super(name, description, unit, constantLabels, labelKeys);
this.absolute = absolute;
}

Expand Down Expand Up @@ -113,7 +114,12 @@ Builder getThis() {
@Override
public DoubleMeasure build() {
return new DoubleMeasureSdk(
getName(), getDescription(), getConstantLabels(), getLabelKeys(), isAbsolute());
getName(),
getDescription(),
getUnit(),
getConstantLabels(),
getLabelKeys(),
isAbsolute());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ final class DoubleObserverSdk extends BaseInstrument implements DoubleObserver {
DoubleObserverSdk(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
boolean monotonic) {
super(name, description, constantLabels, labelKeys);
super(name, description, unit, constantLabels, labelKeys);
this.monotonic = monotonic;
}

Expand Down Expand Up @@ -82,7 +83,12 @@ Builder getThis() {
@Override
public DoubleObserver build() {
return new DoubleObserverSdk(
getName(), getDescription(), getConstantLabels(), getLabelKeys(), isMonotonic());
getName(),
getDescription(),
getUnit(),
getConstantLabels(),
getLabelKeys(),
isMonotonic());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ final class LongCounterSdk extends BaseInstrument implements LongCounter {
private LongCounterSdk(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
boolean monotonic) {
super(name, description, constantLabels, labelKeys);
super(name, description, unit, constantLabels, labelKeys);
this.monotonic = monotonic;
}

Expand Down Expand Up @@ -113,7 +114,12 @@ Builder getThis() {
@Override
public LongCounter build() {
return new LongCounterSdk(
getName(), getDescription(), getConstantLabels(), getLabelKeys(), isMonotonic());
getName(),
getDescription(),
getUnit(),
getConstantLabels(),
getLabelKeys(),
isMonotonic());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ final class LongMeasureSdk extends BaseInstrument implements LongMeasure {
private LongMeasureSdk(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
boolean absolute) {
super(name, description, constantLabels, labelKeys);
super(name, description, unit, constantLabels, labelKeys);
this.absolute = absolute;
}

Expand Down Expand Up @@ -113,7 +114,12 @@ Builder getThis() {
@Override
public LongMeasure build() {
return new LongMeasureSdk(
getName(), getDescription(), getConstantLabels(), getLabelKeys(), isAbsolute());
getName(),
getDescription(),
getUnit(),
getConstantLabels(),
getLabelKeys(),
isAbsolute());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ final class LongObserverSdk extends BaseInstrument implements LongObserver {
LongObserverSdk(
String name,
String description,
String unit,
Map<String, String> constantLabels,
List<String> labelKeys,
boolean monotonic) {
super(name, description, constantLabels, labelKeys);
super(name, description, unit, constantLabels, labelKeys);
this.monotonic = monotonic;
}

Expand Down Expand Up @@ -82,7 +83,12 @@ Builder getThis() {
@Override
public LongObserver build() {
return new LongObserverSdk(
getName(), getDescription(), getConstantLabels(), getLabelKeys(), isMonotonic());
getName(),
getDescription(),
getUnit(),
getConstantLabels(),
getLabelKeys(),
isMonotonic());
}
}
}

0 comments on commit e9a44a2

Please sign in to comment.