Logic of the parseQuery() method in Prometheus HTTP Server

15 views
Skip to first unread message

Nipuni Chandimali

unread,
May 17, 2020, 2:55:17 PM5/17/20
to promethe...@googlegroups.com
I'm trying to understand the logic of the parseQuery() method in Prometheus HTTP Server (implemented in Java).

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;
    }
Can somebody explain what is the logic behind checking whether the decoded URL sub string is equal to name[] ?
Regards
     

Julius Volz

unread,
May 17, 2020, 3:04:29 PM5/17/20
to Nipuni Chandimali, Prometheus Users
See https://github.com/prometheus/client_java#http:

"All HTTP expostion integrations support restricting which time series to return using ?name[]= URL parameters."

It's just code that allows you to add "?name[]=metric_name_to_filter_by" to the end of the /metrics URL, in case you don't want the client library to return all metric names.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/CAKHONj1oSTKYHj_FeNxfwK7MBXuo87hMv0Mjc59HDQHC4kwtPA%40mail.gmail.com.


--
Julius Volz
PromLabs - promlabs.com

Nipuni Chandimali

unread,
May 17, 2020, 8:25:04 PM5/17/20
to Julius Volz, Prometheus Users
Thanks Julius for the prompt response.
Reply all
Reply to author
Forward
0 new messages