Fix ray java worker metric test indentation (#9834)

This commit is contained in:
bermaker
2020-07-31 14:39:41 +08:00
committed by GitHub
parent a47121476f
commit 88e8714bcb
12 changed files with 55 additions and 51 deletions
@@ -17,7 +17,7 @@ public class Count extends Metric {
super(name, tags);
count = new DoubleAdder();
metricNativePointer = NativeMetric.registerCountNative(name, description, unit,
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
Preconditions.checkState(metricNativePointer != 0, "Count native pointer must not be 0.");
}
@@ -13,7 +13,7 @@ public class Gauge extends Metric {
public Gauge(String name, String description, String unit, Map<TagKey, String> tags) {
super(name, tags);
metricNativePointer = NativeMetric.registerGaugeNative(name, description, unit,
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
Preconditions.checkState(metricNativePointer != 0, "Gauge native pointer must not be 0.");
}
@@ -22,8 +22,8 @@ public class Histogram extends Metric {
Map<TagKey, String> tags) {
super(name, tags);
metricNativePointer = NativeMetric.registerHistogramNative(name, description, unit,
boundaries.stream().mapToDouble(Double::doubleValue).toArray(),
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
boundaries.stream().mapToDouble(Double::doubleValue).toArray(),
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
Preconditions.checkState(metricNativePointer != 0,
"Histogram native pointer must not be 0.");
histogramWindow = Collections.synchronizedList(new ArrayList<>());
@@ -32,6 +32,7 @@ public abstract class Metric {
// Sync metric with core worker stats for registry.
// Metric data will be flushed into stats view data inside core worker immediately after
// record is called.
/**
* Flush records to stats in last aggregator.
*/
@@ -51,19 +52,24 @@ public abstract class Metric {
/**
* Get the value to record and then reset.
*
* @return latest updating value.
*/
protected abstract double getAndReset();
/** Update gauge value without tags.
/**
* Update gauge value without tags.
* Update metric info for user.
*
* @param value latest value for updating
*/
public abstract void update(double value);
/** Update gauge value with dynamic tag values.
/**
* Update gauge value with dynamic tag values.
*
* @param value latest value for updating
* @param tags tag map
* @param tags tag map
*/
public void update(double value, Map<TagKey, String> tags) {
update(value);
@@ -39,10 +39,10 @@ public class MetricConfig {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("timeIntervalMs", timeIntervalMs)
.add("threadPoolSize", threadPoolSize)
.add("shutdownWaitTimeMs", shutdownWaitTimeMs)
.toString();
.add("timeIntervalMs", timeIntervalMs)
.add("threadPoolSize", threadPoolSize)
.add("shutdownWaitTimeMs", shutdownWaitTimeMs)
.toString();
}
public static MetricConfigBuilder builder() {
@@ -32,8 +32,8 @@ public class MetricId {
}
MetricId metricId = (MetricId) o;
return type == metricId.type &&
Objects.equals(name, metricId.name) &&
Objects.equals(tags, metricId.tags);
Objects.equals(name, metricId.name) &&
Objects.equals(tags, metricId.tags);
}
@Override
@@ -44,10 +44,10 @@ public class MetricId {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("type", type)
.add("name", name)
.add("tags", tags)
.toString();
.add("type", type)
.add("name", name)
.add("tags", tags)
.toString();
}
public MetricType getType() {
@@ -125,7 +125,7 @@ public class MetricRegistry {
return MetricType.HISTOGRAM;
}
throw new RuntimeException(
"Unknown metric type, the metric is " + metric.getClass().getSimpleName());
"Unknown metric type, the metric is " + metric.getClass().getSimpleName());
}
private MetricId genMetricIdByMetric(Metric metric) {
@@ -11,6 +11,6 @@ public enum MetricType {
SUM,
HISTOGRAM;
HISTOGRAM
}
@@ -26,6 +26,4 @@ class NativeMetric {
public static native void unregisterMetricNative(long gaugePtr);
}
@@ -17,7 +17,7 @@ public class Sum extends Metric {
public Sum(String name, String description, String unit, Map<TagKey, String> tags) {
super(name, tags);
metricNativePointer = NativeMetric.registerSumNative(name, description, unit,
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
tags.keySet().stream().map(TagKey::getTagKey).collect(Collectors.toList()));
Preconditions.checkState(metricNativePointer != 0, "Count native pointer must not be 0.");
this.sum = new DoubleAdder();
}
@@ -10,7 +10,7 @@ public class TagKey {
private String tagKey;
public TagKey(String key) {
tagKey = key;
tagKey = key;
NativeMetric.registerTagkeyNative(key);
}
@@ -38,7 +38,7 @@ public class TagKey {
@Override
public String toString() {
return "TagKey{" +
", tagKey='" + tagKey + '\'' +
'}';
", tagKey='" + tagKey + '\'' +
'}';
}
}
@@ -28,49 +28,49 @@ public class MetricTest extends BaseTest {
int threadPoolSize,
long shutdownWaitTimeMs) {
MetricConfig config = MetricConfig.builder()
.timeIntervalMs(timeIntervalMs)
.threadPoolSize(threadPoolSize)
.shutdownWaitTimeMs(shutdownWaitTimeMs)
.create();
.timeIntervalMs(timeIntervalMs)
.threadPoolSize(threadPoolSize)
.shutdownWaitTimeMs(shutdownWaitTimeMs)
.create();
Metrics.init(config);
return config;
}
private Gauge registerGauge() {
return Metrics.gauge()
.name("metric_gauge")
.description("gauge")
.unit("")
.tags(ImmutableMap.of("tag1", "value1"))
.register();
.name("metric_gauge")
.description("gauge")
.unit("")
.tags(ImmutableMap.of("tag1", "value1"))
.register();
}
private Count registerCount() {
return Metrics.count()
.name("metric_count")
.description("counter")
.unit("1pc")
.tags(ImmutableMap.of("tag1", "value1", "count_tag", "default"))
.register();
.name("metric_count")
.description("counter")
.unit("1pc")
.tags(ImmutableMap.of("tag1", "value1", "count_tag", "default"))
.register();
}
private Sum registerSum() {
return Metrics.sum()
.name("metric_sum")
.description("sum")
.unit("1pc")
.tags(ImmutableMap.of("tag1", "value1", "sum_tag", "default"))
.register();
.name("metric_sum")
.description("sum")
.unit("1pc")
.tags(ImmutableMap.of("tag1", "value1", "sum_tag", "default"))
.register();
}
private Histogram registerHistogram() {
return Metrics.histogram()
.name("metric_histogram")
.description("histogram")
.unit("1pc")
.boundaries(ImmutableList.of(10.0, 15.0, 20.0))
.tags(ImmutableMap.of("tag1", "value1", "histogram_tag", "default"))
.register();
.name("metric_histogram")
.description("histogram")
.unit("1pc")
.boundaries(ImmutableList.of(10.0, 15.0, 20.0))
.tags(ImmutableMap.of("tag1", "value1", "histogram_tag", "default"))
.register();
}
@AfterMethod
@@ -122,7 +122,7 @@ public class MetricTest extends BaseTest {
boundaries.add(15.0);
boundaries.add(12.0);
Histogram histogram = new Histogram("metric_histogram", "histogram", "1pc",
boundaries, tags);
boundaries, tags);
for (int i = 1; i <= 200; ++i) {
histogram.update(i * 1.0d);
}