Skip to content

Commit

Permalink
Make instrument's builder private class (#819)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Cristian Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Feb 5, 2020
1 parent 7365426 commit 65179f8
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,18 @@ public void add(double delta) {
}
}

static final class Builder extends AbstractCounterBuilder<DoubleCounter.Builder, DoubleCounter>
static DoubleCounter.Builder builder(String name) {
return new Builder(name);
}

private static final class Builder
extends AbstractCounterBuilder<DoubleCounter.Builder, DoubleCounter>
implements DoubleCounter.Builder {

private Builder(String name) {
super(name);
}

static DoubleCounter.Builder builder(String name) {
return new Builder(name);
}

@Override
Builder getThis() {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,18 @@ public void record(double value) {
}
}

static final class Builder extends AbstractMeasureBuilder<DoubleMeasure.Builder, DoubleMeasure>
static DoubleMeasure.Builder builder(String name) {
return new Builder(name);
}

private static final class Builder
extends AbstractMeasureBuilder<DoubleMeasure.Builder, DoubleMeasure>
implements DoubleMeasure.Builder {

private Builder(String name) {
super(name);
}

static DoubleMeasure.Builder builder(String name) {
return new Builder(name);
}

@Override
Builder getThis() {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,18 @@ public void add(long delta) {
}
}

static final class Builder extends AbstractCounterBuilder<LongCounter.Builder, LongCounter>
static LongCounter.Builder builder(String name) {
return new Builder(name);
}

private static final class Builder
extends AbstractCounterBuilder<LongCounter.Builder, LongCounter>
implements LongCounter.Builder {

private Builder(String name) {
super(name);
}

static LongCounter.Builder builder(String name) {
return new Builder(name);
}

@Override
Builder getThis() {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,18 @@ public void record(long value) {
}
}

static final class Builder extends AbstractMeasureBuilder<LongMeasure.Builder, LongMeasure>
static LongMeasure.Builder builder(String name) {
return new Builder(name);
}

private static final class Builder
extends AbstractMeasureBuilder<LongMeasure.Builder, LongMeasure>
implements LongMeasure.Builder {

private Builder(String name) {
super(name);
}

static LongMeasure.Builder builder(String name) {
return new Builder(name);
}

@Override
Builder getThis() {
return this;
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ public DoubleGauge.Builder doubleGaugeBuilder(String name) {

@Override
public DoubleCounter.Builder doubleCounterBuilder(String name) {
return DoubleCounterSdk.Builder.builder(name);
return DoubleCounterSdk.builder(name);
}

@Override
public LongCounter.Builder longCounterBuilder(String name) {
return LongCounterSdk.Builder.builder(name);
return LongCounterSdk.builder(name);
}

@Override
public DoubleMeasure.Builder doubleMeasureBuilder(String name) {
return DoubleMeasureSdk.Builder.builder(name);
return DoubleMeasureSdk.builder(name);
}

@Override
public LongMeasure.Builder longMeasureBuilder(String name) {
return LongMeasureSdk.Builder.builder(name);
return LongMeasureSdk.builder(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testDoubleCounter() {
LabelSet labelSet = testSdk.createLabelSet("K", "v");

DoubleCounter doubleCounter =
DoubleCounterSdk.Builder.builder("testCounter")
DoubleCounterSdk.builder("testCounter")
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
.setLabelKeys(Collections.singletonList("sk1"))
.setDescription("My very own counter")
Expand All @@ -64,7 +64,7 @@ public void testDoubleCounter() {
@Test
public void testDoubleCounter_monotonicity() {
DoubleCounter doubleCounter =
DoubleCounterSdk.Builder.builder("testCounter").setMonotonic(true).build();
DoubleCounterSdk.builder("testCounter").setMonotonic(true).build();

thrown.expect(IllegalArgumentException.class);
doubleCounter.add(-45.77d, testSdk.createLabelSet());
Expand All @@ -73,7 +73,7 @@ public void testDoubleCounter_monotonicity() {
@Test
public void testBoundDoubleCounter_monotonicity() {
DoubleCounter doubleCounter =
DoubleCounterSdk.Builder.builder("testCounter").setMonotonic(true).build();
DoubleCounterSdk.builder("testCounter").setMonotonic(true).build();

thrown.expect(IllegalArgumentException.class);
doubleCounter.bind(testSdk.createLabelSet()).add(-9.3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testDoubleMeasure() {
LabelSet labelSet = testSdk.createLabelSet("K", "v");

DoubleMeasure doubleMeasure =
DoubleMeasureSdk.Builder.builder("testMeasure")
DoubleMeasureSdk.builder("testMeasure")
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
.setLabelKeys(Collections.singletonList("sk1"))
.setDescription("My very own double measure")
Expand All @@ -63,17 +63,15 @@ public void testDoubleMeasure() {

@Test
public void testDoubleMeasure_absolute() {
DoubleMeasure doubleMeasure =
DoubleMeasureSdk.Builder.builder("testMeasure").setAbsolute(true).build();
DoubleMeasure doubleMeasure = DoubleMeasureSdk.builder("testMeasure").setAbsolute(true).build();

thrown.expect(IllegalArgumentException.class);
doubleMeasure.record(-45.77d, testSdk.createLabelSet());
}

@Test
public void testBoundDoubleMeasure_absolute() {
DoubleMeasure doubleMeasure =
DoubleMeasureSdk.Builder.builder("testMeasure").setAbsolute(true).build();
DoubleMeasure doubleMeasure = DoubleMeasureSdk.builder("testMeasure").setAbsolute(true).build();

thrown.expect(IllegalArgumentException.class);
doubleMeasure.bind(testSdk.createLabelSet()).record(-9.3f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testLongCounter() {
LabelSet labelSet = testSdk.createLabelSet("K", "v");

LongCounter longCounter =
LongCounterSdk.Builder.builder("testCounter")
LongCounterSdk.builder("testCounter")
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
.setLabelKeys(Collections.singletonList("sk1"))
.setDescription("My very own counter")
Expand All @@ -63,17 +63,15 @@ public void testLongCounter() {

@Test
public void testLongCounter_monotonicity() {
LongCounter longCounter =
LongCounterSdk.Builder.builder("testCounter").setMonotonic(true).build();
LongCounter longCounter = LongCounterSdk.builder("testCounter").setMonotonic(true).build();

thrown.expect(IllegalArgumentException.class);
longCounter.add(-45, testSdk.createLabelSet());
}

@Test
public void testBoundLongCounter_monotonicity() {
LongCounter longCounter =
LongCounterSdk.Builder.builder("testCounter").setMonotonic(true).build();
LongCounter longCounter = LongCounterSdk.builder("testCounter").setMonotonic(true).build();

thrown.expect(IllegalArgumentException.class);
longCounter.bind(testSdk.createLabelSet()).add(-9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testLongMeasure() {
LabelSet labelSet = testSdk.createLabelSet("K", "v");

LongMeasure longMeasure =
LongMeasureSdk.Builder.builder("testMeasure")
LongMeasureSdk.builder("testMeasure")
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
.setLabelKeys(Collections.singletonList("sk1"))
.setDescription("My very own measure")
Expand All @@ -63,17 +63,15 @@ public void testLongMeasure() {

@Test
public void testLongMeasure_absolute() {
LongMeasure longMeasure =
LongMeasureSdk.Builder.builder("testMeasure").setAbsolute(true).build();
LongMeasure longMeasure = LongMeasureSdk.builder("testMeasure").setAbsolute(true).build();

thrown.expect(IllegalArgumentException.class);
longMeasure.record(-45, testSdk.createLabelSet());
}

@Test
public void testBoundLongMeasure_absolute() {
LongMeasure longMeasure =
LongMeasureSdk.Builder.builder("testMeasure").setAbsolute(true).build();
LongMeasure longMeasure = LongMeasureSdk.builder("testMeasure").setAbsolute(true).build();

thrown.expect(IllegalArgumentException.class);
longMeasure.bind(testSdk.createLabelSet()).record(-9);
Expand Down

0 comments on commit 65179f8

Please sign in to comment.