io.helidon.config
helidon-config-hocon
diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java
index 41840c0e68c..9466e4a0c24 100644
--- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java
+++ b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022 Oracle and/or its affiliates.
+ * Copyright (c) 2021, 2023 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.
@@ -29,9 +29,9 @@
import io.helidon.common.http.Http;
import io.helidon.config.Config;
-import io.helidon.reactive.webserver.Handler;
-import io.helidon.reactive.webserver.ServerRequest;
-import io.helidon.reactive.webserver.ServerResponse;
+import io.helidon.nima.webserver.http.Handler;
+import io.helidon.nima.webserver.http.ServerRequest;
+import io.helidon.nima.webserver.http.ServerResponse;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
@@ -63,7 +63,8 @@
* In Micrometer, different registries report their contents in different formats. Further, there is no common abstract
* method defined on {@code MeterRegistry} which all implementations override; each {@code MeterRegistry} has its own
* particular way of furnishing metrics output.
- *
+ *
+ *
* By default, we use a {@code PrometheusMeterRegistry} to support Prometheus/OpenMetrics format. Developers can enroll other
* registries to support other formats. We need to know which registry to use in response to receiving an HTTP request for
* Micrometer metrics output.
@@ -97,7 +98,6 @@ public final class MeterRegistryFactory {
private final CompositeMeterRegistry compositeMeterRegistry;
private final List registryEnrollments;
- private final List nimaRegistryEnrollments;
// for testing
private final Map builtInRegistryEnrollments = new HashMap<>();
@@ -162,9 +162,6 @@ private MeterRegistryFactory(Builder builder) {
builtInRegistryEnrollments.put(builtInRegistryType, meterRegistry);
});
registryEnrollments.forEach(e -> compositeMeterRegistry.add(e.meterRegistry()));
-
- nimaRegistryEnrollments = builder.nimaRegistryEnrollments();
- nimaRegistryEnrollments.forEach(e -> compositeMeterRegistry.add(e.meterRegistry()));
}
/**
@@ -229,19 +226,9 @@ static BuiltInRegistryType valueByName(String name) throws UnrecognizedBuiltInRe
}
}
- Handler matchingHandler(ServerRequest serverRequest, ServerResponse serverResponse) {
- return registryEnrollments.stream()
- .map(e -> e.handlerFn().apply(serverRequest))
- .flatMap(Optional::stream)
- .findFirst()
- .orElse((req, res) -> res
- .status(Http.Status.NOT_ACCEPTABLE_406)
- .send(NO_MATCHING_REGISTRY_ERROR_MESSAGE));
- }
-
io.helidon.nima.webserver.http.Handler matchingHandler(io.helidon.nima.webserver.http.ServerRequest serverRequest,
io.helidon.nima.webserver.http.ServerResponse serverResponse) {
- return nimaRegistryEnrollments.stream()
+ return registryEnrollments.stream()
.map(e -> e.handlerFn().apply(serverRequest))
.flatMap(Optional::stream)
.findFirst()
@@ -256,7 +243,6 @@ io.helidon.nima.webserver.http.Handler matchingHandler(io.helidon.nima.webserver
public static class Builder implements io.helidon.common.Builder {
private final List explicitRegistryEnrollments = new ArrayList<>();
- private final List explicitNimaRegistryEnrollments = new ArrayList<>();
private final Map builtInRegistriesRequested = new HashMap<>();
@@ -320,47 +306,24 @@ public Builder enrollBuiltInRegistry(BuiltInRegistryType builtInRegistryType) {
* @param handlerFunction returns {@code Optional}; if present, capable of responding to the specified request
* @return updated builder instance
*/
- public Builder enrollRegistry(MeterRegistry meterRegistry, Function> handlerFunction) {
+ public Builder enrollRegistry(MeterRegistry meterRegistry,
+ Function> handlerFunction) {
explicitRegistryEnrollments.add(new Enrollment(meterRegistry, handlerFunction));
return this;
}
- /**
- * Records a {@code MetricRegistry} to be managed by {@code MicrometerSupport}, along with the function that returns an
- * {@code Optional} of a {@code Handler} for processing a given request to the Micrometer endpoint.
- *
- * @param meterRegistry the registry to enroll
- * @param handlerFunction returns {@code Optional}; if present, capable of responding to the specified request
- * @return updated builder instance
- */
- public Builder enrollRegistryNima(MeterRegistry meterRegistry,
- Function> handlerFunction) {
- explicitNimaRegistryEnrollments.add(new NimaEnrollment(meterRegistry, handlerFunction));
- return this;
- }
-
// For testing
List logRecords() {
return logRecords;
}
- private List explicitAndBuiltInEnrollments() {
+ List explicitAndBuiltInEnrollments() {
List result = new ArrayList<>(explicitRegistryEnrollments);
builtInRegistriesRequested.forEach((builtInRegistrySupportType, builtInRegistrySupport) -> {
MeterRegistry meterRegistry = builtInRegistrySupport.registry();
result.add(new Enrollment(meterRegistry,
- builtInRegistrySupport.requestToHandlerFn(meterRegistry)));
- });
- return result;
- }
-
- List nimaRegistryEnrollments() {
- List result = new ArrayList<>(explicitNimaRegistryEnrollments);
- builtInRegistriesRequested.forEach((builtInRegistrySupportType, builtInRegistrySupport) -> {
- MeterRegistry meterRegistry = builtInRegistrySupport.registry();
- result.add(new NimaEnrollment(meterRegistry,
- builtInRegistrySupport.requestNimaToHandlerFn(meterRegistry)));
+ builtInRegistrySupport.requestToHandlerFn(meterRegistry)));
});
return result;
}
@@ -432,33 +395,13 @@ Map enrolledBuiltInRegistries() {
return builtInRegistryEnrollments;
}
-
private static class Enrollment {
- private final MeterRegistry meterRegistry;
- private final Function> handlerFn;
-
- private Enrollment(MeterRegistry meterRegistry, Function> handlerFn) {
- this.meterRegistry = meterRegistry;
- this.handlerFn = handlerFn;
- }
-
- private MeterRegistry meterRegistry() {
- return meterRegistry;
- }
-
- private Function> handlerFn() {
- return handlerFn;
- }
- }
-
- private static class NimaEnrollment {
-
private final MeterRegistry meterRegistry;
private final Function> handlerFn;
- private NimaEnrollment(MeterRegistry meterRegistry,
+ private Enrollment(MeterRegistry meterRegistry,
Function> handlerFn) {
this.meterRegistry = meterRegistry;
diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerBuiltInRegistrySupport.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerBuiltInRegistrySupport.java
index e993787ceea..f51ff62d3b8 100644
--- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerBuiltInRegistrySupport.java
+++ b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerBuiltInRegistrySupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022 Oracle and/or its affiliates.
+ * Copyright (c) 2021, 2023 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.
@@ -22,8 +22,6 @@
import io.helidon.config.Config;
import io.helidon.config.ConfigValue;
-import io.helidon.reactive.webserver.Handler;
-import io.helidon.reactive.webserver.ServerRequest;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterRegistryConfig;
@@ -92,10 +90,8 @@ static MicrometerBuiltInRegistrySupport create(MeterRegistryFactory.BuiltInRegis
abstract MeterRegistry createRegistry(MeterRegistryConfig meterRegistryConfig);
- abstract Function> requestToHandlerFn(MeterRegistry registry);
-
abstract Function> requestNimaToHandlerFn(
+ Optional> requestToHandlerFn(
MeterRegistry meterRegistry);
diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerPrometheusRegistrySupport.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerPrometheusRegistrySupport.java
index 13395d68655..38d309ee4df 100644
--- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerPrometheusRegistrySupport.java
+++ b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerPrometheusRegistrySupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022 Oracle and/or its affiliates.
+ * Copyright (c) 2021, 2023 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.
@@ -24,8 +24,6 @@
import io.helidon.common.media.type.MediaTypes;
import io.helidon.config.Config;
import io.helidon.config.ConfigValue;
-import io.helidon.reactive.webserver.Handler;
-import io.helidon.reactive.webserver.ServerRequest;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterRegistryConfig;
@@ -67,7 +65,7 @@ PrometheusMeterRegistry createRegistry(MeterRegistryConfig meterRegistryConfig)
@Override
public Function> requestNimaToHandlerFn(MeterRegistry registry) {
+ Optional> requestToHandlerFn(MeterRegistry registry) {
/*
* Deal with a request if the MediaType is text/plain or the query parameter "type" specifies "prometheus".
*/
@@ -78,26 +76,7 @@ Optional> requestNimaToHandlerFn(MeterRe
.first("type")
.orElse("")
.equals("prometheus")) {
- return Optional.of(NimaPrometheusHandler.create(registry));
- } else {
- return Optional.empty();
- }
- };
- }
-
- @Override
- public Function> requestToHandlerFn(MeterRegistry registry) {
- /*
- * Deal with a request if the MediaType is text/plain or the query parameter "type" specifies "prometheus".
- */
- return (ServerRequest req) -> {
- if (req.headers()
- .bestAccepted(MediaTypes.TEXT_PLAIN).isPresent()
- || req.queryParams()
- .first("type")
- .orElse("")
- .equals("prometheus")) {
- return Optional.of(ReactivePrometheusHandler.create(registry));
+ return Optional.of(PrometheusHandler.create(registry));
} else {
return Optional.empty();
}
diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerSupport.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerSupport.java
deleted file mode 100644
index 348e14231fe..00000000000
--- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerSupport.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright (c) 2021, 2022 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.integrations.micrometer;
-
-import java.util.function.Supplier;
-import java.util.logging.Logger;
-
-import io.helidon.config.Config;
-import io.helidon.config.metadata.Configured;
-import io.helidon.reactive.servicecommon.HelidonRestServiceSupport;
-import io.helidon.reactive.webserver.Handler;
-import io.helidon.reactive.webserver.Routing;
-import io.helidon.reactive.webserver.ServerRequest;
-import io.helidon.reactive.webserver.ServerResponse;
-
-import io.micrometer.core.instrument.MeterRegistry;
-
-/**
- * Implements simple Micrometer support.
- *
- * Developers create Micrometer {@code MeterRegistry} objects and enroll them with
- * {@link Builder}, providing with each enrollment a Helidon {@code Handler} for expressing the registry's
- * data in an HTTP response.
- *
- * Alternatively, developers can enroll any of the built-in registries represented by
- * the {@link MeterRegistryFactory.BuiltInRegistryType} enum.
- *
- * Having enrolled Micrometer meter registries with {@code MicrometerSupport.Builder} and built the
- * {@code MicrometerSupport} object, developers can invoke the {@link #registry()} method and use the returned {@code
- * MeterRegistry} to create or locate meters.
- *
- */
-public class MicrometerSupport extends HelidonRestServiceSupport {
-
- static final String DEFAULT_CONTEXT = "/micrometer";
- private static final String SERVICE_NAME = "Micrometer";
-
- private final MeterRegistryFactory meterRegistryFactory;
-
- private MicrometerSupport(Builder builder) {
- super(Logger.getLogger(MicrometerSupport.class.getName()), builder, SERVICE_NAME);
-
- meterRegistryFactory = builder.meterRegistryFactorySupplier.get();
- }
-
- /**
- * Fluid builder for {@code MicrometerSupport}.
- *
- * @return Builder
- */
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * Creates a new {@code MicrometerSupport} using default settings.
- *
- * @return default MicrometerSupport
- */
- public static MicrometerSupport create() {
- return builder().build();
- }
-
- /**
- * Creates a new {@code MicrometerSupport} using the provided {@code Config} (anchored at the "metrics.micrometer" node).
- *
- * @param config Config settings for Micrometer set-up
- * @return newly-created MicrometerSupport
- */
- public static MicrometerSupport create(Config config) {
- return builder().config(config).build();
- }
-
- /**
- * Returns the composite registry so apps can create and register meters on it.
- *
- * @return the composite registry
- */
- public MeterRegistry registry() {
- return meterRegistryFactory.meterRegistry();
- }
-
- @Override
- public void update(Routing.Rules rules) {
- configureEndpoint(rules, rules);
- }
-
- @Override
- protected void postConfigureEndpoint(Routing.Rules defaultRules, Routing.Rules serviceEndpointRoutingRules) {
- defaultRules
- .any(new MetricsContextHandler(registry()))
- .get(context(), this::getOrOptions)
- .options(context(), this::getOrOptions);
- }
-
- private void getOrOptions(ServerRequest serverRequest, ServerResponse serverResponse) {
- /*
- Each meter registry is paired with a function. For each, invoke the function
- looking for the first non-empty Optional and invoke that handler. If
- none matches then return an error response.
- */
- meterRegistryFactory
- .matchingHandler(serverRequest, serverResponse)
- .accept(serverRequest, serverResponse);
- }
-
- /**
- * Fluid builder for {@code MicrometerSupport} objects.
- */
- @Configured(prefix = "micrometer")
- public static class Builder extends HelidonRestServiceSupport.Builder
- implements io.helidon.common.Builder {
-
- private Supplier meterRegistryFactorySupplier = null;
-
- private Builder() {
- super(DEFAULT_CONTEXT);
- }
-
- @Override
- public MicrometerSupport build() {
- if (null == meterRegistryFactorySupplier) {
- meterRegistryFactorySupplier = () -> MeterRegistryFactory.getInstance(
- MeterRegistryFactory.builder().config(config()));
- }
- return new MicrometerSupport(this);
- }
-
- /**
- * Assigns a {@code MeterRegistryFactory}.
- *
- * @param meterRegistryFactory the MeterRegistry to use
- * @return updated builder instance
- */
- public Builder meterRegistryFactorySupplier(MeterRegistryFactory meterRegistryFactory) {
- this.meterRegistryFactorySupplier = () -> meterRegistryFactory;
- return this;
- }
- }
-
- // this class is created for cleaner tracing of web server handlers
- private static final class MetricsContextHandler implements Handler {
-
- private final MeterRegistry meterRegistry;
-
- private MetricsContextHandler(MeterRegistry meterRegistry) {
- this.meterRegistry = meterRegistry;
- }
-
- @Override
- public void accept(ServerRequest req, ServerResponse res) {
- req.context().register(meterRegistry);
- req.next();
- }
- }
-}
diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/NimaPrometheusHandler.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/PrometheusHandler.java
similarity index 85%
rename from integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/NimaPrometheusHandler.java
rename to integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/PrometheusHandler.java
index 6ac382badc0..8560c9dca1d 100644
--- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/NimaPrometheusHandler.java
+++ b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/PrometheusHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Oracle and/or its affiliates.
+ * Copyright (c) 2022, 2023 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.
@@ -30,16 +30,16 @@
/**
* Handler for dealing with HTTP requests to the Micrometer endpoint that specify prometheus as the registry type.
*/
-class NimaPrometheusHandler implements Handler {
+class PrometheusHandler implements Handler {
private final PrometheusMeterRegistry registry;
- private NimaPrometheusHandler(PrometheusMeterRegistry registry) {
+ private PrometheusHandler(PrometheusMeterRegistry registry) {
this.registry = registry;
}
- static NimaPrometheusHandler create(MeterRegistry registry) {
- return new NimaPrometheusHandler(PrometheusMeterRegistry.class.cast(registry));
+ static PrometheusHandler create(MeterRegistry registry) {
+ return new PrometheusHandler(PrometheusMeterRegistry.class.cast(registry));
}
@Override
diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/ReactivePrometheusHandler.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/ReactivePrometheusHandler.java
deleted file mode 100644
index 9d3cb5b1ef5..00000000000
--- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/ReactivePrometheusHandler.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2022 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.integrations.micrometer;
-
-import java.io.IOException;
-import java.io.StringWriter;
-
-import io.helidon.common.http.Http;
-import io.helidon.common.media.type.MediaTypes;
-import io.helidon.reactive.webserver.Handler;
-import io.helidon.reactive.webserver.ServerRequest;
-import io.helidon.reactive.webserver.ServerResponse;
-
-import io.micrometer.core.instrument.MeterRegistry;
-import io.micrometer.prometheus.PrometheusMeterRegistry;
-
-/**
- * Handler for dealing with HTTP requests to the Micrometer endpoint that specify prometheus as the registry type.
- */
-class ReactivePrometheusHandler implements Handler {
-
- private final PrometheusMeterRegistry registry;
-
- private ReactivePrometheusHandler(PrometheusMeterRegistry registry) {
- this.registry = registry;
- }
-
- static ReactivePrometheusHandler create(MeterRegistry registry) {
- return new ReactivePrometheusHandler(PrometheusMeterRegistry.class.cast(registry));
- }
-
- @Override
- public void accept(ServerRequest req, ServerResponse res) {
- res.headers().contentType(MediaTypes.TEXT_PLAIN);
- if (req.method() == Http.Method.GET) {
- res.send(registry.scrape());
- } else if (req.method() == Http.Method.OPTIONS) {
- StringWriter writer = new StringWriter();
- try {
- MicrometerPrometheusRegistrySupport.metadata(writer, registry);
- res.send(writer.toString());
- } catch (IOException e) {
- res.status(Http.Status.INTERNAL_SERVER_ERROR_500)
- .send(e);
- }
- } else {
- res.status(Http.Status.NOT_IMPLEMENTED_501)
- .send();
- }
- }
-}
diff --git a/integrations/micrometer/micrometer/src/main/java/module-info.java b/integrations/micrometer/micrometer/src/main/java/module-info.java
index 4473494d8cb..f58ffff1f40 100644
--- a/integrations/micrometer/micrometer/src/main/java/module-info.java
+++ b/integrations/micrometer/micrometer/src/main/java/module-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022 Oracle and/or its affiliates.
+ * Copyright (c) 2021, 2023 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.
@@ -36,8 +36,6 @@
requires io.helidon.config;
requires io.helidon.common.http;
- requires io.helidon.reactive.servicecommon;
- requires io.helidon.reactive.webserver.cors;
requires io.helidon.nima.servicecommon;
requires io.helidon.nima.webserver.cors;
diff --git a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerEndpointTests.java b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerEndpointTests.java
index d5d0a09f6d5..147c646bc3a 100644
--- a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerEndpointTests.java
+++ b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerEndpointTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022 Oracle and/or its affiliates.
+ * Copyright (c) 2021, 2023 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.
@@ -15,23 +15,20 @@
*/
package io.helidon.integrations.micrometer;
+import static org.hamcrest.Matchers.is;
+
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;
import io.helidon.common.http.Http;
-import io.helidon.common.media.type.MediaTypes;
import io.helidon.config.Config;
import io.helidon.config.ConfigSources;
-import io.helidon.reactive.webclient.WebClient;
-import io.helidon.reactive.webclient.WebClientResponse;
-import io.helidon.reactive.webserver.Routing;
-import io.helidon.reactive.webserver.WebServer;
+import io.helidon.nima.webclient.WebClient;
+import io.helidon.nima.webserver.WebServer;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.Matchers.is;
-
public class MicrometerEndpointTests {
private static Config overallTestConfig = Config.create(ConfigSources.classpath("/micrometerTestData.json"));
@@ -39,13 +36,13 @@ public class MicrometerEndpointTests {
@Test
public void testDefaultEndpoint() throws ExecutionException, InterruptedException {
- runTest(MicrometerSupport.DEFAULT_CONTEXT, MicrometerSupport::create);
+ runTest(MicrometerFeature.DEFAULT_CONTEXT, MicrometerFeature::create);
}
@Test
public void testExplicitEndpointWithDefaultBuiltInRegistryViaConfig() throws ExecutionException, InterruptedException {
String context = "/aa";
- runTest(context, () -> MicrometerSupport.builder()
+ runTest(context, () -> MicrometerFeature.builder()
.config(overallTestConfig.get("explicitContext").get("metrics.micrometer"))
.build());
}
@@ -53,7 +50,7 @@ public void testExplicitEndpointWithDefaultBuiltInRegistryViaConfig() throws Exe
@Test
public void testExplicitEndpointWithExplicitBuiltInRegistryViaBuilder() throws ExecutionException, InterruptedException {
String context = "/bb";
- runTest(context, () -> MicrometerSupport.builder()
+ runTest(context, () -> MicrometerFeature.builder()
.meterRegistryFactorySupplier(MeterRegistryFactory.builder()
.enrollBuiltInRegistry(MeterRegistryFactory.BuiltInRegistryType.PROMETHEUS)
.build())
@@ -64,12 +61,12 @@ public void testExplicitEndpointWithExplicitBuiltInRegistryViaBuilder() throws E
@Test
public void testExplicitEndpointWithExplicitBuiltInRegistryViaConfig() throws ExecutionException, InterruptedException {
String context = "/cc";
- runTest(context, () -> MicrometerSupport.builder()
+ runTest(context, () -> MicrometerFeature.builder()
.config(overallTestConfig.get("explicitContextWithExplicitBuiltIn").get("metrics.micrometer"))
.build());
}
- private static void runTest(String contextForRequest, Supplier micrometerSupportSupplier)
+ private static void runTest(String contextForRequest, Supplier micrometerFeatureSupplier)
throws ExecutionException, InterruptedException {
WebServer webServer = null;
@@ -78,31 +75,20 @@ private static void runTest(String contextForRequest, Supplier router.addFeature(() -> micrometerFeatureSupplier.get()))
.build()
- .start()
- .await();
-
- WebClientResponse webClientResponse = WebClient.builder()
+ .start();
+ Http.Status status = WebClient.builder()
.baseUri(String.format("http://localhost:%d%s", webServer.port(), contextForRequest))
.build()
.get()
- .accept(MediaTypes.TEXT_PLAIN)
- .request()
- .get();
+// .header(Header.ACCEPT, MediaTypes.TEXT_PLAIN.toString())
+ .request().status();
- MatcherAssert.assertThat(webClientResponse.status(), is(Http.Status.OK_200));
+ MatcherAssert.assertThat(status, is(Http.Status.OK_200));
} finally {
- if (webServer != null) {
- webServer.shutdown()
- .await();
- }
+ webServer.stop();
}
}
- private static Routing.Builder prepareRouting(Supplier micrometerSupportSupplier) {
- return Routing.builder()
- .register(micrometerSupportSupplier.get());
- }
-
}
diff --git a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerSupportBuilderTest.java b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerFeatureBuilderTest.java
similarity index 91%
rename from integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerSupportBuilderTest.java
rename to integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerFeatureBuilderTest.java
index f3d35619875..8ec13a1fc93 100644
--- a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerSupportBuilderTest.java
+++ b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerFeatureBuilderTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2023 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.
@@ -34,14 +34,14 @@
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
-public class MicrometerSupportBuilderTest {
+public class MicrometerFeatureBuilderTest {
@Test
public void testValidBuiltInRegistries() {
MeterRegistryFactory factory = MeterRegistryFactory.builder()
.enrollBuiltInRegistry(MeterRegistryFactory.BuiltInRegistryType.PROMETHEUS, PrometheusConfig.DEFAULT)
.build();
- MicrometerSupport support = MicrometerSupport.builder()
+ MicrometerFeature support = MicrometerFeature.builder()
.meterRegistryFactorySupplier(factory)
.build();
@@ -63,7 +63,7 @@ public void testValidExplicitlyAddedPrometheusRegistry() {
.enrollRegistry(registry, r -> Optional.of((req, resp) -> resp.send(registry.scrape())))
.build();
- MicrometerSupport support = MicrometerSupport.builder()
+ MicrometerFeature support = MicrometerFeature.builder()
.meterRegistryFactorySupplier(factory)
.build();
@@ -86,7 +86,7 @@ public void testBuiltInWithExplicitlyAddedPrometheusRegistries() {
.enrollBuiltInRegistry(MeterRegistryFactory.BuiltInRegistryType.PROMETHEUS, PrometheusConfig.DEFAULT)
.build();
- MicrometerSupport support = MicrometerSupport.builder()
+ MicrometerFeature support = MicrometerFeature.builder()
.meterRegistryFactorySupplier(factory)
.build();
@@ -109,7 +109,7 @@ public void testBuiltInWithSingleGoodType() {
assertThat(factoryBuilder.logRecords(), is(empty()));
MeterRegistryFactory factory = factoryBuilder.build();
- MicrometerSupport support = MicrometerSupport.builder()
+ MicrometerFeature support = MicrometerFeature.builder()
.config(config.get("metrics.micrometer"))
.meterRegistryFactorySupplier(factory)
.build();
@@ -134,10 +134,10 @@ public void testBuiltInWithOneBadType() {
MeterRegistryFactory.Builder factoryBuilder = MeterRegistryFactory.builder()
.config(config.get("metrics.micrometer"));
MeterRegistryFactory factory = factoryBuilder.build();
- MicrometerSupport.Builder builder = MicrometerSupport.builder()
+ MicrometerFeature.Builder builder = MicrometerFeature.builder()
.meterRegistryFactorySupplier(factory);
- MicrometerSupport support = builder.build();
+ MicrometerFeature support = builder.build();
assertThat("Too many or too few enrolled registries", factory.registries().size(), is(1));
@@ -153,12 +153,12 @@ public void testBuiltInWithConfig() {
MeterRegistryFactory factory = factoryBuilder.build();
- MicrometerSupport.Builder builder = MicrometerSupport.builder()
+ MicrometerFeature.Builder builder = MicrometerFeature.builder()
.config(config.get("metrics.micrometer"))
.meterRegistryFactorySupplier(factory);
assertThat(factoryBuilder.logRecords(), is(empty()));
- MicrometerSupport support = builder.build();
+ MicrometerFeature support = builder.build();
Set registries = factory.registries();
assertThat("Unexpectedly found no enrolled registry", registries, is(not(empty())));
@@ -179,12 +179,12 @@ public void testMultipleNamesOnly() {
MeterRegistryFactory factory = factoryBuilder.build();
- MicrometerSupport.Builder builder = MicrometerSupport.builder()
+ MicrometerFeature.Builder builder = MicrometerFeature.builder()
.config(config.get("metrics.micrometer"))
.meterRegistryFactorySupplier(factory);
assertThat(factoryBuilder.logRecords(), is(empty()));
- MicrometerSupport support = builder.build();
+ MicrometerFeature support = builder.build();
// Even though the test data defines two Prometheus registries, internally we use a map to store
// them, keyed by the enum. So the map will contain only one.
diff --git a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerSimplePrometheusTest.java b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerSimplePrometheusTest.java
index 552287b1fb2..d2186897a14 100644
--- a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerSimplePrometheusTest.java
+++ b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerSimplePrometheusTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022 Oracle and/or its affiliates.
+ * Copyright (c) 2021, 2023 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.
@@ -15,16 +15,22 @@
*/
package io.helidon.integrations.micrometer;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import io.helidon.common.http.Http;
+import io.helidon.common.http.Http.Header;
+import io.helidon.common.http.HttpMediaType;
import io.helidon.common.media.type.MediaTypes;
-import io.helidon.reactive.webclient.WebClient;
-import io.helidon.reactive.webclient.WebClientResponse;
-import io.helidon.reactive.webserver.WebServer;
+import io.helidon.nima.webclient.WebClient;
+import io.helidon.nima.webclient.http1.Http1Client;
+import io.helidon.nima.webclient.http1.Http1ClientResponse;
+import io.helidon.nima.webserver.WebServer;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.DistributionSummary;
@@ -35,13 +41,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
public class MicrometerSimplePrometheusTest {
private static PrometheusMeterRegistry registry;
- private MicrometerSupport micrometerSupport;
private Timer timer1;
private Counter counter1;
@@ -50,7 +52,7 @@ public class MicrometerSimplePrometheusTest {
private static WebServer webServer;
- private WebClient webClient;
+ private Http1Client webClient;
@BeforeAll
static void prepAll() {
@@ -58,14 +60,14 @@ static void prepAll() {
.enrollRegistry(registry, req -> {
// If there is no media type, assume text/plain which means, for us, Prometheus.
if (req.headers().bestAccepted(MediaTypes.TEXT_PLAIN).isPresent()
- || req.queryParams().first("type").orElse("").equals("prometheus")) {
- return Optional.of(ReactivePrometheusHandler.create(registry));
+ || req.query().first("type").orElse("").equals("prometheus")) {
+ return Optional.of(PrometheusHandler.create(registry));
} else {
return Optional.empty();
}
})
.build();
- MicrometerSupport.Builder builder = MicrometerSupport.builder()
+ MicrometerFeature.Builder builder = MicrometerFeature.builder()
.meterRegistryFactorySupplier(factory);
webServer = MicrometerTestUtil.startServer(builder);
@@ -85,16 +87,14 @@ public void checkViaMediaType() throws ExecutionException, InterruptedException
timer1.record(2L, TimeUnit.SECONDS);
counter1.increment(3);
gauge1.set(4);
- WebClientResponse response = webClient.get()
- .accept(MediaTypes.TEXT_PLAIN)
+ Http1ClientResponse response = webClient.get()
+ .header(Header.ACCEPT, HttpMediaType.TEXT_PLAIN.toString())
.path("/micrometer")
- .request()
- .get();
-
- assertThat("Unexpected HTTP status", response.status(), is(Http.Status.OK_200));
+ .request();
- String promOutput = response.content().as(String.class).get();
+ String promOutput = response.entity().as(String.class);
+ assertThat("Unexpected HTTP status, response is: " + promOutput, response.status(), is(Http.Status.OK_200));
}
@Test
@@ -102,25 +102,23 @@ public void checkViaQueryParam() throws ExecutionException, InterruptedException
timer1.record(2L, TimeUnit.SECONDS);
counter1.increment(3);
gauge1.set(4);
- WebClientResponse response = webClient.get()
- .accept(MediaTypes.create(MediaTypes.TEXT_PLAIN.type(), "special"))
+ Http1ClientResponse response = webClient.get()
+ .header(Header.ACCEPT, MediaTypes.create(MediaTypes.TEXT_PLAIN.type(), "special").toString())
.path("/micrometer")
.queryParam("type", "prometheus")
- .request()
- .get();
+ .request();
assertThat("Unexpected HTTP status", response.status(), is(Http.Status.OK_200));
- String promOutput = response.content().as(String.class).get();
+ String promOutput = response.entity().as(String.class);
}
@Test
public void checkNoMatch() throws ExecutionException, InterruptedException {
- WebClientResponse response = webClient.get()
- .accept(MediaTypes.create(MediaTypes.TEXT_PLAIN.type(), "special"))
+ Http1ClientResponse response = webClient.get()
+ .header(Header.ACCEPT, MediaTypes.create(MediaTypes.TEXT_PLAIN.type(), "special").toString())
.path("/micrometer")
- .request()
- .get();
+ .request();
assertThat("Expected failed HTTP status", response.status(), is(Http.Status.NOT_ACCEPTABLE_406));
}
diff --git a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerTestAddingMeters.java b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerTestAddingMeters.java
index 69bf8e46ae5..3d045dbbe66 100644
--- a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerTestAddingMeters.java
+++ b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerTestAddingMeters.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2021, 2023 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.
@@ -32,7 +32,7 @@ public void addCounter() {
.enrollBuiltInRegistry(MeterRegistryFactory.BuiltInRegistryType.PROMETHEUS, PrometheusConfig.DEFAULT)
.build();
- MicrometerSupport support = MicrometerSupport.builder()
+ MicrometerFeature support = MicrometerFeature.builder()
.meterRegistryFactorySupplier(factory)
.build();
diff --git a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerTestUtil.java b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerTestUtil.java
index 657cbfa589a..f320368f210 100644
--- a/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerTestUtil.java
+++ b/integrations/micrometer/micrometer/src/test/java/io/helidon/integrations/micrometer/MicrometerTestUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022 Oracle and/or its affiliates.
+ * Copyright (c) 2021, 2023 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.
@@ -16,13 +16,11 @@
package io.helidon.integrations.micrometer;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
-import io.helidon.reactive.webserver.Routing;
-import io.helidon.reactive.webserver.WebServer;
+import io.helidon.nima.webserver.WebServer;
public class MicrometerTestUtil {
@@ -36,7 +34,7 @@ public class MicrometerTestUtil {
* server.
* @return the {@code WebServer} set up with OpenAPI support
*/
- public static WebServer startServer(MicrometerSupport.Builder builder) {
+ public static WebServer startServer(MicrometerFeature.Builder builder) {
try {
return startServer(0, builder);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
@@ -46,16 +44,13 @@ public static WebServer startServer(MicrometerSupport.Builder builder) {
public static WebServer startServer(
int port,
- MicrometerSupport.Builder... builders) throws
+ MicrometerFeature.Builder builder) throws
InterruptedException, ExecutionException, TimeoutException {
- WebServer result = WebServer.builder(Routing.builder()
- .register(builders)
- .build())
+ WebServer result = WebServer.builder()
.port(port)
+ .routing(router -> router.addFeature(() -> builder.build()))
.build()
- .start()
- .toCompletableFuture()
- .get(10, TimeUnit.SECONDS);
+ .start();
LOGGER.log(Level.INFO, "Started server at: https://localhost:{0}", result.port());
return result;
}