[jira] [Commented] (GERONIMO-6658) Issue @Gauge Accept: application/json

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GERONIMO-6658) Issue @Gauge Accept: application/json

JIRA jira@apache.org

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

ASF GitHub Bot commented on GERONIMO-6658:
------------------------------------------

rmannibucau commented on issue #2: GERONIMO-6658 - WIP Fix bug with gauge json
URL: https://github.com/apache/geronimo-metrics/pull/2#issuecomment-442837720
 
 
   To be concrete, here is the proposal:
   
   
       diff --git a/geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/jaxrs/MetricsEndpoints.java b/geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/jaxrs/MetricsEndpoints.java
       index 4293fd5..405cd45 100644
       --- a/geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/jaxrs/MetricsEndpoints.java
       +++ b/geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/jaxrs/MetricsEndpoints.java
       @@ -19,11 +19,13 @@ package org.apache.geronimo.microprofile.metrics.common.jaxrs;
        import static java.util.Collections.emptyMap;
        import static java.util.Collections.singletonMap;
        import static java.util.Optional.ofNullable;
       +import static java.util.function.Function.identity;
        import static java.util.stream.Collectors.joining;
        import static java.util.stream.Collectors.toMap;
       
        import java.util.Collections;
        import java.util.Map;
       +import java.util.function.Function;
        import java.util.stream.Stream;
       
        import javax.ws.rs.GET;
       @@ -133,7 +135,7 @@ public class MetricsEndpoints {
                                  @Context final SecurityContext securityContext,
                                  @Context final UriInfo uriInfo) {
                securityValidator.checkSecurity(securityContext, uriInfo);
       -        return singleEntry(name, findRegistry(registry));
       +        return singleEntry(name, findRegistry(registry), this::map);
            }
       
            @GET
       @@ -147,7 +149,7 @@ public class MetricsEndpoints {
                final MetricRegistry metricRegistry = findRegistry(registry);
                return prometheus.toText(
                        metricRegistry, registry,
       -                singleEntry(name, metricRegistry))
       +                singleEntry(name, metricRegistry, identity()))
                        .toString();
            }
       
       @@ -175,9 +177,10 @@ public class MetricsEndpoints {
                        .collect(toMap(Map.Entry::getKey, e -> mapMeta(e.getValue())));
            }
       
       -    private Map<String, Metric> singleEntry(final String name, final MetricRegistry metricRegistry) {
       +    private <T> Map<String, T> singleEntry(final String name, final MetricRegistry metricRegistry,
       +                                            final Function<Metric, T> metricMapper) {
                return ofNullable(metricRegistry.getMetrics().get(name))
       -                .map(metric -> singletonMap(name, metric))
       +                .map(metric -> singletonMap(name, metricMapper.apply(metric)))
                        .orElseGet(Collections::emptyMap);
            }
   
   And for the test:
   
       package org.apache.geronimo.microprofile.metrics.common;
       
       import static java.util.Collections.singletonMap;
       import static org.junit.Assert.assertEquals;
       
       import javax.ws.rs.core.SecurityContext;
       import javax.ws.rs.core.UriInfo;
       
       import org.apache.geronimo.microprofile.metrics.common.jaxrs.MetricsEndpoints;
       import org.apache.geronimo.microprofile.metrics.common.jaxrs.SecurityValidator;
       import org.apache.geronimo.microprofile.metrics.common.prometheus.PrometheusFormatter;
       import org.eclipse.microprofile.metrics.Gauge;
       import org.junit.Test;
       
       public class MetricsEndpointTest {
           @Test
           public void run() {
               final RegistryImpl registry = new RegistryImpl();
               registry.register("foo", (Gauge<Long>) () -> 1L);
       
               final MetricsEndpoints endpoints = new MetricsEndpoints();
               endpoints.setApplicationRegistry(registry);
               endpoints.setPrometheus(new PrometheusFormatter());
               endpoints.setSecurityValidator(new SecurityValidator() {
                   @Override
                   public void checkSecurity(final SecurityContext securityContext, final UriInfo uriInfo) {
                       // no-op
                   }
               });
               final Object json = endpoints.getJson("application", "foo", null, null);
               assertEquals(singletonMap("foo", 1L), json);
           }
       }
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


> Issue @Gauge Accept: application/json
> -------------------------------------
>
>                 Key: GERONIMO-6658
>                 URL: https://issues.apache.org/jira/browse/GERONIMO-6658
>             Project: Geronimo
>          Issue Type: Bug
>      Security Level: public(Regular issues)
>            Reporter: Ivan Junckes Filho
>            Priority: Major
>
> Trying access a gauge /metrics/application/<metric-name> with "Accept: application/json" I get the error below:
>  
> 21-Nov-2018 17:24:08.811 WARNING [http-nio-8080-exec-4] org.apache.cxf.jaxrs.model.OperationResourceInfoComparator.compare Both org.apache.geronimo.microprofile.metrics.common.jaxrs.MetricsEndpoints#getJson and org.apache.geronimo.microprofile.metrics.jaxrs.CdiMetricsEndpoints#getJson are equal candidates for handling the current request which can lead to unpredictable results
> 21-Nov-2018 17:26:52.183 SEVERE [http-nio-8080-exec-4] org.apache.cxf.jaxrs.utils.JAXRSUtils.logMessageHandlerProblem Problem with writing the data, class java.util.Collections$SingletonMap, ContentType: application/json
> 21-Nov-2018 17:26:52.184 WARNING [http-nio-8080-exec-4] org.apache.cxf.phase.PhaseInterceptorChain.doDefaultLogging Interceptor for {[http://jaxrs.common.metrics.microprofile.geronimo.apache.org/}MetricsEndpoints|http://jaxrs.common.metrics.microprofile.geronimo.apache.org/%7DMetricsEndpoints] has thrown exception, unwinding now
>  org.apache.cxf.interceptor.Fault
> at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleWriteException(JAXRSOutInterceptor.java:396)
> at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:272)
> at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:122)
> at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:84)
> at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
> at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:90)
> at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
> at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
> at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
> at org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:253)
> at org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.tomee.microprofile.jwt.MPJWTFilter.doFilter(MPJWTFilter.java:64)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.geronimo.microprofile.opentracing.microprofile.server.OpenTracingFilter.doFilter(OpenTracingFilter.java:126)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
> at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
> at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
> at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
> at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
> at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
> at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
> at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
> at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
> at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> at java.lang.Thread.run(Thread.java:748)
> Caused by: java.lang.StackOverflowError



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
Reply | Threaded
Open this post in threaded view
|

