Skip to content

Commit d255698

Browse files
committed
add interface to spectator monitors
This interface would allow us to detect when polling whether or not the monitor type reports directly to spectator or would need to be sent in separately.
1 parent cac574b commit d255698

File tree

13 files changed

+78
-30
lines changed

13 files changed

+78
-30
lines changed

servo-core/src/main/java/com/netflix/servo/monitor/AnnotatedNumberMonitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
/**
2626
* Wraps an annotated field and exposes it as a numeric monitor object.
2727
*/
28-
class AnnotatedNumberMonitor extends AbstractMonitor<Number> implements NumericMonitor<Number> {
28+
class AnnotatedNumberMonitor extends AbstractMonitor<Number>
29+
implements NumericMonitor<Number>, SpectatorMonitor {
2930

3031
private final Object object;
3132
private final AccessibleObject field;

servo-core/src/main/java/com/netflix/servo/monitor/BasicCounter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
* The value is the total count for the life of the counter. Observers are responsible
2626
* for converting to a rate and handling overflows if they occur.
2727
*/
28-
public final class BasicCounter extends AbstractMonitor<Number> implements Counter {
28+
public final class BasicCounter extends AbstractMonitor<Number>
29+
implements Counter, SpectatorMonitor {
2930
private final AtomicLong count = new AtomicLong();
3031
private final com.netflix.spectator.api.Counter spectatorCounter;
3132

servo-core/src/main/java/com/netflix/servo/monitor/BasicGauge.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
/**
2525
* A gauge implementation that invokes a specified callable to get the current value.
2626
*/
27-
public final class BasicGauge<T extends Number> extends AbstractMonitor<T> implements Gauge<T> {
27+
public final class BasicGauge<T extends Number> extends AbstractMonitor<T>
28+
implements Gauge<T>, SpectatorMonitor {
2829
private final Callable<T> function;
2930

3031
/**

servo-core/src/main/java/com/netflix/servo/monitor/BasicTimer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
* A simple timer implementation providing the total time, count, min, and max for the times that
2929
* have been recorded.
3030
*/
31-
public class BasicTimer extends AbstractMonitor<Long> implements Timer, CompositeMonitor<Long> {
31+
public class BasicTimer extends AbstractMonitor<Long>
32+
implements Timer, CompositeMonitor<Long>, SpectatorMonitor {
3233

3334
private static final String STATISTIC = "statistic";
3435
private static final String UNIT = "unit";

servo-core/src/main/java/com/netflix/servo/monitor/DoubleCounter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/**
2-
* Copyright 2015 Netflix, Inc.
1+
/*
2+
* Copyright 2011-2018 Netflix, Inc.
33
* <p/>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,8 @@
2828
* The value returned is a rate for the
2929
* previous interval as defined by the step.
3030
*/
31-
class DoubleCounter extends AbstractMonitor<Number> implements NumericMonitor<Number> {
31+
class DoubleCounter extends AbstractMonitor<Number>
32+
implements NumericMonitor<Number>, SpectatorMonitor {
3233

3334
private final StepLong count;
3435
private final com.netflix.spectator.api.Counter spectatorCounter;

servo-core/src/main/java/com/netflix/servo/monitor/DoubleGauge.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/**
2-
* Copyright 2013 Netflix, Inc.
1+
/*
2+
* Copyright 2011-2018 Netflix, Inc.
33
* <p/>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,11 +17,13 @@
1717

1818
import com.google.common.util.concurrent.AtomicDouble;
1919
import com.netflix.servo.SpectatorContext;
20+
import com.netflix.servo.annotations.DataSourceType;
2021

2122
/**
2223
* A {@link Gauge} that reports a double value.
2324
*/
24-
public class DoubleGauge extends NumberGauge {
25+
public class DoubleGauge extends AbstractMonitor<Double>
26+
implements Gauge<Double>, SpectatorMonitor {
2527
private final AtomicDouble number;
2628
private final com.netflix.spectator.api.Gauge spectatorGauge;
2729

@@ -31,9 +33,8 @@ public class DoubleGauge extends NumberGauge {
3133
* @param config configuration for this gauge
3234
*/
3335
public DoubleGauge(MonitorConfig config) {
34-
super(config);
36+
super(config.withAdditionalTag(DataSourceType.GAUGE));
3537
number = new AtomicDouble(0.0);
36-
setBackingNumber(number);
3738
spectatorGauge = SpectatorContext.gauge(config);
3839
}
3940

@@ -86,9 +87,17 @@ public int hashCode() {
8687
* {@inheritDoc}
8788
*/
8889
@Override
89-
public Number getValue(int pollerIdx) {
90+
public Double getValue(int pollerIdx) {
9091
// we return the actual value at the time of the call and not a reference
9192
// to the atomic number so the value doesn't change and is also available to jmx viewers
9293
return number.get();
9394
}
95+
96+
/**
97+
* {@inheritDoc}
98+
*/
99+
@Override
100+
public String toString() {
101+
return "DoubleGauge{config=" + config + ", number=" + number + '}';
102+
}
94103
}

servo-core/src/main/java/com/netflix/servo/monitor/DoubleMaxGauge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* non-negative, the reset value is 0.
2828
*/
2929
public class DoubleMaxGauge extends AbstractMonitor<Double>
30-
implements Gauge<Double> {
30+
implements Gauge<Double>, SpectatorMonitor {
3131
private final StepLong max;
3232
private final com.netflix.spectator.api.Gauge spectatorGauge;
3333

servo-core/src/main/java/com/netflix/servo/monitor/LongGauge.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/**
2-
* Copyright 2013 Netflix, Inc.
1+
/*
2+
* Copyright 2011-2018 Netflix, Inc.
33
* <p/>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,15 @@
1616
package com.netflix.servo.monitor;
1717

1818
import com.netflix.servo.SpectatorContext;
19+
import com.netflix.servo.annotations.DataSourceType;
1920

2021
import java.util.concurrent.atomic.AtomicLong;
2122

2223
/**
2324
* A {@link Gauge} that reports a long value.
2425
*/
25-
public class LongGauge extends NumberGauge {
26+
public class LongGauge extends AbstractMonitor<Long>
27+
implements Gauge<Long>, SpectatorMonitor {
2628
private final AtomicLong number;
2729
private final com.netflix.spectator.api.Gauge spectatorGauge;
2830

@@ -32,9 +34,8 @@ public class LongGauge extends NumberGauge {
3234
* @param config configuration for this gauge
3335
*/
3436
public LongGauge(MonitorConfig config) {
35-
super(config);
37+
super(config.withAdditionalTag(DataSourceType.GAUGE));
3638
number = new AtomicLong(0L);
37-
setBackingNumber(number);
3839
spectatorGauge = SpectatorContext.gauge(config);
3940
}
4041

@@ -85,9 +86,17 @@ public int hashCode() {
8586
* {@inheritDoc}
8687
*/
8788
@Override
88-
public Number getValue(int pollerIdx) {
89+
public Long getValue(int pollerIdx) {
8990
// we return the actual value at the time of the call and not a reference
9091
// to the atomic number so the value doesn't change and is also available to jmx viewers
9192
return number.get();
9293
}
94+
95+
/**
96+
* {@inheritDoc}
97+
*/
98+
@Override
99+
public String toString() {
100+
return "LongGauge{config=" + config + ", number=" + number + '}';
101+
}
93102
}

servo-core/src/main/java/com/netflix/servo/monitor/MaxGauge.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/**
2-
* Copyright 2013 Netflix, Inc.
1+
/*
2+
* Copyright 2011-2018 Netflix, Inc.
33
* <p/>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
* non-negative, the reset value is 0.
2828
*/
2929
public class MaxGauge extends AbstractMonitor<Long>
30-
implements Gauge<Long> {
30+
implements Gauge<Long>, SpectatorMonitor {
3131
private final StepLong max;
3232
private final com.netflix.spectator.api.Gauge spectatorGauge;
3333

servo-core/src/main/java/com/netflix/servo/monitor/NumberGauge.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
/**
2626
* A {@link Gauge} that returns the value stored in {@link Number}.
2727
*/
28-
public class NumberGauge extends AbstractMonitor<Number> implements Gauge<Number> {
28+
public class NumberGauge extends AbstractMonitor<Number>
29+
implements Gauge<Number>, SpectatorMonitor {
2930
private WeakReference<Number> numberRef;
3031

3132
/**

0 commit comments

Comments
 (0)