Skip to content

Commit 74beb5d

Browse files
mrzzyOleksii Moskalenko
authored andcommitted
Add IT to check metric endpoints can be accessed when authentication is enabled
1 parent aac4052 commit 74beb5d

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright 2018-2020 The Feast Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package feast.core.metrics;
18+
19+
import static org.junit.Assert.assertTrue;
20+
21+
import com.squareup.okhttp.OkHttpClient;
22+
import com.squareup.okhttp.Request;
23+
import com.squareup.okhttp.Response;
24+
import feast.core.it.BaseIT;
25+
import java.io.IOException;
26+
import org.junit.jupiter.api.BeforeAll;
27+
import org.junit.jupiter.api.Test;
28+
import org.springframework.boot.test.context.SpringBootTest;
29+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
30+
import org.springframework.boot.web.server.LocalServerPort;
31+
32+
@SpringBootTest(
33+
webEnvironment = WebEnvironment.RANDOM_PORT,
34+
properties = {
35+
"feast.security.authentication.enabled=true",
36+
})
37+
public class CoreMetricsIT extends BaseIT {
38+
private static final String METRIC_ENDPOINT = "/metrics";
39+
private static OkHttpClient httpClient;
40+
@LocalServerPort private int metricsPort;
41+
42+
@BeforeAll
43+
public static void globalSetUp() {
44+
httpClient = new OkHttpClient();
45+
}
46+
47+
/** Test that Feast Core metrics endpoint can be accessed with authentication enabled */
48+
@Test
49+
public void shouldAllowUnauthenticatedAccessToMetricsEndpoint() throws IOException {
50+
Request request =
51+
new Request.Builder()
52+
.url(String.format("http://localhost:%d%s", metricsPort, METRIC_ENDPOINT))
53+
.get()
54+
.build();
55+
Response response = httpClient.newCall(request).execute();
56+
assertTrue(response.isSuccessful());
57+
assertTrue(!response.body().string().isEmpty());
58+
}
59+
}

serving/src/test/java/feast/serving/it/ServingServiceOauthAuthenticationIT.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import static org.junit.jupiter.api.Assertions.assertTrue;
2121
import static org.testcontainers.containers.wait.strategy.Wait.forHttp;
2222

23+
import com.squareup.okhttp.OkHttpClient;
24+
import com.squareup.okhttp.Request;
25+
import com.squareup.okhttp.Response;
2326
import feast.proto.serving.ServingAPIProto.GetOnlineFeaturesRequest;
2427
import feast.proto.serving.ServingAPIProto.GetOnlineFeaturesResponse;
2528
import feast.proto.serving.ServingServiceGrpc.ServingServiceBlockingStub;
@@ -35,6 +38,8 @@
3538
import org.junit.jupiter.api.Test;
3639
import org.junit.runners.model.InitializationError;
3740
import org.springframework.boot.test.context.SpringBootTest;
41+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
42+
import org.springframework.boot.web.server.LocalServerPort;
3843
import org.springframework.test.context.ActiveProfiles;
3944
import org.testcontainers.containers.DockerComposeContainer;
4045
import org.testcontainers.containers.wait.strategy.Wait;
@@ -43,6 +48,7 @@
4348

4449
@ActiveProfiles("it")
4550
@SpringBootTest(
51+
webEnvironment = WebEnvironment.RANDOM_PORT,
4652
properties = {
4753
"feast.core-authentication.enabled=true",
4854
"feast.core-authentication.provider=oauth",
@@ -55,6 +61,7 @@ public class ServingServiceOauthAuthenticationIT extends BaseAuthIT {
5561
static final Map<String, String> options = new HashMap<>();
5662

5763
static final int FEAST_SERVING_PORT = 6566;
64+
@LocalServerPort private int metricsPort;
5865

5966
@ClassRule @Container
6067
public static DockerComposeContainer environment =
@@ -84,6 +91,19 @@ static void globalSetup() throws IOException, InitializationError, InterruptedEx
8491
options.put("grant_type", GRANT_TYPE);
8592
}
8693

94+
/** Test that Feast Serving metrics endpoint can be accessed with authentication enabled */
95+
@Test
96+
public void shouldAllowUnauthenticatedAccessToMetricsEndpoint() throws IOException {
97+
Request request =
98+
new Request.Builder()
99+
.url(String.format("http://localhost:%d/metrics", metricsPort))
100+
.get()
101+
.build();
102+
Response response = new OkHttpClient().newCall(request).execute();
103+
assertTrue(response.isSuccessful());
104+
assertTrue(!response.body().string().isEmpty());
105+
}
106+
87107
@Test
88108
public void shouldAllowUnauthenticatedGetOnlineFeatures() {
89109
// apply feature set

0 commit comments

Comments
 (0)