Add support for templating in `spec.triggers.metadata.query`
#2,757 opened on Mar 14, 2022
Repository metrics
- Stars
- (10,372 stars)
- PR merge metrics
- (PR metrics pending)
Description
Proposal
It'd be great if Keda allowed users to use templates instead of hardcoding the target deployment name in the query when using a scaler like Prometheus. Something along the lines of:
triggers:
- type: prometheus
metadata:
serverAddress: http://<prometheus-host>:9090
metricName: http_requests_total
threshold: '100'
query: sum(rate(http_requests_total{deployment="{{ target-deployment }}"}[2m]))
Keda could then refer to .spec.scaleTargetRef to get the actual value and insert it into the query before running the query. This would enable other operators to interact with ScaledObjects in a cleaner manner.
Use-Case
This would help a controller in creating a ScaledObject for a deployment based on an existing user provided ScaledObject for a different deployment. Right now, copying over the spec of the existing ScaledObject (and inherently the query for the scaler) would lead to the new ScaledObject to scale based on the query meant for the other deployment. This would force some kind of a best effort attempt at modifying the query suitable for the new ScaledObject, which is error prone. Adding support for templates, makes it easier for controllers by letting them just copy pasting the spec and eliminates the need for any hacky query modification.
Anything else?
No response