-
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
api: reorganize API package and add label values endpoint implementation #291
Conversation
This commit adds a client side implementation for fetching label values from prometheus api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good besides comments!
api/prometheus/api.go
Outdated
QueryRange(ctx context.Context, query string, r Range) (model.Value, error) | ||
// QueryLabelValues performs a query for the values of the given label. | ||
QueryLabelValues(ctx context.Context, label string) ([]string, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more consistent with naming we have elsewhere, maybe omit the Query
and just call this LabelValues
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yeah, this should be model.LabelValues
, since we're using the other model
types in here as well.
api/prometheus/api.go
Outdated
|
||
func (h *httpQueryAPI) QueryLabelValues(ctx context.Context, label string) ([]string, error) { | ||
u := h.client.url(epLabelValues, map[string]string{"name": label}) | ||
req, _ := http.NewRequest(http.MethodGet, u.String(), nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never ignore returned errors.
@juliusv, addressed your comments. Thanks for the quick review! |
api/prometheus/api.go
Outdated
QueryRange(ctx context.Context, query string, r Range) (model.Value, error) | ||
// LabelValues performs a query for the values of the given label. | ||
LabelValues(ctx context.Context, label string) (model.LabelValues, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I always understood this interface to only include /api/v1/query*
endpoints. With that, we'd end up with QueryAPI
, LabelsAPI
, AlertmanagerAPI
, etc. interfaces.
I'd say we should either do that, or rename this interface to something like APIv1
(or a better name). Adding all current v1 functions in a QueryAPI
interface doesn't make sense though, as not all are about querying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid concern, and one that we are violating by the page menu hierarchy under which https://prometheus.io/docs/querying/api/ is embedded as well.
I don't like the idea of QueryAPI
, LabelsAPI
, etc. much, but if we also want to add Alertmanager API functionality here eventually, then maybe Prometheus
and Alertmanager
? I'm not even sure whether we should keep the ...API
suffix. Or alternatively, ...Client
instead of ...API
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess Prometheus
and Alertmanager
makes sense since there aren't that many endpoints to justify doing QueryAPI
, LabelsAPI
etc.
Yet? ;) Alertmanager is difficult though, as there are alertmanager related
endpoints in the Prometheus API and the Alertmanager API itself.
I'm pretty sure we'll come up with a new API version though at some point,
so moving everything into a v1 would be good in general (or include the
version in the types, but less readable and common).
…On Mon, Apr 3, 2017, 16:45 André Carvalho ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In api/prometheus/api.go
<#291 (comment)>
:
> QueryRange(ctx context.Context, query string, r Range) (model.Value, error)
+ // LabelValues performs a query for the values of the given label.
+ LabelValues(ctx context.Context, label string) (model.LabelValues, error)
I guess Prometheus and Alertmanager makes sense since there aren't that
many endpoints to justify doing QueryAPI, LabelsAPI etc.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#291 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAANaEsY7UbrQIVpEXvV4cpqLxA_1U8Iks5rsUw5gaJpZM4MwPXD>
.
|
There are alert-related endpoints in Prometheus, but are there Alertmanager-related ones in Prometheus as well? Agree on versioning, but that should happen for each of {Alertmanager, Prometheus, ...}, as their APIs are versioned separately. Maybe use a package for versioning, like the InfluxDB client does? https://godoc.org/github.com/influxdata/influxdb/client/v2 |
Check |
Looks good... I'm not so sure about the |
That's fine though, it's Prometheus's view of what Alertmanagers there are. It's not "an Alertmanager API", or part of it. It's just part of the Prometheus API. I'd be for In each package, I would expect an |
LGTM. If everyone agrees on that, should I update this PR with the new
package/interface structure or open a new issue/pr for that?
|
Completely cool with that. I don't care about a new PR or continue using this one (but changing the name). Just make sure to use separate commits to first change the package structure and then another one to add your new feature/endpoint. |
Yeah! I will update the PR with those, i'll probably have time for that on the next few days |
This commit creates a new package to hold the prometheus v1 API interface. This interface will contain all the funcionality exposed by Prometheus v1 HTTP API. The underlying http client is kept on the api package since it may be reused across diferent API versions and also by the Alertmanager api package (to come.)
Hey @juliusv, @grobie. I've pushed some of the changes we discussed. I've left the http client on a separated package so it can be reused across Prometheus and Alertmanagers APIs(including future versions?). Once you guys are OK with the changes I can rebase and make sure this last change comes before the label values query change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, now you'll get a code review for code you didn't even write.
Looks good in general, due to the changes to the context and http packages, we can greatly simplify the client implementation.
api/client.go
Outdated
"strings" | ||
"time" | ||
|
||
"golang.org/x/net/context" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context package has been integrated into the stdlib, let's use that instead.
api/client.go
Outdated
"time" | ||
|
||
"golang.org/x/net/context" | ||
"golang.org/x/net/context/ctxhttp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not longer necessary, the stdlib http package has native support for context now.
api/client.go
Outdated
|
||
// CancelableTransport is like net.Transport but provides | ||
// per-request cancelation functionality. | ||
type CancelableTransport interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not longer necessary with the new http package. Will also fix #292.
api/client.go
Outdated
} | ||
|
||
func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) { | ||
resp, err := ctxhttp.Do(ctx, &http.Client{Transport: c.transport}, req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll now have to use context.WithCancel here. I guess we should leave that to the user.
This commit removes the now unnecessary CancelableTransport and rely on the net/http context support.
@grobie I've addressed your comments by removing the CancelableTransport and by passing down the ctx to the request (should I create a child context?). We will need to drop go 1.6.x from travis and add go 1.8.x. |
Oh, @beorn7 will need to say if that's actually acceptable as requirement for client_golang users. What's the go1.8 feature? The new context package in stdlib and request.WithCancel() was added in go1.7 I thought? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Oh, I said to add go 1.8 just to keep the last two major versions on travis, we are fine on 1.7+. |
@grobie We are talking only about the |
Once we stop running all tests with go1.6 it becomes very easy to
unknowingly break compatibility in other packages. Although, if you're fine
with such a setup, let's go forward here.
…On Sat, Apr 22, 2017, 19:15 Björn Rabenstein ***@***.***> wrote:
@grobie <https://github.com/grobie> We are talking only about the api
package here, which is not widely used (and arguably
experimental/unmaintained). the client_galang/prometheus/... packages
should still be fine with older Go versions.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#291 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAANaAa_8Dp3tbDq2Pm9YVWG_C5gYLgSks5ryhmcgaJpZM4MwPXD>
.
|
OK, I see. Yeah, that would be bad if the tests for an experimental package had an impact on the ones for a production package in frequent use. Can we use build tags to not run the api tists on older go versions? |
Yes, this should be possible, but we might need to put the build tags in
both the test+api files.
…On Sat, Apr 22, 2017 at 10:01 PM Björn Rabenstein ***@***.***> wrote:
OK, I see.
Yeah, that would be bad if the tests for an experimental package had an
impact on the ones for a production package in frequent use.
Can we use build tags to not run the api tists on older go versions?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#291 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAANaJTCrFCghHGHXfjmpCqiMdXiCme7ks5rykBbgaJpZM4MwPXD>
.
|
I've pushed the change that includes the build tag to the api package files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! One last comment, but looks great!
api/client.go
Outdated
// New returns a new Client. | ||
// | ||
// It is safe to use the returned Client from multiple goroutines. | ||
func New(cfg Config) (Client, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think we should call this NewClient now, as the package is called API but we're not returning a type called api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go after two last nits :) Thanks!
api/client.go
Outdated
|
||
// +build go1.7 | ||
|
||
// Package api provides clients the HTTP API's. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API's -> APIs
clients the -> clients for the
api/prometheus/v1/api.go
Outdated
@@ -234,6 +70,16 @@ type Range struct { | |||
Step time.Duration | |||
} | |||
|
|||
// API provides bindings the Prometheus's v1 API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bindings the -> bindings for
Done, @juliusv |
Thanks! |
The build tag prevents the usage with go 1.8 :( |
@tboerger Are you sure that's the problem? The documentation explicitly states |
I have created #298 now to allow go 1.8 as well. |
This adds a client side implementation for fetching label values from prometheus api.
Would love to get some review on this as this is my first contribution here. Some design questions i may have oversimplified:
Related to #290.