mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 17:07:15 +02:00
Run automatic Java 8 conversion over codebase
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171174380
This commit is contained in:
parent
44df5da771
commit
5edb7935ed
190 changed files with 2312 additions and 3096 deletions
|
@ -153,9 +153,7 @@ public class EventMetric extends AbstractMetric<Distribution> {
|
|||
lock.lock();
|
||||
|
||||
try {
|
||||
if (!values.containsKey(labelValues)) {
|
||||
values.put(labelValues, new MutableDistribution(distributionFitter));
|
||||
}
|
||||
values.computeIfAbsent(labelValues, k -> new MutableDistribution(distributionFitter));
|
||||
|
||||
values.get(labelValues).add(sample, count);
|
||||
valueStartTimestamps.putIfAbsent(labelValues, startTimestamp);
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
package google.registry.monitoring.metrics;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -57,27 +56,24 @@ final class MetricMetrics {
|
|||
"Count of Timeseries being pushed to Monitoring API",
|
||||
"Timeseries Count",
|
||||
LABELS,
|
||||
new Supplier<ImmutableMap<ImmutableList<String>, Long>>() {
|
||||
@Override
|
||||
public ImmutableMap<ImmutableList<String>, Long> get() {
|
||||
HashMap<ImmutableList<String>, Long> timeseriesCount = new HashMap<>();
|
||||
() -> {
|
||||
HashMap<ImmutableList<String>, Long> timeseriesCount = new HashMap<>();
|
||||
|
||||
for (Metric<?> metric : MetricRegistryImpl.getDefault().getRegisteredMetrics()) {
|
||||
ImmutableList<String> key =
|
||||
ImmutableList.of(
|
||||
metric.getMetricSchema().kind().toString(),
|
||||
metric.getValueClass().toString());
|
||||
for (Metric<?> metric : MetricRegistryImpl.getDefault().getRegisteredMetrics()) {
|
||||
ImmutableList<String> key =
|
||||
ImmutableList.of(
|
||||
metric.getMetricSchema().kind().toString(),
|
||||
metric.getValueClass().toString());
|
||||
|
||||
int cardinality = metric.getCardinality();
|
||||
if (!timeseriesCount.containsKey(key)) {
|
||||
timeseriesCount.put(key, (long) cardinality);
|
||||
} else {
|
||||
timeseriesCount.put(key, timeseriesCount.get(key) + cardinality);
|
||||
}
|
||||
int cardinality = metric.getCardinality();
|
||||
if (!timeseriesCount.containsKey(key)) {
|
||||
timeseriesCount.put(key, (long) cardinality);
|
||||
} else {
|
||||
timeseriesCount.put(key, timeseriesCount.get(key) + cardinality);
|
||||
}
|
||||
|
||||
return ImmutableMap.copyOf(timeseriesCount);
|
||||
}
|
||||
|
||||
return ImmutableMap.copyOf(timeseriesCount);
|
||||
},
|
||||
Long.class);
|
||||
|
||||
|
|
|
@ -67,15 +67,11 @@ abstract class AbstractMetricSubject<T, S extends AbstractMetricSubject<T, S>>
|
|||
* Function to convert a metric point to a nice string representation for use in error messages.
|
||||
*/
|
||||
protected final Function<MetricPoint<T>, String> metricPointConverter =
|
||||
new Function<MetricPoint<T>, String>() {
|
||||
@Override
|
||||
public String apply(MetricPoint<T> metricPoint) {
|
||||
return String.format(
|
||||
metricPoint ->
|
||||
String.format(
|
||||
"%s => %s",
|
||||
Joiner.on(':').join(metricPoint.labelValues()),
|
||||
getMessageRepresentation(metricPoint.value()));
|
||||
}
|
||||
};
|
||||
|
||||
protected AbstractMetricSubject(FailureMetadata metadata, Metric<T> actual) {
|
||||
super(metadata, checkNotNull(actual));
|
||||
|
|
|
@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertAbout;
|
|||
import com.google.common.collect.BoundType;
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.common.truth.FailureMetadata;
|
||||
import com.google.common.truth.Subject;
|
||||
import google.registry.monitoring.metrics.Distribution;
|
||||
import google.registry.monitoring.metrics.Metric;
|
||||
import google.registry.monitoring.metrics.MetricPoint;
|
||||
|
@ -48,15 +47,9 @@ public final class DistributionMetricSubject
|
|||
extends AbstractMetricSubject<Distribution, DistributionMetricSubject> {
|
||||
|
||||
/** {@link Subject.Factory} for assertions about {@link Metric<Distribution>} objects. */
|
||||
private static final Subject.Factory<DistributionMetricSubject, Metric<Distribution>>
|
||||
SUBJECT_FACTORY =
|
||||
// The Truth extensibility documentation indicates that the target should be nullable.
|
||||
(FailureMetadata failureMetadata, @Nullable Metric<Distribution> target) ->
|
||||
new DistributionMetricSubject(failureMetadata, target);
|
||||
|
||||
/** Static assertThat({@link Metric<Distribution>}) shortcut method. */
|
||||
public static DistributionMetricSubject assertThat(@Nullable Metric<Distribution> metric) {
|
||||
return assertAbout(SUBJECT_FACTORY).that(metric);
|
||||
return assertAbout(DistributionMetricSubject::new).that(metric);
|
||||
}
|
||||
|
||||
private DistributionMetricSubject(FailureMetadata metadata, Metric<Distribution> actual) {
|
||||
|
|
|
@ -17,7 +17,6 @@ package google.registry.monitoring.metrics.contrib;
|
|||
import static com.google.common.truth.Truth.assertAbout;
|
||||
|
||||
import com.google.common.truth.FailureMetadata;
|
||||
import com.google.common.truth.Subject;
|
||||
import google.registry.monitoring.metrics.Metric;
|
||||
import google.registry.monitoring.metrics.MetricPoint;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -45,14 +44,9 @@ import javax.annotation.Nullable;
|
|||
public final class LongMetricSubject extends AbstractMetricSubject<Long, LongMetricSubject> {
|
||||
|
||||
/** {@link Subject.Factory} for assertions about {@link Metric<Long>} objects. */
|
||||
private static final Subject.Factory<LongMetricSubject, Metric<Long>> SUBJECT_FACTORY =
|
||||
// The Truth extensibility documentation indicates that the target should be nullable.
|
||||
(FailureMetadata failureMetadata, @Nullable Metric<Long> target) ->
|
||||
new LongMetricSubject(failureMetadata, target);
|
||||
|
||||
/** Static assertThat({@link Metric<Long>}) shortcut method. */
|
||||
public static LongMetricSubject assertThat(@Nullable Metric<Long> metric) {
|
||||
return assertAbout(SUBJECT_FACTORY).that(metric);
|
||||
return assertAbout(LongMetricSubject::new).that(metric);
|
||||
}
|
||||
|
||||
private LongMetricSubject(FailureMetadata metadata, Metric<Long> actual) {
|
||||
|
|
|
@ -19,14 +19,11 @@ import static com.google.common.base.Predicates.not;
|
|||
import static com.google.common.collect.Multimaps.filterKeys;
|
||||
import static google.registry.request.Action.Method.POST;
|
||||
import static google.registry.util.FormattingLogger.getLoggerForCallerClass;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.google.api.services.bigquery.Bigquery;
|
||||
import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
|
||||
import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
|
||||
import com.google.api.services.bigquery.model.TableDataInsertAllResponse.InsertErrors;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -85,18 +82,19 @@ public class MetricsExportAction implements Runnable {
|
|||
.execute();
|
||||
|
||||
if (response.getInsertErrors() != null && !response.getInsertErrors().isEmpty()) {
|
||||
throw new RuntimeException(FluentIterable
|
||||
.from(response.getInsertErrors())
|
||||
.transform(new Function<InsertErrors, String>() {
|
||||
@Override
|
||||
public String apply(InsertErrors error) {
|
||||
try {
|
||||
return error.toPrettyString();
|
||||
} catch (IOException e) {
|
||||
return error.toString();
|
||||
}
|
||||
}})
|
||||
.join(Joiner.on('\n')));
|
||||
throw new RuntimeException(
|
||||
response
|
||||
.getInsertErrors()
|
||||
.stream()
|
||||
.map(
|
||||
error -> {
|
||||
try {
|
||||
return error.toPrettyString();
|
||||
} catch (IOException e) {
|
||||
return error.toString();
|
||||
}
|
||||
})
|
||||
.collect(joining("\n")));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.warningfmt("Caught Unknown Exception: %s", e);
|
||||
|
|
|
@ -61,12 +61,7 @@ public class WhiteboxModule {
|
|||
@Provides
|
||||
@Named("insertIdGenerator")
|
||||
static Supplier<String> provideInsertIdGenerator() {
|
||||
return new Supplier<String>() {
|
||||
@Override
|
||||
public String get() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
};
|
||||
return () -> UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
/** Provides an EppMetric builder with the request ID and startTimestamp already initialized. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue