Skip to content

Commit

Permalink
feat: add health-checks for eck elastic beat (argoproj#16563)
Browse files Browse the repository at this point in the history
* feat: add health-checks for eck elastic beat

Signed-off-by: ebuildy <ebuildy@gmail.com>

* fix tests

Signed-off-by: ebuildy <ebuildy@gmail.com>

---------

Signed-off-by: ebuildy <ebuildy@gmail.com>
  • Loading branch information
ebuildy authored and mkieweg committed Jun 11, 2024
1 parent 78170b8 commit 518088e
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 0 deletions.
31 changes: 31 additions & 0 deletions resource_customizations/beat.k8s.elastic.co/Beat/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local hs = {}

if obj.status ~= nil and (obj.status.health ~= nil or obj.status.expectedNodes ~= nil) then
if obj.status.health == "red" then
hs.status = "Degraded"
hs.message = "Elastic Beat status is Red"
return hs
elseif obj.status.health == "green" then
hs.status = "Healthy"
hs.message = "Elastic Beat status is Green"
return hs
elseif obj.status.health == "yellow" then
if obj.status.availableNodes ~= nil and obj.status.expectedNodes ~= nil then
hs.status = "Progressing"
hs.message = "Elastic Beat status is deploying, there is " .. obj.status.availableNodes .. " instance(s) on " .. obj.status.expectedNodes .. " expected"
return hs
else
hs.status = "Progressing"
hs.message = "Elastic Beat phase is progressing"
return hs
end
elseif obj.status.health == nil then
hs.status = "Progressing"
hs.message = "Elastic Beat phase is progressing"
return hs
end
end

hs.status = "Unknown"
hs.message = "Elastic Beat status is unknown. Ensure your ArgoCD is current and then check for/file a bug report: https://github.com/argoproj/argo-cd/issues"
return hs
29 changes: 29 additions & 0 deletions resource_customizations/beat.k8s.elastic.co/Beat/health_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
tests:
- healthStatus:
status: Healthy
message: "Elastic Beat status is Green"
inputPath: testdata/ready_green.yaml
- healthStatus:
status: Progressing
message: "Elastic Beat phase is progressing"
inputPath: testdata/ready_yellow_single_node.yaml
- healthStatus:
status: Progressing
message: "Elastic Beat status is deploying, there is 1 instance(s) on 2 expected"
inputPath: testdata/ready_yellow.yaml
- healthStatus:
status: Progressing
message: "Elastic Beat phase is progressing"
inputPath: testdata/progressing.yaml
- healthStatus:
status: Degraded
message: "Elastic Beat status is Red"
inputPath: testdata/ready_red.yaml
- healthStatus:
status: Unknown
message: "Elastic Beat status is unknown. Ensure your ArgoCD is current and then check for/file a bug report: https://github.com/argoproj/argo-cd/issues"
inputPath: testdata/unknown.yaml
- healthStatus:
status: Unknown
message: "Elastic Beat status is unknown. Ensure your ArgoCD is current and then check for/file a bug report: https://github.com/argoproj/argo-cd/issues"
inputPath: testdata/invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: beat.k8s.elastic.co/v1beta1
kind: Beat
metadata:
name: quickstart
spec:
version: 8.8.8
type: metricbeat
status:
expectedNodes: 1
health: invalid
observedGeneration: 1
version: 8.8.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: beat.k8s.elastic.co/v1beta1
kind: Beat
metadata:
name: quickstart
spec:
version: 8.8.8
type: metricbeat
status:
expectedNodes: 1
observedGeneration: 1
version: 8.8.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: beat.k8s.elastic.co/v1beta1
kind: Beat
metadata:
name: quickstart
spec:
version: 8.8.8
type: metricbeat
status:
expectedNodes: 1
availableNodes: 1
health: green
observedGeneration: 1
version: 8.8.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: beat.k8s.elastic.co/v1beta1
kind: Beat
metadata:
name: quickstart
spec:
version: 8.8.8
type: metricbeat
status:
expectedNodes: 1
health: red
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: beat.k8s.elastic.co/v1beta1
kind: Beat
metadata:
name: quickstart
spec:
version: 8.8.8
type: metricbeat
status:
availableNodes: 1
expectedNodes: 2
health: yellow
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: beat.k8s.elastic.co/v1beta1
kind: Beat
metadata:
name: quickstart
spec:
version: 8.8.8
type: metricbeat
status:
expectedNodes: 1
health: yellow
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: beat.k8s.elastic.co/v1beta1
kind: Beat
metadata:
name: quickstart
spec:
version: 8.8.8
type: metricbeat
status: {}

0 comments on commit 518088e

Please sign in to comment.