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 metrics API scaler docs #239

Merged
merged 8 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions content/blog/keda-2.0-beta.md.draft
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Here are some highlights:
- Provide more information when quering KEDA resources with `kubectl`
- **Extensibility**
- Introduction of External Push scaler ([docs](https://keda.sh/docs/2.0/scalers/external-push/))
- Introduction of Metric API scaler ([docs](https://keda.sh/docs/2.0/scalers/metrics-api/))
- Provide KEDA client-go library

For a full list of changes, we highly recommend going through [our changelog](https://github.com/kedacore/keda/blob/v2/CHANGELOG.md#v200)! With our stable release, we'll provide a full overview of what's released in a new blog post.
Expand Down
80 changes: 80 additions & 0 deletions content/docs/2.0/scalers/metrics-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
+++
title = "Metrics API"
layout = "scaler"
availability = "v2.0+"
maintainer = "Community"
description = "Scale applications based on a metric provided by an API"
go_file = "metrics_api_scaler"
+++

### Trigger Specification

This specification describes the `metrics-api` trigger that scales based on a metric value provided by an API.

This scaler allows users to utilize **any existing APIs** as a metric provider.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bold to emphasize than any API mean in fact any API, so one can scale their deployment using current day length from https://ipgeolocation.io/astronomy-api.html 😃


Here is an example of trigger configuration using metric-api scaler:

```yaml
triggers:
- type: metric-api
metadata:
targetValue: "8"
url: "http://api:3232/api/v1/stats"
valueLocation: "components.worker.tasks"
```

**Parameter list:**
- `url`: Full URL of the API operation to call to get the metric value (eg. `http://app:1317/api/v1/stats`).
- `valueLocation`: [GJSON path notation](https://github.com/tidwall/gjson#path-syntax) to refer to the field in
the payload containing the metric value
- `targetValue`: Target value to scale on. When the metric provided by the API is equal or higher to this value,
KEDA will start scaling out. When the metric is 0 or less, KEDA will scale down to 0.

### Authentication Parameters

Not supported yet.

### Example

Here is a full example of scaled object definition using Metric API trigger:

```yaml
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: http-scaledobject
namespace: keda
labels:
deploymentName: dummy
spec:
maxReplicaCount: 12
scaleTargetRef:
name: dummy
triggers:
- type: metrics-api
metadata:
targetValue: "7"
url: "http://api:3232/components/stats"
valueLocation: 'components.worker.tasks'
```

When checking current metric Metrics API scaler sends GET request to provided `url` and then uses `valueLocation`
to access the value in response's payload.

The above example expects that the API endpoint will return response similar to this one:
```json
{
"components": {
"worker": {
"tasks": 12,
...
},
...
},
...
}
```
Assuming such response, Metrics API trigger will figure out that current metric value is 12.

> NOTE: The value of the metric must be json number type. The value is casted to **integer**.