mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
feat(health): Add healthCheck for CRD DatadogMetric (#23464)
Signed-off-by: Nicolas Richard <nicolas.richard@chime.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
-- Reference CRD can be found here:
|
||||
-- https://github.com/DataDog/helm-charts/blob/main/charts/datadog-crds/templates/datadoghq.com_datadogmetrics_v1.yaml
|
||||
|
||||
hs = {}
|
||||
if obj.status ~= nil and obj.status.conditions ~= nil then
|
||||
for i, condition in ipairs(obj.status.conditions) do
|
||||
-- Check for the "Error: True" condition first
|
||||
if condition.type == "Error" and condition.status == "True" then
|
||||
hs.status = "Degraded"
|
||||
local reason = condition.reason or ""
|
||||
local message = condition.message or "DatadogMetric reported an error"
|
||||
if reason ~= "" then
|
||||
hs.message = reason .. ": " .. message
|
||||
else
|
||||
hs.message = message
|
||||
end
|
||||
return hs
|
||||
end
|
||||
end
|
||||
for i, condition in ipairs(obj.status.conditions) do
|
||||
-- Check for the "Valid: False" condition
|
||||
if condition.type == "Valid" and condition.status == "False" then
|
||||
hs.status = "Degraded"
|
||||
hs.message = condition.message or "DatadogMetric is not valid"
|
||||
return hs
|
||||
end
|
||||
end
|
||||
end
|
||||
-- If no "Degraded" conditions are found, default to Healthy
|
||||
hs.status = "Healthy"
|
||||
hs.message = "DatadogMetric is healthy"
|
||||
return hs
|
||||
@@ -0,0 +1,13 @@
|
||||
tests:
|
||||
- healthStatus:
|
||||
status: Degraded
|
||||
message: "Unable to fetch data from Datadog: Processing data from API failed, reason: no serie was found for this query in API Response, check Cluster Agent logs for QueryIndex errors, query was: max:foo.bar.metric"
|
||||
inputPath: testdata/degraded_error.yaml
|
||||
- healthStatus:
|
||||
status: Degraded
|
||||
message: "The metric query is invalid"
|
||||
inputPath: testdata/degraded_invalid.yaml
|
||||
- healthStatus:
|
||||
status: Healthy
|
||||
message: "DatadogMetric is healthy"
|
||||
inputPath: testdata/healthy.yaml
|
||||
24
resource_customizations/datadoghq.com/DatadogMetric/testdata/degraded_error.yaml
vendored
Normal file
24
resource_customizations/datadoghq.com/DatadogMetric/testdata/degraded_error.yaml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
apiVersion: datadoghq.com/v1alpha1
|
||||
kind: DatadogMetric
|
||||
metadata:
|
||||
name: foo-bar-metric
|
||||
namespace: foo-namespace
|
||||
status:
|
||||
autoscalerReferences:
|
||||
- hpa:foo-namespace/foo-bar-hpa
|
||||
conditions:
|
||||
- lastTransitionTime: "2025-02-05T00:03:00Z"
|
||||
lastUpdateTime: "2025-06-17T17:49:45Z"
|
||||
status: "True"
|
||||
type: Active
|
||||
- lastTransitionTime: "2025-02-05T00:03:00Z"
|
||||
lastUpdateTime: "2025-06-17T17:49:45Z"
|
||||
status: "False"
|
||||
type: Valid
|
||||
- lastTransitionTime: "2025-02-05T00:03:30Z"
|
||||
lastUpdateTime: "2025-06-17T17:49:45Z"
|
||||
message: "Processing data from API failed, reason: no serie was found for this query in API Response, check Cluster Agent logs for QueryIndex errors, query was: max:foo.bar.metric"
|
||||
reason: Unable to fetch data from Datadog
|
||||
status: "True"
|
||||
type: Error
|
||||
currentValue: 0
|
||||
19
resource_customizations/datadoghq.com/DatadogMetric/testdata/degraded_invalid.yaml
vendored
Normal file
19
resource_customizations/datadoghq.com/DatadogMetric/testdata/degraded_invalid.yaml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
apiVersion: datadoghq.com/v1alpha1
|
||||
kind: DatadogMetric
|
||||
metadata:
|
||||
name: foo-bar-metric-invalid
|
||||
namespace: foo-namespace
|
||||
status:
|
||||
autoscalerReferences:
|
||||
- hpa:foo-namespace/foo-bar-hpa
|
||||
conditions:
|
||||
- lastTransitionTime: "2025-02-05T00:03:00Z"
|
||||
lastUpdateTime: "2025-06-17T17:49:45Z"
|
||||
status: "True"
|
||||
type: Active
|
||||
- lastTransitionTime: "2025-02-05T00:03:00Z"
|
||||
lastUpdateTime: "2025-06-17T17:49:45Z"
|
||||
status: "False"
|
||||
type: Valid
|
||||
message: "The metric query is invalid"
|
||||
currentValue: 0
|
||||
25
resource_customizations/datadoghq.com/DatadogMetric/testdata/healthy.yaml
vendored
Normal file
25
resource_customizations/datadoghq.com/DatadogMetric/testdata/healthy.yaml
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
apiVersion: datadoghq.com/v1alpha1
|
||||
kind: DatadogMetric
|
||||
metadata:
|
||||
name: foo-bar-metric
|
||||
namespace: foo-namespace
|
||||
status:
|
||||
autoscalerReferences:
|
||||
- hpa:foo-namespace/foo-bar-hpa
|
||||
conditions:
|
||||
- lastTransitionTime: "2025-04-23T18:40:58Z"
|
||||
lastUpdateTime: "2025-06-17T20:45:05Z"
|
||||
status: "True"
|
||||
type: Active
|
||||
- lastTransitionTime: "2025-06-16T14:07:12Z"
|
||||
lastUpdateTime: "2025-06-17T20:45:05Z"
|
||||
status: "True"
|
||||
type: Valid
|
||||
- lastUpdateTime: "2025-06-17T20:44:30Z"
|
||||
status: "True"
|
||||
type: Updated
|
||||
- lastTransitionTime: "2025-06-16T14:07:12Z"
|
||||
lastUpdateTime: "2025-06-17T20:45:05Z"
|
||||
status: "False"
|
||||
type: Error
|
||||
currentValue: 0
|
||||
Reference in New Issue
Block a user