-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add the ability to use a custom HTTP Client to the push #341
Comments
Good point. Question is how to implement this best. The naive approach would be to duplicate each existing function in the Options approach:// Easy case:
push.Collectors("http://example.org/metrics", "my_job", push.Options{}, myCollector)
// Complex case:
push.Collectors(
"http://example.org/metrics",
"my_job",
push.Options{
Add: true,
Grouping: map[string]string{"zone": "xy"},
Client: &gae.Client{},
},
myCollector1, myCollector2,
) Builder approach// Easy case:
push.New("http://example.org/metrics", "my_job").Collector(myCollector).Push()
// Complex case:
push.New("http://example.org/metrics", "my_job").
Collector(myCollector1).
Collector(myCollector1).
Grouping("zone", "xy").
Client(&gae.Client{}).
Add() I like the builder approach as it naturally allows for multiple Collectors, Gatherers, and even Groupings without maps and/or variadic args. And it would allow to distinguish between the normal push and the "add" push by simply two different methods. It would be a completely different interface. We could simply have them both in the push package and then deprecate the old ones. @shlimp Now your feature request triggered something way bigger. |
This allows adding more options in elegant ways, showcased here by HTTP basic auth and by injecting a custom http.Client. Fixes prometheus#341 and prometheus#372.
Currently, the push to gateway function uses http.DefaultClient to make the request to the pushgateway.
By abling to use a custom client, there can be more flexibility on how requests are sent.
For my specific usage when I encoutered the need, I am using the client from GAE, which doesn't allow at all using the http.DefaultClient, which makes the library unusable in GAE
The text was updated successfully, but these errors were encountered: