how to implement authentication in http_sd api

169 views
Skip to first unread message

木mumu

unread,
Aug 9, 2021, 3:23:26 AM8/9/21
to Prometheus Users
in prometheus.yml,it should be like
  - job_name: 'test'
    metrics_path: '/test'
    authorization:
      credentials: mIrLtzDvPr1b90UG
      type: Token
    static_configs:
      - targets: ['10.236.114.9:8850']
now I want to do this with http_sd,my api result is 
[
{
"labels": {
"__authorization__": {
"credentials": "mIrLtzDvPr1b90UG",
"type": "Token"
},
"__metrics_path__": "/test"
},
"targets": [
]
}
]
the notation for authentication is wrong,how to implement authentication correctly?
Message has been deleted
Message has been deleted

Brian Candler

unread,
Aug 9, 2021, 8:55:16 AM8/9/21
to Prometheus Users
Google groups keeps deleting my responses, so I will try one more time.

The answer is, you can't do this.  Define the credentials statically in the job (as you did in your first example), replace static_configs with http_sd_configs, and set only the targets and auxiliary labels in your http endpoint.


Brian Candler

unread,
Aug 9, 2021, 9:54:52 AM8/9/21
to Prometheus Users
Note that you *can* use labels __metrics_path__, __scheme__ and __param_XXX to override those parts of the scrape config per target, as described here.  But not the authentication settings.

木mumu

unread,
Aug 9, 2021, 10:04:43 PM8/9/21
to Prometheus Users
thanks
If relabel_configs is designed to be exposed, then the prohibition of setting authentication by relabel is a reasonable limitation. But in use, it would be nice to have a private_relabel_configs mechanism in the future
Reply all
Reply to author
Forward
0 new messages