Skip to content

Commit

Permalink
feat: Support aggregation options (#961)
Browse files Browse the repository at this point in the history
* feat: Support aggregation options

Signed-off-by: Jorge Turrado <[email protected]>

* Updates

Signed-off-by: Jorge Turrado <[email protected]>

* Updates

Signed-off-by: Jorge Turrado <[email protected]>

* fix changelog

Signed-off-by: Jorge Turrado <[email protected]>

* style & codegen

Signed-off-by: Jorge Turrado <[email protected]>

* add mocks

Signed-off-by: Jorge Turrado <[email protected]>

* update docs

Signed-off-by: Jorge Turrado <[email protected]>

* fix e2e test

Signed-off-by: Jorge Turrado <[email protected]>

* merge issues

Signed-off-by: Jorge Turrado <[email protected]>

* update manifests

Signed-off-by: Jorge Turrado <[email protected]>

---------

Signed-off-by: Jorge Turrado <[email protected]>
  • Loading branch information
JorTurFer authored Apr 10, 2024
1 parent a8c1258 commit a4f9f39
Show file tree
Hide file tree
Showing 40 changed files with 1,482 additions and 306 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ This changelog keeps track of work items that have been completed and are ready

- **General**: Propagate HTTPScaledObject labels and annotations to ScaledObject ([#840](https://github.com/kedacore/http-add-on/issues/840))
- **General**: Provide support to allow HTTP scaler to work alongside other core KEDA scalers ([#489](https://github.com/kedacore/http-add-on/issues/489))
- **General**: Support aggregation windows ([#882](https://github.com/kedacore/http-add-on/issues/882))

### Improvements

- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))

### Fixes

- **General**: Ensure operator is aware about changes on underlying ScaledObject ([#900](https://github.com/kedacore/http-add-on/issues/900))
Expand All @@ -35,16 +38,13 @@ This changelog keeps track of work items that have been completed and are ready

You can find all deprecations in [this overview](https://github.com/kedacore/http-add-on/labels/breaking-change) and [join the discussion here](https://github.com/kedacore/http-add-on/discussions/categories/deprecations).

New deprecation(s):


Previously announced deprecation(s):

- **General**: Deprecated `.spec.scaleTargetRef.deployment` ([#960](https://github.com/kedacore/http-add-on/discussions/960))
- **General**: Deprecated `KEDA_HTTP_DEPLOYMENT_CACHE_POLLING_INTERVAL_MS` in favor of `KEDA_HTTP_ENDPOINTS_CACHE_POLLING_INTERVAL_MS` ([#438](https://github.com/kedacore/http-add-on/issues/438))
- **General**: Deprecated `targetPendingRequests` in favor of `spec.scalingMetric.*.targetValue` ([#959](https://github.com/kedacore/http-add-on/discussions/959))

### Other

- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
- **General**: Unify loggers ([#958](https://github.com/kedacore/http-add-on/issues/958))

## v0.7.0

Expand Down
18 changes: 14 additions & 4 deletions RELEASE-PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ It should not include every single change but solely what matters to our custome

Add the new released version to the list in `KEDA Version` dropdown in [2_bug_report.yml](https://github.com/kedacore/http-add-on/blob/main/.github/ISSUE_TEMPLATE/2_bug_report.yml).

## 4: Create a new GitHub release
## 4. Update documentation references to current version

Update the links to current version within the file `walkthrough.md`

> ```console
> kubectl create -n $NAMESPACE -f examples/v0.7.0/httpscaledobject.yaml
> ```
> >If you'd like to learn more about this object, please see the [`HTTPScaledObject` reference](THE REFERENCE).
## 5: Create a new GitHub release
[Create a new release](https://github.com/kedacore/http-add-on/releases/new) on the GitHub releases page, using your new release number.
Expand All @@ -30,7 +40,7 @@ The release description should be a short to medium length summary of what has c
After you create the new release, automation in a GitHub action will build and deploy new container images.
## 5: Submit a PR to the [Helm Charts Repository](https://github.com/kedacore/charts)
## 6: Submit a PR to the [Helm Charts Repository](https://github.com/kedacore/charts)
The scope of the changes you'll need to make to the Helm chart vary, but the below list is the minimum set of fields to change:
Expand Down Expand Up @@ -66,11 +76,11 @@ Once you've made changes to the chart, here's how to do submit the change to the

After your PR is merged, you've completed the release. Congratulations! You can optionally write a blog post about it; see the next section if you're interested.

## 6: Publish release on Artifact Hub
## 7: Publish release on Artifact Hub

Publish release on Artifact Hub by creating a new version in [kedacore/external-scalers](https://github.com/kedacore/external-scalers/tree/main/artifacthub/add-ons-http).

## 7: Write a blog post on the documentation site (_optional_)
## 8: Write a blog post on the documentation site (_optional_)

If you believe that your release is large enough to warrant a blog post on the [keda.sh/blog](https://keda.sh/blog/) site, please go to [github.com/kedacore/keda-docs](https://github.com/kedacore/keda-docs) and submit a new PR with a blog article about the release.

Expand Down
33 changes: 32 additions & 1 deletion config/crd/bases/http.keda.sh_httpscaledobjects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,39 @@ spec:
description: (optional) Cooldown period value
format: int32
type: integer
scalingMetric:
description: (optional) Configuration for the metric used for scaling
properties:
concurrency:
description: Scaling based on concurrent requests for a given
target
properties:
targetValue:
default: 100
description: Target value for rate scaling
type: integer
type: object
requestRate:
description: Scaling based the average rate during an specific
time window for a given target
properties:
granularity:
default: 1s
description: Time granularity for rate calculation
type: string
targetValue:
default: 100
description: Target value for rate scaling
type: integer
window:
default: 1m
description: Time window for rate calculation
type: string
type: object
type: object
targetPendingRequests:
description: (optional) Target metric value
description: (optional) DEPRECATED (use SscalingMetric instead) Target
metric value
format: int32
type: integer
required:
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/v0.6.0/http_scaled_object.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The `HTTPScaledObject`

>This document reflects the specification of the `HTTPScaledObject` resource for the `v0.7.0` version.
>This document reflects the specification of the `HTTPScaledObject` resource for the `v0.6.0` version.
Each `HTTPScaledObject` looks approximately like the below:

Expand Down
137 changes: 137 additions & 0 deletions docs/ref/v0.8.0/http_scaled_object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# The `HTTPScaledObject`

>This document reflects the specification of the `HTTPScaledObject` resource for the `v0.8.0` version.
Each `HTTPScaledObject` looks approximately like the below:

```yaml
kind: HTTPScaledObject
apiVersion: http.keda.sh/v1alpha1
metadata:
name: xkcd
spec:
hosts:
- myhost.com
pathPrefixes:
- /test
scaleTargetRef:
name: xkcd
kind: Deployment
apiVersion: apps/v1
service: xkcd
port: 8080
replicas:
min: 5
max: 10
scaledownPeriod: 300
scalingMetric: # requestRate and concurrency are mutually exclusive
requestRate:
granularity: 1s
targetValue: 100
window: 1m
concurrency:
targetValue: 100
```
This document is a narrated reference guide for the `HTTPScaledObject`, and we'll focus on the `spec` field.

## `hosts`

These are the hosts to apply this scaling rule to. All incoming requests with one of these values in their `Host` header will be forwarded to the `Service` and port specified in the below `scaleTargetRef`, and that same `scaleTargetRef`'s workload will be scaled accordingly.

## `pathPrefixes`

>Default: "/"

These are the paths to apply this scaling rule to. All incoming requests with one of these values as path prefix will be forwarded to the `Service` and port specified in the below `scaleTargetRef`, and that same `scaleTargetRef`'s workload will be scaled accordingly.

## `scaleTargetRef`

This is the primary and most important part of the `spec` because it describes:

1. The incoming host to apply this scaling rule to.
2. What workload to scale.
3. The service to which to route HTTP traffic.

### `deployment` (DEPRECTATED: removed as part of v0.9.0)

This is the name of the `Deployment` to scale. It must exist in the same namespace as this `HTTPScaledObject` and shouldn't be managed by any other autoscaling system. This means that there should not be any `ScaledObject` already created for this `Deployment`. The HTTP Add-on will manage a `ScaledObject` internally.

### `name`

This is the name of the workload to scale. It must exist in the same namespace as this `HTTPScaledObject` and shouldn't be managed by any other autoscaling system. This means that there should not be any `ScaledObject` already created for this workload. The HTTP Add-on will manage a `ScaledObject` internally.

### `kind`

This is the kind of the workload to scale.

### `apiVersion`

This is the apiVersion of the workload to scale.

### `service`

This is the name of the service to route traffic to. The add-on will create autoscaling and routing components that route to this `Service`. It must exist in the same namespace as this `HTTPScaledObject` and should route to the same `Deployment` as you entered in the `deployment` field.

### `port`

This is the port to route to on the service that you specified in the `service` field. It should be exposed on the service and should route to a valid `containerPort` on the `Deployment` you gave in the `deployment` field.

### `targetPendingRequests` (DEPRECTATED: removed as part of v0.9.0)

>Default: 100

This is the number of _pending_ (or in-progress) requests that your application needs to have before the HTTP Add-on will scale it. Conversely, if your application has below this number of pending requests, the HTTP add-on will scale it down.

For example, if you set this field to 100, the HTTP Add-on will scale your app up if it sees that there are 200 in-progress requests. On the other hand, it will scale down if it sees that there are only 20 in-progress requests. Note that it will _never_ scale your app to zero replicas unless there are _no_ requests in-progress. Even if you set this value to a very high number and only have a single in-progress request, your app will still have one replica.

### `scaledownPeriod`

>Default: 300

The period to wait after the last reported active before scaling the resource back to 0.

> Note: This time is measured on KEDA side based on in-flight requests, so workloads with few and random traffic could have unexpected scale to 0 cases. In those case we recommend to extend this period to ensure it doesn't happen.


## `scalingMetric`

This is the second most important part of the `spec` because it describes how the workload has to scale. This section contains 2 nested sections (`requestRate` and `concurrency`) which are mutually exclusive between themselves.

### `requestRate`

This section enables scaling based on the request rate.

> **NOTE**: Requests information is stored in memory, aggragating long periods (longer than 5 minutes) or too fine granularity (less than 1 second) could produce perfomance issues or memory usage increase.

> **NOTE 2**: Although updating `window` and/or `granularity` is something doable, the process just replaces all the stored request count infomation. This can produce unexpected scaling behaviours until the window is populated again.

#### `targetValue`

>Default: 100

This is the target value for the scaling configuration.

#### `window`

>Default: "1m"

This value defines the aggregation window for the request rate calculation.

#### `granularity`

>Default: "1s"

This value defines the granualarity of the aggregated requests for the request rate calculation.

### `concurrency`

This section enables scaling based on the request concurrency.

> **NOTE**: This is the only scaling behaviour before v0.8.0

#### `targetValue`

>Default: 100

This is the target value for the scaling configuration.
5 changes: 2 additions & 3 deletions docs/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ For scenerios where you want to integrate HTTP Add-On scaler with other keda sca

> 💡 Ensure that your ScaledObject is created with a different name than the `HTTPScaledObject` to ensure your ScaledObject is not removed by the reconciler.
It is reccomended that you first deploy your HTTPScaledObject with no annotation set in order to obtain the latest trigger spec to use on your own managed ScaledObject.
If you don't know how to set the external scaler in the ScaledObject, you can deploy first your HTTPScaledObject with no annotation set in order to obtain the latest trigger spec to use on your own managed ScaledObject.

1. Deploy your `HTTPScaledObject` with annotation set to false

Expand All @@ -112,8 +112,7 @@ For example:
triggers:
- type: external-push
metadata:
hosts: example-service
pathPrefixes: ""
httpScaledObject: YOUR_HTTPSCALEDOBJECT_NAME
scalerAddress: keda-http-add-on-external-scaler.keda:9090
```

Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ go 1.21

require (
github.com/go-logr/logr v1.4.1
github.com/go-logr/zapr v1.3.0
github.com/golang/mock v1.7.0-rc.1.0.20220812172401-5b455625bd2c
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-immutable-radix/v2 v2.1.0
github.com/kedacore/keda/v2 v2.13.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.31.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.26.0
golang.org/x/sync v0.6.0
google.golang.org/grpc v1.61.0
google.golang.org/protobuf v1.33.0
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/code-generator v0.29.0
k8s.io/code-generator v0.29.3
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
sigs.k8s.io/controller-runtime v0.17.1
sigs.k8s.io/kustomize/kustomize/v5 v5.3.0
Expand All @@ -35,15 +34,15 @@ require (
github.com/expr-lang/expr v1.15.8 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/swag v0.22.7 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
Expand Down Expand Up @@ -72,6 +71,7 @@ require (
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20231121155337-90ade8b19d09 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ github.com/golang/mock v1.7.0-rc.1.0.20220812172401-5b455625bd2c h1:8AzxBXzXPCzl
github.com/golang/mock v1.7.0-rc.1.0.20220812172401-5b455625bd2c/go.mod h1:s42URUywIqd+OcERslBJvOjepvNymP31m3q8d/GkuRs=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -254,8 +254,8 @@ k8s.io/apimachinery v0.29.0 h1:+ACVktwyicPz0oc6MTMLwa2Pw3ouLAfAon1wPLtG48o=
k8s.io/apimachinery v0.29.0/go.mod h1:eVBxQ/cwiJxH58eK/jd/vAk4mrxmVlnpBH5J2GbMeis=
k8s.io/client-go v0.29.0 h1:KmlDtFcrdUzOYrBhXHgKw5ycWzc3ryPX5mQe0SkG3y8=
k8s.io/client-go v0.29.0/go.mod h1:yLkXH4HKMAywcrD82KMSmfYg2DlE8mepPR4JGSo5n38=
k8s.io/code-generator v0.29.0 h1:2LQfayGDhaIlaamXjIjEQlCMy4JNCH9lrzas4DNW1GQ=
k8s.io/code-generator v0.29.0/go.mod h1:5bqIZoCxs2zTRKMWNYqyQWW/bajc+ah4rh0tMY8zdGA=
k8s.io/code-generator v0.29.3 h1:m7E25/t9R9NvejspO2zBdyu+/Gl0Z5m7dCRc680KS14=
k8s.io/code-generator v0.29.3/go.mod h1:x47ofBhN4gxYFcxeKA1PYXeaPreAGaDN85Y/lNUsPoM=
k8s.io/component-base v0.29.0 h1:T7rjd5wvLnPBV1vC4zWd/iWRbV8Mdxs+nGaoaFzGw3s=
k8s.io/component-base v0.29.0/go.mod h1:sADonFTQ9Zc9yFLghpDpmNXEdHyQmFIGbiuZbqAXQ1M=
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 h1:pWEwq4Asjm4vjW7vcsmijwBhOr1/shsbSYiWXmNGlks=
Expand Down
Loading

0 comments on commit a4f9f39

Please sign in to comment.