Remove long values from stats, not too much value added, only complexity. (#114)
This commit is contained in:
parent
e313e97821
commit
b06d642293
|
|
@ -20,8 +20,6 @@ import javax.annotation.concurrent.NotThreadSafe;
|
|||
import openconsensus.internal.Utils;
|
||||
import openconsensus.metrics.data.AttachmentValue;
|
||||
import openconsensus.stats.data.Measure;
|
||||
import openconsensus.stats.data.Measure.MeasureDouble;
|
||||
import openconsensus.stats.data.Measure.MeasureLong;
|
||||
import openconsensus.tags.TagMap;
|
||||
|
||||
/**
|
||||
|
|
@ -33,26 +31,15 @@ import openconsensus.tags.TagMap;
|
|||
public abstract class MeasureMap {
|
||||
|
||||
/**
|
||||
* Associates the {@link MeasureDouble} with the given value. Subsequent updates to the same
|
||||
* {@link MeasureDouble} will overwrite the previous value.
|
||||
* Associates the {@link Measure} with the given value. Subsequent updates to the same {@link
|
||||
* Measure} will overwrite the previous value.
|
||||
*
|
||||
* @param measure the {@link MeasureDouble}
|
||||
* @param measure the {@link Measure}
|
||||
* @param value the value to be associated with {@code measure}
|
||||
* @return this
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract MeasureMap put(MeasureDouble measure, double value);
|
||||
|
||||
/**
|
||||
* Associates the {@link MeasureLong} with the given value. Subsequent updates to the same {@link
|
||||
* MeasureLong} will overwrite the previous value.
|
||||
*
|
||||
* @param measure the {@link MeasureLong}
|
||||
* @param value the value to be associated with {@code measure}
|
||||
* @return this
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract MeasureMap put(MeasureLong measure, long value);
|
||||
public abstract MeasureMap put(Measure measure, double value);
|
||||
|
||||
/**
|
||||
* Associate the contextual information of an {@code Exemplar} to this {@link MeasureMap}.
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@ import java.util.List;
|
|||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.stats.data.Measure.MeasureDouble;
|
||||
import openconsensus.stats.data.Measure.MeasureLong;
|
||||
import openconsensus.stats.data.Measure;
|
||||
import openconsensus.stats.view.ViewComponent;
|
||||
import openconsensus.stats.view.ViewManager;
|
||||
import openconsensus.stats.view.data.View;
|
||||
|
|
@ -81,17 +80,11 @@ final class NoopStats {
|
|||
|
||||
private static final class NoopMeasureMap extends MeasureMap {
|
||||
@Override
|
||||
public MeasureMap put(MeasureDouble measure, double value) {
|
||||
public MeasureMap put(Measure measure, double value) {
|
||||
Utils.checkArgument(value >= 0.0, "Unsupported negative values.");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MeasureMap put(MeasureLong measure, long value) {
|
||||
Utils.checkArgument(value >= 0, "Unsupported negative values.");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void record() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@ import openconsensus.internal.Utils;
|
|||
* @since 0.1.0
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract class Measure {
|
||||
static final int NAME_MAX_LENGTH = 255;
|
||||
private static final int NAME_MAX_LENGTH = 255;
|
||||
private static final String ERROR_MESSAGE_INVALID_NAME =
|
||||
"Name should be a ASCII string with a length no greater than "
|
||||
+ NAME_MAX_LENGTH
|
||||
|
|
@ -69,109 +70,22 @@ public abstract class Measure {
|
|||
*/
|
||||
public abstract String getUnit();
|
||||
|
||||
/**
|
||||
* Returns a {@code Type} corresponding to the underlying value of this {@code Measure}.
|
||||
*
|
||||
* @return the {@code Type} for the value of this {@code Measure}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract Type getType();
|
||||
|
||||
// Prevents this class from being subclassed anywhere else.
|
||||
private Measure() {}
|
||||
Measure() {}
|
||||
|
||||
/**
|
||||
* {@link Measure} with {@code Double} typed values.
|
||||
* Constructs a new {@link Measure}.
|
||||
*
|
||||
* @param name name of {@code Measure}. Suggested format: {@code <web_host>/<path>}.
|
||||
* @param description description of {@code Measure}.
|
||||
* @param unit unit of {@code Measure}.
|
||||
* @return a {@code Measure}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract static class MeasureDouble extends Measure {
|
||||
|
||||
MeasureDouble() {}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link MeasureDouble}.
|
||||
*
|
||||
* @param name name of {@code Measure}. Suggested format: {@code <web_host>/<path>}.
|
||||
* @param description description of {@code Measure}.
|
||||
* @param unit unit of {@code Measure}.
|
||||
* @return a {@code MeasureDouble}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static MeasureDouble create(String name, String description, String unit) {
|
||||
Utils.checkArgument(
|
||||
StringUtils.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH,
|
||||
ERROR_MESSAGE_INVALID_NAME);
|
||||
return new AutoValue_Measure_MeasureDouble(name, description, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String getName();
|
||||
|
||||
@Override
|
||||
public abstract String getDescription();
|
||||
|
||||
@Override
|
||||
public abstract String getUnit();
|
||||
|
||||
@Override
|
||||
public final Type getType() {
|
||||
return Type.DOUBLE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Measure} with {@code Long} typed values.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract static class MeasureLong extends Measure {
|
||||
|
||||
MeasureLong() {}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link MeasureLong}.
|
||||
*
|
||||
* @param name name of {@code Measure}. Suggested format: {@code <web_host>/<path>}.
|
||||
* @param description description of {@code Measure}.
|
||||
* @param unit unit of {@code Measure}.
|
||||
* @return a {@code MeasureLong}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static MeasureLong create(String name, String description, String unit) {
|
||||
Utils.checkArgument(
|
||||
StringUtils.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH,
|
||||
ERROR_MESSAGE_INVALID_NAME);
|
||||
return new AutoValue_Measure_MeasureLong(name, description, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String getName();
|
||||
|
||||
@Override
|
||||
public abstract String getDescription();
|
||||
|
||||
@Override
|
||||
public abstract String getUnit();
|
||||
|
||||
@Override
|
||||
public final Type getType() {
|
||||
return Type.LONG;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An enum that represents all the possible value types for a {@code Measure} or a {@code
|
||||
* Measurement}.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public enum Type {
|
||||
LONG,
|
||||
DOUBLE
|
||||
public static Measure create(String name, String description, String unit) {
|
||||
Utils.checkArgument(
|
||||
StringUtils.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH,
|
||||
ERROR_MESSAGE_INVALID_NAME);
|
||||
return new AutoValue_Measure(name, description, unit);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,15 +18,14 @@ package openconsensus.stats.data;
|
|||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import openconsensus.stats.data.Measure.MeasureDouble;
|
||||
import openconsensus.stats.data.Measure.MeasureLong;
|
||||
|
||||
/**
|
||||
* Immutable representation of a Measurement.
|
||||
* Immutable representation of a measurement.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract class Measurement {
|
||||
|
||||
/**
|
||||
|
|
@ -37,98 +36,22 @@ public abstract class Measurement {
|
|||
public abstract Measure getMeasure();
|
||||
|
||||
/**
|
||||
* Returns the double value for the {@link Measurement}.
|
||||
* Returns the value for the {@link Measurement}.
|
||||
*
|
||||
* <p>This method should only be called with {@link MeasurementDouble}.
|
||||
*
|
||||
* @return the double value.
|
||||
* @return the value.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public double getDoubleValue() {
|
||||
throw new UnsupportedOperationException(
|
||||
String.format("This type can only return %s data", getType().name()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long value for the {@link Measurement}.
|
||||
*
|
||||
* <p>This method should only be called with {@link MeasurementLong}.
|
||||
*
|
||||
* @return the long value.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public long getLongValue() {
|
||||
throw new UnsupportedOperationException(
|
||||
String.format("This type can only return %s data", getType().name()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code Measure.Type} corresponding to the underlying value of this {@code
|
||||
* Measurement}.
|
||||
*
|
||||
* @return the {@code Measure.Type} for the value of this {@code Measurement}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract Measure.Type getType();
|
||||
public abstract double getValue();
|
||||
|
||||
// Prevents this class from being subclassed anywhere else.
|
||||
private Measurement() {}
|
||||
Measurement() {}
|
||||
|
||||
/**
|
||||
* {@code Double} typed {@link Measurement}.
|
||||
* Constructs a new {@link Measurement}.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract static class MeasurementDouble extends Measurement {
|
||||
MeasurementDouble() {}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link MeasurementDouble}.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static MeasurementDouble create(MeasureDouble measure, double value) {
|
||||
return new AutoValue_Measurement_MeasurementDouble(measure, value, Measure.Type.DOUBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract MeasureDouble getMeasure();
|
||||
|
||||
@Override
|
||||
public abstract double getDoubleValue();
|
||||
|
||||
@Override
|
||||
public abstract Measure.Type getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code Long} typed {@link Measurement}.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract static class MeasurementLong extends Measurement {
|
||||
MeasurementLong() {}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link MeasurementLong}.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static MeasurementLong create(MeasureLong measure, long value) {
|
||||
return new AutoValue_Measurement_MeasurementLong(measure, value, Measure.Type.LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract MeasureLong getMeasure();
|
||||
|
||||
@Override
|
||||
public abstract long getLongValue();
|
||||
|
||||
@Override
|
||||
public abstract Measure.Type getType();
|
||||
public static Measurement create(Measure measure, double value) {
|
||||
return new AutoValue_Measurement(measure, value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue