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 4 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
166 changes: 166 additions & 0 deletions content/docs/2.0/scalers/metrics-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
+++
turbaszek marked this conversation as resolved.
Show resolved Hide resolved
title = "Metrics API"
layout = "scaler"
availability = "v2.0+"
maintainer = "Community"
description = "Scale applications based on a metric from an API"
turbaszek marked this conversation as resolved.
Show resolved Hide resolved
go_file = "metrics_api_scaler"
+++

### Trigger Specification

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

The metrics API requires following configuration values:
- `url` string representing the base URL of the API (i.e `http://app:1317/api/v1/`).
turbaszek marked this conversation as resolved.
Show resolved Hide resolved
- `metricName` the metric name to be used to retrieve value. Scaler will look for metric value under
`url/metric/{metricName}` endpoint. For more information check next section.
- `targetValue` the target value is the target value to scale on. When the metric provided by the
turbaszek marked this conversation as resolved.
Show resolved Hide resolved
API is equal or higher to this value, KEDA will start scaling out.
turbaszek marked this conversation as resolved.
Show resolved Hide resolved

An example of triggers configuration using metric API scaler:

```yaml
turbaszek marked this conversation as resolved.
Show resolved Hide resolved
tomkerkhove marked this conversation as resolved.
Show resolved Hide resolved
triggers:
- type: metric-api
metadata:
targetValue: "1"
url: "http://api:3232/api/v1"
metricName: "workersNumber"
```

**Note**:
turbaszek marked this conversation as resolved.
Show resolved Hide resolved
This scaler scales deployment to 0 if and only if the value of the metric is lower or equal to zero.

### Trigger prerequisites

To use an external API it has to comply with:

```yaml
openapi: 3.0.1
info:
title: KEDA - External Metric Source Petstore
description: >-
This is the specification to comply with for external KEDA metric sources.
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
version: 1.0.0
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
servers:
- url: 'https://samples.keda.sh/'
tags:
- name: Health
description: Operations about runtime health
- name: Metrics
description: Operations about providing metrics to KEDA
paths:
/api/v1/metric/{metric}:
get:
summary: Get Metric
description: Get value for a given metric
operationId: GetMetric
parameters:
- name: metric
in: path
required: true
schema:
type: string
description: Name of the metric for which information is requested
responses:
'200':
description: Metric inforation was provided
content:
application/json:
schema:
$ref: '#/components/schemas/ReportedMetric'
'404':
description: Metric is not supported
'401':
$ref: '#/components/responses/UnauthorizedError'
'500':
description: Unable to determine metric information
tags:
- Metrics
security:
- basic_auth: []
- api_key: []
/api/v1/metrics:
get:
summary: Get All Metrics
description: Provides a list of all supported metrics
operationId: GetMetrics
responses:
'200':
description: Metric inforation was provided
content:
application/json:
schema:
$ref: '#/components/schemas/MetricInfo'
'401':
$ref: '#/components/responses/UnauthorizedError'
'500':
description: Unable to determine metric information
tags:
- Metrics
security:
- basic_auth: []
- api_key: []
/api/v1/health:
get:
summary: Get Health
description: Provides information about the health of the runtime
operationId: GetHealth
responses:
'200':
description: External metric source is healthy
'401':
$ref: '#/components/responses/UnauthorizedError'
'500':
description: External metric source is not healthy
tags:
- Health
security:
- basic_auth: []
- api_key: []
components:
schemas:
MetricInfo:
type: array
items:
type: object
properties:
name:
type: string
ReportedMetric:
type: object
required:
- name
- value
properties:
name:
type: string
value:
type: number
responses:
UnauthorizedError:
description: Authentication information is missing or invalid
securitySchemes:
basic_auth:
type: http
scheme: basic
api_key:
type: apiKey
name: X-API-Key
in: header
security:
- basic_auth: []
- api_key: []
```

The `/health` endpoint is used once when creating new `metricsAPIScaler`.