You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/12/17 23:48:21 UTC

[GitHub] [pulsar] zzzming opened a new pull request #8995: remove duplicated broker prometheus metrics type

zzzming opened a new pull request #8995:
URL: https://github.com/apache/pulsar/pull/8995


   ### Motivation
   
   If there are multiple topics from different namespaces, the broker prometheus metrics will print out duplicated `# TYPE` definition for pulsar_ml_AddEntryBytesRate and other managed ledger metrics.
   
   In fact, this problem can be verified by `promtool` https://github.com/prometheus/prometheus#building-from-source
   
   On the broker, run this command to check validity of Pulsar broker metric format.
   `curl localhost:8080/metrics/ | ~/go/bin/promtool check metrics`
   
   ### Modifications
   
   To prevent duplicated metrics type definition, the definition is now tracked and only printed out once. It leverages the existing metrics name Set already defined under parseMetricsToPrometheusMetrics() in PrometheusMetricsGenerator.java
   
   ### Verifying this change
   
   - [ x] Make sure that the change passes the CI checks.
   
   This change added tests and can be verified as follows:
   
   Added two topics under new namespaces to trigger conditions that duplicated prometheus type could happen previously under testManagedLedgerStats() of PrometheusMetricsTest.java. Updated test cases checks this duplicated type problem.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API: no
     - The schema: no
     - The default values of configurations: no
     - The wire protocol: no
     - The rest endpoints: no
     - The admin cli options: no
     - Anything that affects deployment: no
   
   ### Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? 
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


----------------------------------------------------------------
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.

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



[GitHub] [pulsar] zzzming commented on a change in pull request #8995: remove duplicated broker prometheus metrics type

Posted by GitBox <gi...@apache.org>.
zzzming commented on a change in pull request #8995:
URL: https://github.com/apache/pulsar/pull/8995#discussion_r545865868



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java
##########
@@ -591,18 +595,63 @@ public void testManagedLedgerStats() throws Exception {
                 System.out.println(e.getKey() + ": " + e.getValue())
         );
 
