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 service initial scale annotation and validation #7678

Merged

Conversation

taragu
Copy link
Contributor

@taragu taragu commented Apr 22, 2020

Add new autoscaling annotation initialScale and validation.

/lint
/hold
for Part 1

Part 2 of #7682

Release Note

NONE

/assign @dprotaso @markusthoemmes @vagababov

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 22, 2020
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Apr 22, 2020
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 22, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@taragu: 2 warnings.

In response to this:

Add new autoscaling annotation initialScale and validation.

/lint
/hold
for Part 1

Part 2 of #4098

Release Note

NONE

/assign @dprotaso @markusthoemmes @vagababov

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

pkg/apis/autoscaling/annotation_validation.go Show resolved Hide resolved
pkg/apis/autoscaling/register.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added area/API API objects and controllers area/autoscale labels Apr 22, 2020
@taragu taragu force-pushed the tara-init-scale-0-validations branch 2 times, most recently from fae5677 to 2cb3a98 Compare April 24, 2020 19:19
@taragu
Copy link
Contributor Author

taragu commented Apr 24, 2020

/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 24, 2020
if len(anns) == 0 {
return nil
}
return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns)))
return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns).Also(validateInitialScale(allowInitScaleZero, anns))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please break this line.

@@ -37,11 +37,12 @@ func getIntGE0(m map[string]string, k string) (int64, *apis.FieldError) {
return i, nil
}

