Rename all encoding methods to start with the word encode for consistency

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143973446
This commit is contained in:
shikhman 2017-01-09 09:53:30 -08:00 committed by Ben McIlwain
parent 2a3a17d653
commit e981bad0b3
2 changed files with 18 additions and 18 deletions

View file

@ -127,7 +127,7 @@ public class StackdriverWriter implements MetricWriter {
private final RateLimiter rateLimiter; private final RateLimiter rateLimiter;
/** /**
* Constructs a StackdriverWriter. * Constructs a {@link StackdriverWriter}.
* *
* <p>The monitoringClient must have read and write permissions to the Cloud Monitoring API v3 on * <p>The monitoringClient must have read and write permissions to the Cloud Monitoring API v3 on
* the provided project. * the provided project.
@ -135,7 +135,7 @@ public class StackdriverWriter implements MetricWriter {
@Inject @Inject
public StackdriverWriter( public StackdriverWriter(
Monitoring monitoringClient, Monitoring monitoringClient,
String project, @Named("stackdriverGcpProject") String project,
MonitoredResource monitoredResource, MonitoredResource monitoredResource,
@Named("stackdriverMaxQps") int maxQps, @Named("stackdriverMaxQps") int maxQps,
@Named("stackdriverMaxPointsPerRequest") int maxPointsPerRequest) { @Named("stackdriverMaxPointsPerRequest") int maxPointsPerRequest) {
@ -148,7 +148,7 @@ public class StackdriverWriter implements MetricWriter {
} }
@VisibleForTesting @VisibleForTesting
static ImmutableList<LabelDescriptor> createLabelDescriptors( static ImmutableList<LabelDescriptor> encodeLabelDescriptors(
ImmutableSet<google.registry.monitoring.metrics.LabelDescriptor> labelDescriptors) { ImmutableSet<google.registry.monitoring.metrics.LabelDescriptor> labelDescriptors) {
List<LabelDescriptor> stackDriverLabelDescriptors = new ArrayList<>(labelDescriptors.size()); List<LabelDescriptor> stackDriverLabelDescriptors = new ArrayList<>(labelDescriptors.size());
@ -164,14 +164,14 @@ public class StackdriverWriter implements MetricWriter {
} }
@VisibleForTesting @VisibleForTesting
static <V> MetricDescriptor createMetricDescriptor( static <V> MetricDescriptor encodeMetricDescriptor(
google.registry.monitoring.metrics.Metric<V> metric) { google.registry.monitoring.metrics.Metric<V> metric) {
return new MetricDescriptor() return new MetricDescriptor()
.setType(METRIC_DOMAIN + metric.getMetricSchema().name()) .setType(METRIC_DOMAIN + metric.getMetricSchema().name())
.setDescription(metric.getMetricSchema().description()) .setDescription(metric.getMetricSchema().description())
.setDisplayName(metric.getMetricSchema().valueDisplayName()) .setDisplayName(metric.getMetricSchema().valueDisplayName())
.setValueType(ENCODED_METRIC_TYPES.get(metric.getValueClass())) .setValueType(ENCODED_METRIC_TYPES.get(metric.getValueClass()))
.setLabels(createLabelDescriptors(metric.getMetricSchema().labels())) .setLabels(encodeLabelDescriptors(metric.getMetricSchema().labels()))
.setMetricKind(ENCODED_METRIC_KINDS.get(metric.getMetricSchema().kind().name())); .setMetricKind(ENCODED_METRIC_KINDS.get(metric.getMetricSchema().kind().name()));
} }
@ -230,7 +230,7 @@ public class StackdriverWriter implements MetricWriter {
return registeredDescriptors.get(metric); return registeredDescriptors.get(metric);
} }
MetricDescriptor descriptor = createMetricDescriptor(metric); MetricDescriptor descriptor = encodeMetricDescriptor(metric);
rateLimiter.acquire(); rateLimiter.acquire();
// We try to create a descriptor, but it may have been created already, so we re-fetch it on // We try to create a descriptor, but it may have been created already, so we re-fetch it on

View file

@ -82,7 +82,7 @@ public class StackdriverWriterTest {
"desc", "desc",
"vdn", "vdn",
ImmutableSet.of(LabelDescriptor.create("label", "description"))); ImmutableSet.of(LabelDescriptor.create("label", "description")));
descriptor = StackdriverWriter.createMetricDescriptor(metric); descriptor = StackdriverWriter.encodeMetricDescriptor(metric);
when(client.projects()).thenReturn(projects); when(client.projects()).thenReturn(projects);
when(projects.metricDescriptors()).thenReturn(metricDescriptors); when(projects.metricDescriptors()).thenReturn(metricDescriptors);
when(projects.timeSeries()).thenReturn(timeSeries); when(projects.timeSeries()).thenReturn(timeSeries);
@ -185,7 +185,7 @@ public class StackdriverWriterTest {
client client
.projects() .projects()
.metricDescriptors() .metricDescriptors()
.create(PROJECT, StackdriverWriter.createMetricDescriptor(metric))) .create(PROJECT, StackdriverWriter.encodeMetricDescriptor(metric)))
.execute(); .execute();
} }
@ -201,7 +201,7 @@ public class StackdriverWriterTest {
client client
.projects() .projects()
.metricDescriptors() .metricDescriptors()
.create(PROJECT, StackdriverWriter.createMetricDescriptor(metric))) .create(PROJECT, StackdriverWriter.encodeMetricDescriptor(metric)))
.execute(); .execute();
} }
@ -272,8 +272,8 @@ public class StackdriverWriterTest {
} }
@Test @Test
public void createMetricDescriptor_simpleMetric_encodes() { public void encodeMetricDescriptor_simpleMetric_encodes() {
MetricDescriptor descriptor = StackdriverWriter.createMetricDescriptor(metric); MetricDescriptor descriptor = StackdriverWriter.encodeMetricDescriptor(metric);
assertThat(descriptor.getType()).isEqualTo("custom.googleapis.com/name"); assertThat(descriptor.getType()).isEqualTo("custom.googleapis.com/name");
assertThat(descriptor.getValueType()).isEqualTo("INT64"); assertThat(descriptor.getValueType()).isEqualTo("INT64");
@ -288,14 +288,14 @@ public class StackdriverWriterTest {
} }
@Test @Test
public void createLabelDescriptors_simpleLabels_encodes() { public void encodeLabelDescriptors_simpleLabels_encodes() {
ImmutableSet<LabelDescriptor> descriptors = ImmutableSet<LabelDescriptor> descriptors =
ImmutableSet.of( ImmutableSet.of(
LabelDescriptor.create("label1", "description1"), LabelDescriptor.create("label1", "description1"),
LabelDescriptor.create("label2", "description2")); LabelDescriptor.create("label2", "description2"));
ImmutableList<com.google.api.services.monitoring.v3.model.LabelDescriptor> encodedDescritors = ImmutableList<com.google.api.services.monitoring.v3.model.LabelDescriptor> encodedDescritors =
StackdriverWriter.createLabelDescriptors(descriptors); StackdriverWriter.encodeLabelDescriptors(descriptors);
assertThat(encodedDescritors) assertThat(encodedDescritors)
.containsExactly( .containsExactly(
@ -364,7 +364,7 @@ public class StackdriverWriterTest {
ImmutableSet.of(LabelDescriptor.create("label", "description")), ImmutableSet.of(LabelDescriptor.create("label", "description")),
Long.class); Long.class);
when(metricDescriptorCreate.execute()) when(metricDescriptorCreate.execute())
.thenReturn(StackdriverWriter.createMetricDescriptor(metric)); .thenReturn(StackdriverWriter.encodeMetricDescriptor(metric));
MetricPoint<Long> nativePoint = MetricPoint<Long> nativePoint =
MetricPoint.create( MetricPoint.create(
metric, ImmutableList.of("foo"), new Instant(1337), new Instant(1337), 10L); metric, ImmutableList.of("foo"), new Instant(1337), new Instant(1337), 10L);
@ -392,7 +392,7 @@ public class StackdriverWriterTest {
"vdn", "vdn",
ImmutableSet.of(LabelDescriptor.create("label", "description")), ImmutableSet.of(LabelDescriptor.create("label", "description")),
Boolean.class); Boolean.class);
MetricDescriptor boolDescriptor = StackdriverWriter.createMetricDescriptor(boolMetric); MetricDescriptor boolDescriptor = StackdriverWriter.encodeMetricDescriptor(boolMetric);
when(metricDescriptorCreate.execute()).thenReturn(boolDescriptor); when(metricDescriptorCreate.execute()).thenReturn(boolDescriptor);
MetricPoint<Boolean> nativePoint = MetricPoint<Boolean> nativePoint =
MetricPoint.create(boolMetric, ImmutableList.of("foo"), new Instant(1337), true); MetricPoint.create(boolMetric, ImmutableList.of("foo"), new Instant(1337), true);
@ -420,7 +420,7 @@ public class StackdriverWriterTest {
"vdn", "vdn",
ImmutableSet.of(LabelDescriptor.create("label", "description")), ImmutableSet.of(LabelDescriptor.create("label", "description")),
Distribution.class); Distribution.class);
MetricDescriptor descriptor = StackdriverWriter.createMetricDescriptor(metric); MetricDescriptor descriptor = StackdriverWriter.encodeMetricDescriptor(metric);
when(metricDescriptorCreate.execute()).thenReturn(descriptor); when(metricDescriptorCreate.execute()).thenReturn(descriptor);
MutableDistribution distribution = MutableDistribution distribution =
new MutableDistribution(CustomFitter.create(ImmutableSet.of(5.0))); new MutableDistribution(CustomFitter.create(ImmutableSet.of(5.0)));
@ -461,7 +461,7 @@ public class StackdriverWriterTest {
"vdn", "vdn",
ImmutableSet.of(LabelDescriptor.create("label", "description")), ImmutableSet.of(LabelDescriptor.create("label", "description")),
Distribution.class); Distribution.class);
MetricDescriptor descriptor = StackdriverWriter.createMetricDescriptor(metric); MetricDescriptor descriptor = StackdriverWriter.encodeMetricDescriptor(metric);
when(metricDescriptorCreate.execute()).thenReturn(descriptor); when(metricDescriptorCreate.execute()).thenReturn(descriptor);
MutableDistribution distribution = new MutableDistribution(LinearFitter.create(2, 5.0, 3.0)); MutableDistribution distribution = new MutableDistribution(LinearFitter.create(2, 5.0, 3.0));
distribution.add(0.0, 1L); distribution.add(0.0, 1L);
@ -504,7 +504,7 @@ public class StackdriverWriterTest {
"vdn", "vdn",
ImmutableSet.of(LabelDescriptor.create("label", "description")), ImmutableSet.of(LabelDescriptor.create("label", "description")),
Distribution.class); Distribution.class);
MetricDescriptor descriptor = StackdriverWriter.createMetricDescriptor(metric); MetricDescriptor descriptor = StackdriverWriter.encodeMetricDescriptor(metric);
when(metricDescriptorCreate.execute()).thenReturn(descriptor); when(metricDescriptorCreate.execute()).thenReturn(descriptor);
MutableDistribution distribution = MutableDistribution distribution =
new MutableDistribution(ExponentialFitter.create(2, 3.0, 0.5)); new MutableDistribution(ExponentialFitter.create(2, 3.0, 0.5));