+        Map<String, String> typeDefs = new HashMap<String, String>();
+        Map<String, String> metricNames = new HashMap<String, String>();
+
+        Pattern typePattern = Pattern.compile("^#\\s+TYPE\\s+(\\w+)\\s+(\\w+)");
+        Pattern metricNamePattern = Pattern.compile("^(\\w+)\\{.+");
+
+	    Splitter.on("\n").split(metricsStr).forEach(line -> {

Review comment:
       Removed the tab. Can you clarify what's the intention issue? The code block is to catch any issues with duplicated definition of metrics TYPE and also ensures the metric name matches the ones defined in the type definition header.




----------------------------------------------------------------
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.

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



[GitHub] [pulsar] zzzming commented on a change in pull request #8995: remove duplicated broker prometheus metrics type

Posted by GitBox <gi...@apache.org>.
zzzming commented on a change in pull request #8995:
URL: https://github.com/apache/pulsar/pull/8995#discussion_r545865868



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java
##########
@@ -591,18 +595,63 @@ public void testManagedLedgerStats() throws Exception {
                 System.out.println(e.getKey() + ": " + e.getValue())
         );
 
+        Map<String, String> typeDefs = new HashMap<String, String>();
+        Map<String, String> metricNames = new HashMap<String, String>();
+
+        Pattern typePattern = Pattern.compile("^#\\s+TYPE\\s+(\\w+)\\s+(\\w+)");
+        Pattern metricNamePattern = Pattern.compile("^(\\w+)\\{.+");
+
+	    Splitter.on("\n").split(metricsStr).forEach(line -> {

Review comment:
       Removed the tab. The code block is to catch any issues with duplicated definition of metrics TYPE and also ensures the metric name matches the ones defined in the type definition header.




----------------------------------------------------------------
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.

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



[GitHub] [pulsar] zzzming commented on pull request #8995: remove duplicated broker prometheus metrics type

Posted by GitBox <gi...@apache.org>.
zzzming commented on pull request #8995:
URL: https://github.com/apache/pulsar/pull/8995#issuecomment-748209345


   /pulsarbot run-failure-checks


----------------------------------------------------------------
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.

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



[GitHub] [pulsar] zzzming commented on a change in pull request #8995: remove duplicated broker prometheus metrics type

Posted by GitBox <gi...@apache.org>.
zzzming commented on a change in pull request #8995:
URL: https://github.com/apache/pulsar/pull/8995#discussion_r545864142



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java
##########
@@ -591,18 +595,63 @@ public void testManagedLedgerStats() throws Exception {
                 System.out.println(e.getKey() + ": " + e.getValue())
         );
 
+        Map<String, String> typeDefs = new HashMap<String, String>();
+        Map<String, String> metricNames = new HashMap<String, String>();
+
+        Pattern typePattern = Pattern.compile("^#\\s+TYPE\\s+(\\w+)\\s+(\\w+)");
+        Pattern metricNamePattern = Pattern.compile("^(\\w+)\\{.+");
+
+	    Splitter.on("\n").split(metricsStr).forEach(line -> {
+            if (line.isEmpty()) {
+                return;
+            }
+            if (line.startsWith("#")) {
+                // Check for duplicate type definitions
+                Matcher typeMatcher = typePattern.matcher(line);
+                checkArgument(typeMatcher.matches());
+                String metricName = typeMatcher.group(1);
+                String type = typeMatcher.group(2);
+
+                // From https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md
+                // "Only one TYPE line may exist for a given metric name."
+                if (!typeDefs.containsKey(metricName)) {
+                    typeDefs.put(metricName, type);
+                } else {
+                    fail("Duplicate type definition found for TYPE definition " + metricName);
+                    System.out.println(metricsStr);

Review comment:
       removed




----------------------------------------------------------------
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.

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



[GitHub] [pulsar] eolivelli commented on pull request #8995: remove duplicated broker prometheus metrics type

Posted by GitBox <gi...@apache.org>.
eolivelli commented on pull request #8995:
URL: https://github.com/apache/pulsar/pull/8995#issuecomment-748119867


   @sijie @wolfstudy  can we pick this change to 2.6.3 and 2.7.1 ?


----------------------------------------------------------------
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.

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



[GitHub] [pulsar] sijie commented on a change in pull request #8995: remove duplicated broker prometheus metrics type

Posted by GitBox <gi...@apache.org>.
sijie commented on a change in pull request #8995:
URL: https://github.com/apache/pulsar/pull/8995#discussion_r545660683



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java
##########
@@ -591,18 +595,63 @@ public void testManagedLedgerStats() throws Exception {
                 System.out.println(e.getKey() + ": " + e.getValue())
         );
 
+        Map<String, String> typeDefs = new HashMap<String, String>();
+        Map<String, String> metricNames = new HashMap<String, String>();
+
+        Pattern typePattern = Pattern.compile("^#\\s+TYPE\\s+(\\w+)\\s+(\\w+)");
+        Pattern metricNamePattern = Pattern.compile("^(\\w+)\\{.+");
+
+	    Splitter.on("\n").split(metricsStr).forEach(line -> {
+            if (line.isEmpty()) {
+                return;
+            }
+            if (line.startsWith("#")) {
+                // Check for duplicate type definitions
+                Matcher typeMatcher = typePattern.matcher(line);
+                checkArgument(typeMatcher.matches());
+                String metricName = typeMatcher.group(1);
+                String type = typeMatcher.group(2);
+
+                // From https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md
+                // "Only one TYPE line may exist for a given metric name."
+                if (!typeDefs.containsKey(metricName)) {
+                    typeDefs.put(metricName, type);
+                } else {
+                    fail("Duplicate type definition found for TYPE definition " + metricName);
+                    System.out.println(metricsStr);

Review comment:
       I am not sure why do we need this line if it will fail before this line.

##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java
##########
@@ -591,18 +595,63 @@ public void testManagedLedgerStats() throws Exception {
                 System.out.println(e.getKey() + ": " + e.getValue())
         );
 
+        Map<String, String> typeDefs = new HashMap<String, String>();
+        Map<String, String> metricNames = new HashMap<String, String>();
+
+        Pattern typePattern = Pattern.compile("^#\\s+TYPE\\s+(\\w+)\\s+(\\w+)");
+        Pattern metricNamePattern = Pattern.compile("^(\\w+)\\{.+");
+
+	    Splitter.on("\n").split(metricsStr).forEach(line -> {

Review comment:
       I think this block has intention issue.

##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/PrometheusMetricsTest.java
##########
@@ -591,18 +595,63 @@ public void testManagedLedgerStats() throws Exception {
                 System.out.println(e.getKey() + ": " + e.getValue())
         );
 
+        Map<String, String> typeDefs = new HashMap<String, String>();
+        Map<String, String> metricNames = new HashMap<String, String>();
+
+        Pattern typePattern = Pattern.compile("^#\\s+TYPE\\s+(\\w+)\\s+(\\w+)");
+        Pattern metricNamePattern = Pattern.compile("^(\\w+)\\{.+");
+
+	    Splitter.on("\n").split(metricsStr).forEach(line -> {

Review comment:
       We don't use tabs in the code.




----------------------------------------------------------------
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.

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



[GitHub] [pulsar] sijie merged pull request #8995: remove duplicated broker prometheus metrics type

Posted by GitBox <gi...@apache.org>.
sijie merged pull request #8995:
URL: https://github.com/apache/pulsar/pull/8995


   


----------------------------------------------------------------
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.

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