mirror of
https://github.com/google/nomulus.git
synced 2025-05-02 13:07:50 +02:00
The cardinality of this new metric is: buckets - 16 path + method - around 100 (the number of Actions we have) authLevel - at most 3 success - 2 Total: 16*100*3*2 = 9,600 This is still low, especially for the value it could give in understanding our system (graphs of all endpoints, how often are they called, how long they take, how often do they fail) Instead of "success true/false", we might want to give the actual status code. This can be a bit annoying because HttpServletResponse doesn't have a getStatus. But it's possible, and worth considering. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=219312400
61 lines
2.3 KiB
Java
61 lines
2.3 KiB
Java
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.request;
|
|
|
|
import static com.google.monitoring.metrics.EventMetric.DEFAULT_FITTER;
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
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 org.joda.time.Duration;
|
|
|
|
class RequestMetrics {
|
|
|
|
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
|
|
|
private static final ImmutableSet<LabelDescriptor> REQUEST_LABEL_DESCRIPTORS =
|
|
ImmutableSet.of(
|
|
LabelDescriptor.create("path", "target path"),
|
|
LabelDescriptor.create("method", "request method"),
|
|
LabelDescriptor.create("authLevel", "how the user was authenticated"),
|
|
LabelDescriptor.create("success", "whether the request succeeded"));
|
|
|
|
static final EventMetric requestDurationMetric =
|
|
MetricRegistryImpl.getDefault()
|
|
.newEventMetric(
|
|
"/request/processing_time",
|
|
"Action processing time",
|
|
"milliseconds",
|
|
REQUEST_LABEL_DESCRIPTORS,
|
|
DEFAULT_FITTER);
|
|
|
|
public RequestMetrics() {}
|
|
|
|
public void record(
|
|
Duration duration, String path, Action.Method method, AuthLevel authLevel, boolean success) {
|
|
requestDurationMetric.record(
|
|
duration.getMillis(),
|
|
path,
|
|
String.valueOf(method),
|
|
String.valueOf(authLevel),
|
|
String.valueOf(success));
|
|
logger.atInfo().log(
|
|
"Action called for path=%s, method=%s, authLevel=%s, success=%s. Took: %.3fs",
|
|
path, method, authLevel, success, duration.getMillis() / 1000d);
|
|
}
|
|
}
|