tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (TOMEE-2290) Metrics Microprofile Example for @Timed
Date Mon, 26 Nov 2018 13:34:00 GMT

    [ https://issues.apache.org/jira/browse/TOMEE-2290?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16698928#comment-16698928
] 

ASF GitHub Bot commented on TOMEE-2290:
---------------------------------------

Github user rmannibucau commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/218#discussion_r236248396
  
    --- Diff: examples/mp-metrics-timed/src/test/java/WeatherServiceTest.java ---
    @@ -0,0 +1,151 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You 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
    + * <p/>
    + * http://www.apache.org/licenses/LICENSE-2.0
    + * <p/>
    + * 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.
    + */
    +
    +import org.apache.cxf.jaxrs.client.WebClient;
    +import org.jboss.arquillian.container.test.api.Deployment;
    +import org.jboss.arquillian.junit.Arquillian;
    +import org.jboss.arquillian.test.api.ArquillianResource;
    +import org.jboss.shrinkwrap.api.ShrinkWrap;
    +import org.jboss.shrinkwrap.api.asset.StringAsset;
    +import org.jboss.shrinkwrap.api.spec.WebArchive;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +
    +import javax.json.Json;
    +import javax.json.JsonObject;
    +import javax.ws.rs.core.MediaType;
    +import javax.ws.rs.core.Response;
    +import java.io.StringReader;
    +import java.net.URL;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertTrue;
    +
    +@RunWith(Arquillian.class)
    +public class WeatherServiceTest {
    +
    +    @Deployment(testable = false)
    +    public static WebArchive createDeployment() {
    +        final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test.war")
    +                .addClass(WeatherService.class)
    +                .addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml");
    +        return webArchive;
    +    }
    +
    +    @ArquillianResource
    +    private URL base;
    +
    +    @Test
    +    public void testTimedMetric() {
    +        WebClient.create(base.toExternalForm())
    +                .path("/weather/day/status")
    +                .get(String.class);
    +
    +        final String metricPath = "/metrics/application/weather_day_status";
    +        assertPrometheusFormat(metricPath);
    +        assertJsonFormat(metricPath);
    +    }
    +
    +    private void assertPrometheusFormat(final String metricPath) {
    +        final String metric = WebClient.create(base.toExternalForm())
    +                .path(metricPath)
    +                .accept(MediaType.TEXT_PLAIN)
    +                .get(String.class);
    +
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds summary
timer"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds_count
timer"));
    +        assertTrue(metric.contains("application:weather_day_status_seconds_count 1.0"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_rate_per_second
timer"));
    +        assertTrue(metric.contains("application:weather_day_status_rate_per_second"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_one_min_rate_per_second
timer"));
    +        assertTrue(metric.contains("application:weather_day_status_one_min_rate_per_second"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_five_min_rate_per_second
timer"));
    +        assertTrue(metric.contains("application:weather_day_status_five_min_rate_per_second"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_fifteen_min_rate_per_second
time"));
    +        assertTrue(metric.contains("application:weather_day_status_fifteen_min_rate_per_second"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_min_seconds
timer"));
    +        assertTrue(metric.contains("application:weather_day_status_min_seconds"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_max_seconds
timer"));
    +        assertTrue(metric.contains("application:weather_day_status_max_seconds"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_mean_seconds
timer"));
    +        assertTrue(metric.contains("application:weather_day_status_mean_seconds"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_stddev_seconds
timer"));
    +        assertTrue(metric.contains("application:weather_day_status_stddev_seconds"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
    +        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.5\"}"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
    +        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.75\"}"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
    +        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.95\"}"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
    +        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.98\"}"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
    +        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.99\"}"));
    +        assertTrue(metric.contains("# TYPE application:weather_day_status_seconds timer"));
    +        assertTrue(metric.contains("application:weather_day_status_seconds{quantile=\"0.999\"}"));
    +    }
    +
    +    private void assertJsonFormat(final String metricPath) {
    +        final String metric = WebClient.create(base.toExternalForm())
    +                .path(metricPath)
    +                .accept(MediaType.APPLICATION_JSON)
    +                .get(String.class);
    +
    +        assertTrue(metric.contains("count"));
    +        assertTrue(metric.contains("meanRate"));
    +        assertTrue(metric.contains("fifteenMinRate"));
    +        assertTrue(metric.contains("fiveMinRate"));
    +        assertTrue(metric.contains("oneMinRate"));
    +        assertTrue(metric.contains("min"));
    +        assertTrue(metric.contains("max"));
    +        assertTrue(metric.contains("mean"));
    +        assertTrue(metric.contains("stddev"));
    +        assertTrue(metric.contains("p50"));
    +        assertTrue(metric.contains("p75"));
    +        assertTrue(metric.contains("p95"));
    +        assertTrue(metric.contains("p98"));
    +        assertTrue(metric.contains("p99"));
    +        assertTrue(metric.contains("p999"));
    +
    +    }
    +
    +    @Test
    +    public void testTimedMetricMetadata() {
    +        final Response response = WebClient.create(base.toExternalForm())
    +                .path("/metrics/application/weather_day_status")
    +                .accept(MediaType.APPLICATION_JSON)
    +                .options();
    +        final String metaData = response.readEntity(String.class);
    +        JsonObject metadataJson = Json.createReader(new StringReader(metaData)).readObject();
    +
    +        final String expected = "{\n" +
    +                "  \"weather_day_status\": {\n" +
    +                "    \"description\": \"This metric shows the weather status of the day.\",\n"
+
    +                "    \"displayName\": \"Weather Day Status\",\n" +
    +                "    \"name\": \"weather_day_status\",\n" +
    +                "    \"reusable\": false,\n" +
    +                "    \"tags\": \"\",\n" +
    +                "    \"type\": \"timer\",\n" +
    +                "    \"typeRaw\": \"TIMER\",\n" +
    +                "    \"unit\": \"nanoseconds\"\n" +
    +                "  }\n" +
    +                "}";
    +
    +        JsonObject expectedJson = Json.createReader(new StringReader(expected)).readObject();
    +        assertEquals(expectedJson, metadataJson);
    --- End diff --
    
    this is not stable so either assert using keys (keys1.size() == keys2.size() &&
for all key value ==) or using another way to write the assertEquals


> Metrics Microprofile Example for @Timed
> ---------------------------------------
>
>                 Key: TOMEE-2290
>                 URL: https://issues.apache.org/jira/browse/TOMEE-2290
>             Project: TomEE
>          Issue Type: Sub-task
>            Reporter: Ivan Junckes Filho
>            Assignee: Ivan Junckes Filho
>            Priority: Major
>              Labels: pull-request-available
>
> We would like to have an example for MicroProfile Metrics @Timed annotation.
> Here is a quick tutorial on MicroProfile Metrics if you are not aware:
> [https://www.tomitribe.com/blog/getting-started-with-microprofile-metrics/]
> Fork / clone the TomEE project from here:
> [https://github.com/apache/tomee]
> Example name should be _mp-metrics-timed_, following the standard already in the project.
> All the examples are in:
> [https://github.com/apache/tomee/tree/master/examples]
> See this example of @Counted for reference:
> [https://github.com/apache/tomee/tree/master/examples/mp-metrics-counted]
> See these two PRs for the diff for @Counted, it will help you see how simple it is:
> [https://github.com/apache/tomee/pull/203]
> [https://github.com/apache/tomee/pull/207]
> What you have to do is:
> 1 - Create a JAX-RS resource WeatherService that has one method with @Timed
> 2 - Have a WeatherServiceTest for the GET and OPTIONS scenarios of @Timed
> 3 - Make sure you have tests for Prometheus and JSON formats
> 4 - Make sure all the tests pass
> After that submit a PR and we'll review it.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message