mirror of
https://github.com/jlengrand/helidon.git
synced 2026-03-10 08:21:17 +00:00
Remove MP Metrics 1.0-to-2.0 bridge component and related classes in other components (#1879)
This commit is contained in:
@@ -42,10 +42,6 @@
|
||||
<groupId>io.helidon.common</groupId>
|
||||
<artifactId>helidon-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.helidon.common</groupId>
|
||||
<artifactId>helidon-common-metrics</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.helidon.config</groupId>
|
||||
<artifactId>helidon-config-mp</artifactId>
|
||||
|
||||
@@ -56,27 +56,31 @@ final class BaseRegistry extends Registry {
|
||||
private static final String CONFIG_METRIC_ENABLED_BASE = "base.";
|
||||
static final String BASE_ENABLED_KEY = CONFIG_METRIC_ENABLED_BASE + "enabled";
|
||||
|
||||
private static final Metadata MEMORY_USED_HEAP =
|
||||
new HelidonMetadata("memory.usedHeap",
|
||||
"Used Heap Memory",
|
||||
"Displays the amount of used heap memory in bytes.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.BYTES);
|
||||
private static final Metadata MEMORY_USED_HEAP = Metadata.builder()
|
||||
.withName("memory.usedHeap")
|
||||
.withDisplayName("Used Heap Memory")
|
||||
.withDescription("Displays the amount of used heap memory in bytes.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.BYTES)
|
||||
.build();
|
||||
|
||||
private static final Metadata MEMORY_COMMITTED_HEAP =
|
||||
new HelidonMetadata("memory.committedHeap",
|
||||
"Committed Heap Memory",
|
||||
private static final Metadata MEMORY_COMMITTED_HEAP = Metadata.builder()
|
||||
.withName("memory.committedHeap")
|
||||
.withDisplayName("Committed Heap Memory")
|
||||
.withDescription(
|
||||
"Displays the amount of memory in bytes that is "
|
||||
+ "committed for the Java virtual "
|
||||
+ "machine to use. This amount of memory is "
|
||||
+ "guaranteed for the Java virtual "
|
||||
+ "machine to use.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.BYTES);
|
||||
+ "machine to use.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.BYTES)
|
||||
.build();
|
||||
|
||||
private static final Metadata MEMORY_MAX_HEAP =
|
||||
new HelidonMetadata("memory.maxHeap",
|
||||
"Max Heap Memory",
|
||||
private static final Metadata MEMORY_MAX_HEAP = Metadata.builder()
|
||||
.withName("memory.maxHeap")
|
||||
.withDisplayName("Max Heap Memory")
|
||||
.withDescription(
|
||||
"Displays the maximum amount of heap memory in bytes that can"
|
||||
+ " be used for "
|
||||
+ "memory management. This attribute displays -1 if "
|
||||
@@ -88,84 +92,94 @@ final class BaseRegistry extends Registry {
|
||||
+ "committed memory. The Java virtual machine may fail"
|
||||
+ " to allocate memory "
|
||||
+ "even if the amount of used memory does not exceed "
|
||||
+ "this maximum size.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.BYTES);
|
||||
+ "this maximum size.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.BYTES)
|
||||
.build();
|
||||
|
||||
private static final Metadata JVM_UPTIME =
|
||||
new HelidonMetadata("jvm.uptime",
|
||||
"JVM Uptime",
|
||||
private static final Metadata JVM_UPTIME = Metadata.builder()
|
||||
.withName("jvm.uptime")
|
||||
.withDisplayName("JVM Uptime")
|
||||
.withDescription(
|
||||
"Displays the start time of the Java virtual machine in "
|
||||
+ "milliseconds. This "
|
||||
+ "attribute displays the approximate time when the Java "
|
||||
+ "virtual machine "
|
||||
+ "started.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.MILLISECONDS);
|
||||
+ "started.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.MILLISECONDS)
|
||||
.build();
|
||||
|
||||
private static final Metadata THREAD_COUNT =
|
||||
new HelidonMetadata("thread.count",
|
||||
"Thread Count",
|
||||
"Displays the current number of live threads including both "
|
||||
+ "daemon and nondaemon threads",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.NONE);
|
||||
private static final Metadata THREAD_COUNT = Metadata.builder()
|
||||
.withName("thread.count")
|
||||
.withDisplayName("Thread Count")
|
||||
.withDescription("Displays the current number of live threads including both "
|
||||
+ "daemon and nondaemon threads")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
private static final Metadata THREAD_DAEMON_COUNT =
|
||||
new HelidonMetadata("thread.daemon.count",
|
||||
"Daemon Thread Count",
|
||||
"Displays the current number of live daemon threads.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.NONE);
|
||||
private static final Metadata THREAD_DAEMON_COUNT = Metadata.builder()
|
||||
.withName("thread.daemon.count")
|
||||
.withDisplayName("Daemon Thread Count")
|
||||
.withDescription("Displays the current number of live daemon threads.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
private static final Metadata THREAD_MAX_COUNT =
|
||||
new HelidonMetadata("thread.max.count",
|
||||
"Peak Thread Count",
|
||||
"Displays the peak live thread count since the Java "
|
||||
private static final Metadata THREAD_MAX_COUNT = Metadata.builder()
|
||||
.withName("thread.max.count")
|
||||
.withDisplayName("Peak Thread Count")
|
||||
.withDescription("Displays the peak live thread count since the Java "
|
||||
+ "virtual machine started or "
|
||||
+ "peak was reset. This includes daemon and "
|
||||
+ "non-daemon threads.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.NONE);
|
||||
+ "non-daemon threads.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
private static final Metadata CL_LOADED_COUNT =
|
||||
new HelidonMetadata("classloader.loadedClasses.count",
|
||||
"Current Loaded Class Count",
|
||||
"Displays the number of classes that are currently loaded in "
|
||||
+ "the Java virtual machine.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.NONE);
|
||||
private static final Metadata CL_LOADED_COUNT = Metadata.builder()
|
||||
.withName("classloader.loadedClasses.count")
|
||||
.withDisplayName("Current Loaded Class Count")
|
||||
.withDescription("Displays the number of classes that are currently loaded in "
|
||||
+ "the Java virtual machine.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
private static final Metadata CL_LOADED_TOTAL =
|
||||
new HelidonMetadata("classloader.loadedClasses.total",
|
||||
"Total Loaded Class Count",
|
||||
"Displays the total number of classes that have been loaded "
|
||||
+ "since the Java virtual machine has started execution.",
|
||||
MetricType.COUNTER,
|
||||
MetricUnits.NONE);
|
||||
private static final Metadata CL_LOADED_TOTAL = Metadata.builder()
|
||||
.withName("classloader.loadedClasses.total")
|
||||
.withDisplayName("Total Loaded Class Count")
|
||||
.withDescription("Displays the total number of classes that have been loaded "
|
||||
+ "since the Java virtual machine has started execution.")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
private static final Metadata CL_UNLOADED_COUNT =
|
||||
new HelidonMetadata("classloader.unloadedClasses.total",
|
||||
"Total Unloaded Class Count",
|
||||
"Displays the total number of classes unloaded since the Java "
|
||||
+ "virtual machine has started execution.",
|
||||
MetricType.COUNTER,
|
||||
MetricUnits.NONE);
|
||||
private static final Metadata CL_UNLOADED_COUNT = Metadata.builder()
|
||||
.withName("classloader.unloadedClasses.total")
|
||||
.withDisplayName("Total Unloaded Class Count")
|
||||
.withDescription("Displays the total number of classes unloaded since the Java "
|
||||
+ "virtual machine has started execution.")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
private static final Metadata OS_AVAILABLE_CPU =
|
||||
new HelidonMetadata("cpu.availableProcessors",
|
||||
"Available Processors",
|
||||
"Displays the number of processors available to the Java "
|
||||
private static final Metadata OS_AVAILABLE_CPU = Metadata.builder()
|
||||
.withName("cpu.availableProcessors")
|
||||
.withDisplayName("Available Processors")
|
||||
.withDescription("Displays the number of processors available to the Java "
|
||||
+ "virtual machine. This "
|
||||
+ "value may change during a particular invocation of"
|
||||
+ " the virtual machine.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.NONE);
|
||||
+ " the virtual machine.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
private static final Metadata OS_LOAD_AVERAGE =
|
||||
new HelidonMetadata("cpu.systemLoadAverage",
|
||||
"System Load Average",
|
||||
"Displays the system load average for the last minute. The "
|
||||
private static final Metadata OS_LOAD_AVERAGE = Metadata.builder()
|
||||
.withName("cpu.systemLoadAverage")
|
||||
.withDisplayName("System Load Average")
|
||||
.withDescription("Displays the system load average for the last minute. The "
|
||||
+ "system load average "
|
||||
+ "is the sum of the number of runnable entities "
|
||||
+ "queued to the available "
|
||||
@@ -182,9 +196,10 @@ final class BaseRegistry extends Registry {
|
||||
+ "and may be queried frequently. The load average may"
|
||||
+ " be unavailable on some "
|
||||
+ "platforms where it is expensive to implement this "
|
||||
+ "method.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.NONE);
|
||||
+ "method.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
private final Config config;
|
||||
|
||||
@@ -237,25 +252,31 @@ final class BaseRegistry extends Registry {
|
||||
}
|
||||
|
||||
private static Metadata gcTimeMeta() {
|
||||
return new HelidonMetadata("gc.time",
|
||||
"Garbage Collection Time",
|
||||
return Metadata.builder()
|
||||
.withName("gc.time")
|
||||
.withDisplayName("Garbage Collection Time")
|
||||
.withDescription(
|
||||
"Displays the approximate accumulated collection elapsed time in milliseconds. "
|
||||
+ "This attribute displays -1 if the collection elapsed time is undefined for this "
|
||||
+ "collector. The Java virtual machine implementation may use a high resolution "
|
||||
+ "timer to measure the elapsed time. This attribute may display the same value "
|
||||
+ "even if the collection count has been incremented if the collection elapsed "
|
||||
+ "time is very short.",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.MILLISECONDS);
|
||||
+ "time is very short.")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.MILLISECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Metadata gcCountMeta() {
|
||||
return new HelidonMetadata("gc.total",
|
||||
"Garbage Collection Count",
|
||||
return Metadata.builder()
|
||||
.withName("gc.total")
|
||||
.withDisplayName("Garbage Collection Count")
|
||||
.withDescription(
|
||||
"Displays the total number of collections that have occurred. This attribute lists "
|
||||
+ "-1 if the collection count is undefined for this collector.",
|
||||
MetricType.COUNTER,
|
||||
MetricUnits.NONE);
|
||||
+ "-1 if the collection count is undefined for this collector.")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static void register(BaseRegistry registry, Metadata meta, Metric metric, Tag... tags) {
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.helidon.metrics;
|
||||
|
||||
import org.eclipse.microprofile.metrics.DefaultMetadata;
|
||||
import org.eclipse.microprofile.metrics.MetricType;
|
||||
import org.eclipse.microprofile.metrics.MetricUnits;
|
||||
|
||||
/**
|
||||
* Class HelidonMetadata. In MP Metrics 2.0, {@link org.eclipse.microprofile.metrics.Metadata}
|
||||
* is now immutable and a builder was added. This class allows creation of metadata
|
||||
* directly using a constructor to avoid switching to a builder in dozens of locations.
|
||||
* Can be used from other packages unfortunately.
|
||||
*/
|
||||
public class HelidonMetadata extends DefaultMetadata {
|
||||
|
||||
/**
|
||||
* Construct immutable metadata.
|
||||
*
|
||||
* @param name Metric name.
|
||||
* @param type Metric type.
|
||||
*/
|
||||
public HelidonMetadata(String name, MetricType type) {
|
||||
super(name, null, null, type, MetricUnits.NONE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct immutable metadata.
|
||||
*
|
||||
* @param name Metric name.
|
||||
* @param displayName Metric display name.
|
||||
* @param description Metric description.
|
||||
* @param type Metric type.
|
||||
* @param unit Metric unit.
|
||||
* @param reusable Reusable flag.
|
||||
*/
|
||||
public HelidonMetadata(String name, String displayName, String description, MetricType type,
|
||||
String unit, boolean reusable) {
|
||||
super(name, displayName, description, type, unit, reusable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct immutable metadata.
|
||||
*
|
||||
* @param name Metric name.
|
||||
* @param displayName Metric display name.
|
||||
* @param description Metric description.
|
||||
* @param type Metric type.
|
||||
* @param unit Metric unit.
|
||||
*/
|
||||
public HelidonMetadata(String name, String displayName, String description, MetricType type, String unit) {
|
||||
super(name, displayName, description, type, unit, true);
|
||||
}
|
||||
}
|
||||
@@ -280,8 +280,14 @@ final class HelidonTimer extends MetricImpl implements Timer {
|
||||
private final Clock clock;
|
||||
|
||||
TimerImpl(String repoType, String name, Clock clock) {
|
||||
this.meter = HelidonMeter.create(repoType, new HelidonMetadata(name, MetricType.METERED), clock);
|
||||
this.histogram = HelidonHistogram.create(repoType, new HelidonMetadata(name, MetricType.HISTOGRAM));
|
||||
this.meter = HelidonMeter.create(repoType, Metadata.builder()
|
||||
.withName(name)
|
||||
.withType(MetricType.METERED)
|
||||
.build(), clock);
|
||||
this.histogram = HelidonHistogram.create(repoType, Metadata.builder()
|
||||
.withName(name)
|
||||
.withType(MetricType.HISTOGRAM)
|
||||
.build());
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.helidon.metrics;
|
||||
|
||||
import io.helidon.common.metrics.InternalBridge;
|
||||
import io.helidon.common.metrics.InternalBridge.Metadata.MetadataBuilder;
|
||||
import io.helidon.config.Config;
|
||||
|
||||
/**
|
||||
* Implements the metrics bridge interface based on MP Metrics 2.0.
|
||||
*/
|
||||
public class InternalBridgeImpl implements InternalBridge {
|
||||
|
||||
@Override
|
||||
public RegistryFactory getRegistryFactory() {
|
||||
return io.helidon.metrics.RegistryFactory.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryFactory createRegistryFactory() {
|
||||
return io.helidon.metrics.RegistryFactory.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryFactory createRegistryFactory(Config config) {
|
||||
return io.helidon.metrics.RegistryFactory.create(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricID.Factory getMetricIDFactory() {
|
||||
return new InternalMetricIDImpl.FactoryImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder.Factory getMetadataBuilderFactory() {
|
||||
return new InternalMetadataBuilderImpl.FactoryImpl();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.helidon.metrics;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.helidon.common.metrics.InternalBridge;
|
||||
import io.helidon.common.metrics.InternalBridge.Metadata;
|
||||
import io.helidon.common.metrics.InternalBridge.Metadata.MetadataBuilder;
|
||||
|
||||
import org.eclipse.microprofile.metrics.MetricType;
|
||||
|
||||
/**
|
||||
* Fluent-style builder for version-neutral {@link Metadata}.
|
||||
*
|
||||
*/
|
||||
class InternalMetadataBuilderImpl implements MetadataBuilder {
|
||||
|
||||
private final org.eclipse.microprofile.metrics.MetadataBuilder delegate;
|
||||
|
||||
InternalMetadataBuilderImpl() {
|
||||
delegate = new org.eclipse.microprofile.metrics.MetadataBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder withName(String name) {
|
||||
delegate.withName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder withDisplayName(String displayName) {
|
||||
delegate.withDisplayName(displayName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder withDescription(String description) {
|
||||
delegate.withDescription(description);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder withType(MetricType type) {
|
||||
delegate.withType(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder withUnit(String unit) {
|
||||
delegate.withUnit(unit);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder reusable() {
|
||||
delegate.reusable();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder notReusable() {
|
||||
delegate.notReusable();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata.MetadataBuilder withTags(Map<String, String> tags) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalBridge.Metadata build() {
|
||||
return new InternalMetadataImpl(delegate.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return delegate.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj != null)
|
||||
&& (this.getClass().isAssignableFrom(obj.getClass()))
|
||||
&& delegate.equals(((InternalMetadataBuilderImpl) obj).delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
static class FactoryImpl implements Factory {
|
||||
|
||||
@Override
|
||||
public Metadata.MetadataBuilder newMetadataBuilder() {
|
||||
return new InternalMetadataBuilderImpl();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.helidon.metrics;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import io.helidon.common.metrics.InternalBridge.Metadata;
|
||||
|
||||
import org.eclipse.microprofile.metrics.MetricType;
|
||||
|
||||
/**
|
||||
* Metrics 2.0-based implementation of the version-neutral {@code Metadata} interface.
|
||||
*/
|
||||
class InternalMetadataImpl implements Metadata {
|
||||
|
||||
private final org.eclipse.microprofile.metrics.Metadata delegate;
|
||||
|
||||
/**
|
||||
* Creates a new metadata instance, delegating to the specified 2.0 metadata.
|
||||
* @param delegate
|
||||
*/
|
||||
InternalMetadataImpl(org.eclipse.microprofile.metrics.Metadata delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return delegate.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getDescription() {
|
||||
return delegate.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return delegate.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricType getTypeRaw() {
|
||||
return delegate.getTypeRaw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getUnit() {
|
||||
return delegate.getUnit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReusable() {
|
||||
return delegate.isReusable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getTags() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return delegate.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj != null)
|
||||
&& (this.getClass().isAssignableFrom(obj.getClass()))
|
||||
&& delegate.equals(((InternalMetadataImpl) obj).delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.helidon.metrics;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.helidon.common.metrics.InternalBridge;
|
||||
|
||||
import org.eclipse.microprofile.metrics.MetricID;
|
||||
import org.eclipse.microprofile.metrics.Tag;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class InternalMetricIDImpl implements InternalBridge.MetricID {
|
||||
|
||||
private final MetricID delegate;
|
||||
|
||||
InternalMetricIDImpl(String name) {
|
||||
delegate = new org.eclipse.microprofile.metrics.MetricID(name);
|
||||
}
|
||||
|
||||
InternalMetricIDImpl(String name, Map<String, String> tags) {
|
||||
delegate = new org.eclipse.microprofile.metrics.MetricID(name, toTagArray(tags));
|
||||
}
|
||||
|
||||
private Tag[] toTagArray(Map<String, String> tags) {
|
||||
return tags.entrySet().stream()
|
||||
.map(entry -> new Tag(entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.toList())
|
||||
.toArray(new Tag[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getTags() {
|
||||
return delegate.getTags();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 37 * hash + Objects.hashCode(this.delegate);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final InternalMetricIDImpl other = (InternalMetricIDImpl) obj;
|
||||
return Objects.equals(this.delegate, other.delegate);
|
||||
}
|
||||
|
||||
static class FactoryImpl implements Factory {
|
||||
|
||||
@Override
|
||||
public io.helidon.common.metrics.InternalBridge.MetricID newMetricID(String name) {
|
||||
return new InternalMetricIDImpl(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public io.helidon.common.metrics.InternalBridge.MetricID newMetricID(String name, Map<String, String> tags) {
|
||||
return new InternalMetricIDImpl(name, tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ import io.helidon.webserver.cors.CorsEnabledServiceHelper;
|
||||
import io.helidon.webserver.cors.CrossOriginConfig;
|
||||
|
||||
import org.eclipse.microprofile.metrics.Counter;
|
||||
import org.eclipse.microprofile.metrics.Metadata;
|
||||
import org.eclipse.microprofile.metrics.Meter;
|
||||
import org.eclipse.microprofile.metrics.Metric;
|
||||
import org.eclipse.microprofile.metrics.MetricID;
|
||||
@@ -342,29 +343,37 @@ public final class MetricsSupport implements Service {
|
||||
* tags.
|
||||
*/
|
||||
Registry vendor = rf.getARegistry(MetricRegistry.Type.VENDOR);
|
||||
Counter totalCount = vendor.counter(new HelidonMetadata(metricPrefix + "count",
|
||||
"Total number of HTTP requests",
|
||||
"Each request (regardless of HTTP method) will increase this counter",
|
||||
MetricType.COUNTER,
|
||||
MetricUnits.NONE));
|
||||
Counter totalCount = vendor.counter(Metadata.builder()
|
||||
.withName(metricPrefix + "count")
|
||||
.withDisplayName("Total number of HTTP requests")
|
||||
.withDescription("Each request (regardless of HTTP method) will increase this counter")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build());
|
||||
|
||||
Meter totalMeter = vendor.meter(new HelidonMetadata(metricPrefix + "meter",
|
||||
"Meter for overall HTTP requests",
|
||||
"Each request will mark the meter to see overall throughput",
|
||||
MetricType.METERED,
|
||||
MetricUnits.NONE));
|
||||
Meter totalMeter = vendor.meter(Metadata.builder()
|
||||
.withName(metricPrefix + "meter")
|
||||
.withDisplayName("Meter for overall HTTP requests")
|
||||
.withDescription("Each request will mark the meter to see overall throughput")
|
||||
.withType(MetricType.METERED)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build());
|
||||
|
||||
vendor.counter(new HelidonMetadata("grpc.requests.count",
|
||||
"Total number of gRPC requests",
|
||||
"Each gRPC request (regardless of the method) will increase this counter",
|
||||
MetricType.COUNTER,
|
||||
MetricUnits.NONE));
|
||||
vendor.counter(Metadata.builder()
|
||||
.withName("grpc.requests.count")
|
||||
.withDisplayName("Total number of gRPC requests")
|
||||
.withDescription("Each gRPC request (regardless of the method) will increase this counter")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build());
|
||||
|
||||
vendor.meter(new HelidonMetadata("grpc.requests.meter",
|
||||
"Meter for overall gRPC requests",
|
||||
"Each gRPC request will mark the meter to see overall throughput",
|
||||
MetricType.METERED,
|
||||
MetricUnits.NONE));
|
||||
vendor.meter(Metadata.builder()
|
||||
.withName("grpc.requests.meter")
|
||||
.withDisplayName("Meter for overall gRPC requests")
|
||||
.withDescription("Each gRPC request will mark the meter to see overall throughput")
|
||||
.withType(MetricType.METERED)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build());
|
||||
|
||||
rules.any((req, res) -> {
|
||||
totalCount.inc();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,6 @@ import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -41,7 +40,6 @@ import org.eclipse.microprofile.metrics.Counter;
|
||||
import org.eclipse.microprofile.metrics.Gauge;
|
||||
import org.eclipse.microprofile.metrics.Histogram;
|
||||
import org.eclipse.microprofile.metrics.Metadata;
|
||||
import org.eclipse.microprofile.metrics.MetadataBuilder;
|
||||
import org.eclipse.microprofile.metrics.Meter;
|
||||
import org.eclipse.microprofile.metrics.Metric;
|
||||
import org.eclipse.microprofile.metrics.MetricFilter;
|
||||
@@ -54,7 +52,7 @@ import org.eclipse.microprofile.metrics.Timer;
|
||||
/**
|
||||
* Metrics registry.
|
||||
*/
|
||||
public class Registry extends MetricRegistry implements io.helidon.common.metrics.InternalBridge.MetricRegistry {
|
||||
public class Registry extends MetricRegistry {
|
||||
|
||||
private static final Tag[] NO_TAGS = new Tag[0];
|
||||
private static final Map<Class<? extends HelidonMetric>, MetricType> METRIC_TO_TYPE_MAP = prepareMetricToTypeMap();
|
||||
@@ -108,16 +106,6 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
return counter(metadata, NO_TAGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Counter counter(io.helidon.common.metrics.InternalBridge.Metadata metadata) {
|
||||
return counter(toMetadata(metadata));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Counter counter(io.helidon.common.metrics.InternalBridge.Metadata metadata, Map<String, String> tags) {
|
||||
return counter(toMetadata(metadata), toTags(tags));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Counter counter(String name, Tag... tags) {
|
||||
return getOrRegisterMetric(name, HelidonCounter::create, HelidonCounter.class, tags);
|
||||
@@ -138,16 +126,6 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
return histogram(metadata, NO_TAGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Histogram histogram(io.helidon.common.metrics.InternalBridge.Metadata metadata) {
|
||||
return histogram(toMetadata(metadata));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Histogram histogram(io.helidon.common.metrics.InternalBridge.Metadata metadata, Map<String, String> tags) {
|
||||
return histogram(toMetadata(metadata), toTags(tags));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Histogram histogram(String name, Tag... tags) {
|
||||
return getOrRegisterMetric(name, HelidonHistogram::create, HelidonHistogram.class, tags);
|
||||
@@ -168,16 +146,6 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
return meter(metadata, NO_TAGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meter meter(io.helidon.common.metrics.InternalBridge.Metadata metadata) {
|
||||
return meter(toMetadata(metadata));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meter meter(io.helidon.common.metrics.InternalBridge.Metadata metadata, Map<String, String> tags) {
|
||||
return meter(toMetadata(metadata), toTags(tags));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meter meter(String name, Tag... tags) {
|
||||
return getOrRegisterMetric(name, HelidonMeter::create, HelidonMeter.class, tags);
|
||||
@@ -198,16 +166,6 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
return timer(metadata, NO_TAGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timer timer(io.helidon.common.metrics.InternalBridge.Metadata metadata) {
|
||||
return timer(toMetadata(metadata));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timer timer(io.helidon.common.metrics.InternalBridge.Metadata metadata, Map<String, String> tags) {
|
||||
return timer(toMetadata(metadata), toTags(tags));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timer timer(String name, Tag... tags) {
|
||||
return getOrRegisterMetric(name, HelidonTimer::create, HelidonTimer.class, tags);
|
||||
@@ -364,81 +322,6 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
return Collections.unmodifiableMap(allMetrics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<io.helidon.common.metrics.InternalBridge.MetricID, Metric> getBridgeMetrics(
|
||||
Predicate<? super Map.Entry<? extends io.helidon.common.metrics.InternalBridge.MetricID,
|
||||
? extends Metric>> predicate) {
|
||||
|
||||
final Map<io.helidon.common.metrics.InternalBridge.MetricID, Metric> result = new HashMap<>();
|
||||
|
||||
allMetrics.entrySet().stream()
|
||||
.map(Registry::toBridgeEntry)
|
||||
.filter(predicate)
|
||||
.forEach(entry -> result.put(entry.getKey(), entry.getValue()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<io.helidon.common.metrics.InternalBridge.MetricID, Metric> getBridgeMetrics() {
|
||||
return getBridgeMetrics(entry -> true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<io.helidon.common.metrics.InternalBridge.MetricID, Gauge> getBridgeGauges() {
|
||||
return getBridgeMetrics(getGauges(), Gauge.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<io.helidon.common.metrics.InternalBridge.MetricID, Counter> getBridgeCounters() {
|
||||
return getBridgeMetrics(getCounters(), Counter.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<io.helidon.common.metrics.InternalBridge.MetricID, Histogram> getBridgeHistograms() {
|
||||
return getBridgeMetrics(getHistograms(), Histogram.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<io.helidon.common.metrics.InternalBridge.MetricID, Meter> getBridgeMeters() {
|
||||
return getBridgeMetrics(getMeters(), Meter.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<io.helidon.common.metrics.InternalBridge.MetricID, Timer> getBridgeTimers() {
|
||||
return getBridgeMetrics(getTimers(), Timer.class);
|
||||
}
|
||||
|
||||
private static <T extends Metric> SortedMap<io.helidon.common.metrics.InternalBridge.MetricID, T> getBridgeMetrics(
|
||||
SortedMap<MetricID, T> metrics, Class<T> clazz) {
|
||||
return metrics.entrySet().stream()
|
||||
.map(Registry::toBridgeEntry)
|
||||
.filter(entry -> clazz.isAssignableFrom(entry.getValue().getClass()))
|
||||
.collect(TreeMap::new,
|
||||
(map, entry) -> map.put(entry.getKey(), clazz.cast(entry.getValue())),
|
||||
Map::putAll);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T extends Metric> T register(
|
||||
io.helidon.common.metrics.InternalBridge.Metadata metadata, T metric) throws IllegalArgumentException {
|
||||
return register(toMetadata(metadata), metric);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Metric> T register(
|
||||
io.helidon.common.metrics.InternalBridge.MetricID metricID, T metric) throws IllegalArgumentException {
|
||||
return register(toMetadata(metricID.getName(), metric), metric, toTags(metricID.getTags()));
|
||||
}
|
||||
|
||||
private static Map.Entry<? extends io.helidon.common.metrics.InternalBridge.MetricID,
|
||||
? extends Metric> toBridgeEntry(
|
||||
Map.Entry<? extends MetricID, ? extends Metric> entry) {
|
||||
return new AbstractMap.SimpleEntry<>(new InternalMetricIDImpl(
|
||||
entry.getKey().getName(), entry.getKey().getTags()),
|
||||
entry.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Access a metric by name. Used by FT library.
|
||||
*
|
||||
@@ -449,13 +332,6 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
return getOptionalMetricEntry(metricName).map(Map.Entry::getValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Map.Entry<? extends io.helidon.common.metrics.InternalBridge.MetricID,
|
||||
? extends Metric>> getBridgeMetric(String metricName) {
|
||||
return getOptionalMetricEntry(metricName)
|
||||
.map(Registry::toBridgeEntry);
|
||||
}
|
||||
|
||||
// -- Public not overridden -----------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -492,18 +368,6 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
|
||||
// -- Package private -----------------------------------------------------
|
||||
|
||||
static Metadata toMetadata(io.helidon.common.metrics.InternalBridge.Metadata metadata) {
|
||||
final MetadataBuilder builder = new MetadataBuilder();
|
||||
builder.withName(metadata.getName())
|
||||
.withDisplayName(metadata.getDisplayName())
|
||||
.withType(metadata.getTypeRaw())
|
||||
.reusable(metadata.isReusable());
|
||||
|
||||
metadata.getDescription().ifPresent(builder::withDescription);
|
||||
metadata.getUnit().ifPresent(builder::withUnit);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
Optional<Map.Entry<MetricID, HelidonMetric>> getOptionalMetricEntry(String metricName) {
|
||||
return getOptionalMetricWithIDsEntry(metricName).map(entry -> {
|
||||
final MetricID metricID = entry.getValue().get(0);
|
||||
@@ -649,7 +513,10 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
return getOptionalMetric(metricName, clazz, tags)
|
||||
.orElseGet(() -> {
|
||||
final Metadata metadata = getOrRegisterMetadata(metricName, newType,
|
||||
() -> new HelidonMetadata(metricName, newType), tags);
|
||||
() -> Metadata.builder()
|
||||
.withName(metricName)
|
||||
.withType(newType)
|
||||
.build(), tags);
|
||||
return registerMetric(metricName, metricFactory.apply(type.getName(), metadata),
|
||||
tags);
|
||||
});
|
||||
@@ -675,7 +542,10 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
final MetricType metricType = MetricType.from(metric.getClass());
|
||||
|
||||
final Metadata metadata = getOrRegisterMetadata(metricName, metricType,
|
||||
() -> new HelidonMetadata(metricName, metricType), NO_TAGS);
|
||||
() -> Metadata.builder()
|
||||
.withName(metricName)
|
||||
.withType(metricType)
|
||||
.build(), NO_TAGS);
|
||||
registerMetric(metricName, toImpl(metadata, metric), NO_TAGS);
|
||||
return metric;
|
||||
}
|
||||
@@ -840,8 +710,8 @@ public class Registry extends MetricRegistry implements io.helidon.common.metric
|
||||
.orElse(MetricType.INVALID);
|
||||
}
|
||||
|
||||
private static <T extends Metric> HelidonMetadata toMetadata(String name, T metric) {
|
||||
return new HelidonMetadata(name, toType(metric));
|
||||
private static <T extends Metric> Metadata toMetadata(String name, T metric) {
|
||||
return Metadata.builder().withName(name).withType(toType(metric)).build();
|
||||
}
|
||||
|
||||
private static MetricType toType(Metric metric) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,7 +42,7 @@ import org.eclipse.microprofile.metrics.MetricRegistry.Type;
|
||||
*/
|
||||
// this class is not immutable, as we may need to update registries with configuration post creation
|
||||
// see Github issue #360
|
||||
public final class RegistryFactory implements io.helidon.common.metrics.InternalBridge.MetricRegistry.RegistryFactory {
|
||||
public final class RegistryFactory {
|
||||
private static final RegistryFactory INSTANCE = create();
|
||||
|
||||
private final EnumMap<Type, Registry> registries = new EnumMap<>(Type.class);
|
||||
@@ -156,11 +156,6 @@ public final class RegistryFactory implements io.helidon.common.metrics.Internal
|
||||
return publicRegistries.get(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public io.helidon.common.metrics.InternalBridge.MetricRegistry getBridgeRegistry(Type type) {
|
||||
return io.helidon.common.metrics.InternalBridge.MetricRegistry.class.cast(getRegistry(type));
|
||||
}
|
||||
|
||||
private void update(Config config) {
|
||||
this.config.set(config);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ module io.helidon.metrics {
|
||||
requires java.logging;
|
||||
|
||||
requires io.helidon.common;
|
||||
requires io.helidon.common.metrics;
|
||||
requires io.helidon.webserver.cors;
|
||||
|
||||
requires transitive microprofile.metrics.api;
|
||||
@@ -32,8 +31,5 @@ module io.helidon.metrics {
|
||||
requires io.helidon.config.mp;
|
||||
requires microprofile.config.api;
|
||||
|
||||
provides io.helidon.common.metrics.InternalBridge
|
||||
with io.helidon.metrics.InternalBridgeImpl;
|
||||
|
||||
exports io.helidon.metrics;
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
io.helidon.metrics.InternalBridgeImpl
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,11 +63,13 @@ public class HelidonConcurrentGaugeTest {
|
||||
|
||||
@BeforeAll
|
||||
static void initClass() {
|
||||
meta = new HelidonMetadata("aConcurrentGauge",
|
||||
"aConcurrentGauge",
|
||||
"aConcurrentGauge",
|
||||
MetricType.CONCURRENT_GAUGE,
|
||||
MetricUnits.NONE);
|
||||
meta = Metadata.builder()
|
||||
.withName("aConcurrentGauge")
|
||||
.withDisplayName("aConcurrentGauge")
|
||||
.withDescription("aConcurrentGauge")
|
||||
.withType(MetricType.CONCURRENT_GAUGE)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
System.out.println("Minimum required seconds within minute is " + MIN_REQUIRED_SECONDS
|
||||
+ ", so SECONDS_THRESHOLD is " + SECONDS_THRESHOLD);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,11 +47,13 @@ class HelidonCounterTest {
|
||||
|
||||
@BeforeAll
|
||||
static void initClass() {
|
||||
meta = new HelidonMetadata("theName",
|
||||
"theDisplayName",
|
||||
"theDescription",
|
||||
MetricType.COUNTER,
|
||||
MetricUnits.NONE);
|
||||
meta = Metadata.builder()
|
||||
.withName("theName")
|
||||
.withDisplayName("theDisplayName")
|
||||
.withDescription("theDescription")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,11 +45,13 @@ public class HelidonGaugeTest {
|
||||
|
||||
@BeforeAll
|
||||
static void initClass() {
|
||||
meta = new HelidonMetadata("aGauge",
|
||||
"aGauge",
|
||||
"aGauge",
|
||||
MetricType.GAUGE,
|
||||
MetricUnits.NONE);
|
||||
meta = Metadata.builder()
|
||||
.withName("aGauge")
|
||||
.withDisplayName("aGauge")
|
||||
.withDescription("aGauge")
|
||||
.withType(MetricType.GAUGE)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -124,11 +124,13 @@ class HelidonHistogramTest {
|
||||
|
||||
@BeforeAll
|
||||
static void initClass() {
|
||||
meta = new HelidonMetadata("file_sizes",
|
||||
"theDisplayName",
|
||||
"Users file size",
|
||||
MetricType.HISTOGRAM,
|
||||
MetricUnits.KILOBYTES);
|
||||
meta = Metadata.builder()
|
||||
.withName("file_sizes")
|
||||
.withDisplayName("theDisplayName")
|
||||
.withDescription("Users file size")
|
||||
.withType(MetricType.HISTOGRAM)
|
||||
.withUnit(MetricUnits.KILOBYTES)
|
||||
.build();
|
||||
|
||||
histoInt = HelidonHistogram.create("application", meta);
|
||||
histoIntID = new MetricID("file_sizes");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,11 +53,13 @@ class HelidonMeterTest {
|
||||
|
||||
@BeforeAll
|
||||
static void initClass() throws InterruptedException {
|
||||
Metadata meta = new HelidonMetadata("requests",
|
||||
"Requests",
|
||||
"Tracks the number of requests to the server",
|
||||
MetricType.METERED,
|
||||
MetricUnits.PER_SECOND);
|
||||
Metadata meta = Metadata.builder()
|
||||
.withName("requests")
|
||||
.withDisplayName("Requests")
|
||||
.withDescription("Tracks the number of requests to the server")
|
||||
.withType(MetricType.METERED)
|
||||
.withUnit(MetricUnits.PER_SECOND)
|
||||
.build();
|
||||
|
||||
LongAdder nanoTime = new LongAdder();
|
||||
LongAdder milliTime = new LongAdder();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,11 +66,13 @@ class HelidonTimerTest {
|
||||
|
||||
@BeforeAll
|
||||
static void initClass() {
|
||||
meta = new HelidonMetadata("response_time",
|
||||
"Responses",
|
||||
"Server response time for /index.html",
|
||||
MetricType.TIMER,
|
||||
MetricUnits.NANOSECONDS);
|
||||
meta = Metadata.builder()
|
||||
.withName("response_time")
|
||||
.withDisplayName("Responses")
|
||||
.withDescription("Server response time for /index.html")
|
||||
.withType(MetricType.TIMER)
|
||||
.withUnit(MetricUnits.NANOSECONDS)
|
||||
.build();
|
||||
|
||||
dataSetTimer = HelidonTimer.create("application", meta, dataSetTimerClock);
|
||||
dataSetTimerID = new MetricID("response_time");
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.helidon.metrics;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.helidon.common.metrics.InternalBridge;
|
||||
import io.helidon.common.metrics.InternalBridge.Metadata;
|
||||
|
||||
import org.eclipse.microprofile.metrics.Counter;
|
||||
import org.eclipse.microprofile.metrics.MetricID;
|
||||
import org.eclipse.microprofile.metrics.MetricRegistry;
|
||||
import org.eclipse.microprofile.metrics.MetricType;
|
||||
import org.eclipse.microprofile.metrics.MetricUnits;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class InternalBridgeTest {
|
||||
|
||||
private static io.helidon.common.metrics.InternalBridge ib;
|
||||
private static io.helidon.common.metrics.InternalBridge.MetricRegistry.RegistryFactory ibFactory;
|
||||
private static RegistryFactory factory;
|
||||
private static io.helidon.common.metrics.InternalBridge.MetricRegistry ibVendor;
|
||||
private static MetricRegistry vendor;
|
||||
private static io.helidon.common.metrics.InternalBridge.MetricRegistry ibApp;
|
||||
private static MetricRegistry app;
|
||||
|
||||
public InternalBridgeTest() {
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
private static void loadFactory() {
|
||||
ib = io.helidon.common.metrics.InternalBridge.INSTANCE;
|
||||
ibFactory = ib.getRegistryFactory();
|
||||
factory = RegistryFactory.getInstance();
|
||||
ibVendor = ibFactory.getBridgeRegistry(MetricRegistry.Type.VENDOR);
|
||||
vendor = factory.getRegistry(MetricRegistry.Type.VENDOR);
|
||||
ibApp = ibFactory.getBridgeRegistry(MetricRegistry.Type.APPLICATION);
|
||||
app = factory.getRegistry(MetricRegistry.Type.APPLICATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBridgeRegistryFactory() {
|
||||
assertSame(factory, ibFactory, "Factory and neutral factory do not match");
|
||||
assertSame(vendor, ibVendor, "Vendor registries via the two factories do not match");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTags() {
|
||||
String globalTags = System.getenv(MetricID.GLOBAL_TAGS_VARIABLE);
|
||||
Map<String, String> expectedTags = new HashMap<>();
|
||||
expectedTags.put("t1", "one");
|
||||
expectedTags.put("t2", "two");
|
||||
|
||||
if (globalTags != null) {
|
||||
Arrays.stream(globalTags.split(","))
|
||||
.map(expr -> {
|
||||
final int eq = expr.indexOf("=");
|
||||
if (eq <= 0) {
|
||||
return null;
|
||||
}
|
||||
String tag = expr.substring(0, eq);
|
||||
String value = expr.substring(eq + 1);
|
||||
return new AbstractMap.SimpleEntry<>(tag, value);
|
||||
})
|
||||
.filter(entry -> entry != null)
|
||||
.forEach(entry -> expectedTags.put(entry.getKey(), entry.getValue()));
|
||||
|
||||
}
|
||||
|
||||
org.eclipse.microprofile.metrics.Tag[] expectedTagsArray =
|
||||
expectedTags.entrySet().stream()
|
||||
.map(entry -> new org.eclipse.microprofile.metrics.Tag(entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.toList())
|
||||
.toArray(new org.eclipse.microprofile.metrics.Tag[0]);
|
||||
|
||||
Metadata internalMetadata = InternalBridge.newMetadataBuilder()
|
||||
.withName("MyCounter")
|
||||
.withDisplayName("MyCounter display")
|
||||
.withDescription("This is a test counter")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
org.eclipse.microprofile.metrics.Metadata metadata = new org.eclipse.microprofile.metrics.MetadataBuilder()
|
||||
.withName("MyCounter")
|
||||
.withDisplayName("MyCounter display")
|
||||
.withDescription("This is a test counter")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
Counter counter = ibApp.counter(internalMetadata, expectedTags);
|
||||
|
||||
org.eclipse.microprofile.metrics.MetricID expectedMetricID =
|
||||
new org.eclipse.microprofile.metrics.MetricID("MyCounter", expectedTagsArray);
|
||||
|
||||
SortedMap<MetricID, Counter> matchedCounters = app.getCounters(
|
||||
(metricID, metric) -> metricID.getName().equals("MyCounter"));
|
||||
|
||||
assertEquals(1, matchedCounters.size());
|
||||
assertEquals(counter, matchedCounters.get(expectedMetricID));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -69,11 +69,13 @@ class MetricImplTest {
|
||||
|
||||
@BeforeAll
|
||||
public static void initClass() {
|
||||
Metadata meta = new HelidonMetadata("theName",
|
||||
"theDisplayName",
|
||||
"theDescription",
|
||||
MetricType.COUNTER,
|
||||
MetricUnits.NONE);
|
||||
Metadata meta = Metadata.builder()
|
||||
.withName("theName")
|
||||
.withDisplayName("theDisplayName")
|
||||
.withDescription("theDescription")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.build();
|
||||
|
||||
impl = new MetricImpl("base", meta) {
|
||||
@Override
|
||||
@@ -88,7 +90,10 @@ class MetricImplTest {
|
||||
};
|
||||
implID = new MetricID(meta.getName());
|
||||
|
||||
meta = new HelidonMetadata("counterWithoutDescription", MetricType.COUNTER);
|
||||
meta = Metadata.builder()
|
||||
.withName("counterWithoutDescription")
|
||||
.withType(MetricType.COUNTER)
|
||||
.build();
|
||||
|
||||
implWithoutDescription = new MetricImpl("base", meta) {
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,8 +60,14 @@ public class RegistryTest {
|
||||
|
||||
@Test
|
||||
void testSameNameDifferentTagsDifferentTypes() {
|
||||
Metadata metadata1 = new HelidonMetadata("counter2", MetricType.COUNTER);
|
||||
Metadata metadata2 = new HelidonMetadata("counter2", MetricType.TIMER);
|
||||
Metadata metadata1 = Metadata.builder()
|
||||
.withName("counter2")
|
||||
.withType(MetricType.COUNTER)
|
||||
.build();
|
||||
Metadata metadata2 = Metadata.builder()
|
||||
.withName("counter2")
|
||||
.withType(MetricType.TIMER)
|
||||
.build();
|
||||
registry.counter(metadata1, tag1);
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
|
||||
() -> registry.timer(metadata2, tag2));
|
||||
@@ -70,10 +76,22 @@ public class RegistryTest {
|
||||
|
||||
@Test
|
||||
void testIncompatibleReuseNoTags() {
|
||||
Metadata metadata1 = new HelidonMetadata("counter3", "display name",
|
||||
"description", MetricType.COUNTER, MetricUnits.NONE, true);
|
||||
Metadata metadata2 = new HelidonMetadata("counter3", "display name",
|
||||
"description", MetricType.COUNTER, MetricUnits.NONE, false);
|
||||
Metadata metadata1 = Metadata.builder()
|
||||
.withName("counter3")
|
||||
.withDisplayName("display name")
|
||||
.withDescription("description")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.reusable(true)
|
||||
.build();
|
||||
Metadata metadata2 = Metadata.builder()
|
||||
.withName("counter3")
|
||||
.withDisplayName("display name")
|
||||
.withDescription("description")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.reusable(false)
|
||||
.build();
|
||||
|
||||
registry.counter(metadata1);
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
|
||||
@@ -83,10 +101,22 @@ public class RegistryTest {
|
||||
|
||||
@Test
|
||||
void testIncompatibleReuseWithTags() {
|
||||
Metadata metadata1 = new HelidonMetadata("counter4", "display name",
|
||||
"description", MetricType.COUNTER, MetricUnits.NONE, true);
|
||||
Metadata metadata2 = new HelidonMetadata("counter4", "display name",
|
||||
"description", MetricType.COUNTER, MetricUnits.NONE, false);
|
||||
Metadata metadata1 = Metadata.builder()
|
||||
.withName("counter4")
|
||||
.withDisplayName("display name")
|
||||
.withDescription("description")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.reusable(true)
|
||||
.build();
|
||||
Metadata metadata2 = Metadata.builder()
|
||||
.withName("counter4")
|
||||
.withDisplayName("display name")
|
||||
.withDescription("description")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.reusable(false)
|
||||
.build();
|
||||
|
||||
registry.counter(metadata1, tag1);
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
|
||||
@@ -96,10 +126,22 @@ public class RegistryTest {
|
||||
|
||||
@Test
|
||||
void testSameIDSameReuseDifferentOtherMetadata() {
|
||||
Metadata metadata1 = new HelidonMetadata("counter5", "display name",
|
||||
"description", MetricType.COUNTER, MetricUnits.NONE, true);
|
||||
Metadata metadata2 = new HelidonMetadata("counter5", "OTHER display name",
|
||||
"description", MetricType.COUNTER, MetricUnits.NONE, true);
|
||||
Metadata metadata1 = Metadata.builder()
|
||||
.withName("counter5")
|
||||
.withDisplayName("display name")
|
||||
.withDescription("description")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.reusable(true)
|
||||
.build();
|
||||
Metadata metadata2 = Metadata.builder()
|
||||
.withName("counter5")
|
||||
.withDisplayName("OTHER display name")
|
||||
.withDescription("description")
|
||||
.withType(MetricType.COUNTER)
|
||||
.withUnit(MetricUnits.NONE)
|
||||
.reusable(true)
|
||||
.build();
|
||||
|
||||
registry.counter(metadata1, tag1);
|
||||
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
|
||||
|
||||
Reference in New Issue
Block a user