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 PushScaler interface and impl external-push scaler #865

Merged
merged 4 commits into from
Jun 16, 2020
Merged

Add PushScaler interface and impl external-push scaler #865

merged 4 commits into from
Jun 16, 2020

Conversation

ahmelsayed
Copy link
Contributor

Closes #820

Signed-off-by: Ahmed ElSayed ahmels@microsoft.com

This PR introduces

type PushScaler interface {
	Scaler

	// Run is the only writer to the active channel and must close it once done.
	Run(ctx context.Context, active chan<- bool)
}

with 1 implementation in an external-push scaler with the following grpc call

service ExternalScaler {
  rpc StreamIsActive(ScaledObjectRef) returns (stream IsActiveResponse) {}
}

ExternalScaler also keeps a pool of GRPC connections per-metadata hash. So if there are multiple scaledObjects all pointing to the same grpc endpoint with the same metadata, they will all use the same grpc.ClientConn with separate grpc.Client per-scaledObject.

This PR also removes the following methods from the external scaler interface:

service ExternalScaler {
-    rpc New(NewRequest) returns (google.protobuf.Empty) {}
-    rpc Close(ScaledObjectRef) returns (google.protobuf.Empty) {}
}

This is a breaking change for external scaler.

Checklist

Fixes #820

Closes #820

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
@tomkerkhove
Copy link
Member

Might be a stupid question but is there a reason why this impacts the external scaler spec? How I understood it it was going to be a new “push” scaler built in the core.

go.mod Outdated
@@ -21,11 +21,12 @@ require (
github.com/go-redis/redis v6.15.7+incompatible
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/mock v1.4.3
github.com/golang/protobuf v1.3.5
github.com/golang/protobuf v1.3.2
Copy link
Member

Choose a reason for hiding this comment

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

Is this downgrade on purpose?

Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

LGTM

@ahmelsayed
Copy link
Contributor Author

ahmelsayed commented Jun 3, 2020

Might be a stupid question but is there a reason why this impacts the external scaler spec? How I understood it it was going to be a new “push” scaler built in the core.

@tomkerkhove It's a really good question. It didn't have to alter the existing scaler, I just meant to add a completely new scaler, external-push, but since a bunch of grpc plumbing code will be shared between then I was taking a look at the existing scaler, and thought of few improvements to it.

This PR can be thought of as 2 parts:

  1. all files under pkg/scaling/* (and the interface in pkg/scalers/scaler.go) are the "core" part of it. This change allows a scaler to implement a method where they'll get a write channel to an active state anytime.

  2. all the external scaler changes under pkg/scalers/* are adding support for external-push and making changes to the existing external scaler.

The reason to change external scaler was just to clean up the contract a bit. The current contract is this:

service ExternalScaler {
    rpc New(NewRequest) returns (google.protobuf.Empty) {}
    rpc IsActive(ScaledObjectRef) returns (IsActiveResponse) {}
    rpc GetMetricSpec(ScaledObjectRef) returns (GetMetricSpecResponse) {}
    rpc GetMetrics(GetMetricsRequest) returns (GetMetricsResponse) {}
    rpc Close(ScaledObjectRef) returns (google.protobuf.Empty) {}
}

When I was implementing external scalers for testing the contract for "new" and "close" as GRPC calls is very awkward/unclear. In fact both the example external scalers we have don't do anything on Close (durable and artemis) and durable also just logs the request on New. Artemis uses new to store some global metadata, but this locks it to only 1 scaledObject. Handling this on per invocation for IsActive is a more flexible and doesn't require every implementation to handle state. This PR adds IsActiveStreaming that allows the implementation to return isActive: true any time.

@tomkerkhove
Copy link
Member

@ahmelsayed Thanks for the info! So if you build an external scaler, we don't mandate it to support pull & push but merely just give the contract or am I understanding it wrong (sorry, have to dig deeper on this topic).

Just want to avoid that it's becoming more complex to write an external scaler while we don't need the complexity.

@zroubalik
Copy link
Member

zroubalik commented Jun 3, 2020

@ahmelsayed Thanks for the info! So if you build an external scaler, we don't mandate it to support pull & push but merely just give the contract or am I understanding it wrong (sorry, have to dig deeper on this topic).

@tomkerkhove Yeah, that's correct. See there are 2 types of External scaler:

case "external":
return scalers.NewExternalScaler(name, namespace, triggerMetadata)
case "external-push":
return scalers.NewExternalPushScaler(name, namespace, triggerMetadata)

@tomkerkhove
Copy link
Member

:shipit:

@ahmelsayed
Copy link
Contributor Author

btw, is there a place we're tracking breaking changes in v2? I can add a couple of lines to the CHANGELOG for this.

@zroubalik
Copy link
Member

btw, is there a place we're tracking breaking changes in v2? I can add a couple of lines to the CHANGELOG for this.

@ahmelsayed that's right. We don't have anything atm, the same goes for docs. Start the v2 section in Changelog with this PR and I'll add the other changes then.

@tomkerkhove
Copy link
Member

Since it has not been shipped yet, would it make sense to use "Upcoming" or move the WIP to a Google Doc?

@zroubalik
Copy link
Member

@tomkerkhove the changelog will be in the v2 branch, so it will not interfere with master branch.

@tomkerkhove
Copy link
Member

Good point, sounds good to me 👍

@zroubalik
Copy link
Member

@ahmelsayed are going to add the Changelog as part of this PR or do you want to create another? If it is the latter option we can merge this PR.

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
@ahmelsayed
Copy link
Contributor Author

Sorry for the delay, I was out the last couple of weeks. I added a line to the CHANGELOG for this breaking change. We can add another PR for other breaking changes in v2.

I also opened a docs PR here kedacore/keda-docs#193

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
@zroubalik zroubalik merged commit 804c1b9 into kedacore:v2 Jun 16, 2020
@ahmelsayed ahmelsayed deleted the ahmels/push-scaler branch June 16, 2020 19:47
zroubalik pushed a commit to zroubalik/keda that referenced this pull request Jun 17, 2020
* Add PushScaler interface and impl external-push scaler

Closes kedacore#820

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>

* pass metadata to scaler

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>

* add section for breaking changes in the CHANGELOG

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>

* use correct protoc-gen-go version

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
zroubalik pushed a commit to zroubalik/keda that referenced this pull request Jul 7, 2020
* Add PushScaler interface and impl external-push scaler

Closes kedacore#820

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>

* pass metadata to scaler

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>

* add section for breaking changes in the CHANGELOG

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>

* use correct protoc-gen-go version

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
zroubalik pushed a commit that referenced this pull request Aug 6, 2020
* Add PushScaler interface and impl external-push scaler

Closes #820

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>

* pass metadata to scaler

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>

* add section for breaking changes in the CHANGELOG

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>

* use correct protoc-gen-go version

Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants