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

Add external metric type to HPA API #60096

Merged
merged 3 commits into from Feb 23, 2018

Conversation

MaciekPytel
Copy link
Contributor

@MaciekPytel MaciekPytel commented Feb 20, 2018

What this PR does / why we need it:
Add external metric type to HPA API proposed in xref kubernetes/community#1801

Release note:

Allows HorizontalPodAutoscaler to use global metrics not associated with any Kubernetes object (for example metrics from a hoster service running outside of Kubernetes cluster).

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 20, 2018
@MaciekPytel
Copy link
Contributor Author

/sig-autoscaling

@DirectXMan12 Can you take a look?

@k8s-github-robot k8s-github-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Feb 20, 2018
@MaciekPytel MaciekPytel added the sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. label Feb 20, 2018
@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 Feb 21, 2018
}

if src.TargetAverageValue != nil && src.TargetAverageValue.Sign() != 1 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("targetAverageValue"), src.TargetAverageValue, "must be positive"))
Copy link
Contributor

Choose a reason for hiding this comment

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

we'll want to re-evaluate this later, because it's not strictly true for custom metrics

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I'm not sure what the specific use-case is and how do we want to handle metric value changing signs, but in general I see no reason not to allow it later on.

type ExternalMetricSource struct {
// metricName is the name of the metric in question.
MetricName string `json:"metricName" protobuf:"bytes,1,name=metricName"`
// MetricSelector is used to identify a specific time series
Copy link
Contributor

Choose a reason for hiding this comment

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

lowercase in public API docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed everywhere

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.

minor nits inline. This also needs HPA changes themselves, no?

// MetricSelector is used to identify a specific time series
// within a given metric.
MetricSelector metav1.LabelSelector
// TargetValue is the target value of the metric (as a quantity).
Copy link
Member

Choose a reason for hiding this comment

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

Since these next fields represent a one-of, they should probably be in a struct. This should document clearly what happens if no value is specified.

e.g

external:
  metricName: foobar
  target:
    value: 100

What do you think?

Copy link
Contributor

@mwielgus mwielgus Feb 21, 2018

Choose a reason for hiding this comment

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

There is no big difference between grouping 2 fields in a struct and having them "inline". However in other places in this version of the api we have the target inline. So structs will be kindof inconsistent. We can do it in v2beta2, changing target to structs both in ObjectMetrics and ExernalMetrics.

No value behaviour should obviously be documented.

Copy link
Member

Choose a reason for hiding this comment

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

I can accept the consistency argument. We have very inconsistent use of one-of blocks throughout the system. Really this should be explicitly discriminated:

external:
  metricName: foobar
  target:
    type: Value
    value: 100

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Documented that exactly one of the two must be specified. As @mwielgus wrote - we already have TargetAverageUtilization and TargetAverageValue in resource metrics. I agree with your argument, but I think consistency within a single API object should take precedence in this case. If we used different approach with external and left resource as is we would end up with HPA objects looking like this:

- resource:
    targetAverageValue:  100
- external:
    target:
      type: Average
      value: 100

I believe I'm in agreement with @DirectXMan12 that we want a v2beta2 to (at minimum) add targetAverageValue to object metrics. This would already be backward incompatible, so maybe we can consider changing all targets to structs then?

Copy link
Member

Choose a reason for hiding this comment

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

ACK

@thockin
Copy link
Member

thockin commented Feb 22, 2018

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 22, 2018
@thockin
Copy link
Member

thockin commented Feb 22, 2018

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MaciekPytel, thockin

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

@MaciekPytel
Copy link
Contributor Author

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 22, 2018
@MaciekPytel
Copy link
Contributor Author

@DirectXMan12 I've created a separate PR with implementation (to keep things more readable): #60243.

@mwielgus
Copy link
Contributor

Corresponding proposal merged. Removing hold.

@mwielgus mwielgus removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 22, 2018
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 60208, 60084, 60183, 59713, 60096). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit b22b785 into kubernetes:master Feb 23, 2018
allErrs := field.ErrorList{}

if len(src.MetricName) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("metricName"), "must specify a metric name"))
Copy link
Member

Choose a reason for hiding this comment

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

since this will be used as a single path segment in URL-building, this should be validated with path.IsValidPathSegmentName

k8s-github-robot pushed a commit that referenced this pull request Feb 27, 2018
Automatic merge from submit-queue (batch tested with PRs 59310, 60424, 60308, 60436, 60020). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Add support for external metrics in kubectl

**What this PR does / why we need it**:
Add support for metrics coming from external sources when describing or printing horizontal pod autoscaler objects. API change: #60096

@MaciekPytel @DirectXMan12 

**Release note**:
```
NONE
```
k8s-github-robot pushed a commit that referenced this pull request Feb 27, 2018
Automatic merge from submit-queue (batch tested with PRs 60433, 59982, 59128, 60243, 60440). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Implement external metric in HPA

This implement the changes to HPA introduced in #60096
@snowplayfire
Copy link
Contributor

I want to add a new field for hpa like this PR, and I write 'Convert_xxx' and 'autoConvert_xxx' for the new field. But conversion-gengenerate and override my manual 'Convert_xxx' and 'autoConvert_xxx' when compile.

Can anyone tell me how to avoid the override? Or Is there any docs about conversion-gen?

Thanks very much!

@thockin
Copy link
Member

thockin commented Jun 15, 2020

Most of the time, conversion code can be auto-generated. Occasionally you need to to help it out. The conversion code generator will create autoConvert* functions. If it does not find a manually defined Convert* function, it will generate that as a wrapper.

To add manual code, you create the Convert function, which should first call autoConvert* and then you make whatever manual changes you need to make.

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. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants