LianYi
July 19, 2021, 12:58am
1
Hi Prometheus Team
I want to know if i can prevent Prometheus from encoding the characters
scrape_configs:
job_name: ‘somename’
params:
prefix: [‘finatra’]
url: [‘http://:9090/admin/metrics.json’]
When i do that,i get params encoded:
url=http%3A%2F%2F%3A9090%2Fadmin%2Fmetrics.json
Is there any idea?
Thanks
Hi LianYi,
The metrics path encoding can be avoided by using the metrics_path option in the job.
The HTTP resource path on which to fetch metrics from targets.
[ metrics_path: | default = /metrics ]
Reference:
Example:
job_name: ‘somename’
metrics_path: /admin/metrics.json
scrape_interval: 20s
static_configs:
targets: [<target_ip_address>:80’]
I am not familiar with avoiding encoding of the general params. Good question.
LianYi
July 26, 2021, 1:15am
3
Thanks a lot for your reply
just like your configurations:
job_name: ‘somename’
metrics_path: /admin/metrics.json
scrape_interval: 20s
static_configs:
* targets: [‘10.56.1.28:80’]
the url is 10.56.1.28:80/admin/metrics.json
then i want to get some params, so i configure like this :
job_name: ‘somename’
metrics_path: /admin/metrics.json?url=http://1.1.1.1:9990/admin/metrics.json
scrape_interval: 20s
static_configs:
* targets: [‘10.56.1.28:80’]
what i want is: 10.56.1.28:80/admin/metrics.json?url=http://1.1.1.1:9990/admin/metrics.json
when i captured the packets from tcpdump,the url was encoded like this:
10.56.1.28:80/admin/metrics.json%3Furl=http%3A%2F%2F%1.1.1.1%3A9990/admin/metrics.json
then i got an answer from stackoverflow:https://stackoverflow.com/questions/40172415/question-mark-in-prometheus-metrics-path-gets-encoded
like the issue,i can’t get the correct url what i want yet!
What is an example of a working URL? That should help convert to a Prometheus config.
LianYi
July 26, 2021, 2:04am
5
the working url what i want is:
10.56.1.28:80/admin/metrics.json?url=http://1.1.1.1:9990/admin/metrics.json
but i got:
10.56.1.28:80/admin/metrics.json%3Furl=http%3A%2F%2F%1.1.1.1%3A9990/admin/metrics.json
just like a ‘Get’ mode http request,but some parameters got encoded
also some reserved characters in RFC3986,like “?” ,":","/"
The above might be closer but it looks like the “?” sign still gets encoded for the browser to handle it.
When the “endpoint” URL is clicked I see the URL as:
http://10.56.1.28/admin/metrics.json%3Furl=http://1.1.1.1:9990/admin/metrics.json
I found this relating to the question mark:
opened 04:10AM - 19 Apr 19 UTC
closed 01:10PM - 19 Apr 19 UTC
Hello All,
We are trying to scrape targets using urls like following:
http… ://example.com:1234/service/metrics?&b1234
sample config:
```
- job_name: test-1
metrics_path: /service/metrics?&b1234
scheme: http
static_configs:
- targets:
- example.com:1234
```
Here example.com is a VIP url which load balances across multiple JVMs. In order to connect to a specific JVM, an affinity url is constructed using "&b1234". The load balancer uses this to identify which JVM to connect.
However, Prometheus converts "?" to "%3F" while scraping and as a result gets 404.
Can you help us in identifying a solution for this. I tried using params, but it needs a key, value structure.
Note: Due to security reasons, we cannot directly connect to the individual JVM ports.
Also this is interesting:
https://www.debugcn.com/en/article/15572338.html
LianYi
July 27, 2021, 2:27am
7
Thanks a lot for your help
As a result,we can not write these to metrics_path
so need to use params configuration?
https://stackoverflow.com/questions/40172415/question-mark-in-prometheus-metrics-path-gets-encoded
looks well at this time
But when I click the “Endpoint” URL,I get
http://10.56.1.28/metrics?prefix=finatra&url=http%3A%2F%2F1.1.1.1%3A9090%2Fadmin%2Fmetrics.json
of course, this is not what I want And will give rise to requesting false
Looks like Prometheus “URL Encodes” the metrics_path parameter URL by design.
This video says “do not encode the whole URL”.
My opinion is there should be an option to “Not URL encode” the metrics_path at all.
I guess we have to hope someone else provides some feedback.
What happens when you click on the Prometheus target link? Does the target show any logs?
LianYi
July 28, 2021, 7:03am
9
I agree with you
When I click on the target link, I get 404 because of the error URL
So I test all the characters mentioned by RFC 3986:
metrics_path : :/?#[]@ !$&`()*+,;= -._~
And I get:
LianYi
July 28, 2021, 8:12am
10
Maybe they are right And the working of decoding URL must do by the server
1 Like