Convert class for metric field to AutoValue

This reduces the number of static methods for creating fields and allows
us to extend the Field class in future.

Change-Id: Ieaaacddd03b1e04e4e91f000eff950ecb292ec25
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2019-06-26 11:12:14 +02:00
parent 9ded2760b0
commit 441ac9783d
22 changed files with 144 additions and 175 deletions

View File

@@ -28,15 +28,18 @@ public class RequestMetrics {
@Inject @Inject
public RequestMetrics(MetricMaker metricMaker) { public RequestMetrics(MetricMaker metricMaker) {
Field<Integer> statusCodeField =
Field.ofInteger("status").description("HTTP status code").build();
errors = errors =
metricMaker.newCounter( metricMaker.newCounter(
"http/server/error_count", "http/server/error_count",
new Description("Rate of REST API error responses").setRate().setUnit("errors"), new Description("Rate of REST API error responses").setRate().setUnit("errors"),
Field.ofInteger("status", "HTTP status code")); statusCodeField);
successes = successes =
metricMaker.newCounter( metricMaker.newCounter(
"http/server/success_count", "http/server/success_count",
new Description("Rate of REST API success responses").setRate().setUnit("successes"), new Description("Rate of REST API success responses").setRate().setUnit("successes"),
Field.ofInteger("status", "HTTP status code")); statusCodeField);
} }
} }

View File

