Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][stats] Enhance bookie metrics to support URL parameter filtering #4164

Closed
wants to merge 1 commit into from

Conversation

zwOvO
Copy link
Contributor

@zwOvO zwOvO commented Dec 27, 2023

Motivation

Allow filtering of metrics using URL parameters, for example:

/metrics?m_regex=bookkeeper_server_thread_executor_queue
/metrics?m_regex=.*_thread_executor_queue

Master Issue: #4143

@hangc0276
Copy link
Contributor

@asafm Would you please help take a look at this improvement? Thanks.

@asafm
Copy link
Contributor

asafm commented Jan 2, 2024

@hangc0276 /metrics should be Prometheus compatible.
If you look at the Prometheus Java client, setting up a server, exposing /metrics you'll see it only supports specifying the metric names, using the query param name[].

    protected static Set<String> parseQuery(String query) throws IOException {
        Set<String> names = new HashSet<String>();
        if (query != null) {
            String[] pairs = query.split("&");
            for (String pair : pairs) {
                int idx = pair.indexOf("=");
                if (idx != -1 && URLDecoder.decode(pair.substring(0, idx), "UTF-8").equals("name[]")) {
                    names.add(URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
                }
            }
        }
        return names;
    }

Besides that, I presume the idea is that BookKeeper users will transition into OpenTelemetry which is already available. For now, even OpenTelemetry Java SDK doesn't support filtering YET.
I added a proposal to OTel specifications and it was approved, and hopefully in the following months it will be implemented.

For now I recommend not adding it, and using OTel collector to scrape /metrics and filter out any unwanted metrics.

@zwOvO
Copy link
Contributor Author

zwOvO commented Jan 4, 2024

OK, Now I am filtering JVM metrics by writing a Python server proxy
——————

#!/bin/python

import SimpleHTTPServer
import SocketServer
import subprocess
import requests

class CustomHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/metrics':
            
            response = requests.get('http://localhost:8080/metrics/')
            output = '\n'.join(line for line in response.text.split('\n') if 'jvm' in line)
            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            self.wfile.write(output)

PORT = 9001
httpd = SocketServer.TCPServer(("", PORT), CustomHandler)
print "Server running on port", PORT
httpd.serve_forever()

@zwOvO zwOvO closed this Jan 4, 2024
@asafm
Copy link
Contributor

asafm commented Jan 4, 2024

OK, Now I am filtering JVM metrics by writing a Python server proxy ——————

#!/bin/python

import SimpleHTTPServer
import SocketServer
import subprocess
import requests

class CustomHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/metrics':
            
            response = requests.get('http://localhost:8080/metrics/')
            output = '\n'.join(line for line in response.text.split('\n') if 'jvm' in line)
            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            self.wfile.write(output)

PORT = 9001
httpd = SocketServer.TCPServer(("", PORT), CustomHandler)
print "Server running on port", PORT
httpd.serve_forever()

You can just use OTel Collector. It has built-in functionality to do just that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants