mirror of
https://github.com/google/nomulus.git
synced 2025-06-29 07:43:37 +02:00
Bucket RDAP metrics by type (#220)
* Bucket RDAP metrics by type * Rename method * Use Guava Splitter and a joining Collector * Use Iterables.limit * Whoops, extra paren * Checkstyle
This commit is contained in:
parent
efcd57eea4
commit
13b1c0b352
1 changed files with 17 additions and 1 deletions
|
@ -16,12 +16,17 @@ package google.registry.request;
|
|||
|
||||
import static com.google.monitoring.metrics.EventMetric.DEFAULT_FITTER;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.monitoring.metrics.EventMetric;
|
||||
import com.google.monitoring.metrics.LabelDescriptor;
|
||||
import com.google.monitoring.metrics.MetricRegistryImpl;
|
||||
import google.registry.request.auth.AuthLevel;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.joda.time.Duration;
|
||||
|
||||
class RequestMetrics {
|
||||
|
@ -50,7 +55,7 @@ class RequestMetrics {
|
|||
Duration duration, String path, Action.Method method, AuthLevel authLevel, boolean success) {
|
||||
requestDurationMetric.record(
|
||||
duration.getMillis(),
|
||||
path,
|
||||
truncatePath(path),
|
||||
String.valueOf(method),
|
||||
String.valueOf(authLevel),
|
||||
String.valueOf(success));
|
||||
|
@ -58,4 +63,15 @@ class RequestMetrics {
|
|||
"Action called for path=%s, method=%s, authLevel=%s, success=%s. Took: %.3fs",
|
||||
path, method, authLevel, success, duration.getMillis() / 1000d);
|
||||
}
|
||||
|
||||
private static String truncatePath(String path) {
|
||||
// We want to bucket RDAP requests by type to use less metric space,
|
||||
// e.g. "/rdap/domains" rather than "/rdap/domains/foo.tld"
|
||||
if (path.startsWith("/rdap")) {
|
||||
List<String> splitPath = Splitter.on("/").omitEmptyStrings().splitToList(path);
|
||||
return Streams.stream(Iterables.limit(splitPath, 2))
|
||||
.collect(Collectors.joining("/", "/", "/"));
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue