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
Support metric label selector for custom metrics #35
Conversation
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.
generally looks good. Thanks so much for putting this together -- I had been meaning to rebase my changes and push them, but these are in a much better state than my own.
One thing to note: we may have to end up copying a bunch of API machinery over -- I'm expecting that ListerWithOptions may be delayed a while or rejected (somewhat reasonably), since it doesn't have a use beyond the CM adapter, and we've been encouraged in the past to just fork API machinery for the CM adapter.
@@ -64,6 +64,20 @@ func (ch *CMHandlers) registerResourceHandlers(a *MetricsAPIInstaller, ws *restf | |||
return err | |||
} | |||
|
|||
listOptions, _, _ := lister.NewListOptions() |
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.
please add a comment clarifying why we have both list options and extra list options
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.
As the standard ListOptions
is defined as a struct and not an interface, I don't know of a way to use a single object that could be extended with polymorphism. So there is a standard list options as defined by the ListOptions
struct, plus the extra options defined by the CM adapter.
I'll add a comment in the code when the question where the ListerWithOptions
should go is resolved.
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.
My initial suggestion would be to say that custom list options should ,inline
embed the base ListOptions, but I think your idea is actually fine as well :-).
@DirectXMan12 Thanks for the review. Let me know how we can move the question of the |
@DirectXMan12 this PR requires #34 so it may have to be re-open. |
Yep, didn't mean to close it, sorry about that |
I suspect moving the changes into the CM adapter codebase might be the best option, if it's not too hairy. Alternatively, show up at one of the SIG APIMachinery meetings in person and ask, perhaps? That's generally a quick way to get a resolution. If you have concrete evidence of the maintenance burden/duplicate code, it'd be good evidence for why we should have in in core API machinery. |
Sounds good. I'll try to show up at the APIMachinery SIG ASAP. In the meantime, I'll upgrade this PR by integrating the required bits and we'll have material to iterate on. |
cf00c84
to
3ec1933
Compare
I've updated the PR with 4bf4950 that contains the bits required from the API server, so that removes the pre-requisite on kubernetes/kubernetes#69806. |
3ec1933
to
4bf4950
Compare
db19feb
to
ce275f5
Compare
Rebased on master branch as #34 has been merged. |
ce275f5
to
e9da6de
Compare
@brancz can you or at @metalmatze or someone PTAL |
Looking at the code this lgtm. I'm missing a higher level description of what actually is going to change with this PR to be honest. |
While I see the use for this, I'm wondering if it's actually something we should pursue. It maps somewhat ok to the Prometheus data model, but in Prometheus different labels means a different time-series, so should a list return multiple results with the same metrics name but different labels? My feeling is that the changes we have been thinking about regarding configuration to define what a custom metric is to be converted into in Prometheus might be more pragmatic (in regards to the prometheus-k8s-adapter). |
drive-by comment: the adapter probably should try and support most/all of the features in the metrics APIs |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@astefanutti, can we proceed with this PR? I can approve if we get confirmation from @brancz that it's OK to pursue.
100% agreed. It's really great that this adapter is refactored so that it can be used as the library, but especially now it will be super useful to support all the features, instead of all adapters implementing them for themselves. I see a discussion on kubernetes/kubernetes#69806 about supporting custom options - it would be ideal if apiserver package could support our use case. I think we should return to the discussion to understand what are the issues with that - if these are serious concerns, maybe this proposal should be reconsidered/updated: https://github.com/kubernetes/enhancements/blob/master/keps/sig-autoscaling/0032-enhance-hpa-metrics-specificity.md#alternatives |
cc @s-urbaniak (he has been working more closely on metrics API things lately than me so I’d like to hear his opinion). |
@kawych happy to update and proceed with the PR, if we can get an agreement on how to deal with custom list options. |
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've took a closer look at the code and it looks mostly fine - in the comments I've requested a clarification of parts of the code, but the general approach LGTM and the code looks OK. I'm going to give @s-urbaniak at least one more day to voice his doubts and then approve.
@@ -286,3 +286,9 @@ func restfulListResource(r rest.Lister, rw rest.Watcher, scope handlers.RequestS | |||
handlers.ListResource(r, rw, scope, forceWatch, minRequestTimeout)(res.ResponseWriter, req.Request) |
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.
Is this function still used?
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.
Yes, for external metrics.
cm_rest "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/apiserver/registry/rest" | ||
) | ||
|
||
func ListResourceWithOptions(r cm_rest.ListerWithOptions, rw rest.Watcher, scope handlers.RequestScope, forceWatch bool, minRequestTimeout time.Duration) http.HandlerFunc { |
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.
AFAIU the watch is not supported and forceWatch is unused, please remove
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.
done
List(ctx context.Context, options *metainternalversion.ListOptions, extraOptions runtime.Object) (runtime.Object, error) | ||
|
||
// NewListOptions returns an empty options object that will be used to pass extra options | ||
// to the List method. It may return a bool and a string, if true, the |
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.
Can you please explain better the third returned value? AFAIU the second one indicates whether the third one is present?
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.
Your understanding is correct. It is taken verbatim from NewGetterOptions
.
// Log only long List requests (ignore Watch). | ||
defer trace.LogIfLong(500 * time.Millisecond) | ||
trace.Step("About to List from storage") | ||
extraOpts, subpath, subpathKey := r.NewListOptions() |
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.
nit: subpath is not the best name for boolean value, maybe hasSubpath?
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.
done
@kawych thanks for the review. I’ll be AFK until end of this week. I’ll update the PR next week with your comments. |
I've just rebased the PR and updated it with the review. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kawych The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
post-merge lgtm from my side 👍 Sorry, I have been on a long PTO. |
This PR requires the following to be merged for it to compile and before being merged:
Support List with options for RESTful storage services kubernetes/kubernetes#69806