You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/08/11 10:21:40 UTC

[GitHub] [ozone] dombizita opened a new pull request, #3677: HDDS-7045. Election info is out of date in Recon

dombizita opened a new pull request, #3677:
URL: https://github.com/apache/ozone/pull/3677

   ## What changes were proposed in this pull request?
   
   The Last Leader Election and No. of Elections columns in the Pipelines page had incorrect or no data previously. This issue is caused by a few small things. These columns only have data, if any metrics service providers like Prometheus is configured, which is assumable from a [comment](https://github.com/apache/ozone/blob/64032cc223d314ac1e93558dc538663cec4a1a92/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/PipelineEndpoint.java#L108) in the code. I added a tooltip to these columns with this information and if no metrics service provider is configured in the cluster, the columns will show NA.
   
   If you configured Prometheus the No. of Elections had data, but the Last Leader Election didn't. This happened, because the Last Leader Election's metric name was incorrect. `lastLeaderElapsedTime` was added in this [RATIS-1049](https://issues.apache.org/jira/browse/RATIS-1049) to Ratis, but that seemed to be 0 for every case. I found `lastLeaderElectionElapsedTime` metric in Ratis which gave back the elapsed in milliseconds since a datanode was elected in a pipeline, so I used that. The method that queried the right metric from the provider didn't queried it correctly, as it always returned the first metric for each query. So I made two methods for each metric. For the No. of Elections I asked for a pipeline's all metrics, so I got as many metrics as many datanodes are in the pipeline. As each metric gives me how many times that datanode was elected in the pipeline, I summed up these. For the Last Leader Election I asked for the pipeline's leader node's value as that shows me how
  much time elapsed since that datanode was last elected in the pipeline.
   
   I also changed some examples in files as you need to add `http://prometheus:9090` (not localhost) if you want to add Prometheus's endpoint.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-7045
   
   ## How was this patch tested?
   
   I tested it locally in the `compose/ozone` environment with and without Prometheus configured.
   https://github.com/dombizita/ozone/actions/runs/2834395620


-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] dombizita commented on a diff in pull request #3677: HDDS-7045. Election info is out of date in Recon

Posted by GitBox <gi...@apache.org>.
dombizita commented on code in PR #3677:
URL: https://github.com/apache/ozone/pull/3677#discussion_r948070379


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/PipelineEndpoint.java:
##########
@@ -130,25 +130,55 @@ public Response getPipelines() {
     return Response.ok(pipelinesResponse).build();
   }
 
-  private Optional<Long> getMetricValue(String metricName, String groupId) {
+  private Long getElectionCountMetricValue(String groupId) {
+    Long electionCount = 0L;
     String metricsQuery = String.format(
-        "query=%s{group=\"%s\"}", metricName, groupId);
+            "query=ratis_leader_election_electionCount{group=\"%s\"}", groupId);
     try {
       List<Metric> metrics = metricsServiceProvider.getMetricsInstant(
-          metricsQuery);
+              metricsQuery);
+      if (!metrics.isEmpty()) {
+        for (Metric m : metrics) {
+          TreeMap<Double, Double> values = (TreeMap<Double, Double>)
+                  m.getValues();
+          if (!values.isEmpty()) {
+            electionCount += Optional.of(values.firstEntry().getValue()
+                    .longValue()).orElse(0L);

Review Comment:
   As we discussed offline, the optional is unnecessary as I am checking if the values is empty one line above. With this way there will always be a first entry and also its value. I updated my patch based on this. 



-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] smengcl commented on a diff in pull request #3677: HDDS-7045. Election info is out of date in Recon

Posted by GitBox <gi...@apache.org>.
smengcl commented on code in PR #3677:
URL: https://github.com/apache/ozone/pull/3677#discussion_r946529412


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/PipelineEndpoint.java:
##########
@@ -130,25 +130,55 @@ public Response getPipelines() {
     return Response.ok(pipelinesResponse).build();
   }
 
-  private Optional<Long> getMetricValue(String metricName, String groupId) {
+  private Long getElectionCountMetricValue(String groupId) {
+    Long electionCount = 0L;
     String metricsQuery = String.format(
-        "query=%s{group=\"%s\"}", metricName, groupId);
+            "query=ratis_leader_election_electionCount{group=\"%s\"}", groupId);
     try {
       List<Metric> metrics = metricsServiceProvider.getMetricsInstant(
-          metricsQuery);
+              metricsQuery);
+      if (!metrics.isEmpty()) {
+        for (Metric m : metrics) {
+          TreeMap<Double, Double> values = (TreeMap<Double, Double>)
+                  m.getValues();
+          if (!values.isEmpty()) {
+            electionCount += Optional.of(values.firstEntry().getValue()
+                    .longValue()).orElse(0L);
+          }
+        }
+      }
+    } catch (Exception ex) {
+      if (LOG.isErrorEnabled()) {
+        LOG.error(String.format("Unable to get metrics value for " +
+                "ratis_leader_election_electionCount"), ex);
+      }
+    }
+    return electionCount;
+  }
+
+  private Long getLastLeaderElectionElapsedTimeMetricValue(String groupId,
+                                                           UUID uuid) {
+    String metricsQuery = String.format(
+            "query=ratis_leader_election_lastLeaderElectionElapsedTime{group=" +
+                    "\"%s\",exported_instance=\"%s\"}", groupId,
+            uuid.toString());
+    try {
+      List<Metric> metrics = metricsServiceProvider.getMetricsInstant(
+              metricsQuery);
       if (!metrics.isEmpty()) {
         TreeMap<Double, Double> values = (TreeMap<Double, Double>)
-            metrics.get(0).getValues();
+                metrics.get(0).getValues();
         if (!values.isEmpty()) {
-          return Optional.of(values.firstEntry().getValue().longValue());
+          return Optional.of(values.firstEntry().getValue().longValue())
+                  .orElse(0L);

Review Comment:
   How about returning -1 to indicate error?
   
   ```suggestion
                     .orElse(-1L);
   ```



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/PipelineEndpoint.java:
##########
@@ -130,25 +130,55 @@ public Response getPipelines() {
     return Response.ok(pipelinesResponse).build();
   }
 
-  private Optional<Long> getMetricValue(String metricName, String groupId) {
+  private Long getElectionCountMetricValue(String groupId) {
+    Long electionCount = 0L;
     String metricsQuery = String.format(
-        "query=%s{group=\"%s\"}", metricName, groupId);
+            "query=ratis_leader_election_electionCount{group=\"%s\"}", groupId);
     try {
       List<Metric> metrics = metricsServiceProvider.getMetricsInstant(
-          metricsQuery);
+              metricsQuery);
+      if (!metrics.isEmpty()) {
+        for (Metric m : metrics) {
+          TreeMap<Double, Double> values = (TreeMap<Double, Double>)
+                  m.getValues();
+          if (!values.isEmpty()) {
+            electionCount += Optional.of(values.firstEntry().getValue()
+                    .longValue()).orElse(0L);

Review Comment:
   In which cases will this optional value become absent?



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/PipelineEndpoint.java:
##########
@@ -130,25 +130,55 @@ public Response getPipelines() {
     return Response.ok(pipelinesResponse).build();
   }
 
-  private Optional<Long> getMetricValue(String metricName, String groupId) {
+  private Long getElectionCountMetricValue(String groupId) {
+    Long electionCount = 0L;
     String metricsQuery = String.format(
-        "query=%s{group=\"%s\"}", metricName, groupId);
+            "query=ratis_leader_election_electionCount{group=\"%s\"}", groupId);
     try {
       List<Metric> metrics = metricsServiceProvider.getMetricsInstant(
-          metricsQuery);
+              metricsQuery);
+      if (!metrics.isEmpty()) {
+        for (Metric m : metrics) {
+          TreeMap<Double, Double> values = (TreeMap<Double, Double>)
+                  m.getValues();
+          if (!values.isEmpty()) {
+            electionCount += Optional.of(values.firstEntry().getValue()
+                    .longValue()).orElse(0L);
+          }
+        }
+      }
+    } catch (Exception ex) {

Review Comment:
   I wanted to say we preferred catching a more detailed exception than such a generic one, but I figured it is not easy to do so at the moment because `getMetricsInstant()` throws generic exception atm.



-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai merged pull request #3677: HDDS-7045. Election info is out of date in Recon

Posted by GitBox <gi...@apache.org>.
adoroszlai merged PR #3677:
URL: https://github.com/apache/ozone/pull/3677


-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on pull request #3677: HDDS-7045. Election info is out of date in Recon

Posted by GitBox <gi...@apache.org>.
adoroszlai commented on PR #3677:
URL: https://github.com/apache/ozone/pull/3677#issuecomment-1219342627

   Thanks @dombizita for the fix, @smengcl for the review.


-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org