func ValidateAnnotations(anns map[string]string) *apis.FieldError {
// ValidateAnnotations verifies the autoscaling annotations.
func ValidateAnnotations(allowInitScaleZero bool, anns map[string]string) *apis.FieldError {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the context get passed in here? With more switches, we'd otherwise grow the signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markusthoemmes there's a cyclic package import problem if we do so because we have to import knative.dev/serving/pkg/apis/config in knative.dev/serving/pkg/apis/autoscaling to get the configmap.

can't load package: import cycle not allowed
package knative.dev/serving/pkg/apis/autoscaling
	imports knative.dev/serving/pkg/apis/config
	imports knative.dev/serving/pkg/autoscaler/config
	imports knative.dev/serving/pkg/apis/autoscaling

Is there any workaround for this problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, probably not an easy one 🤔. Maybe it's fine for now 🤷‍♂️

// InitialScaleAnnotationKey is the annotation to specify the initial scale of
// a revision when a service is initially deployed. This number can be set to 0 iff
// allow-zero-initial-scale of config-autoscaler is true.
InitialScaleAnnotationKey = GroupName + "/initialScale"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Put this next to min and maxscale.

allowZeroInitialScale := false
if config.FromContext(ctx) != nil {
autoscalerConfig := config.FromContext(ctx).Autoscaler
if autoscalerConfig != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would this ever be nil? Just for tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is just for the tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably annotate tests instead? If we have cruft, I'd rather have it in tests than in production code.

@@ -160,11 +162,40 @@ func TestValidateObjectMetadata(t *testing.T) {
},
},
expectErr: (*apis.FieldError)(nil),
}, {
name: "cluster allows zero revision initial scale",
ctx: config.ToContext(context.Background(), asCfg(map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not manually construct the config here?

allowZeroInitialScale := false
if apisconfig.FromContext(ctx) != nil {
autoscalerConfig := apisconfig.FromContext(ctx).Autoscaler
if autoscalerConfig != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above: When would this ever be nil? Same for the config in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for the tests. Would it be better if we make sure all of the test contexts has the config instead of making this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, yeah. This feels a little weird to reason about in production code.

@@ -57,8 +58,15 @@ func (r *Revision) Validate(ctx context.Context) *apis.FieldError {

// Validate ensures RevisionTemplateSpec is properly configured.
func (rt *RevisionTemplateSpec) Validate(ctx context.Context) *apis.FieldError {
allowZeroInitialScale := false
if apisconfig.FromContext(ctx) != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

See above.

pkg/apis/autoscaling/annotation_validation.go Outdated Show resolved Hide resolved
pkg/apis/autoscaling/annotation_validation.go Show resolved Hide resolved
allowZeroInitialScale := false
if config.FromContext(ctx) != nil {
autoscalerConfig := config.FromContext(ctx).Autoscaler
if autoscalerConfig != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably annotate tests instead? If we have cruft, I'd rather have it in tests than in production code.

pkg/apis/serving/v1/revision_validation_test.go Outdated Show resolved Hide resolved
@taragu
Copy link
Contributor Author

taragu commented Apr 28, 2020

@vagababov @markusthoemmes this is ready for another look

Comment on lines 45 to 46
return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns).
Also(validateInitialScale(allowInitScaleZero, anns))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns).
Also(validateInitialScale(allowInitScaleZero, anns))))
return validateMinMaxScale(anns).Also(validateFloats(anns))
.Also(validateWindows(anns).Also(validateMetric(anns)
.Also(validateInitialScale(allowInitScaleZero, anns))))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make it three lines, but I'm getting compiler errors if I put the dot at the beginning of the new line

pkg/apis/autoscaling/v1alpha1/metric_validation.go Outdated Show resolved Hide resolved
pkg/apis/autoscaling/v1alpha1/pa_validation.go Outdated Show resolved Hide resolved
Comment on lines 174 to 163
expectErr: (&apis.FieldError{Message: "", Paths: []string(nil), Details: ""}).Also(
(&apis.FieldError{Message: "", Paths: []string(nil), Details: ""}).Also(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have those empty errors? We should be able to delete them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a result of the chained .Alsos

return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns).
If we have a test case for error in validating metric annotation and class annotation, we will also see the empty errors (but one less).

Copy link
Contributor

Choose a reason for hiding this comment

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

I just removed the empty errors here: #7752
They are completely redundant and unnecessary. FieldError code removes them anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah i see.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still see the empty errors. Did you push?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♀️ I missed those. they are updated now

Tara Gu added 6 commits April 29, 2020 08:53
@taragu taragu force-pushed the tara-init-scale-0-validations branch from 37bfa31 to 1596cc9 Compare April 29, 2020 12:54
Comment on lines 61 to 63
allowZeroInitialScale := false
autoscalerConfig := apisconfig.FromContextOrDefaults(ctx).Autoscaler
allowZeroInitialScale = autoscalerConfig.AllowZeroInitialScale
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
allowZeroInitialScale := false
autoscalerConfig := apisconfig.FromContextOrDefaults(ctx).Autoscaler
allowZeroInitialScale = autoscalerConfig.AllowZeroInitialScale
allowZeroInitialScale = apisconfig.FromContextOrDefaults(ctx).Autoscaler.AllowZeroInitialScale

For all other occasions too.

@@ -147,11 +150,62 @@ func TestValidateObjectMetadata(t *testing.T) {
"testAnnotation": "testValue",
},
},
}, {
name: "revision initial scale not parseable",
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't all the negative test live close to the implementation, i.e. in the autoscaling validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. Should we remove these negative test cases here then?

@taragu
Copy link
Contributor Author

taragu commented Apr 30, 2020

@markusthoemmes @vagababov would you please take another look?

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

Mostly fine by me.
There seem some unresolved comments with Markus, so I'll let him approve.
/lgtm


func autoscalerConfigCtx(allowInitialScaleZero bool, initialScale int) context.Context {
testConfigs := &config.Config{}
testConfigs.Autoscaler, _ = autoscalerconfig.NewConfigFromMap(map[string]string{})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just populate the map?

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 30, 2020
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Apr 30, 2020
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/serving/metadata_validation.go 98.2% 98.3% 0.0
pkg/apis/serving/v1/revision_validation.go 94.4% 94.6% 0.2
pkg/apis/serving/v1alpha1/revision_validation.go 96.1% 96.2% 0.1

@knative-test-reporter-robot

The following jobs failed:

Test name Triggers Retries
pull-knative-serving-integration-tests pull-knative-serving-integration-tests
pull-knative-serving-integration-tests
2/3

Automatically retrying due to test flakiness...
/test pull-knative-serving-integration-tests

@dprotaso
Copy link
Member

dprotaso commented May 4, 2020

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 4, 2020
@dprotaso
Copy link
Member

dprotaso commented May 4, 2020

/lgtm cancel
/approve

This should setup Markus to lgtm it and it should merge

@knative-prow-robot knative-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed lgtm Indicates that a PR is ready to be merged. labels May 4, 2020
Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 7, 2020
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, markusthoemmes, taragu

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

@knative-prow-robot knative-prow-robot merged commit fb75f94 into knative:master May 7, 2020
@taragu taragu deleted the tara-init-scale-0-validations branch July 29, 2020 11:44
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. area/API API objects and controllers area/autoscale cla: yes Indicates the PR's author has signed the CLA. lgtm 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.

8 participants