Dynatrace scaler does not trigger fallback when DQL returns MISSING_BUCKET_PERMISSIONS
Report
When using the Dynatrace scaler with a DQL query, Dynatrace returns a successful query response (state: SUCCEEDED) even when the token does not have permission to read the metrics bucket.
The completed query result contains a MISSING_BUCKET_PERMISSIONS warning in result.metadata.grail.notifications while still being reported as SUCCEEDED.
If the DQL query is written to return r = 0 when no metric data is available, KEDA treats the query as successful and the trigger as inactive. As a result, the configured fallback is not activated.
This can be problematic with minReplicaCount: 0, because a permissions issue may be interpreted in the same way as a legitimate zero metric value and the workload can scale to zero.
Expected Behavior
A Dynatrace response indicating that the requested metrics cannot be read because of missing bucket permissions should be considered as a scaler failure, so that the normal KEDA fallback mechanism can take effect.
Actual Behavior
Dynatrace returns HTTP success and state: SUCCEEDED, but the response also contains:
{
"records": [
{
"r": 0.0
}
],
"metadata": {
"grail": {
"notifications": [
{
"message": "No bucket permissions for table metrics.",
"notificationType": "MISSING_BUCKET_PERMISSIONS",
"severity": "WARNING"
}
]
}
}
}The Dynatrace scaler remains healthy and no query error is reported. So, KEDA does not report a scaler failure, numberOfFailures remains 0, and the configured fallback is not activated.
ScaledObject status:
health:
s0-dynatrace:
numberOfFailures: 0
status: Happy
fallback:
reason: NoFallbackFoundSteps to Reproduce the Problem
In Dynatrace, create or use an existing metric that can be queried through Grail, and create a valid platform token
DT_TOKENthat can authenticate successfully but intentionally does not have permission to read themetricsbucket.Create a DQL query that explicitly returns
r = 0when no matching metric data is available, and save it as a valid Dynatrace API request payload:
QUERY=$(cat <<'DQL'
timeseries metric_count = sum(<existing-metric-key>, default:0),
from: now()-2h
| fieldsAdd metric_total = arraySum(metric_count)
| fields metric_total
| append [data record(metric_total = 0)]
| summarize r = toDouble(sum(metric_total))
DQL
)
jq -n \
--arg query "$QUERY" \
'{
query: $query,
timezone: "UTC",
requestTimeoutMilliseconds: 60000,
maxResultRecords: 10
}' > /tmp/dt-query.jsonReplace <existing-metric-key> with a metric available in the Dynatrace environment.
- Configure fallback on the ScaledObject, for example:
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: dynatrace-fallback-repro
namespace: default
spec:
scaleTargetRef:
name: test-deployment
minReplicaCount: 0
maxReplicaCount: 2
pollingInterval: 60
cooldownPeriod: 30
fallback:
failureThreshold: 1
replicas: 2
behavior: static
triggers:
- type: dynatrace
authenticationRef:
name: dynatrace-auth
kind: ClusterTriggerAuthentication
metadata:
query: >-
timeseries metric_count = sum(example.metric, default:0),
from: now()-2h
| fieldsAdd metric_total = arraySum(metric_count)
| fields metric_total
| append [data record(metric_total = 0)]
| summarize r = toDouble(sum(metric_total))
threshold: "1"
activationThreshold: "0"- Execute the query using the same Dynatrace token configured for the scaler:
curl -sS -X POST \
"$DT_HOST/platform/storage/query/v1/query:execute?enrich=metric-metadata" \
-H "Authorization: Bearer $DT_TOKEN" \
-H "Content-Type: application/json" \
--data @/tmp/dt-query.json- Observe that Dynatrace returns a successful query response (
state: SUCCEEDED) withr: 0, while also reporting:
notificationType: MISSING_BUCKET_PERMISSIONS
message: "No bucket permissions for table metrics."- Observe that KEDA considers the scaler healthy and fallback is not activated.
Logs from KEDA operator
KEDA Version
2.20.1
Kubernetes Version
1.35
Platform
Microsoft Azure
Scaler Details
Dynatrace
Would you be open to contributing a fix?
Maybe
Anything else?
From looking at the current Dynatrace scaler implementation, it appears that the DQL response handling uses the query state and result.records[].r, while Grail notifications are not evaluated
One possible direction might be to treat permission-related notifications such as MISSING_BUCKET_PERMISSIONS as a scaler error, allowing the existing fallback mechanism to handle the condition. However, I would leave the appropriate handling to the maintainers.
Thanks
Source: kedacore/keda