Skip to content

Commit

Permalink
Merge branch '1.1.x' into 1.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Dec 13, 2019
2 parents ec16013 + 099fa5a commit 4030391
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import com.google.monitoring.v3.*;
import com.google.protobuf.Timestamp;
import io.micrometer.core.annotation.Incubating;
import io.micrometer.core.instrument.*;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.*;
import io.micrometer.core.instrument.config.MissingRequiredConfigurationException;
import io.micrometer.core.instrument.distribution.CountAtBucket;
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
Expand Down Expand Up @@ -65,6 +65,7 @@
*/
@Incubating(since = "1.1.0")
public class StackdriverMeterRegistry extends StepMeterRegistry {

private static final ThreadFactory DEFAULT_THREAD_FACTORY = new NamedThreadFactory("stackdriver-metrics-publisher");

/**
Expand Down Expand Up @@ -122,7 +123,7 @@ public void start(ThreadFactory threadFactory) {
} else {
try {
this.client = MetricServiceClient.create(metricServiceSettings);
logger.info("publishing metrics to stackdriver every " + TimeUtils.format(config.step()));
logger.info("publishing metrics to stackdriver every {}", TimeUtils.format(config.step()));
super.start(threadFactory);
} catch (Exception e) {
logger.error("unable to create stackdriver client", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,31 @@
*/
package io.micrometer.stackdriver;

import java.util.regex.Pattern;

import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.config.NamingConvention;
import io.micrometer.core.instrument.util.StringUtils;
import io.micrometer.core.lang.Nullable;

import java.util.regex.Pattern;

/**
* {@link NamingConvention} for Stackdriver.
*
*
* Names are mapped to Stackdriver's metric type names and tag keys are mapped to its metric label names.
*
* @see <a href="https://cloud.google.com/monitoring/api/v3/metrics-details">"Naming rules" section on Stackdriver's reference documentation</a>
*
* @see <a href="https://cloud.google.com/monitoring/api/v3/metrics-details">"Naming rules" section on Stackdriver's reference documentation</a>
* and
* @see <a href="https://cloud.google.com/monitoring/quotas#custom_metrics_quotas">"Custom Metrics" on the Stackdriver's Quotas and limits reference documentation</a>
*
* @author Jon Schneider
* @since 1.1.0
*/
public class StackdriverNamingConvention implements NamingConvention {

private static final int MAX_NAME_LENGTH = 200;
private static final int MAX_TAG_KEY_LENGTH = 100;
private static final int MAX_TAG_VALUE_LENGTH = 1024;
private static final Pattern NAME_BLACKLIST = Pattern.compile("[^\\w./_]");
private static final Pattern TAG_KEY_BLACKLIST = Pattern.compile("[^\\w_]");
private final NamingConvention nameDelegate;
Expand Down Expand Up @@ -62,4 +67,9 @@ private String sanitize(String value, Pattern blacklist, int maxLength) {
public String tagKey(String key) {
return sanitize(tagKeyDelegate.tagKey(key), TAG_KEY_BLACKLIST, MAX_TAG_KEY_LENGTH);
}

@Override
public String tagValue(String value) {
return StringUtils.truncate(value, MAX_TAG_VALUE_LENGTH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ void tagValue() {
assertThat(namingConvention.tagValue("my.tag.value")).isEqualTo("my.tag.value");
}

@Test
void tooLongTagValue() {
assertThat(namingConvention.tagValue("thisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolong"))
.isEqualTo("thisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistoolongthisistool");
}

}

0 comments on commit 4030391

Please sign in to comment.