From 49e2bd7fe99b8f7181b539913ef65d244f6c946a Mon Sep 17 00:00:00 2001 From: Tim Quinn Date: Wed, 27 May 2020 11:58:17 -0500 Subject: [PATCH] Remove MP Metrics 1.0-to-2.0 bridge component and related classes in other components (#1879) --- CHANGELOG.md | 22 + bom/pom.xml | 5 - common/metrics/pom.xml | 45 - .../common/metrics/InternalBridge.java | 771 ------------------ .../common/metrics/InternalTagImpl.java | 95 --- .../io/helidon/common/metrics/Loader.java | 59 -- .../helidon/common/metrics/package-info.java | 27 - common/metrics/src/main/java/module-info.java | 28 - common/pom.xml | 3 +- grpc/metrics/pom.xml | 4 - .../io/helidon/grpc/metrics/GrpcMetrics.java | 36 +- grpc/metrics/src/main/java/module-info.java | 1 - .../metrics/GrpcMetricsInterceptorIT.java | 28 +- metrics/metrics/pom.xml | 4 - .../java/io/helidon/metrics/BaseRegistry.java | 199 +++-- .../io/helidon/metrics/HelidonMetadata.java | 68 -- .../java/io/helidon/metrics/HelidonTimer.java | 10 +- .../helidon/metrics/InternalBridgeImpl.java | 53 -- .../metrics/InternalMetadataBuilderImpl.java | 115 --- .../helidon/metrics/InternalMetadataImpl.java | 99 --- .../helidon/metrics/InternalMetricIDImpl.java | 94 --- .../io/helidon/metrics/MetricsSupport.java | 49 +- .../java/io/helidon/metrics/Registry.java | 154 +--- .../io/helidon/metrics/RegistryFactory.java | 9 +- .../metrics/src/main/java/module-info.java | 4 - .../io.helidon.common.metrics.InternalBridge | 17 - .../metrics/HelidonConcurrentGaugeTest.java | 14 +- .../helidon/metrics/HelidonCounterTest.java | 14 +- .../io/helidon/metrics/HelidonGaugeTest.java | 14 +- .../helidon/metrics/HelidonHistogramTest.java | 14 +- .../io/helidon/metrics/HelidonMeterTest.java | 14 +- .../io/helidon/metrics/HelidonTimerTest.java | 14 +- .../helidon/metrics/InternalBridgeTest.java | 130 --- .../io/helidon/metrics/MetricImplTest.java | 19 +- .../java/io/helidon/metrics/RegistryTest.java | 72 +- microprofile/fault-tolerance/pom.xml | 6 +- .../faulttolerance/FaultToleranceMetrics.java | 33 +- .../src/main/java/module-info.java | 3 +- .../faulttolerance/MetricsTest.java | 14 +- .../microprofile/metrics/MetricProducer.java | 28 +- .../metrics/MetricsCdiExtension.java | 87 +- .../metrics/RegistryProducer.java | 30 +- .../metrics/src/main/java/module-info.java | 3 +- .../metrics/MetricsMpServiceTest.java | 15 +- 44 files changed, 442 insertions(+), 2081 deletions(-) delete mode 100644 common/metrics/pom.xml delete mode 100644 common/metrics/src/main/java/io/helidon/common/metrics/InternalBridge.java delete mode 100644 common/metrics/src/main/java/io/helidon/common/metrics/InternalTagImpl.java delete mode 100644 common/metrics/src/main/java/io/helidon/common/metrics/Loader.java delete mode 100644 common/metrics/src/main/java/io/helidon/common/metrics/package-info.java delete mode 100644 common/metrics/src/main/java/module-info.java delete mode 100644 metrics/metrics/src/main/java/io/helidon/metrics/HelidonMetadata.java delete mode 100644 metrics/metrics/src/main/java/io/helidon/metrics/InternalBridgeImpl.java delete mode 100644 metrics/metrics/src/main/java/io/helidon/metrics/InternalMetadataBuilderImpl.java delete mode 100644 metrics/metrics/src/main/java/io/helidon/metrics/InternalMetadataImpl.java delete mode 100644 metrics/metrics/src/main/java/io/helidon/metrics/InternalMetricIDImpl.java delete mode 100644 metrics/metrics/src/main/resources/META-INF/services/io.helidon.common.metrics.InternalBridge delete mode 100644 metrics/metrics/src/test/java/io/helidon/metrics/InternalBridgeTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 2913eea50..cfc34f63b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,28 @@ This is the fourth milestone release of Helidon 2.0. ### Backward incompatible changes +#### Internal `helidon-common-metrics` and Related Classes Removed +Later releases of Helidon 1.x included the `helidon-common-metrics` component and related +classes which provided a common interface to ease the transition from MicroProfile +Metrics 1.x to 2.x. +Although intended for use only by Helidon subsystems rather than +by developers and users, the component and its contents had to be public so multiple Helidon +subsystems could use them. +Therefore, user code might have used these elements. + +This release removes this common interface and associated classes. +Any user code that used these internal classes can use the corresponding supported classes in +`io.helidon.metrics:helidon-metrics` and MicroProfile Metrics 2.0 instead. + +|Helidon Artifact |Interfaces/Classes | +|--------------|----------------| +|`io.helidon.common:helidon-common-metrics` |Entire artifact, including all `io.helidon.common.metrics...` classes | +|`io.helidon.metrics:helidon-metrics` |`HelidonMetadata` | +| |`InternalBridgeImpl` | +| |`InternalMetadataBuilderImpl` | +| |`InternalMetadataImpl` | +| |`InternalMetricIDImpl` | + ## [2.0.0-M3] ### Notes diff --git a/bom/pom.xml b/bom/pom.xml index 0727e9de4..0ac2202f8 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -555,11 +555,6 @@ helidon-common-context ${helidon.version} - - io.helidon.common - helidon-common-metrics - ${helidon.version} - diff --git a/common/metrics/pom.xml b/common/metrics/pom.xml deleted file mode 100644 index 3fd541fe7..000000000 --- a/common/metrics/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - 4.0.0 - - io.helidon.common - helidon-common-project - 2.0.0-SNAPSHOT - - helidon-common-metrics - - Helidon Common Metrics - - - Helidon Metrics common definitions - - - - - io.helidon.config - helidon-config - - - org.eclipse.microprofile.metrics - microprofile-metrics-api - provided - - - diff --git a/common/metrics/src/main/java/io/helidon/common/metrics/InternalBridge.java b/common/metrics/src/main/java/io/helidon/common/metrics/InternalBridge.java deleted file mode 100644 index eddef8d98..000000000 --- a/common/metrics/src/main/java/io/helidon/common/metrics/InternalBridge.java +++ /dev/null @@ -1,771 +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. - * - */ -package io.helidon.common.metrics; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import io.helidon.config.Config; - -import org.eclipse.microprofile.metrics.Counter; -import org.eclipse.microprofile.metrics.Gauge; -import org.eclipse.microprofile.metrics.Histogram; -import org.eclipse.microprofile.metrics.Meter; -import org.eclipse.microprofile.metrics.Metric; -import org.eclipse.microprofile.metrics.MetricType; -import org.eclipse.microprofile.metrics.Timer; - -/** - * Internal abstraction layer for MicroProfile 1.1 and 2.0. - *

- * Only Helidon internal clients of metrics should use this interface. Other - * clients should use Helidon BOMs or bundles which will use the appropriate - * versions of Helidon metrics and MicroProfile Metrics. - *

- * Implementations provide for getting instances of these features: - *

- * This interface is organized accordingly. Each of these exposes a factory and - * an instance of that factory. (The metadata builder from MP Metrics 2.0 is the - * factory for metadata, and therefore is nested under metadata in this - * interface. ) The top level of the bridge also exposes a few convenience - * methods for getting new instances of a version-specific implementations of the types. - */ -public interface InternalBridge { - - /** - * Returns the singleton instance of the bridge. - */ - InternalBridge INSTANCE = Loader.internalBridge(); - - /** - * - * @return the singleton metric ID factory - */ - MetricID.Factory getMetricIDFactory(); - - /** - * - * @return the singleton metadata builder factory - */ - Metadata.MetadataBuilder.Factory getMetadataBuilderFactory(); - - /** - * - * @return the singleton registry factory - */ - MetricRegistry.RegistryFactory getRegistryFactory(); - - /** - * - * @return a metadata builder - */ - static Metadata.MetadataBuilder newMetadataBuilder() { - return INSTANCE.getMetadataBuilderFactory().newMetadataBuilder(); - } - - /** - * Creates a new {@code RegistryFactory} with the default configuration, as - * exposed through the {@code InternalBridge.RegistryFactory} interface. - * - * @return the new {@code RegistryFactory} - */ - MetricRegistry.RegistryFactory createRegistryFactory(); - - /** - * Creates a new {@code RegistryFactory} with the specified configuration, - * as exposed through the {@code InternalBridge.RegistryFactory} interface. - * - * @param config the Helidon {@link Config} to use in initializing the - * factory. - * @return the new {@code RegistryFactory} - */ - MetricRegistry.RegistryFactory createRegistryFactory(Config config); - - /** - * Abstraction of the {@code MetricRegistry} behavior used by internal - * Helidon clients. - *

- * The exposed methods use version-neutral abstractions for - * {@code Metadata}, {@code MetricID}, and {@code Tag} which are used by - * MicroProfile Metrics. Some methods have {@code bridge} in their names because - * the corresponding MicroProfile Metrics methods changed return type but - * kept the same signature from 1.1 to 2.0, so here they need distinct names - * to distinguish them from the spec-prescribed methods (that do not use the - * version-neutral constructs). - */ - public interface MetricRegistry { - - /** - * Finds or creates a new {@code Counter} using the specified - * version-neutral {@code Metadata}. - * - * @param metadata used in locating and, if needed, building the counter - * @return the {@code Counter} - */ - Counter counter(Metadata metadata); - - /** - * Finds or creates a new {@code} Counter using the specified - * version-neutral {@code Metadata} and version-neutral {@code Tag}s. - * - * @param metadata used in locating and, if needed, building the counter - * @param tags used in locating and, if needed, building the counter - * @return the {@code Counter} - */ - Counter counter(Metadata metadata, Map tags); - - /** - * Finds or creates a new {@code Counter} using the specified name. - * - * @param name name for the new {@code Counter} - * @return the {@code Counter} - */ - Counter counter(String name); - - /** - * Finds or creates a new {@code Meter} using the specified - * version-neutral {@code Metadata}. - * - * @param metadata used in locating and, if needed, building the meter - * @return the {@code Meter} - */ - Meter meter(Metadata metadata); - - /** - * Finds or creates a new {@code Meter} using the specified - * version-neutral {@code Metadata} and version-neutral {@code Tag}s. - * - * @param metadata used in locating and, if needed, building the meter - * @param tags used in locating and, if needed, building the meter - * @return the {@code Meter} - */ - Meter meter(Metadata metadata, Map tags); - - /** - * Finds or creates a new {@code Meter} using the specified name. - * - * @param name used in locating and, if needed, building the meter - * @return the {@code Meter} - */ - Meter meter(String name); - - /** - * Finds or creates a new {@code Histogram} using the specified - * version-neutral {@code Metadata}. - * - * @param metadata used in locating and, if needed, building the - * histogram - * @return the {@code Histogram} - */ - Histogram histogram(Metadata metadata); - - /** - * Finds or creates a new {@code Histogram} using the specified - * version-neutral {@code Metadata} and version-neutral {@code Tag}s. - * - * @param metadata used in locating and, if needed, building the - * histogram - * @param tags used in locating and, if needed, building the histogram - * @return the {@code Histogram} - */ - Histogram histogram(Metadata metadata, Map tags); - - /** - * Finds or creates a new {@code Histogram} using the specified - * {@code Metadata}. - * - * @param name used in locating and, if needed, building the histogram - * @return the {@code Histogram} - */ - Histogram histogram(String name); - - /** - * Finds or creates a new {@code Timer} using the specified - * version-neutral {@code Metadata}. - * - * @param metadata used in locating and, if needed, building the timer - * @return the {@code Timer} - */ - Timer timer(Metadata metadata); - - /** - * Finds or creates a new {@code Timer} using the specified - * version-neutral {@code Metadata} and version-neutral {@code Tag}s. - * - * @param metadata used in locating and, if needed, building the timer - * @param tags used in locationg and, if needed, building the timer - * @return the {@code Timer} - */ - Timer timer(Metadata metadata, Map tags); - - /** - * Finds or creates a new {@code Timer} using the specified name. - * - * @param name used in locating and, if needed, building the timer - * @return the {@code Timer} - */ - Timer timer(String name); - - /** - * Returns all metrics from the registry as a map of version-neutral - * {@link MetricID}s to {@code Metric}s. - * - * @return the metrics - */ - Map getBridgeMetrics(); - - /** - * Returns all metrics from the registry as a map of version-neutral - * {@link MetricID}s to {@code Metric}s, filtered by the provided - * {@link Predicate}. - * - * @param predicate for selecting which metrics to include in the result - * @return the metrics matching the criteria expressed in the predicate - */ - Map getBridgeMetrics( - Predicate> predicate); - - /** - * Returns an {@link Optional} of the {@code MetricID} and - * {@link Metric} of the metric matching the given name. If multiple - * metrics match on the name (this can happen in MP Metrics 2.0 if the - * metrics were created with different tags) then the method returns the - * first metric with that name, if any. - * - * @param metricName name of the metric to find - * @return {@code Optional} of a {@code Map.Entry} for the matching ID - * and metric - */ - Optional> getBridgeMetric(String metricName); - - /** - * Returns the names of all metrics in the registry. - * - * @return a {@code Set} containing the names - */ - SortedSet getNames(); - - /** - * Returns all {@code Counter} metrics in the registry as a map of - * version-neutral {@link MetricID} to {@link Metric} entries. - * - * @return a map of all counters - */ - SortedMap getBridgeCounters(); - - /** - * Returns all {@code Gauge} metrics in the registry as a map of - * version-neutral {@link MetricID} to {@link Metric} entries. - * - * @return a map of all gauges - */ - SortedMap getBridgeGauges(); - - /** - * Returns all {@code Histogram} metrics in the registry as a map of - * version-neutral {@link MetricID} to {@link Metric} entries. - * - * @return a map of all histograms - */ - SortedMap getBridgeHistograms(); - - /** - * Returns all {@code Meter} metrics in the registry as a map of - * version-neutral {@link MetricID} to {@link Metric} entries. - * - * @return a map of all meters - */ - SortedMap getBridgeMeters(); - - /** - * Returns all {@code Timer} metrics in the registry as a map of - * version-neutral {@link MetricID} to {@link Metric} entries. - * - * @return a map of all timers - */ - SortedMap getBridgeTimers(); - - /** - * Registers a new metric using the specified version-neutral - * {@link Metadata} and the typed metric itself. - * - * @param the metric type - * @param metadata the metadata used in registering the metric - * @param metric the metric to register - * @return the registered metric - * @throws IllegalArgumentException if a metric with the same name but - * inconsistent metadata is already registered - */ - T register(Metadata metadata, T metric) throws IllegalArgumentException; - - /** - * Registers a new metric using the specified version-neutral - * {@link MetricID} and the typed metric itself. - * - * @param the metric type - * @param metricID the metric ID to be used in registering the metric - * @param metric the metric to register - * @return the registered metric - * @throws IllegalArgumentException if a metric with the same identify - * but inconsistent metadata is already registered - */ - T register(MetricID metricID, T metric) throws IllegalArgumentException; - - /** - * Removes the metrics with matching name from the registry. - * - * @param name name of the metric - * @return true if a matching metric was removed; false otherwise - */ - boolean remove(String name); - - /** - * Abstraction of the {@code RegistryFactory} behavior used by internal - * Helidon clients. - *

- * Using the name {@code RegistryFactory} here instead of just {@code Factory} - * should simplify changing the client code to use only the MP Metrics 2.0 - * implementation later. - */ - public interface RegistryFactory { - - /** - * The factory's singleton instance. - */ - RegistryFactory INSTANCE = Loader.registryFactory(); - - /** - * Returns the MicroProfile metric {@code MetricRegistry} of the - * indicated registry type typed as the internal abstraction. - * - * @param type registry type selected - * @return {@code MetricRegistry} of the selected type - */ - MetricRegistry getBridgeRegistry(org.eclipse.microprofile.metrics.MetricRegistry.Type type); - } - } - - /** - * Version-neutral abstraction of a metric identifier. - *

- * Note that for a metric with tags, the tags are ALWAYS present in the - * neutral {@code MetricID}. We want to encourage the internal clients to - * use the newer programming style, retrieving tags from the ID rather than - * the metadata (where it was stored in MP Metrics 1.1). - */ - public interface MetricID extends Comparable { - - /** - * - * @return the name from the identifier - */ - String getName(); - - /** - * - * @return the tags from the identifier, as a {@code Map} - */ - Map getTags(); - - /** - * Provides the tags as a {@code List}. The returned {@code Tag} objects - * are separate from those associated with the ID so changes to the tags - * made by the caller do not perturb the original ID. - * - * @return the {@code Tag}s - */ - default List getTagsAsList() { - return getTags().entrySet().stream() - .map(entry -> Tag.newTag(entry.getKey(), entry.getValue())) - .collect(Collectors.toList()); - } - - /** - * Describes the tags as a single string: name1=value1,name2=value2,... - * - * @return {@code String} containing the tags - */ - default String getTagsAsString() { - return getTags().entrySet().stream() - .map((entry) -> String.format("%s=%s", entry.getKey(), entry.getValue())) - .collect(Collectors.joining(",")); - } - - /** - * Compares this instance to another object (per {@code Comparable}. - * - * @param o the other object to compare to - * @return -1, 0, +1 depending on whether this instance is less than, - * equal to, or greater than the other object. - */ - @Override - default int compareTo(MetricID o) { - int result = getName().compareTo(Objects.requireNonNull(o).getName()); - if (result != 0) { - return result; - } - result = getTags().size() - o.getTags().size(); - if (result == 0) { - Iterator> thisIterator = getTags().entrySet().iterator(); - Iterator> otherIterator = o.getTags().entrySet().iterator(); - while (thisIterator.hasNext() && otherIterator.hasNext()) { - Map.Entry thisEntry = thisIterator.next(); - Map.Entry otherEntry = otherIterator.next(); - result = thisEntry.getKey().compareTo(otherEntry.getKey()); - if (result != 0) { - return result; - } else { - result = thisEntry.getValue().compareTo(otherEntry.getValue()); - if (result != 0) { - return result; - } - } - } - } - return result; - } - - /** - * Creates new {@code MetricID} instances. - */ - public interface Factory { - - /** - * Singleton instance of the factory. - */ - Factory INSTANCE = Loader.metricIDFactory(); - - /** - * Creates a version-neutral {@code MetricID} initialized with the - * specified name and any global tags. - * - * @param name name of the metric to create - * @return the new {@code MetricID} - */ - InternalBridge.MetricID newMetricID(String name); - - /** - * Creates a version-neutral {@code MetricID} initializes with the - * specified name and tags. - * - * @param name name of the metric to create - * @param tags tags to associated with the new ID - * @return the new {@code MetricID} - */ - InternalBridge.MetricID newMetricID(String name, Map tags); - } - } - - /** - * Version-neutral abstraction of metric metadata. - *

- * Although this interface supports tags, if you are using MicroProfile - * Metrics 2.0 or later the system ignores tags associated with metadata. - */ - public interface Metadata { - - /** - * - * @return the metric name stored in the metadata - */ - String getName(); - - /** - * - * @return the display name - */ - String getDisplayName(); - - /** - * - * @return an {@code Optional} of the metadata description - */ - Optional getDescription(); - - /** - * - * @return the metric type as a {@code String} - */ - String getType(); - - /** - * - * @return the metric type as a MicroProfile Metrics {link MetricType} - */ - MetricType getTypeRaw(); - - /** - * - * @return an {@code Optional} of the unit associated with this metadata - */ - Optional getUnit(); - - /** - * - * @return whether metrics described by this metadata are reusable or - * not - */ - boolean isReusable(); - - /** - * Returns the tags associated with the metadata. - *

- * Note that if you are using MicroProfile Metrics 2.0 and later the - * tags associated with this version-neutral metadata are ignored. - * - * @return tags - */ - Map getTags(); - - /** - * Prepares a version-neutral {@link Metadata} instance using the - * specified values, avoiding the need to create and act on a builder. - *

- * Note that although this method accepts tags, if you are using - * MicroProfile Metrics 2.0 or later the returned metadata will not - * include the tags. - * - * @param name name for the metrics associated with the metadata - * @param displayName display name - * @param description description of the metric - * @param type {@code MetricType} of the metric - * @param unit unit that applies to the metric - * @param isReusable whether or not metrics based on this metadata - * should be reusable - * @param tags name/value pairs representing tags - * @return the prepared version-neutral {@code Metadata} - */ - static InternalBridge.Metadata newMetadata(String name, String displayName, String description, - MetricType type, String unit, boolean isReusable, Map tags) { - final MetadataBuilder builder = MetadataBuilder.Factory.INSTANCE.newMetadataBuilder() - .withName(name) - .withDescription(description) - .withDisplayName(displayName) - .withType(type) - .withTags(tags) - .withUnit(unit); - return (isReusable ? builder.reusable() : builder.notReusable()).build(); - } - - /** - * Prepares a version-neutral {@link Metadata} instance using the - * specified values, avoiding the need to create and act on a builder. - *

- * Note that although this method accepts tags, if you are using - * MicroProfile Metrics 2.0 or later the returned metadata will not - * include the tags. - *

- * Also note that whether the metadata is reusable relies on the - * underlying MicroProfile Metrics version you are using. - * - * @param name name for the metrics associated with the metadata - * @param displayName display name - * @param description description of the metric - * @param type {@code MetricType} of the metric - * @param unit unit that applies to the metric - * @param tags name/value pairs representing tags - * @return the prepared version-neutral {@code Metadata} - */ - static InternalBridge.Metadata newMetadata(String name, String displayName, String description, - MetricType type, String unit, Map tags) { - return MetadataBuilder.Factory.INSTANCE.newMetadataBuilder() - .withName(name) - .withDescription(description) - .withDisplayName(displayName) - .withType(type) - .withTags(tags) - .withUnit(unit) - .build(); - } - - /** - * Prepares a version-neutral {@link Metadata} instance using the - * specified values, avoiding the need to create and act on a builder. - *

- * Note that whether the metadata is reusable relies on the underlying - * MicroProfile Metrics version you are using. - * - * @param name name for the metrics associated with the metadata - * @param displayName display name - * @param description description of the metric - * @param type {@code MetricType} of the metric - * @param unit unit that applies to the metric - * @return the prepared version-neutral {@code Metadata} - */ - static InternalBridge.Metadata newMetadata(String name, String displayName, String description, - MetricType type, String unit) { - return MetadataBuilder.Factory.INSTANCE.newMetadataBuilder() - .withName(name) - .withDescription(description) - .withDisplayName(displayName) - .withType(type) - .withUnit(unit) - .build(); - } - - /** - * Fluent-style builder for version-neutral {@link Metadata}. - *

- * The name is from MP Metrics but is actually the factory for {@code Metadata} - * in the design of the bridge. - * - */ - public interface MetadataBuilder { - - /** - * Sets the name. - * - * @param name name to be used in the metadata; cannot be null - * @return the same builder - */ - MetadataBuilder withName(String name); - - /** - * Sets the display name. - * - * @param displayName display name to be used in the metadata; - * cannot be null - * @return the same builder - */ - MetadataBuilder withDisplayName(String displayName); - - /** - * Sets the description. - * - * @param description description to be used in the metadata; cannot - * be null - * @return the same builder - */ - MetadataBuilder withDescription(String description); - - /** - * Sets the metric type. - * - * @param type {@link MetricType} to be used in the metadata; cannot - * be null - * @return the same builder - */ - MetadataBuilder withType(MetricType type); - - /** - * Sets the unit. - * - * @param unit unit to be used in the metadata; cannot be null - * @return the same builder - */ - MetadataBuilder withUnit(String unit); - - /** - * Sets that the resulting metadata will be reusable. - * - * @return the same builder - */ - MetadataBuilder reusable(); - - /** - * Sets that the resulting metadata will not be reusable. - * - * @return the same builder - */ - MetadataBuilder notReusable(); - - /** - * Sets the tags. - *

- * Note that when you use MicroProfile Metrics 2.0 or later, tags - * associated with metadata are ignored except within the metadata - * itself. - * - * @param tags map conveying the tags to be used in the metadata; - * @return the same builder - */ - MetadataBuilder withTags(Map tags); - - /** - * Creates a {@link Metadata} instance using the values set by - * invocations of the various {@code withXXX} methods. - * - * @return the version-neutral {@code Metadata} - * @throws IllegalStateException if the name was never set - */ - InternalBridge.Metadata build(); - - /** - * Factory for {@code MetadataBuilder} instances. - */ - public interface Factory { - - /** - * The factory's singleton instance. - */ - Factory INSTANCE = Loader.metadataBuilderFactory(); - - /** - * Returns a new version-specific {@code MetadataBuilder} that - * implements the neutral interface. - * - * @return the builder - */ - MetadataBuilder newMetadataBuilder(); - } - } - - } - - /** - * Version-neutral representation of a tag. - */ - public interface Tag { - - /** - * Creates a new version-neutral tag with the specified name and value. - * - * @param name name for the new tag - * @param value value for the new tag - * @return the new version-neutral tag - */ - static Tag newTag(String name, String value) { - return new InternalTagImpl(name, value); - } - - /** - * - * @return the tag's name - */ - String getTagName(); - - /** - * - * @return the tag's value - */ - String getTagValue(); - } - -} diff --git a/common/metrics/src/main/java/io/helidon/common/metrics/InternalTagImpl.java b/common/metrics/src/main/java/io/helidon/common/metrics/InternalTagImpl.java deleted file mode 100644 index bc88236fd..000000000 --- a/common/metrics/src/main/java/io/helidon/common/metrics/InternalTagImpl.java +++ /dev/null @@ -1,95 +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. - * - */ -package io.helidon.common.metrics; - -import java.util.Objects; - -/** - * Version-neutral implementation of {@code Tag} expressing a name/value pair. - *

- * To create a new instance of this class, use the - * {@link InternalBridge.Tag#newTag(java.lang.String, java.lang.String)} method. - */ -class InternalTagImpl implements InternalBridge.Tag { - - private final String name; - private final String value; - - /** - * Creates a new tag. - * - * @param name used for the tag - * @param value used for the tag - */ - InternalTagImpl(String name, String value) { - this.name = name; - this.value = value; - } - - /** - * - * @return the name of the tag - */ - @Override - public String getTagName() { - return name; - } - - /** - * - * @return the value of the tag - */ - @Override - public String getTagValue() { - return value; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 59 * hash + Objects.hashCode(this.name); - hash = 59 * hash + Objects.hashCode(this.value); - 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 InternalTagImpl other = (InternalTagImpl) obj; - if (!Objects.equals(this.name, other.name)) { - return false; - } - if (!Objects.equals(this.value, other.value)) { - return false; - } - return true; - } - - @Override - public String toString() { - return String.format("Tag{%s=%s}", name, value); - } - -} diff --git a/common/metrics/src/main/java/io/helidon/common/metrics/Loader.java b/common/metrics/src/main/java/io/helidon/common/metrics/Loader.java deleted file mode 100644 index 3cafec5c8..000000000 --- a/common/metrics/src/main/java/io/helidon/common/metrics/Loader.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. - * 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.common.metrics; - -import java.util.Iterator; -import java.util.ServiceLoader; - -/** - * Uses the Java service loader mechanism to find an implementation of the - * internal bridge and offer access to the various factories that implementation - * provides. - */ -class Loader { - private static final io.helidon.common.metrics.InternalBridge BRIDGE = loadInternalBridge(); - - static io.helidon.common.metrics.InternalBridge internalBridge() { - return BRIDGE; - } - - static io.helidon.common.metrics.InternalBridge.MetricRegistry.RegistryFactory registryFactory() { - return BRIDGE.getRegistryFactory(); - } - - static io.helidon.common.metrics.InternalBridge.MetricID.Factory metricIDFactory() { - return BRIDGE.getMetricIDFactory(); - } - - static io.helidon.common.metrics.InternalBridge.Metadata.MetadataBuilder.Factory metadataBuilderFactory() { - return BRIDGE.getMetadataBuilderFactory(); - } - - private static io.helidon.common.metrics.InternalBridge loadInternalBridge() { - for (Iterator it = - ServiceLoader.load(io.helidon.common.metrics.InternalBridge.class).iterator(); - it.hasNext();) { - return it.next(); - } - throw new RuntimeException("Could not find implementation of bridge " - + io.helidon.common.metrics.InternalBridge.class.getName() + " to load"); - } - - private Loader() { - } - -} diff --git a/common/metrics/src/main/java/io/helidon/common/metrics/package-info.java b/common/metrics/src/main/java/io/helidon/common/metrics/package-info.java deleted file mode 100644 index 43ca98ba1..000000000 --- a/common/metrics/src/main/java/io/helidon/common/metrics/package-info.java +++ /dev/null @@ -1,27 +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. - * - */ - -/** - * A collection of version-neutral interfaces (and some implementations where they - * apply to all versions) of constructs used in MicroProfile Metrics. - *

- * Note: Only Helidon internal clients of metrics should use the classes and - * interfaces in this package. The abstracting interfaces expose only the bare - * minimum surface area of their version-specific counterparts that are used by - * the various internal Helidon clients of metrics. - */ -package io.helidon.common.metrics; diff --git a/common/metrics/src/main/java/module-info.java b/common/metrics/src/main/java/module-info.java deleted file mode 100644 index c78b1a180..000000000 --- a/common/metrics/src/main/java/module-info.java +++ /dev/null @@ -1,28 +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. - * - */ - -module io.helidon.common.metrics { - - requires io.helidon.config; - requires transitive microprofile.metrics.api; - - exports io.helidon.common.metrics; - - uses io.helidon.common.metrics.InternalBridge; - - -} diff --git a/common/pom.xml b/common/pom.xml index d00f59cb8..16d131029 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -1,7 +1,7 @@