|
| 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 | +} |
0 commit comments