mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-05 17:27:51 +00:00
Add --prometheus-verb to support POST requests to prometheus servers
This commit is contained in:
parent
9008b12a01
commit
a8742cff28
2 changed files with 37 additions and 12 deletions
|
|
@ -74,6 +74,8 @@ type PrometheusAdapter struct {
|
|||
PrometheusTokenFile string
|
||||
// PrometheusHeaders is a k=v list of headers to set on requests to PrometheusURL
|
||||
PrometheusHeaders []string
|
||||
// PrometheusVerb is a verb to set on requests to PrometheusURL
|
||||
PrometheusVerb string
|
||||
// AdapterConfigFile points to the file containing the metrics discovery configuration.
|
||||
AdapterConfigFile string
|
||||
// MetricsRelistInterval is the interval at which to relist the set of available metrics
|
||||
|
|
@ -90,6 +92,10 @@ func (cmd *PrometheusAdapter) makePromClient() (prom.Client, error) {
|
|||
return nil, fmt.Errorf("invalid Prometheus URL %q: %v", baseURL, err)
|
||||
}
|
||||
|
||||
if cmd.PrometheusVerb != http.MethodGet && cmd.PrometheusVerb != http.MethodPost {
|
||||
return nil, fmt.Errorf("unsupported Prometheus Http Verb %q", cmd.PrometheusVerb)
|
||||
}
|
||||
|
||||
var httpClient *http.Client
|
||||
|
||||
if cmd.PrometheusCAFile != "" {
|
||||
|
|
@ -117,7 +123,7 @@ func (cmd *PrometheusAdapter) makePromClient() (prom.Client, error) {
|
|||
}
|
||||
genericPromClient := prom.NewGenericAPIClient(httpClient, baseURL, parseHeaderArgs(cmd.PrometheusHeaders))
|
||||
instrumentedGenericPromClient := mprom.InstrumentGenericAPIClient(genericPromClient, baseURL.String())
|
||||
return prom.NewClientForAPI(instrumentedGenericPromClient), nil
|
||||
return prom.NewClientForAPI(instrumentedGenericPromClient, cmd.PrometheusVerb), nil
|
||||
}
|
||||
|
||||
func (cmd *PrometheusAdapter) addFlags() {
|
||||
|
|
@ -137,6 +143,8 @@ func (cmd *PrometheusAdapter) addFlags() {
|
|||
"Optional file containing the bearer token to use when connecting with Prometheus")
|
||||
cmd.Flags().StringArrayVar(&cmd.PrometheusHeaders, "prometheus-header", cmd.PrometheusHeaders,
|
||||
"Optional header to set on requests to prometheus-url. Can be repeated")
|
||||
cmd.Flags().StringVar(&cmd.PrometheusVerb, "prometheus-verb", cmd.PrometheusVerb,
|
||||
"HTTP Verb to set on requests to Prometheus.")
|
||||
cmd.Flags().StringVar(&cmd.AdapterConfigFile, "config", cmd.AdapterConfigFile,
|
||||
"Configuration file containing details of how to transform between Prometheus metrics "+
|
||||
"and custom metrics API resources")
|
||||
|
|
@ -274,6 +282,7 @@ func main() {
|
|||
// set up flags
|
||||
cmd := &PrometheusAdapter{
|
||||
PrometheusURL: "https://localhost",
|
||||
PrometheusVerb: http.MethodGet,
|
||||
MetricsRelistInterval: 10 * time.Minute,
|
||||
}
|
||||
cmd.Name = "prometheus-metrics-adapter"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue