mirror of
https://github.com/google/nomulus.git
synced 2025-08-03 16:32:11 +02:00
Add RDAP metric class
The code to use this class will come in future CLs, to avoid a huge CL. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=175162557
This commit is contained in:
parent
2aa897e698
commit
ff1ab08302
10 changed files with 570 additions and 10 deletions
|
@ -11,6 +11,7 @@ java_library(
|
|||
"//java/google/registry/config",
|
||||
"//java/google/registry/flows",
|
||||
"//java/google/registry/model",
|
||||
"//java/google/registry/monitoring/metrics",
|
||||
"//java/google/registry/request",
|
||||
"//java/google/registry/request/auth",
|
||||
"//java/google/registry/ui/server/registrar",
|
||||
|
|
|
@ -419,7 +419,7 @@ public abstract class RdapActionBase implements Runnable {
|
|||
resources,
|
||||
(someExcluded && (resources.size() < rdapResultSetMaxSize + 1))
|
||||
? IncompletenessWarningType.MIGHT_BE_INCOMPLETE
|
||||
: IncompletenessWarningType.NONE,
|
||||
: IncompletenessWarningType.COMPLETE,
|
||||
numResourcesQueried);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -464,14 +464,14 @@ public class RdapDomainSearchAction extends RdapActionBase {
|
|||
domains,
|
||||
(numHostKeysSearched >= MAX_NAMESERVERS_IN_FIRST_STAGE)
|
||||
? IncompletenessWarningType.MIGHT_BE_INCOMPLETE
|
||||
: IncompletenessWarningType.NONE,
|
||||
: IncompletenessWarningType.COMPLETE,
|
||||
now);
|
||||
}
|
||||
}
|
||||
|
||||
/** Output JSON for a list of domains, with no incompleteness warnings. */
|
||||
private RdapSearchResults makeSearchResults(List<DomainResource> domains, DateTime now) {
|
||||
return makeSearchResults(domains, IncompletenessWarningType.NONE, now);
|
||||
return makeSearchResults(domains, IncompletenessWarningType.COMPLETE, now);
|
||||
}
|
||||
|
||||
/** Output JSON from data in an {@link RdapResultSet} object. */
|
||||
|
|
|
@ -219,7 +219,7 @@ public class RdapEntitySearchAction extends RdapActionBase {
|
|||
((contactResource != null) && shouldBeVisible(contactResource, now))
|
||||
? ImmutableList.of(contactResource)
|
||||
: ImmutableList.of(),
|
||||
IncompletenessWarningType.NONE,
|
||||
IncompletenessWarningType.COMPLETE,
|
||||
getMatchingRegistrars(partialStringQuery.getInitialString()),
|
||||
now);
|
||||
// Handle queries with a wildcard (or including deleted), but no suffix. Because the handle
|
||||
|
@ -328,6 +328,6 @@ public class RdapEntitySearchAction extends RdapActionBase {
|
|||
ImmutableList.copyOf(jsonOutputList),
|
||||
(jsonOutputList.size() < rdapResultSetMaxSize)
|
||||
? incompletenessWarningType
|
||||
: IncompletenessWarningType.NONE);
|
||||
: IncompletenessWarningType.COMPLETE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,20 @@
|
|||
|
||||
package google.registry.rdap;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.monitoring.metrics.DistributionFitter;
|
||||
import google.registry.monitoring.metrics.EventMetric;
|
||||
import google.registry.monitoring.metrics.FibonacciFitter;
|
||||
import google.registry.monitoring.metrics.IncrementableMetric;
|
||||
import google.registry.monitoring.metrics.LabelDescriptor;
|
||||
import google.registry.monitoring.metrics.MetricRegistryImpl;
|
||||
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
|
||||
import google.registry.request.Action;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** RDAP Instrumentation. */
|
||||
public class RdapMetrics {
|
||||
|
||||
|
@ -28,4 +42,259 @@ public class RdapMetrics {
|
|||
NAMESERVER,
|
||||
NAMESERVERS
|
||||
}
|
||||
|
||||
enum SearchType {
|
||||
NONE,
|
||||
BY_DOMAIN_NAME,
|
||||
BY_NAMESERVER_NAME,
|
||||
BY_NAMESERVER_ADDRESS,
|
||||
BY_FULL_NAME,
|
||||
BY_HANDLE
|
||||
}
|
||||
|
||||
enum WildcardType {
|
||||
NO_WILDCARD,
|
||||
PREFIX,
|
||||
SUFFIX,
|
||||
PREFIX_AND_SUFFIX,
|
||||
INVALID,
|
||||
TREATED_AS_WILDCARD
|
||||
}
|
||||
|
||||
private static final int MAX_RECORDED_PREFIX_LENGTH = 5;
|
||||
private static final String MAX_PREFIX_LENGTH_LABEL = "5+";
|
||||
|
||||
private static final ImmutableSet<LabelDescriptor> LABEL_DESCRIPTORS_FOR_REQUESTS =
|
||||
ImmutableSet.of(
|
||||
LabelDescriptor.create("endpoint_type", "The RDAP endpoint."),
|
||||
LabelDescriptor.create("include_deleted", "Whether deleted records are included."),
|
||||
LabelDescriptor.create("registrar_specified", "Whether a registrar was specified"),
|
||||
LabelDescriptor.create("authorization", "Type of user authorization"),
|
||||
LabelDescriptor.create("httpMethod", "HTTP request method"));
|
||||
|
||||
private static final ImmutableSet<LabelDescriptor> LABEL_DESCRIPTORS_FOR_RESPONSES =
|
||||
ImmutableSet.of(
|
||||
LabelDescriptor.create("endpoint_type", "The RDAP endpoint."),
|
||||
LabelDescriptor.create("search_type", "The identifier type used to search."),
|
||||
LabelDescriptor.create("wildcard_type", "The search string wildcard type."),
|
||||
LabelDescriptor.create("status_code", "Returned HTTP status code"),
|
||||
LabelDescriptor.create(
|
||||
"incompleteness_warning_type",
|
||||
"Warning status returned with result set (e.g. truncated, incomplete"));
|
||||
|
||||
private static final ImmutableSet<LabelDescriptor> LABEL_DESCRIPTORS_FOR_RETRIEVAL_COUNTS =
|
||||
ImmutableSet.of(
|
||||
LabelDescriptor.create("endpoint_type", "The RDAP endpoint."),
|
||||
LabelDescriptor.create("search_type", "The identifier type used to search."),
|
||||
LabelDescriptor.create("wildcard_type", "The search string wildcard type."),
|
||||
LabelDescriptor.create(
|
||||
"prefix_length",
|
||||
String.format(
|
||||
"The length of the prefix before the wildcard (limited to %d).",
|
||||
MAX_RECORDED_PREFIX_LENGTH)),
|
||||
LabelDescriptor.create("include_deleted", "Whether deleted records are included."));
|
||||
|
||||
// Fibonacci fitter more suitable for integer-type values. Allows values between 0 and 4181,
|
||||
// which is the 19th Fibonacci number.
|
||||
private static final DistributionFitter FIBONACCI_FITTER = FibonacciFitter.create(4181);
|
||||
|
||||
@VisibleForTesting
|
||||
static final IncrementableMetric requests =
|
||||
MetricRegistryImpl.getDefault()
|
||||
.newIncrementableMetric(
|
||||
"/rdap/requests",
|
||||
"Count of RDAP Requests",
|
||||
"count",
|
||||
LABEL_DESCRIPTORS_FOR_REQUESTS);
|
||||
|
||||
@VisibleForTesting
|
||||
static final IncrementableMetric responses =
|
||||
MetricRegistryImpl.getDefault()
|
||||
.newIncrementableMetric(
|
||||
"/rdap/responses",
|
||||
"Count of RDAP Responses",
|
||||
"count",
|
||||
LABEL_DESCRIPTORS_FOR_RESPONSES);
|
||||
|
||||
@VisibleForTesting
|
||||
static final EventMetric numberOfDomainsRetrieved =
|
||||
MetricRegistryImpl.getDefault()
|
||||
.newEventMetric(
|
||||
"/rdap/num_domains_retrieved",
|
||||
"Number of domains retrieved",
|
||||
"count",
|
||||
LABEL_DESCRIPTORS_FOR_RETRIEVAL_COUNTS,
|
||||
FIBONACCI_FITTER);
|
||||
|
||||
@VisibleForTesting
|
||||
static final EventMetric numberOfHostsRetrieved =
|
||||
MetricRegistryImpl.getDefault()
|
||||
.newEventMetric(
|
||||
"/rdap/num_hosts_retrieved",
|
||||
"Number of hosts retrieved",
|
||||
"count",
|
||||
LABEL_DESCRIPTORS_FOR_RETRIEVAL_COUNTS,
|
||||
FIBONACCI_FITTER);
|
||||
|
||||
@VisibleForTesting
|
||||
static final EventMetric numberOfContactsRetrieved =
|
||||
MetricRegistryImpl.getDefault()
|
||||
.newEventMetric(
|
||||
"/rdap/num_contacts_retrieved",
|
||||
"Number of contacts retrieved",
|
||||
"count",
|
||||
LABEL_DESCRIPTORS_FOR_RETRIEVAL_COUNTS,
|
||||
FIBONACCI_FITTER);
|
||||
|
||||
@Inject
|
||||
public RdapMetrics() {}
|
||||
|
||||
private static String getLabelStringForPrefixLength(int prefixLength) {
|
||||
return (prefixLength >= MAX_RECORDED_PREFIX_LENGTH)
|
||||
? MAX_PREFIX_LENGTH_LABEL
|
||||
: String.valueOf(prefixLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the RDAP metrics.
|
||||
*
|
||||
* <p>This is intended to be called at the conclusion of a query, with the parameters specifying
|
||||
* everything that happened. This method takes the data and updates metrics which offer several
|
||||
* ways of looking at the data, since cardinality constraints prevent us from saving all the
|
||||
* information in a single metric.
|
||||
*/
|
||||
public void updateMetrics(
|
||||
RdapMetricInformation rdapMetricInformation) {
|
||||
requests.increment(
|
||||
rdapMetricInformation.endpointType().toString(),
|
||||
rdapMetricInformation.includeDeleted() ? "YES" : "NO",
|
||||
rdapMetricInformation.registrarSpecified() ? "YES" : "NO",
|
||||
rdapMetricInformation.role().toString(),
|
||||
rdapMetricInformation.requestMethod().toString());
|
||||
responses.increment(
|
||||
rdapMetricInformation.endpointType().toString(),
|
||||
rdapMetricInformation.searchType().toString(),
|
||||
rdapMetricInformation.wildcardType().toString(),
|
||||
String.valueOf(rdapMetricInformation.statusCode()),
|
||||
rdapMetricInformation.incompletenessWarningType().toString());
|
||||
if (rdapMetricInformation.numDomainsRetrieved().isPresent()) {
|
||||
numberOfDomainsRetrieved.record(
|
||||
rdapMetricInformation.numDomainsRetrieved().get(),
|
||||
rdapMetricInformation.endpointType().toString(),
|
||||
rdapMetricInformation.searchType().toString(),
|
||||
rdapMetricInformation.wildcardType().toString(),
|
||||
getLabelStringForPrefixLength(rdapMetricInformation.prefixLength()),
|
||||
rdapMetricInformation.includeDeleted() ? "YES" : "NO");
|
||||
}
|
||||
if (rdapMetricInformation.numHostsRetrieved().isPresent()) {
|
||||
numberOfHostsRetrieved.record(
|
||||
rdapMetricInformation.numHostsRetrieved().get(),
|
||||
rdapMetricInformation.endpointType().toString(),
|
||||
rdapMetricInformation.searchType().toString(),
|
||||
rdapMetricInformation.wildcardType().toString(),
|
||||
getLabelStringForPrefixLength(rdapMetricInformation.prefixLength()),
|
||||
rdapMetricInformation.includeDeleted() ? "YES" : "NO");
|
||||
}
|
||||
if (rdapMetricInformation.numContactsRetrieved().isPresent()) {
|
||||
numberOfContactsRetrieved.record(
|
||||
rdapMetricInformation.numContactsRetrieved().get(),
|
||||
rdapMetricInformation.endpointType().toString(),
|
||||
rdapMetricInformation.searchType().toString(),
|
||||
rdapMetricInformation.wildcardType().toString(),
|
||||
getLabelStringForPrefixLength(rdapMetricInformation.prefixLength()),
|
||||
rdapMetricInformation.includeDeleted() ? "YES" : "NO");
|
||||
}
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
abstract static class RdapMetricInformation {
|
||||
|
||||
/** The type of RDAP endpoint (domain, domains, nameserver, etc.). */
|
||||
abstract EndpointType endpointType();
|
||||
|
||||
/** The search type (by domain name, by nameserver name, etc.). */
|
||||
abstract SearchType searchType();
|
||||
|
||||
/** The type of wildcarding requested (prefix, suffix, etc.). */
|
||||
abstract WildcardType wildcardType();
|
||||
|
||||
/**
|
||||
* The length of the prefix string before the wildcard, if any; any length longer than
|
||||
* MAX_RECORDED_PREFIX_LENGTH is limited to MAX_RECORDED_PREFIX_LENGTH when recording the
|
||||
* metric, to avoid cardinality problems.
|
||||
*/
|
||||
abstract int prefixLength();
|
||||
|
||||
/** Whether the search included deleted records. */
|
||||
abstract boolean includeDeleted();
|
||||
|
||||
/** Whether the search requested a specific registrar. */
|
||||
abstract boolean registrarSpecified();
|
||||
|
||||
/** Type of authentication/authorization: public, admin or registrar. */
|
||||
abstract RdapAuthorization.Role role();
|
||||
|
||||
/** Http request method (GET, POST, HEAD, etc.). */
|
||||
abstract Action.Method requestMethod();
|
||||
|
||||
/** Http status code. */
|
||||
abstract int statusCode();
|
||||
|
||||
/** Incompleteness warning type (e.g. truncated). */
|
||||
abstract IncompletenessWarningType incompletenessWarningType();
|
||||
|
||||
/**
|
||||
* Number of domains retrieved from the database; this might be more than were actually returned
|
||||
* in the response; absent if a search was not performed.
|
||||
*/
|
||||
abstract Optional<Long> numDomainsRetrieved();
|
||||
|
||||
/**
|
||||
* Number of hosts retrieved from the database; this might be more than were actually returned
|
||||
* in the response; absent if a search was not performed.
|
||||
*/
|
||||
abstract Optional<Long> numHostsRetrieved();
|
||||
|
||||
/**
|
||||
* Number of contacts retrieved from the database; this might be more than were actually
|
||||
* returned in the response; absent if a search was not performed.
|
||||
*/
|
||||
abstract Optional<Long> numContactsRetrieved();
|
||||
|
||||
@AutoValue.Builder
|
||||
abstract static class Builder {
|
||||
abstract Builder setEndpointType(EndpointType endpointType);
|
||||
|
||||
abstract Builder setSearchType(SearchType searchType);
|
||||
|
||||
abstract Builder setWildcardType(WildcardType wildcardType);
|
||||
|
||||
abstract Builder setPrefixLength(int prefixLength);
|
||||
|
||||
abstract Builder setIncludeDeleted(boolean includeDeleted);
|
||||
|
||||
abstract Builder setRegistrarSpecified(boolean registrarSpecified);
|
||||
|
||||
abstract Builder setRole(RdapAuthorization.Role role);
|
||||
|
||||
abstract Builder setRequestMethod(Action.Method requestMethod);
|
||||
|
||||
abstract Builder setStatusCode(int statusCode);
|
||||
|
||||
abstract Builder setIncompletenessWarningType(
|
||||
IncompletenessWarningType incompletenessWarningType);
|
||||
|
||||
abstract Builder setNumDomainsRetrieved(long numDomainsRetrieved);
|
||||
|
||||
abstract Builder setNumHostsRetrieved(long numHostsRetrieved);
|
||||
|
||||
abstract Builder setNumContactsRetrieved(long numContactRetrieved);
|
||||
|
||||
abstract RdapMetricInformation build();
|
||||
}
|
||||
|
||||
static Builder builder() {
|
||||
return new AutoValue_RdapMetrics_RdapMetricInformation.Builder();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
return makeSearchResults(hostList, IncompletenessWarningType.NONE, now);
|
||||
return makeSearchResults(hostList, IncompletenessWarningType.COMPLETE, now);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
abstract class RdapResultSet<T extends EppResource> {
|
||||
|
||||
static <S extends EppResource> RdapResultSet<S> create(List<S> resources) {
|
||||
return create(resources, IncompletenessWarningType.NONE, resources.size());
|
||||
return create(resources, IncompletenessWarningType.COMPLETE, resources.size());
|
||||
}
|
||||
|
||||
static <S extends EppResource> RdapResultSet<S> create(
|
||||
|
@ -43,4 +43,3 @@ abstract class RdapResultSet<T extends EppResource> {
|
|||
/** Number of resources retrieved from the database in the process of assembling the data set. */
|
||||
abstract int numResourcesRetrieved();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ abstract class RdapSearchResults {
|
|||
enum IncompletenessWarningType {
|
||||
|
||||
/** Result set is complete. */
|
||||
NONE,
|
||||
COMPLETE,
|
||||
|
||||
/** Result set has been limited to the maximum size. */
|
||||
TRUNCATED,
|
||||
|
@ -46,7 +46,7 @@ abstract class RdapSearchResults {
|
|||
}
|
||||
|
||||
static RdapSearchResults create(ImmutableList<ImmutableMap<String, Object>> jsonList) {
|
||||
return create(jsonList, IncompletenessWarningType.NONE);
|
||||
return create(jsonList, IncompletenessWarningType.COMPLETE);
|
||||
}
|
||||
|
||||
static RdapSearchResults create(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue