Skip to content

Commit a0b0485

Browse files
committed
metrics and openapi endpoint authorized
Signed-off-by: tvallin <[email protected]>
1 parent 7dce029 commit a0b0485

File tree

42 files changed

+237
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+237
-40
lines changed

archetypes/helidon/src/main/archetype/common/observability.xml

-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
161161
]]></value>
162162
</list>
163163
<list key="Main-routing-builder" if="${flavor} == 'se'">
164-
<value><![CDATA[.addFeature(ObserveFeature.create(MetricsObserveProvider.create(MetricsFeature.create())))]]></value>
165164
<value><![CDATA[.register("/metrics-greet", metricsService)]]></value>
166165
</list>
167166
<list key="MetricsService-imports" if="${flavor} == 'se'">

archetypes/helidon/src/main/archetype/se/custom/observability.xml

+14-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,20 @@
112112
}
113113
]]></value>
114114
</list>
115-
<list key="Observe-feature-builder">
116-
<value if="${metrics}"><![CDATA[ .addProvider(MetricsObserveProvider.create())]]></value>
115+
<list key="yaml-config-entries">
116+
<value if="${metrics}"><![CDATA[
117+
metrics:
118+
permit-all: true
119+
]]></value>
120+
</list>
121+
<list key="config-test">
122+
<value if="${metrics}"><![CDATA[
123+
metrics:
124+
permit-all: true
125+
]]></value>
126+
</list>
127+
<list key="Main-routing-builder" if="${metrics}">
128+
<value><![CDATA[.addFeature(ObserveFeature.create(config))]]></value>
117129
</list>
118130
<list key="Abstract-tests">
119131
<value if="${metrics}"><![CDATA[

examples/cors/src/main/resources/application.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ app:
2020
server:
2121
port: 8080
2222
host: 0.0.0.0
23+
24+
metrics:
25+
permit-all: true
2326

2427
restrictive-cors:
2528
allow-origins: ["http://foo.com", "http://there.com"]

examples/metrics/exemplar/src/main/resources/application.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
2+
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -22,3 +22,5 @@ server:
2222
host: 0.0.0.0
2323
tracing:
2424
service: "hello-world"
25+
metrics:
26+
permit-all: true

examples/metrics/http-status-count-se/src/main/java/io/helidon/examples/se/httpstatuscount/Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void setup(WebServerConfig.Builder server) {
7171
static void routing(HttpRouting.Builder routing, Config config) {
7272
SimpleGreetService simpleGreetService = new SimpleGreetService(config);
7373
GreetService greetService = new GreetService(config);
74-
routing.addFeature(ObserveFeature.create())
74+
routing.addFeature(ObserveFeature.create(config))
7575
.register(HttpStatusMetricService.create()) // no endpoint, just metrics updates
7676
.register("/simple-greet", simpleGreetService)
7777
.register("/greet", greetService);

examples/metrics/http-status-count-se/src/main/resources/application.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2022 Oracle and/or its affiliates.
2+
# Copyright (c) 2022, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -21,4 +21,7 @@ server:
2121
app:
2222
greeting: "Hello"
2323

24+
metrics:
25+
permit-all: true
26+
2427

examples/metrics/http-status-count-se/src/test/resources/application.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2022 Oracle and/or its affiliates.
2+
# Copyright (c) 2022, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -24,3 +24,5 @@ app:
2424
security:
2525
enabled: false
2626

27+
metrics:
28+
permit-all: true

examples/metrics/kpi/src/main/java/io/helidon/examples/metrics/kpi/Main.java

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ private static MetricsFeature metricsSupportWithoutConfig() {
120120
return MetricsFeature.builder()
121121
.metricsConfig(MetricsConfig.builder()
122122
.keyPerformanceIndicatorMetricsConfig(configBuilder))
123+
.permitAll(true)
123124
.build();
124125
}
125126
}

examples/metrics/kpi/src/main/resources/application.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2021 Oracle and/or its affiliates.
2+
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ server:
2222
host: 0.0.0.0
2323

2424
metrics:
25+
permit-all: true
2526
key-performance-indicators:
2627
extended: true
2728
long-running:

examples/microprofile/cors/src/main/resources/META-INF/microprofile-config.properties

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020 Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -20,3 +20,5 @@ config_ordinal=1000
2020
# Microprofile server properties
2121
server.port=8080
2222
server.host=0.0.0.0
23+
24+
metrics.permit-all=true

examples/microprofile/multiport/src/main/resources/application.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2021 Oracle and/or its affiliates.
2+
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ server:
2626

2727
# Metrics and health run on admin port
2828
metrics:
29+
permit-all: true
2930
routing: "admin"
3031

3132
health:

examples/microprofile/openapi-basic/src/main/resources/META-INF/microprofile-config.properties

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, 2021 Oracle and/or its affiliates.
2+
# Copyright (c) 2019, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -23,3 +23,5 @@ server.host=0.0.0.0
2323

2424
mp.openapi.filter=io.helidon.microprofile.examples.openapi.basic.internal.SimpleAPIFilter
2525
mp.openapi.model.reader=io.helidon.microprofile.examples.openapi.basic.internal.SimpleAPIModelReader
26+
27+
openapi.permit-all=true

examples/microprofile/openapi-basic/src/test/resources/META-INF/microprofile-config.properties

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, 2021 Oracle and/or its affiliates.
2+
# Copyright (c) 2019, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -20,3 +20,5 @@ config_ordinal=1000
2020
# Microprofile server properties
2121
server.port=-1
2222
server.host=0.0.0.0
23+
24+
openapi.permit-all=true

examples/openapi/src/main/resources/application.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, 2021 Oracle and/or its affiliates.
2+
# Copyright (c) 2019, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -20,6 +20,9 @@ app:
2020
server:
2121
port: 8080
2222
host: 0.0.0.0
23+
24+
metrics:
25+
permit-all: true
2326

2427
openapi:
2528
filter: io.helidon.examples.openapi.internal.SimpleAPIFilter

examples/quickstarts/helidon-quickstart-mp/src/main/resources/META-INF/microprofile-config.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2018, 2020 Oracle and/or its affiliates.
2+
# Copyright (c) 2018, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -23,3 +23,4 @@ server.host=0.0.0.0
2323

2424
# Enable the optional MicroProfile Metrics REST.request metrics
2525
metrics.rest-request.enabled=true
26+
metrics.permit-all=true

examples/quickstarts/helidon-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.helidon.examples.quickstart.se;
1818

19+
import io.helidon.config.Config;
1920
import io.helidon.logging.common.LogConfig;
2021
import io.helidon.openapi.OpenApiFeature;
2122
import io.helidon.webserver.WebServer;
@@ -42,8 +43,10 @@ public static void main(String[] args) {
4243
// load logging configuration
4344
LogConfig.configureRuntime();
4445

46+
Config config = Config.create();
47+
4548
WebServer server = WebServer.builder()
46-
.routing(Main::routing)
49+
.routing(r -> routing(r, config))
4750
.build()
4851
.start();
4952

@@ -53,11 +56,11 @@ public static void main(String[] args) {
5356
/**
5457
* Updates HTTP Routing and registers observe providers.
5558
*/
56-
static void routing(HttpRouting.Builder routing) {
59+
static void routing(HttpRouting.Builder routing, Config config) {
5760
OpenApiFeature openApi = OpenApiFeature.builder().build();
5861
GreetService greetService = new GreetService();
5962
routing.addFeature(openApi)
6063
.register("/greet", greetService)
61-
.addFeature(ObserveFeature.create());
64+
.addFeature(ObserveFeature.create(config));
6265
}
6366
}

examples/quickstarts/helidon-quickstart-se/src/main/resources/application.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ app:
1919

2020
server:
2121
port: 8080
22-
host: 0.0.0.0
22+
host: 0.0.0.0
23+
24+
metrics:
25+
permit-all: true

examples/quickstarts/helidon-quickstart-se/src/test/java/io/helidon/examples/quickstart/se/MainTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.helidon.examples.quickstart.se;
1818

19+
import io.helidon.config.Config;
1920
import io.helidon.http.Status;
2021
import io.helidon.webclient.http1.Http1Client;
2122
import io.helidon.webclient.http1.Http1ClientResponse;
@@ -40,7 +41,7 @@ protected MainTest(Http1Client client) {
4041

4142
@SetUpRoute
4243
static void routing(HttpRouting.Builder builder) {
43-
Main.routing(builder);
44+
Main.routing(builder, Config.create());
4445
}
4546

4647
@Test

examples/quickstarts/helidon-standalone-quickstart-mp/src/main/resources/META-INF/microprofile-config.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, 2020 Oracle and/or its affiliates.
2+
# Copyright (c) 2019, 2023 Oracle and/or its affiliates.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -23,3 +23,4 @@ server.host=0.0.0.0
2323

2424
# Enable the optional MicroProfile Metrics REST.request metrics
2525
metrics.rest-request.enabled=true
26+
metrics.permit-all=true

examples/quickstarts/helidon-standalone-quickstart-se/src/main/java/io/helidon/examples/quickstart/se/Main.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.helidon.examples.quickstart.se;
1818

19+
import io.helidon.config.Config;
1920
import io.helidon.logging.common.LogConfig;
2021
import io.helidon.webserver.WebServer;
2122
import io.helidon.webserver.http.HttpRouting;
@@ -41,8 +42,10 @@ public static void main(String[] args) {
4142
// load logging configuration
4243
LogConfig.configureRuntime();
4344

45+
Config config = Config.create();
46+
4447
WebServer server = WebServer.builder()
45-
.routing(Main::routing)
48+
.routing(r -> routing(r, config))
4649
.build()
4750
.start();
4851

@@ -52,9 +55,9 @@ public static void main(String[] args) {
5255
/**
5356
* Updates HTTP Routing and registers observe providers.
5457
*/
55-
static void routing(HttpRouting.Builder routing) {
58+
static void routing(HttpRouting.Builder routing, Config config) {
5659
GreetService greetService = new GreetService();
5760
routing.register("/greet", greetService)
58-
.addFeature(ObserveFeature.create());
61+
.addFeature(ObserveFeature.create(config));
5962
}
6063
}

examples/quickstarts/helidon-standalone-quickstart-se/src/main/resources/application.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ app:
1919

2020
server:
2121
port: 8080
22-
host: 0.0.0.0
22+
host: 0.0.0.0
23+
24+
metrics:
25+
permit-all: true

examples/quickstarts/helidon-standalone-quickstart-se/src/test/java/io/helidon/examples/quickstart/se/MainTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.helidon.examples.quickstart.se;
1818

19+
import io.helidon.config.Config;
1920
import io.helidon.http.Status;
2021
import io.helidon.webclient.http1.Http1Client;
2122
import io.helidon.webclient.http1.Http1ClientResponse;
@@ -40,7 +41,7 @@ protected MainTest(Http1Client client) {
4041

4142
@SetUpRoute
4243
static void routing(HttpRouting.Builder builder) {
43-
Main.routing(builder);
44+
Main.routing(builder, Config.create());
4445
}
4546

4647
@Test

metrics/api/src/main/java/io/helidon/metrics/api/MetricsConfigBlueprint.java

+8
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ static List<Tag> createTags(String pairs) {
129129
@ConfiguredOption("true")
130130
boolean enabled();
131131

132+
/**
133+
* Whether metrics endpoint should be authorized.
134+
*
135+
* @return if metrics are configured to be authorized
136+
*/
137+
@ConfiguredOption("true")
138+
boolean permitAll();
139+
132140
/**
133141
* Key performance indicator metrics settings.
134142
*

microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/HelloWorldTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
*/
5555
@HelidonTest
5656
@AddConfig(key = "metrics." + MetricsCdiExtension.REST_ENDPOINTS_METRIC_ENABLED_PROPERTY_NAME, value = "true")
57+
@AddConfig(key = "metrics.permit-all", value = "true")
5758
class HelloWorldTest {
5859

5960
@Inject

microprofile/openapi/src/test/java/io/helidon/microprofile/openapi/BasicServerTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import io.helidon.http.Status;
2121
import io.helidon.microprofile.tests.junit5.AddBean;
22+
import io.helidon.microprofile.tests.junit5.AddConfig;
2223
import io.helidon.microprofile.tests.junit5.HelidonTest;
2324
import io.helidon.openapi.OpenApiFeature;
2425

@@ -39,6 +40,7 @@
3940
@HelidonTest
4041
@AddBean(TestApp.class)
4142
@AddBean(TestApp3.class)
43+
@AddConfig(key = "openapi.permit-all", value = "true")
4244
public class BasicServerTest {
4345

4446
private static Map<String, Object> yaml;

microprofile/openapi/src/test/resources/serverConfig.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
#
1616

1717
openapi:
18+
permit-all: true
1819
web-context: /otheropenapi
1920
port: 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (c) 2023 Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
openapi:
18+
permit-all: true

0 commit comments

Comments
 (0)