Re: [jira] [Commented] (GERONIMO-6658) Issue @Gauge Accept: application/json

Ivan Junckes Filho
Hey  Romain, I did all your suggestions.


Can you review and merge please?

On Thu, Nov 29, 2018 at 11:43 AM ASF GitHub Bot (JIRA) <[hidden email]> wrote:

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

ASF GitHub Bot commented on GERONIMO-6658:
------------------------------------------

rmannibucau commented on issue #2: GERONIMO-6658 - WIP Fix bug with gauge json
URL: https://github.com/apache/geronimo-metrics/pull/2#issuecomment-442837720


   To be concrete, here is the proposal:


       diff --git a/geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/jaxrs/MetricsEndpoints.java b/geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/jaxrs/MetricsEndpoints.java
       index 4293fd5..405cd45 100644
       --- a/geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/jaxrs/MetricsEndpoints.java
       +++ b/geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/jaxrs/MetricsEndpoints.java
       @@ -19,11 +19,13 @@ package org.apache.geronimo.microprofile.metrics.common.jaxrs;
        import static java.util.Collections.emptyMap;
        import static java.util.Collections.singletonMap;
        import static java.util.Optional.ofNullable;
       +import static java.util.function.Function.identity;
        import static java.util.stream.Collectors.joining;
        import static java.util.stream.Collectors.toMap;

        import java.util.Collections;
        import java.util.Map;
       +import java.util.function.Function;
        import java.util.stream.Stream;

        import javax.ws.rs.GET;
       @@ -133,7 +135,7 @@ public class MetricsEndpoints {
                                  @Context final SecurityContext securityContext,
                                  @Context final UriInfo uriInfo) {
                securityValidator.checkSecurity(securityContext, uriInfo);
       -        return singleEntry(name, findRegistry(registry));
       +        return singleEntry(name, findRegistry(registry), this::map);
            }

            @GET
       @@ -147,7 +149,7 @@ public class MetricsEndpoints {
                final MetricRegistry metricRegistry = findRegistry(registry);
                return prometheus.toText(
                        metricRegistry, registry,
       -                singleEntry(name, metricRegistry))
       +                singleEntry(name, metricRegistry, identity()))
                        .toString();
            }

       @@ -175,9 +177,10 @@ public class MetricsEndpoints {
                        .collect(toMap(Map.Entry::getKey, e -> mapMeta(e.getValue())));
            }

       -    private Map<String, Metric> singleEntry(final String name, final MetricRegistry metricRegistry) {
       +    private <T> Map<String, T> singleEntry(final String name, final MetricRegistry metricRegistry,
       +                                            final Function<Metric, T> metricMapper) {
                return ofNullable(metricRegistry.getMetrics().get(name))
       -                .map(metric -> singletonMap(name, metric))
       +                .map(metric -> singletonMap(name, metricMapper.apply(metric)))
                        .orElseGet(Collections::emptyMap);
            }

   And for the test:

       package org.apache.geronimo.microprofile.metrics.common;

       import static java.util.Collections.singletonMap;
       import static org.junit.Assert.assertEquals;

       import javax.ws.rs.core.SecurityContext;
       import javax.ws.rs.core.UriInfo;

       import org.apache.geronimo.microprofile.metrics.common.jaxrs.MetricsEndpoints;
       import org.apache.geronimo.microprofile.metrics.common.jaxrs.SecurityValidator;
       import org.apache.geronimo.microprofile.metrics.common.prometheus.PrometheusFormatter;
       import org.eclipse.microprofile.metrics.Gauge;
       import org.junit.Test;

       public class MetricsEndpointTest {
           @Test
           public void run() {
               final RegistryImpl registry = new RegistryImpl();
               registry.register("foo", (Gauge<Long>) () -> 1L);

               final MetricsEndpoints endpoints = new MetricsEndpoints();
               endpoints.setApplicationRegistry(registry);
               endpoints.setPrometheus(new PrometheusFormatter());
               endpoints.setSecurityValidator(new SecurityValidator() {
                   @Override
                   public void checkSecurity(final SecurityContext securityContext, final UriInfo uriInfo) {
                       // no-op
                   }
               });
               final Object json = endpoints.getJson("application", "foo", null, null);
               assertEquals(singletonMap("foo", 1L), json);
           }
       }


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


> Issue @Gauge Accept: application/json
> -------------------------------------
>
>                 Key: GERONIMO-6658
>                 URL: https://issues.apache.org/jira/browse/GERONIMO-6658
>             Project: Geronimo
>          Issue Type: Bug
>      Security Level: public(Regular issues)
>            Reporter: Ivan Junckes Filho
>            Priority: Major
>
> Trying access a gauge /metrics/application/<metric-name> with "Accept: application/json" I get the error below:
>  
> 21-Nov-2018 17:24:08.811 WARNING [http-nio-8080-exec-4] org.apache.cxf.jaxrs.model.OperationResourceInfoComparator.compare Both org.apache.geronimo.microprofile.metrics.common.jaxrs.MetricsEndpoints#getJson and org.apache.geronimo.microprofile.metrics.jaxrs.CdiMetricsEndpoints#getJson are equal candidates for handling the current request which can lead to unpredictable results
> 21-Nov-2018 17:26:52.183 SEVERE [http-nio-8080-exec-4] org.apache.cxf.jaxrs.utils.JAXRSUtils.logMessageHandlerProblem Problem with writing the data, class java.util.Collections$SingletonMap, ContentType: application/json
> 21-Nov-2018 17:26:52.184 WARNING [http-nio-8080-exec-4] org.apache.cxf.phase.PhaseInterceptorChain.doDefaultLogging Interceptor for {[http://jaxrs.common.metrics.microprofile.geronimo.apache.org/}MetricsEndpoints|http://jaxrs.common.metrics.microprofile.geronimo.apache.org/%7DMetricsEndpoints] has thrown exception, unwinding now
>  org.apache.cxf.interceptor.Fault
> at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleWriteException(JAXRSOutInterceptor.java:396)
> at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:272)
> at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:122)
> at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:84)
> at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
> at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:90)
> at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
> at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
> at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
> at org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:253)
> at org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.tomee.microprofile.jwt.MPJWTFilter.doFilter(MPJWTFilter.java:64)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.geronimo.microprofile.opentracing.microprofile.server.OpenTracingFilter.doFilter(OpenTracingFilter.java:126)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
> at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
> at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
> at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
> at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
> at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
> at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
> at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
> at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
> at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> at java.lang.Thread.run(Thread.java:748)
> Caused by: java.lang.StackOverflowError



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