Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
tck/rest/src/main/java/org/eclipse/microprofile/metrics/test/HistogramTimerConfigBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* ******************************************************************** | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICES file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* ******************************************************************** | ||
* | ||
*/ | ||
|
||
package org.eclipse.microprofile.metrics.test; | ||
|
||
import org.eclipse.microprofile.metrics.MetricRegistry; | ||
import org.eclipse.microprofile.metrics.annotation.Timed; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class HistogramTimerConfigBean { | ||
|
||
@Inject | ||
private MetricRegistry applicationRegistry; | ||
|
||
@Timed(name = "annotatedTimerCustomPercentile", absolute = true) | ||
public void timeMeAnnotatedTimerCustomPercentile() { | ||
|
||
} | ||
|
||
@Timed(name = "annotatedTimerNoPercentile", absolute = true) | ||
public void timeMeAnnotatedTimerNoPercentile() { | ||
|
||
} | ||
|
||
@Timed(name = "annotatedTimerCustomBucketsDefaultPercentile", absolute = true) | ||
public void timeMeAnnotatedTimerCustomBucketsDefaultPercentile() { | ||
|
||
} | ||
|
||
@Timed(name = "annotatedTimerCustomBucketsCustomPercentile", absolute = true) | ||
public void timeMeAnnotatedTimerCustomBucketsCustomPercentile() { | ||
|
||
} | ||
|
||
@Timed(name = "annotatedTimerCustomBucketsNoPercentile", absolute = true) | ||
public void timeMeAnnotatedTimerCustomBucketsNoPercentile() { | ||
|
||
} | ||
|
||
|
||
public void programmaticHistograms(){ | ||
applicationRegistry.histogram("histogramCustomPercentile"); | ||
applicationRegistry.histogram("histogramNoPercentile"); | ||
|
||
applicationRegistry.histogram("histogramCustomBucketsDefaultPercentile"); | ||
applicationRegistry.histogram("histogramCustomBucketsCustomPercentile"); | ||
applicationRegistry.histogram("histogramCustomBucketsNoPercentile"); | ||
|
||
} | ||
|
||
public void programmaticTimers(){ | ||
applicationRegistry.timer("timerCustomPercentile"); | ||
applicationRegistry.timer("timerNoPercentile"); | ||
|
||
applicationRegistry.timer("timerCustomBucketsDefaultPercentile"); | ||
applicationRegistry.timer("timerCustomBucketsCustomPercentile"); | ||
applicationRegistry.timer("timerCustomBucketsNoPercentile"); | ||
} | ||
|
||
} |
126 changes: 126 additions & 0 deletions
126
.../src/main/java/org/eclipse/microprofile/metrics/test/HistogramTimerConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
********************************************************************** | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICES file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
**********************************************************************/ | ||
|
||
package org.eclipse.microprofile.metrics.test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.RestAssured.when; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.Matchers.anyOf; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.junit.InSequence; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.restassured.RestAssured; | ||
import io.restassured.builder.ResponseBuilder; | ||
import io.restassured.http.Header; | ||
import io.restassured.response.Response; | ||
import jakarta.inject.Inject; | ||
|
||
/** | ||
* Rest Test Kit | ||
* | ||
* @author Heiko W. Rupp <hrupp@redhat.com> | ||
* @author Don Bourne <dbourne@ca.ibm.com> | ||
*/ | ||
@SuppressWarnings("CdiInjectionPointsInspection") | ||
@RunWith(Arquillian.class) | ||
public class HistogramTimerConfigurationTest { | ||
private static final String TEXT_PLAIN = "text/plain"; | ||
|
||
private static final String PROM_APP_LABEL_REGEX = "mp_app=\"[-/A-Za-z0-9]+\""; | ||
|
||
private static final String DEFAULT_PROTOCOL = "http"; | ||
private static final String DEFAULT_HOST = "localhost"; | ||
private static final int DEFAULT_PORT = 8080; | ||
|
||
public static final double TOLERANCE = 0.025; | ||
|
||
/* | ||
* Filters out _app tag plus any leading or trailing commas | ||
*/ | ||
private static String filterOutAppLabelPromMetrics(String responseBody) { | ||
return responseBody.replaceAll(PROM_APP_LABEL_REGEX, "").replaceAll("\\{,", "{").replaceAll(",\\}", "}"); | ||
} | ||
|
||
@Inject | ||
private MetricAppBean metricAppBean; | ||
|
||
@BeforeClass | ||
static public void setup() throws MalformedURLException { | ||
// set base URI and port number to use for all requests | ||
String serverUrl = System.getProperty("test.url"); | ||
String protocol = DEFAULT_PROTOCOL; | ||
String host = DEFAULT_HOST; | ||
int port = DEFAULT_PORT; | ||
|
||
if (serverUrl != null) { | ||
URL url = new URL(serverUrl); | ||
protocol = url.getProtocol(); | ||
host = url.getHost(); | ||
port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort(); | ||
} | ||
|
||
RestAssured.baseURI = protocol + "://" + host; | ||
RestAssured.port = port; | ||
|
||
// set user name and password to use for basic authentication for all requests | ||
String userName = System.getProperty("test.user"); | ||
String password = System.getProperty("test.pwd"); | ||
|
||
if (userName != null && password != null) { | ||
RestAssured.authentication = RestAssured.basic(userName, password); | ||
RestAssured.useRelaxedHTTPSValidation(); | ||
} | ||
|
||
} | ||
|
||
@Deployment | ||
public static WebArchive createDeployment() { | ||
WebArchive jar = ShrinkWrap.create(WebArchive.class).addClass(MetricAppBean.class) | ||
.addAsWebInfResource("META-INF/beans.xml", "beans.xml") | ||
.addAsWebInfResource("META-INF/microprofile-config.properties", "microprofile-config.properties"); | ||
|
||
System.out.println(jar.toString(true)); | ||
return jar; | ||
} | ||
|
||
@Test | ||
@RunAsClient | ||
@InSequence(1) | ||
public void testTextPlainResponseContentType() { | ||
Header acceptHeader = new Header("Accept", TEXT_PLAIN); | ||
|
||
given().header(acceptHeader).when().get("/metrics").then().statusCode(200).and().contentType(TEXT_PLAIN); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
tck/rest/src/main/resources/META-INF/microprofile-config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
********************************************************************** | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICES file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
**********************************************************************/ | ||
mp.metrics.distribution.percentile=annotatedTimerCustomPercentile=0.3,0.5,0.6 |