Richard-Yi opened a new issue #13206:
URL: https://github.com/apache/pulsar/issues/13206


   Currently, pulsar use `/metric` endpoint to expose its metrics in prometheus 
format,but it cannot be reused by other plugins such as aop/kop..
   I checked the source code. Pulsar defines `PrometheusRawMetricsProvider` to 
abstract the metrics provider class.
   ```java
   /**
    * The prometheus metrics provider for generate prometheus format metrics.
    */
   public interface PrometheusRawMetricsProvider {
   
       /**
        * Generate the metrics from the metrics provider.
        * @param stream the stream that write the metrics to
        */
       void generate(SimpleTextOutputStream stream);
   }
   
   ```
   But In `PrometheusMetricsServlet`, It only collect the metric from 
`PrometheusMetricsGenerator`, which only contains metrics from pulsar itself.
   ```java
       @Override
       protected void doGet(HttpServletRequest request, HttpServletResponse 
response)
               throws ServletException, IOException {
           AsyncContext context = request.startAsync();
           context.setTimeout(metricsServletTimeoutMs);
           executor.execute(safeRun(() -> {
               HttpServletResponse res = (HttpServletResponse) 
context.getResponse();
               try {
                   res.setStatus(HttpStatus.OK_200);
                   res.setContentType("text/plain");
                   PrometheusMetricsGenerator.generate(pulsar, 
shouldExportTopicMetrics, shouldExportConsumerMetrics,
                           shouldExportProducerMetrics, 
splitTopicAndPartitionLabel, res.getOutputStream(),
                           metricsProviders);
                   context.complete();
   
               } catch (Exception e) {
                   log.error("Failed to generate prometheus stats", e);
                   res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
                   context.complete();
               }
           }));
       }
   ```
   
   


-- 
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: [email protected]

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


Reply via email to