diff --git a/examples/integrations/micrometer/se/pom.xml b/examples/integrations/micrometer/se/pom.xml index 1a9bf9c2b19..2b20e8efb96 100644 --- a/examples/integrations/micrometer/se/pom.xml +++ b/examples/integrations/micrometer/se/pom.xml @@ -55,33 +55,29 @@ - io.helidon.reactive.webserver - helidon-reactive-webserver + io.helidon.nima.webserver + helidon-nima-webserver io.helidon.config helidon-config-yaml - io.helidon.reactive.webserver - helidon-reactive-webserver-cors + io.helidon.nima.http.media + helidon-nima-http-media-jsonp io.helidon.integrations.micrometer helidon-integrations-micrometer - - io.helidon.reactive.media - helidon-reactive-media-jsonp - org.junit.jupiter junit-jupiter-api test - io.helidon.reactive.webclient - helidon-reactive-webclient + io.helidon.nima.webclient + helidon-nima-webclient test @@ -89,5 +85,10 @@ hamcrest-all test + + io.helidon.nima.testing.junit5 + helidon-nima-testing-junit5-webserver + test + diff --git a/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/micrometer/se/GreetService.java b/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/micrometer/se/GreetService.java index e016ce726db..6701b9bf84c 100644 --- a/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/micrometer/se/GreetService.java +++ b/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/micrometer/se/GreetService.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. @@ -20,10 +20,11 @@ import io.helidon.common.http.Http; import io.helidon.config.Config; -import io.helidon.reactive.webserver.Routing; -import io.helidon.reactive.webserver.ServerRequest; -import io.helidon.reactive.webserver.ServerResponse; -import io.helidon.reactive.webserver.Service; +import io.helidon.nima.webserver.http.HttpRequest; +import io.helidon.nima.webserver.http.HttpRules; +import io.helidon.nima.webserver.http.HttpService; +import io.helidon.nima.webserver.http.ServerRequest; +import io.helidon.nima.webserver.http.ServerResponse; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.Timer; @@ -51,7 +52,7 @@ *