@@ -41,19 +41,20 @@ public class RestApiMetrics {
@Inject @Inject
RestApiMetrics(MetricMaker metrics) { RestApiMetrics(MetricMaker metrics) {
Field<String> view = Field.ofString("view", "view implementation class"); Field<String> viewField =
Field.ofString("view").description("view implementation class").build();
count = count =
metrics.newCounter( metrics.newCounter(
"http/server/rest_api/count", "http/server/rest_api/count",
new Description("REST API calls by view").setRate(), new Description("REST API calls by view").setRate(),
view); viewField);
errorCount = errorCount =
metrics.newCounter( metrics.newCounter(
"http/server/rest_api/error_count", "http/server/rest_api/error_count",
new Description("REST API errors by view").setRate(), new Description("REST API errors by view").setRate(),
view, viewField,
Field.ofInteger("error_code", "HTTP status code")); Field.ofInteger("error_code").description("HTTP status code").build());
serverLatency = serverLatency =
metrics.newTimer( metrics.newTimer(
@@ -61,7 +62,7 @@ public class RestApiMetrics {
new Description("REST API call latency by view") new Description("REST API call latency by view")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
view); viewField);
responseBytes = responseBytes =
metrics.newHistogram( metrics.newHistogram(
@@ -69,7 +70,7 @@ public class RestApiMetrics {
new Description("Size of response on network (may be gzip compressed)") new Description("Size of response on network (may be gzip compressed)")
.setCumulative() .setCumulative()
.setUnit(Units.BYTES), .setUnit(Units.BYTES),
view); viewField);
} }
String view(ViewData viewData) { String view(ViewData viewData) {

View File

@@ -60,14 +60,13 @@ public abstract class QueryProcessor<T> {
final Timer1<String> executionTime; final Timer1<String> executionTime;
Metrics(MetricMaker metricMaker) { Metrics(MetricMaker metricMaker) {
Field<String> index = Field.ofString("index", "index name");
executionTime = executionTime =
metricMaker.newTimer( metricMaker.newTimer(
"query/query_latency", "query/query_latency",
new Description("Successful query latency, accumulated over the life of the process") new Description("Successful query latency, accumulated over the life of the process")
.setCumulative() .setCumulative()
.setUnit(Description.Units.MILLISECONDS), .setUnit(Description.Units.MILLISECONDS),
index); Field.ofString("index").description("index name").build());
} }
} }

View File

@@ -8,6 +8,8 @@ java_library(
"//java/com/google/gerrit/lifecycle", "//java/com/google/gerrit/lifecycle",
"//java/com/google/gerrit/server/logging", "//java/com/google/gerrit/server/logging",
"//lib:guava", "//lib:guava",
"//lib/auto:auto-value",
"//lib/auto:auto-value-annotations",
"//lib/flogger:api", "//lib/flogger:api",
"//lib/guice", "//lib/guice",
"//lib/jgit/org.eclipse.jgit:jgit", "//lib/jgit/org.eclipse.jgit:jgit",

View File

@@ -16,6 +16,8 @@ package com.google.gerrit.metrics;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import com.google.auto.value.AutoValue;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
/** /**
@@ -23,26 +25,19 @@ import java.util.function.Function;
* *
* @param <T> type of field * @param <T> type of field
*/ */
public class Field<T> { @AutoValue
public abstract class Field<T> {
/** /**
* Break down metrics by boolean true/false. * Break down metrics by boolean true/false.
* *
* @param name field name * @param name field name
* @return boolean field * @return builder for the boolean field
*/ */
public static Field<Boolean> ofBoolean(String name) { public static Field.Builder<Boolean> ofBoolean(String name) {
return ofBoolean(name, null); return new AutoValue_Field.Builder<Boolean>()
} .valueType(Boolean.class)
.formatter(Object::toString)
/** .name(name);
* Break down metrics by boolean true/false.
*
* @param name field name
* @param description field description
* @return boolean field
*/
public static Field<Boolean> ofBoolean(String name, String description) {
return new Field<>(name, Boolean.class, description);
} }
/** /**
@@ -50,50 +45,10 @@ public class Field<T> {
* *
* @param enumType type of enum * @param enumType type of enum
* @param name field name * @param name field name
* @return enum field * @return builder for the enum field
*/ */
public static <E extends Enum<E>> Field<E> ofEnum(Class<E> enumType, String name) { public static <E extends Enum<E>> Field.Builder<E> ofEnum(Class<E> enumType, String name) {
return ofEnum(enumType, name, null); return new AutoValue_Field.Builder<E>().valueType(enumType).formatter(Enum::name).name(name);
}
/**
* Break down metrics by cases of an enum.
*
* @param enumType type of enum
* @param name field name
* @param description field description
* @return enum field
*/
public static <E extends Enum<E>> Field<E> ofEnum(
Class<E> enumType, String name, String description) {
return new Field<>(name, enumType, description);
}
/**
* Break down metrics by string.
*
* <p>Each unique string will allocate a new submetric. <b>Do not use user content as a field
* value</b> as field values are never reclaimed.
*
* @param name field name
* @return string field
*/
public static Field<String> ofString(String name) {
return ofString(name, null);
}
/**
* Break down metrics by string.
*
* <p>Each unique string will allocate a new submetric. <b>Do not use user content as a field
* value</b> as field values are never reclaimed.
*
* @param name field name
* @param description field description
* @return string field
*/
public static Field<String> ofString(String name, String description) {
return new Field<>(name, String.class, description);
} }
/** /**
@@ -103,66 +58,59 @@ public class Field<T> {
* value</b> as field values are never reclaimed. * value</b> as field values are never reclaimed.
* *
* @param name field name * @param name field name
* @return integer field * @return builder for the integer field
*/ */
public static Field<Integer> ofInteger(String name) { public static Field.Builder<Integer> ofInteger(String name) {
return ofInteger(name, null); return new AutoValue_Field.Builder<Integer>()
.valueType(Integer.class)
.formatter(Object::toString)
.name(name);
} }
/** /**
* Break down metrics by integer. * Break down metrics by string.
* *
* <p>Each unique integer will allocate a new submetric. <b>Do not use user content as a field * <p>Each unique string will allocate a new submetric. <b>Do not use user content as a field
* value</b> as field values are never reclaimed. * value</b> as field values are never reclaimed.
* *
* @param name field name * @param name field name
* @param description field description * @return builder for the string field
* @return integer field
*/ */
public static Field<Integer> ofInteger(String name, String description) { public static Field.Builder<String> ofString(String name) {
return new Field<>(name, Integer.class, description); return new AutoValue_Field.Builder<String>()
} .valueType(String.class)
.formatter(s -> s)
private final String name; .name(name);
private final Class<T> keyType;
private final Function<T, String> formatter;
private final String description;
private Field(String name, Class<T> keyType, String description) {
checkArgument(name.matches("^[a-z_]+$"), "name must match [a-z_]");
this.name = name;
this.keyType = keyType;
this.formatter = initFormatter(keyType);
this.description = description;
} }
/** @return name of this field within the metric. */ /** @return name of this field within the metric. */
public String getName() { public abstract String name();
return name;
}
/** @return type of value used within the field. */ /** @return type of value used within the field. */
public Class<T> getType() { public abstract Class<T> valueType();
return keyType;
}
/** @return description text for the field explaining its range of values. */ /** @return description text for the field explaining its range of values. */
public String getDescription() { public abstract Optional<String> description();
return description;
}
public Function<T, String> formatter() { /** @return formatter to format field values. */
return formatter; public abstract Function<T, String> formatter();
}
private static <T> Function<T, String> initFormatter(Class<T> keyType) { @AutoValue.Builder
if (keyType == String.class) { public abstract static class Builder<T> {
return s -> (String) s; abstract Builder<T> name(String name);
} else if (keyType == Integer.class || keyType == Boolean.class) {
return Object::toString; abstract Builder<T> valueType(Class<T> type);
} else if (Enum.class.isAssignableFrom(keyType)) {
return in -> ((Enum<?>) in).name(); abstract Builder<T> formatter(Function<T, String> formatter);
}
throw new IllegalStateException("unsupported type " + keyType.getName()); public abstract Builder<T> description(String description);
abstract Field<T> autoBuild();
public Field<T> build() {
Field<T> field = autoBuild();
checkArgument(field.name().matches("^[a-z_]+$"), "name must match [a-z_]");
return field;
}
} }
} }

View File

@@ -189,10 +189,10 @@ class MetricJson {
String description; String description;
FieldJson(Field<?> field) { FieldJson(Field<?> field) {
this.name = field.getName(); this.name = field.name();
this.description = field.getDescription(); this.description = field.description().orElse(null);
this.type = this.type =
Enum.class.isAssignableFrom(field.getType()) ? field.getType().getSimpleName() : null; Enum.class.isAssignableFrom(field.valueType()) ? field.valueType().getSimpleName() : null;
} }
} }
} }

View File

@@ -148,12 +148,15 @@ public class ProcMetricModule extends MetricModule {
} }
private void procJvmGc(MetricMaker metrics) { private void procJvmGc(MetricMaker metrics) {
Field<String> gcNameField =
Field.ofString("gc_name").description("The name of the garbage collector").build();
CallbackMetric1<String, Long> gcCount = CallbackMetric1<String, Long> gcCount =
metrics.newCallbackMetric( metrics.newCallbackMetric(
"proc/jvm/gc/count", "proc/jvm/gc/count",
Long.class, Long.class,
new Description("Number of GCs").setCumulative(), new Description("Number of GCs").setCumulative(),
Field.ofString("gc_name", "The name of the garbage collector")); gcNameField);
CallbackMetric1<String, Long> gcTime = CallbackMetric1<String, Long> gcTime =
metrics.newCallbackMetric( metrics.newCallbackMetric(
@@ -162,7 +165,7 @@ public class ProcMetricModule extends MetricModule {
new Description("Approximate accumulated GC elapsed time") new Description("Approximate accumulated GC elapsed time")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
Field.ofString("gc_name", "The name of the garbage collector")); gcNameField);
metrics.newTrigger( metrics.newTrigger(
gcCount, gcCount,

View File

@@ -33,7 +33,7 @@ import java.util.Set;
public class CacheMetrics { public class CacheMetrics {
@Inject @Inject
public CacheMetrics(MetricMaker metrics, DynamicMap<Cache<?, ?>> cacheMap) { public CacheMetrics(MetricMaker metrics, DynamicMap<Cache<?, ?>> cacheMap) {
Field<String> F_NAME = Field.ofString("cache_name"); Field<String> F_NAME = Field.ofString("cache_name").build();
CallbackMetric1<String, Long> memEnt = CallbackMetric1<String, Long> memEnt =
metrics.newCallbackMetric( metrics.newCallbackMetric(

View File

@@ -98,7 +98,7 @@ public class ChangeFinder {
new Description("Total number of API calls per identifier type.") new Description("Total number of API calls per identifier type.")
.setRate() .setRate()
.setUnit("requests"), .setUnit("requests"),
Field.ofEnum(ChangeIdType.class, "change_id_type")); Field.ofEnum(ChangeIdType.class, "change_id_type").build());
List<ChangeIdType> configuredChangeIdTypes = List<ChangeIdType> configuredChangeIdTypes =
ConfigUtil.getEnumList(config, "change", "api", "allowedIdentifier", ChangeIdType.ALL); ConfigUtil.getEnumList(config, "change", "api", "allowedIdentifier", ChangeIdType.ALL);
// Ensure that PROJECT_NUMERIC_ID can't be removed // Ensure that PROJECT_NUMERIC_ID can't be removed

View File

@@ -31,7 +31,7 @@ public class EventsMetrics implements EventListener {
metricMaker.newCounter( metricMaker.newCounter(
"events", "events",
new Description("Triggered events").setRate().setUnit("triggered events"), new Description("Triggered events").setRate().setUnit("triggered events"),
Field.ofString("type")); Field.ofString("type").build());
} }
@Override @Override

View File

@@ -71,7 +71,7 @@ public class UiActions {
new com.google.gerrit.metrics.Description("Latency for RestView#getDescription calls") new com.google.gerrit.metrics.Description("Latency for RestView#getDescription calls")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
Field.ofString("view")); Field.ofString("view").build());
} }
public <R extends RestResource> Iterable<UiAction.Description> from( public <R extends RestResource> Iterable<UiAction.Description> from(

View File

@@ -43,14 +43,14 @@ public class UploadPackMetricsHook implements PostUploadHook {
@Inject @Inject
UploadPackMetricsHook(MetricMaker metricMaker) { UploadPackMetricsHook(MetricMaker metricMaker) {
Field<Operation> operation = Field.ofEnum(Operation.class, "operation"); Field<Operation> operationField = Field.ofEnum(Operation.class, "operation").build();
requestCount = requestCount =
metricMaker.newCounter( metricMaker.newCounter(
"git/upload-pack/request_count", "git/upload-pack/request_count",
new Description("Total number of git-upload-pack requests") new Description("Total number of git-upload-pack requests")
.setRate() .setRate()
.setUnit("requests"), .setUnit("requests"),
operation); operationField);
counting = counting =
metricMaker.newTimer( metricMaker.newTimer(
@@ -58,7 +58,7 @@ public class UploadPackMetricsHook implements PostUploadHook {
new Description("Time spent in the 'Counting...' phase") new Description("Time spent in the 'Counting...' phase")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
operation); operationField);
compressing = compressing =
metricMaker.newTimer( metricMaker.newTimer(
@@ -66,7 +66,7 @@ public class UploadPackMetricsHook implements PostUploadHook {
new Description("Time spent in the 'Compressing...' phase") new Description("Time spent in the 'Compressing...' phase")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
operation); operationField);
writing = writing =
metricMaker.newTimer( metricMaker.newTimer(
@@ -74,7 +74,7 @@ public class UploadPackMetricsHook implements PostUploadHook {
new Description("Time spent transferring bytes to client") new Description("Time spent transferring bytes to client")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
operation); operationField);
packBytes = packBytes =
metricMaker.newHistogram( metricMaker.newHistogram(
@@ -82,7 +82,7 @@ public class UploadPackMetricsHook implements PostUploadHook {
new Description("Distribution of sizes of packs sent to clients") new Description("Distribution of sizes of packs sent to clients")
.setCumulative() .setCumulative()
.setUnit(Units.BYTES), .setUnit(Units.BYTES),
operation); operationField);
} }
@Override @Override

View File

@@ -199,7 +199,14 @@ public class AsyncReceiveCommits implements PreReceiveHook {
metricMaker.newHistogram( metricMaker.newHistogram(
"receivecommits/changes_per_push", "receivecommits/changes_per_push",
new Description("number of changes uploaded in a single push.").setCumulative(), new Description("number of changes uploaded in a single push.").setCumulative(),
Field.ofEnum(PushType.class, "type", "type of push (create/replace, autoclose)")); Field.ofEnum(PushType.class, "type")
.description("type of push (create/replace, autoclose)")
.build());
Field<PushType> pushTypeField =
Field.ofEnum(PushType.class, "type")
.description("type of push (create/replace, autoclose, normal)")
.build();
latencyPerChange = latencyPerChange =
metricMaker.newTimer( metricMaker.newTimer(
@@ -209,8 +216,7 @@ public class AsyncReceiveCommits implements PreReceiveHook {
+ "(Only includes pushes which contain changes.)") + "(Only includes pushes which contain changes.)")
.setUnit(Units.MILLISECONDS) .setUnit(Units.MILLISECONDS)
.setCumulative(), .setCumulative(),
Field.ofEnum( pushTypeField);
PushType.class, "type", "type of push (create/replace, autoclose, normal)"));
latencyPerPush = latencyPerPush =
metricMaker.newTimer( metricMaker.newTimer(
@@ -218,8 +224,7 @@ public class AsyncReceiveCommits implements PreReceiveHook {
new Description("processing delay for a processing single push") new Description("processing delay for a processing single push")
.setUnit(Units.MILLISECONDS) .setUnit(Units.MILLISECONDS)
.setCumulative(), .setCumulative(),
Field.ofEnum( pushTypeField);
PushType.class, "type", "type of push (create/replace, autoclose, normal)"));
timeouts = timeouts =
metricMaker.newCounter( metricMaker.newCounter(

View File

@@ -45,7 +45,7 @@ class NoteDbMetrics {
@Inject @Inject
NoteDbMetrics(MetricMaker metrics) { NoteDbMetrics(MetricMaker metrics) {
Field<NoteDbTable> view = Field.ofEnum(NoteDbTable.class, "table"); Field<NoteDbTable> tableField = Field.ofEnum(NoteDbTable.class, "table").build();
updateLatency = updateLatency =
metrics.newTimer( metrics.newTimer(
@@ -53,7 +53,7 @@ class NoteDbMetrics {
new Description("NoteDb update latency by table") new Description("NoteDb update latency by table")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
view); tableField);
stageUpdateLatency = stageUpdateLatency =
metrics.newTimer( metrics.newTimer(
@@ -61,7 +61,7 @@ class NoteDbMetrics {
new Description("Latency for staging updates to NoteDb by table") new Description("Latency for staging updates to NoteDb by table")
.setCumulative() .setCumulative()
.setUnit(Units.MICROSECONDS), .setUnit(Units.MICROSECONDS),
view); tableField);
readLatency = readLatency =
metrics.newTimer( metrics.newTimer(
@@ -69,7 +69,7 @@ class NoteDbMetrics {
new Description("NoteDb read latency by table") new Description("NoteDb read latency by table")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
view); tableField);
parseLatency = parseLatency =
metrics.newTimer( metrics.newTimer(
@@ -77,6 +77,6 @@ class NoteDbMetrics {
new Description("NoteDb parse latency by table") new Description("NoteDb parse latency by table")
.setCumulative() .setCumulative()
.setUnit(Units.MICROSECONDS), .setUnit(Units.MICROSECONDS),
view); tableField);
} }
} }

View File

@@ -95,8 +95,8 @@ public class Sequences {
new Description("Latency of requesting IDs from repo sequences") new Description("Latency of requesting IDs from repo sequences")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
Field.ofEnum(SequenceType.class, "sequence"), Field.ofEnum(SequenceType.class, "sequence").build(),
Field.ofBoolean("multiple")); Field.ofBoolean("multiple").build());
} }
public int nextAccountId() { public int nextAccountId() {

View File

@@ -118,22 +118,26 @@ public class PluginContext<T> {
@Inject @Inject
PluginMetrics(MetricMaker metricMaker) { PluginMetrics(MetricMaker metricMaker) {
Field<String> pluginNameField = Field.ofString("plugin_name").build();
Field<String> classNameField = Field.ofString("class_name").build();
Field<String> exportNameField = Field.ofString("export_name").build();
this.latency = this.latency =
metricMaker.newTimer( metricMaker.newTimer(
"plugin/latency", "plugin/latency",
new Description("Latency for plugin invocation") new Description("Latency for plugin invocation")
.setCumulative() .setCumulative()
.setUnit(Units.MILLISECONDS), .setUnit(Units.MILLISECONDS),
Field.ofString("plugin_name"), pluginNameField,
Field.ofString("class_name"), classNameField,
Field.ofString("export_name")); exportNameField);
this.errorCount = this.errorCount =
metricMaker.newCounter( metricMaker.newCounter(
"plugin/error_count", "plugin/error_count",
new Description("Number of plugin errors").setCumulative().setUnit("errors"), new Description("Number of plugin errors").setCumulative().setUnit("errors"),
Field.ofString("plugin_name"), pluginNameField,
Field.ofString("class_name"), classNameField,
Field.ofString("export_name")); exportNameField);
} }
Timer3.Context startLatency(Extension<?> extension) { Timer3.Context startLatency(Extension<?> extension) {

View File

@@ -135,7 +135,7 @@ public class ProjectState {
new Description("Latency for access computations in ProjectState") new Description("Latency for access computations in ProjectState")
.setCumulative() .setCumulative()
.setUnit(Units.NANOSECONDS), .setUnit(Units.NANOSECONDS),
Field.ofString("method")); Field.ofString("method").build());
if (isAllProjects && !Permission.canBeOnAllProjects(AccessSection.ALL, Permission.OWNER)) { if (isAllProjects && !Permission.canBeOnAllProjects(AccessSection.ALL, Permission.OWNER)) {
localOwners = Collections.emptySet(); localOwners = Collections.emptySet();

View File

@@ -111,7 +111,7 @@ public class RetryHelper {
@Inject @Inject
Metrics(MetricMaker metricMaker) { Metrics(MetricMaker metricMaker) {
Field<ActionType> view = Field.ofEnum(ActionType.class, "action_type"); Field<ActionType> actionTypeField = Field.ofEnum(ActionType.class, "action_type").build();
attemptCounts = attemptCounts =
metricMaker.newCounter( metricMaker.newCounter(
"action/retry_attempt_count", "action/retry_attempt_count",
@@ -120,7 +120,7 @@ public class RetryHelper {
+ " (0 == single attempt, no retry)") + " (0 == single attempt, no retry)")
.setCumulative() .setCumulative()
.setUnit("attempts"), .setUnit("attempts"),
view); actionTypeField);
timeoutCount = timeoutCount =
metricMaker.newCounter( metricMaker.newCounter(
"action/retry_timeout_count", "action/retry_timeout_count",
@@ -128,7 +128,7 @@ public class RetryHelper {
"Number of action executions of RetryHelper that ultimately timed out") "Number of action executions of RetryHelper that ultimately timed out")
.setCumulative() .setCumulative()
.setUnit("timeouts"), .setUnit("timeouts"),
view); actionTypeField);
} }
} }

View File

@@ -80,7 +80,9 @@ public class ProcMetricModuleTest {
public void counter1() { public void counter1() {
Counter1<String> cntr = Counter1<String> cntr =
metrics.newCounter( metrics.newCounter(
"test/count", new Description("simple test").setCumulative(), Field.ofString("action")); "test/count",
new Description("simple test").setCumulative(),
Field.ofString("action").build());
Counter total = get("test/count_total", Counter.class); Counter total = get("test/count_total", Counter.class);
assertThat(total.getCount()).isEqualTo(0); assertThat(total.getCount()).isEqualTo(0);
@@ -105,7 +107,7 @@ public class ProcMetricModuleTest {
new Description("simple test") new Description("simple test")
.setCumulative() .setCumulative()
.setFieldOrdering(FieldOrdering.PREFIX_FIELDS_BASENAME), .setFieldOrdering(FieldOrdering.PREFIX_FIELDS_BASENAME),
Field.ofString("action")); Field.ofString("action").build());
Counter total = get("test/count_total", Counter.class); Counter total = get("test/count_total", Counter.class);
assertThat(total.getCount()).isEqualTo(0); assertThat(total.getCount()).isEqualTo(0);

View File

@@ -230,24 +230,24 @@ public class PerformanceLogContextTest {
metricMaker.newTimer( metricMaker.newTimer(
"test2/latency", "test2/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo")); Field.ofString("foo").build());
timer1.start("value1").close(); timer1.start("value1").close();
Timer2<String, String> timer2 = Timer2<String, String> timer2 =
metricMaker.newTimer( metricMaker.newTimer(
"test3/latency", "test3/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo"), Field.ofString("foo").build(),
Field.ofString("bar")); Field.ofString("bar").build());
timer2.start("value1", "value2").close(); timer2.start("value1", "value2").close();
Timer3<String, String, String> timer3 = Timer3<String, String, String> timer3 =
metricMaker.newTimer( metricMaker.newTimer(
"test4/latency", "test4/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo"), Field.ofString("foo").build(),
Field.ofString("bar"), Field.ofString("bar").build(),
Field.ofString("baz")); Field.ofString("baz").build());
timer3.start("value1", "value2", "value3").close(); timer3.start("value1", "value2", "value3").close();
assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).hasSize(4); assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).hasSize(4);
@@ -289,24 +289,24 @@ public class PerformanceLogContextTest {
metricMaker.newTimer( metricMaker.newTimer(
"test1/latency", "test1/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo")); Field.ofString("foo").build());
timer1.start(null).close(); timer1.start(null).close();
Timer2<String, String> timer2 = Timer2<String, String> timer2 =
metricMaker.newTimer( metricMaker.newTimer(
"test2/latency", "test2/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo"), Field.ofString("foo").build(),
Field.ofString("bar")); Field.ofString("bar").build());
timer2.start(null, null).close(); timer2.start(null, null).close();
Timer3<String, String, String> timer3 = Timer3<String, String, String> timer3 =
metricMaker.newTimer( metricMaker.newTimer(
"test3/latency", "test3/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo"), Field.ofString("foo").build(),
Field.ofString("bar"), Field.ofString("bar").build(),
Field.ofString("baz")); Field.ofString("baz").build());
timer3.start(null, null, null).close(); timer3.start(null, null, null).close();
assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).hasSize(3); assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).hasSize(3);
@@ -345,24 +345,26 @@ public class PerformanceLogContextTest {
Timer1<String> timer1 = Timer1<String> timer1 =
metricMaker.newTimer( metricMaker.newTimer(
"test2/latency", new Description("Latency metric for testing"), Field.ofString("foo")); "test2/latency",
new Description("Latency metric for testing"),
Field.ofString("foo").build());
timer1.start("value1").close(); timer1.start("value1").close();
Timer2<String, String> timer2 = Timer2<String, String> timer2 =
metricMaker.newTimer( metricMaker.newTimer(
"test3/latency", "test3/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo"), Field.ofString("foo").build(),
Field.ofString("bar")); Field.ofString("bar").build());
timer2.start("value1", "value2").close(); timer2.start("value1", "value2").close();
Timer3<String, String, String> timer3 = Timer3<String, String, String> timer3 =
metricMaker.newTimer( metricMaker.newTimer(
"test4/latency", "test4/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo"), Field.ofString("foo").build(),
Field.ofString("bar"), Field.ofString("bar").build(),
Field.ofString("baz")); Field.ofString("baz").build());
timer3.start("value1", "value2", "value3").close(); timer3.start("value1", "value2", "value3").close();
assertThat(LoggingContext.getInstance().isPerformanceLogging()).isFalse(); assertThat(LoggingContext.getInstance().isPerformanceLogging()).isFalse();
@@ -391,24 +393,24 @@ public class PerformanceLogContextTest {
metricMaker.newTimer( metricMaker.newTimer(
"test2/latency", "test2/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo")); Field.ofString("foo").build());
timer1.start("value1").close(); timer1.start("value1").close();
Timer2<String, String> timer2 = Timer2<String, String> timer2 =
metricMaker.newTimer( metricMaker.newTimer(
"test3/latency", "test3/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo"), Field.ofString("foo").build(),
Field.ofString("bar")); Field.ofString("bar").build());
timer2.start("value1", "value2").close(); timer2.start("value1", "value2").close();
Timer3<String, String, String> timer3 = Timer3<String, String, String> timer3 =
metricMaker.newTimer( metricMaker.newTimer(
"test4/latency", "test4/latency",
new Description("Latency metric for testing"), new Description("Latency metric for testing"),
Field.ofString("foo"), Field.ofString("foo").build(),
Field.ofString("bar"), Field.ofString("bar").build(),
Field.ofString("baz")); Field.ofString("baz").build());
timer3.start("value1", "value2", "value3").close(); timer3.start("value1", "value2", "value3").close();
assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).isEmpty(); assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).isEmpty();