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=16698929#comment-16698929
] 

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_r236249672
  
    --- 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"));
    --- End diff --
    
    as a general rule put a small description and the actual value in "message" parameter
of the assert
    
    proposal:
    
         Stream.of("expected text 1", "expected text 2")
            .forEach(text -> assertTrue("Expected: " + text + " to be present in " + metric,
metric.contains(text)));
    
    Also for an example you don't need to assert that much so just checking "application:weather_day_status_seconds_count
1.0" can be sufficient for the demonstration IMHO


> 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