*/ -public class GreetService implements Service { +public class GreetService implements HttpService { /** * The config value for the key {@code greeting}. @@ -74,14 +75,14 @@ public class GreetService implements Service { * @param rules the routing rules. */ @Override - public void update(Routing.Rules rules) { + public void routing(HttpRules rules) { rules - .get((req, resp) -> getTimer.record((Runnable) req::next)) // Update the timer with every GET. + .get((req, resp) -> getTimer.record(resp::next)) // Update the timer with every GET. .get("/", this::getDefaultMessageHandler) .get("/{name}", (req, resp) -> { personalizedGetCounter.increment(); - req.next(); + resp.next(); }, // Count personalized GETs... this::getMessageHandler) // ...and process them. .put("/greeting", this::updateGreetingHandler); @@ -92,7 +93,7 @@ public void update(Routing.Rules rules) { * @param request the server request * @param response the server response */ - private void getDefaultMessageHandler(ServerRequest request, + private void getDefaultMessageHandler(HttpRequest request, ServerResponse response) { sendResponse(response, "World"); } @@ -104,7 +105,7 @@ private void getDefaultMessageHandler(ServerRequest request, */ private void getMessageHandler(ServerRequest request, ServerResponse response) { - String name = request.path().param("name"); + String name = request.path().pathParameters().first("name").get(); sendResponse(response, name); } @@ -135,6 +136,7 @@ private void updateGreetingFromJson(JsonObject jo, ServerResponse response) { */ private void updateGreetingHandler(ServerRequest request, ServerResponse response) { - request.content().as(JsonObject.class).thenAccept(jo -> updateGreetingFromJson(jo, response)); + JsonObject obj = request.content().as(JsonObject.class); + updateGreetingFromJson(obj, response); } } diff --git a/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/micrometer/se/Main.java b/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/micrometer/se/Main.java index dee9c7279b7..0fb3d65fb0b 100644 --- a/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/micrometer/se/Main.java +++ b/examples/integrations/micrometer/se/src/main/java/io/helidon/examples/micrometer/se/Main.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.examples.micrometer.se; -import io.helidon.common.reactive.Single; import io.helidon.config.Config; -import io.helidon.integrations.micrometer.MicrometerSupport; +import io.helidon.integrations.micrometer.MicrometerFeature; import io.helidon.logging.common.LogConfig; -import io.helidon.reactive.media.jsonp.JsonpSupport; -import io.helidon.reactive.webserver.Routing; -import io.helidon.reactive.webserver.WebServer; +import io.helidon.nima.webserver.WebServer; +import io.helidon.nima.webserver.http.HttpRouting; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.Timer; @@ -43,6 +41,7 @@ private Main() { /** * Application main entry point. + * * @param args command line arguments. */ public static void main(final String[] args) { @@ -51,48 +50,33 @@ public static void main(final String[] args) { /** * Start the server. - * @return the created {@link WebServer} instance */ - static Single startServer() { + static WebServer startServer() { // load logging configuration LogConfig.configureRuntime(); - // By default this will pick up application.yaml from the classpath + // By default, this will pick up application.yaml from the classpath Config config = Config.create(); - // Get webserver config from the "server" section of application.yaml - WebServer server = WebServer.builder(createRouting(config)) + WebServer server = WebServer.builder() .config(config.get("server")) - .port(-1) - .addMediaSupport(JsonpSupport.create()) - .build(); + .routing(r -> setupRouting(r, config)) + .build() + .start(); - // Try to start the server. If successful, print some info and arrange to - // print a message at shutdown. If unsuccessful, print the exception. - // Server threads are not daemon. No need to block. Just react. - return server.start() - .peek(ws -> { - System.out.println( - "WEB server is up! http://localhost:" + ws.port() + "/greet"); - ws.whenShutdown().thenRun(() - -> System.out.println("WEB server is DOWN. Good bye!")); - }) - .onError(t -> { - System.err.println("Startup failed: " + t.getMessage()); - t.printStackTrace(System.err); - }); + System.out.println("WEB server is up! http://localhost:" + server.port() + "/greet"); + return server; } /** - * Creates new {@link Routing}. + * Setup routing. * - * @return routing configured with JSON support, Micrometer metrics, and the greeting service - * @param config configuration of this server + * @param routing routing builder + * @param config config */ - private static Routing createRouting(Config config) { - - MicrometerSupport micrometerSupport = MicrometerSupport.create(); + static void setupRouting(HttpRouting.Builder routing, Config config) { + MicrometerFeature micrometerSupport = MicrometerFeature.create(config); Counter personalizedGetCounter = micrometerSupport.registry() .counter(PERSONALIZED_GETS_COUNTER_NAME); Timer getTimer = Timer.builder(ALL_GETS_TIMER_NAME) @@ -101,9 +85,7 @@ private static Routing createRouting(Config config) { GreetService greetService = new GreetService(config, getTimer, personalizedGetCounter); - return Routing.builder() - .register(micrometerSupport) // Micrometer support at "/micrometer" - .register("/greet", greetService) - .build(); + routing.register("/greet", greetService) + .addFeature(micrometerSupport); } } diff --git a/examples/integrations/micrometer/se/src/test/java/io/helidon/examples/micrometer/se/MainTest.java b/examples/integrations/micrometer/se/src/test/java/io/helidon/examples/micrometer/se/MainTest.java index f167b71cc6d..79c611254b6 100644 --- a/examples/integrations/micrometer/se/src/test/java/io/helidon/examples/micrometer/se/MainTest.java +++ b/examples/integrations/micrometer/se/src/test/java/io/helidon/examples/micrometer/se/MainTest.java @@ -16,40 +16,40 @@ package io.helidon.examples.micrometer.se; import java.util.Collections; -import java.util.concurrent.TimeUnit; import io.helidon.common.http.Http; -import io.helidon.reactive.media.jsonp.JsonpSupport; -import io.helidon.reactive.webclient.WebClient; -import io.helidon.reactive.webclient.WebClientResponse; -import io.helidon.reactive.webserver.WebServer; +import io.helidon.config.Config; +import io.helidon.nima.testing.junit5.webserver.ServerTest; +import io.helidon.nima.testing.junit5.webserver.SetUpServer; +import io.helidon.nima.webclient.http1.Http1Client; +import io.helidon.nima.webclient.http1.Http1ClientResponse; +import io.helidon.nima.webserver.ServerConfig; +import io.helidon.nima.webserver.ServerConfig.Builder; import jakarta.json.Json; import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.CoreMatchers.containsString; // we need to first call the methods, before validating metrics @TestMethodOrder(MethodOrderer.OrderAnnotation.class) +@ServerTest public class MainTest { private static final JsonBuilderFactory JSON_BF = Json.createBuilderFactory(Collections.emptyMap()); private static final JsonObject TEST_JSON_OBJECT; - private static WebServer webServer; - private static WebClient webClient; private static double expectedPersonalizedGets; private static double expectedAllGets; + private final Http1Client client; static { TEST_JSON_OBJECT = JSON_BF.createObjectBuilder() @@ -57,42 +57,13 @@ public class MainTest { .build(); } - @BeforeAll - public static void startTheServer() { - webServer = Main.startServer() - .await(10, TimeUnit.SECONDS); - - webClient = WebClient.builder() - .baseUri("http://localhost:" + webServer.port()) - .addMediaSupport(JsonpSupport.create()) - .build(); + public MainTest(Http1Client client) { + this.client = client; } - @AfterAll - public static void stopServer() { - if (webServer != null) { - webServer.shutdown() - .await(10, TimeUnit.SECONDS); - } - } - - private static JsonObject get() { - return get("/greet"); - } - - private static JsonObject get(String path) { - JsonObject jsonObject = webClient.get() - .path(path) - .request(JsonObject.class) - .await(); - expectedAllGets++; - return jsonObject; - } - - private static JsonObject personalizedGet(String name) { - JsonObject result = get("/greet/" + name); - expectedPersonalizedGets++; - return result; + @SetUpServer + public static void setup(Builder builder) { + builder.routing(r -> Main.setupRouting(r, Config.create())); } @Test @@ -112,13 +83,12 @@ void testNamedGreeting() { @Test @Order(3) void testUpdateGreeting() { - - WebClientResponse response = webClient.put() + try (Http1ClientResponse response = client.put() .path("/greet/greeting") - .submit(TEST_JSON_OBJECT) - .await(); + .submit(TEST_JSON_OBJECT)) { - assertThat(response.status(), is(Http.Status.NO_CONTENT_204)); + assertThat(response.status(), is(Http.Status.NO_CONTENT_204)); + } JsonObject jsonObject = personalizedGet("Joe"); assertThat(jsonObject.getString("greeting"), is("Hola Joe!")); @@ -127,16 +97,13 @@ void testUpdateGreeting() { @Test @Order(4) void testMicrometer() { - WebClientResponse response = webClient.get() + Http1ClientResponse response = client.get() .path("/micrometer") - .request() - .await(); + .request(); assertThat(response.status().code(), is(200)); - String output = response.content() - .as(String.class) - .await(); + String output = response.as(String.class); String expected = Main.ALL_GETS_TIMER_NAME + "_seconds_count " + expectedAllGets; assertThat("Unable to find expected all-gets timer count " + expected + "; output is " + output, output, containsString(expected)); // all gets; the put @@ -148,4 +115,22 @@ void testMicrometer() { output, containsString(expected)); response.close(); } + + private JsonObject get() { + return get("/greet"); + } + + private JsonObject get(String path) { + JsonObject jsonObject = client.get() + .path(path) + .request(JsonObject.class); + expectedAllGets++; + return jsonObject; + } + + private JsonObject personalizedGet(String name) { + JsonObject result = get("/greet/" + name); + expectedPersonalizedGets++; + return result; + } } diff --git a/integrations/micrometer/micrometer/pom.xml b/integrations/micrometer/micrometer/pom.xml index 53854eda6af..0f74a60221a 100644 --- a/integrations/micrometer/micrometer/pom.xml +++ b/integrations/micrometer/micrometer/pom.xml @@ -58,23 +58,10 @@ helidon-common-features-api true - - io.helidon.reactive.webserver - helidon-reactive-webserver - provided - - - io.helidon.reactive.webserver - helidon-reactive-webserver-cors - io.helidon.config helidon-config - - io.helidon.reactive.service-common - helidon-reactive-service-common - io.helidon.nima.webserver helidon-nima-webserver @@ -84,6 +71,10 @@ io.helidon.nima.webserver helidon-nima-webserver-cors + + io.helidon.nima.webclient + helidon-nima-webclient + io.helidon.nima.service-common helidon-nima-service-common @@ -112,11 +103,6 @@ hamcrest-all test - - io.helidon.reactive.webclient - helidon-reactive-webclient - test - 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; }