Skip to content

Commit

Permalink
Respect named port selection in MicrometerSupport for endpoint (#8518)
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Quinn <tim.quinn@oracle.com>
  • Loading branch information
tjquinno authored Mar 22, 2024
1 parent bf8918e commit 4397854
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 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.cdi;

import io.helidon.microprofile.tests.junit5.AddConfig;
import io.helidon.microprofile.tests.junit5.HelidonTest;
import io.helidon.microprofile.tests.junit5.Socket;

import jakarta.enterprise.inject.se.SeContainer;
import jakarta.inject.Inject;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

@HelidonTest
@AddConfig(key = "server.sockets.1.name", value = "micrometer-socket")
@AddConfig(key = "server.sockets.1.bind-address", value = "0.0.0.0")
@AddConfig(key = "micrometer.routing", value = AlternateSocketTest.SOCKET_NAME)
@AddConfig(key = "micrometer.web-context", value = AlternateSocketTest.WEB_CONTEXT)
class AlternateSocketTest {

static final String WEB_CONTEXT = "/mymicrometer";
static final String SOCKET_NAME = "micrometer-socket";

@Inject
@Socket(SOCKET_NAME)
private WebTarget webTargetForNamedSocket;

@Inject
private WebTarget webTargetDefault;

@Test
void testAlternateSocket(SeContainer seContainer) {
Response response = webTargetForNamedSocket.path(WEB_CONTEXT)
.request()
.get();

assertThat("Access to named socket", response.getStatus(), is(Response.Status.OK.getStatusCode()));

Response defaultResponse = webTargetDefault.path(WEB_CONTEXT)
.request()
.get();
assertThat("Access to default socket", defaultResponse.getStatus(), is(Response.Status.NOT_FOUND.getStatusCode()));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
* Copyright (c) 2021, 2024 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.
Expand Down Expand Up @@ -100,7 +100,7 @@ public void update(Routing.Rules rules) {

@Override
protected void postConfigureEndpoint(Routing.Rules defaultRules, Routing.Rules serviceEndpointRoutingRules) {
defaultRules
serviceEndpointRoutingRules
.any(new MetricsContextHandler(registry()))
.get(context(), this::getOrOptions)
.options(context(), this::getOrOptions);
Expand Down

0 comments on commit 4397854

Please sign in to comment.