You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/08/18 07:06:16 UTC

[GitHub] [cloudstack] shwstppr commented on a change in pull request #5329: metrics: fix hostsmetricsresponse for zero cpu, locale

shwstppr commented on a change in pull request #5329:
URL: https://github.com/apache/cloudstack/pull/5329#discussion_r690959912



##########
File path: plugins/metrics/src/main/java/org/apache/cloudstack/response/HostMetricsResponse.java
##########
@@ -212,4 +216,13 @@ public void setMemoryAllocatedDisableThreshold(final Long memAllocated, final Lo
         }
     }
 
+    private Double parseCPU(String cpu) {

Review comment:
       Added test

##########
File path: plugins/metrics/src/main/java/org/apache/cloudstack/response/HostMetricsResponse.java
##########
@@ -212,4 +216,13 @@ public void setMemoryAllocatedDisableThreshold(final Long memAllocated, final Lo
         }
     }
 
+    private Double parseCPU(String cpu) {
+        DecimalFormat decimalFormat = new DecimalFormat("#.##");
+        try {
+            return decimalFormat.parse(cpu).doubleValue();
+        } catch (ParseException e) {
+            throw new CloudRuntimeException(e);

Review comment:
       @nvazquez as the ParseException is thrown as CloudRuntimeException, it will get logged:
   ```
   INFO  [c.c.a.ApiServer] (qtp357350214-317:ctx-828b25d5) (logid:77b09f95) Timezone offset from UTC is: 0.0
   ERROR [c.c.a.ApiServer] (qtp357350214-32:ctx-f4aa35d7 ctx-d7301148) (logid:b4fa39eb) unhandled exception executing api command: [Ljava.lang.String;@1a6da41c
   com.cloud.utils.exception.CloudRuntimeException: Unparseable number: "abc"
   	at org.apache.cloudstack.response.HostMetricsResponse.parseCPU(HostMetricsResponse.java:228)
   	at org.apache.cloudstack.response.HostMetricsResponse.setCpuUsed(HostMetricsResponse.java:125)
   	at org.apache.cloudstack.metrics.MetricsServiceImpl.listHostMetrics(MetricsServiceImpl.java:284)
   	at org.apache.cloudstack.api.ListHostsMetricsCmd.execute(ListHostsMetricsCmd.java:50)
   	at com.cloud.api.ApiDispatcher.dispatch(ApiDispatcher.java:156)
   	at com.cloud.api.ApiServer.queueCommand(ApiServer.java:764)
   	at com.cloud.api.ApiServer.handleRequest(ApiServer.java:588)
   	at com.cloud.api.ApiServlet.processRequestInContext(ApiServlet.java:321)
   	at com.cloud.api.ApiServlet$1.run(ApiServlet.java:134)
   	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext$1.call(DefaultManagedContext.java:55)
   	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.callWithContext(DefaultManagedContext.java:102)
   	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.runWithContext(DefaultManagedContext.java:52)
   	at com.cloud.api.ApiServlet.processRequest(ApiServlet.java:131)
   	at com.cloud.api.ApiServlet.doGet(ApiServlet.java:93)
   	at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
   	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
   	at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service(ServletHolder.java:1386)
   	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755)
   	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1617)
   	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:226)
   	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1604)
   	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:545)
   	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
   	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:590)
   	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
   	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
   	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610)
   	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
   	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1300)
   	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
   	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)
   	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580)
   	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
   	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1215)
   	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
   	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
   	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
   	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
   	at org.eclipse.jetty.server.Server.handle(Server.java:500)
   	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
   	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)
   	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
   	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
   	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
   	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
   	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
   	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
   	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
   	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
   	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:135)
   	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
   	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
   	at java.base/java.lang.Thread.run(Thread.java:829)
   Caused by: java.text.ParseException: Unparseable number: "abc"
   	at java.base/java.text.NumberFormat.parse(NumberFormat.java:431)
   	at org.apache.cloudstack.response.HostMetricsResponse.parseCPU(HostMetricsResponse.java:226)
   	at org.apache.cloudstack.response.HostMetricsResponse.setCpuUsed(HostMetricsResponse.java:125)
   	... 51 more
   ```
   
   And API will fail in this case:
   ```
   (local) 🐝 > list hostsmetrics  id=fc75a8b3-263d-4231-8635-45715edea15a
   🙈 Error: (HTTP 530, error code 0) Unparseable number: "abc"
   ```
   
   PR description shows API output. With the change (similar to main branch), `listHostsMetrics` API won't fail when there is 0 cpu for host or locale issue and it will just report `∞%` or `NaN Ghz` as values.
   Change for not showing these invalid values can considered in a separate PR.




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

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org