Skip to content
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

Merged
merged 3 commits into from Jul 2, 2019

Conversation

astefanutti
Copy link
Member

@astefanutti astefanutti commented Oct 15, 2018

This PR requires the following to be merged for it to compile and before being merged:

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 15, 2018
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 15, 2018
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a 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()
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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 :-).

@astefanutti
Copy link
Member Author

@DirectXMan12 Thanks for the review. Let me know how we can move the question of the ListerWithOptions forward. If you think the best option is to move the changes from kubernetes/kubernetes#69806 into the CM adapter codebase, I'll take care of updating this PR.

@astefanutti
Copy link
Member Author

@DirectXMan12 this PR requires #34 so it may have to be re-open.

@DirectXMan12
Copy link
Contributor

Yep, didn't mean to close it, sorry about that

@DirectXMan12
Copy link
Contributor

Thanks for the review. Let me know how we can move the question of the ListerWithOptions forward

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.

@astefanutti
Copy link
Member Author

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.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 15, 2018
@astefanutti
Copy link
Member Author

astefanutti commented Nov 15, 2018

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.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 16, 2018
@astefanutti
Copy link
Member Author

Rebased on master branch as #34 has been merged.

@DirectXMan12
Copy link
Contributor

@brancz can you or at @metalmatze or someone PTAL

@metalmatze
Copy link

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.

@brancz
Copy link

brancz commented Jan 7, 2019

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).

@DirectXMan12
Copy link
Contributor

drive-by comment: the adapter probably should try and support most/all of the features in the metrics APIs

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 28, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 28, 2019
@k8s-ci-robot k8s-ci-robot added the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label May 28, 2019
@kawych
Copy link
Contributor

kawych commented Jun 17, 2019

/cc @kawych
/uncc @piosz
/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Jun 17, 2019
@k8s-ci-robot k8s-ci-robot requested review from kawych and removed request for piosz June 17, 2019 11:01
@kawych
Copy link
Contributor

kawych commented Jun 17, 2019

@astefanutti, can we proceed with this PR? I can approve if we get confirmation from @brancz that it's OK to pursue.

@brancz @DirectXMan12

drive-by comment: the adapter probably should try and support most/all of the features in the metrics APIs

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

@brancz
Copy link

brancz commented Jun 17, 2019

cc @s-urbaniak (he has been working more closely on metrics API things lately than me so I’d like to hear his opinion).

@astefanutti
Copy link
Member Author

astefanutti commented Jun 23, 2019

@kawych happy to update and proceed with the PR, if we can get an agreement on how to deal with custom list options.

Copy link
Contributor

@kawych kawych left a 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)
Copy link
Contributor

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?

Copy link
Member Author

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 {
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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()
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@astefanutti
Copy link
Member Author

@kawych thanks for the review. I’ll be AFK until end of this week. I’ll update the PR next week with your comments.

@astefanutti
Copy link
Member Author

I've just rebased the PR and updated it with the review.

@kawych
Copy link
Contributor

kawych commented Jul 2, 2019

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 2, 2019
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 2, 2019
@k8s-ci-robot k8s-ci-robot merged commit 8fcee3f into kubernetes-sigs:master Jul 2, 2019
@s-urbaniak
Copy link
Contributor

post-merge lgtm from my side 👍 Sorry, I have been on a long PTO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants