Skip to content

Commit 34fb0a7

Browse files
committed
add health check probe metric test
Signed-off-by: Phil Brookes <[email protected]>
1 parent 48bd400 commit 34fb0a7

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed

config/examples/kube-prometheus/bundle.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,25 @@ data:
17391739
labelsFromPath:
17401740
type: ["type"]
17411741
valueFrom: ["status"]
1742+
- groupVersionKind:
1743+
group: kuadrant.io
1744+
kind: "DNSHealthCheckProbe"
1745+
version: "v1alpha1"
1746+
metricNamePrefix: kuadrant_dnshealthcheckprobe
1747+
labelsFromPath:
1748+
name:
1749+
- metadata
1750+
- name
1751+
namespace:
1752+
- metadata
1753+
- namespace
1754+
metrics:
1755+
- name: "healthy_status"
1756+
help: "DNS Probe current status"
1757+
each:
1758+
type: Gauge
1759+
gauge:
1760+
path: [status, healthy]
17421761
kind: ConfigMap
17431762
metadata:
17441763
name: custom-resource-state
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.14.0
7+
name: dnshealthcheckprobes.kuadrant.io
8+
spec:
9+
group: kuadrant.io
10+
names:
11+
kind: DNSHealthCheckProbe
12+
listKind: DNSHealthCheckProbeList
13+
plural: dnshealthcheckprobes
14+
singular: dnshealthcheckprobe
15+
scope: Namespaced
16+
versions:
17+
- additionalPrinterColumns:
18+
- description: DNSHealthCheckProbe healthy.
19+
jsonPath: .status.healthy
20+
name: Healthy
21+
type: boolean
22+
name: v1alpha1
23+
schema:
24+
openAPIV3Schema:
25+
description: DNSHealthCheckProbe is the Schema for the dnshealthcheckprobes
26+
API
27+
properties:
28+
apiVersion:
29+
description: |-
30+
APIVersion defines the versioned schema of this representation of an object.
31+
Servers should convert recognized schemas to the latest internal value, and
32+
may reject unrecognized values.
33+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
34+
type: string
35+
kind:
36+
description: |-
37+
Kind is a string value representing the REST resource this object represents.
38+
Servers may infer this from the endpoint the client submits requests to.
39+
Cannot be updated.
40+
In CamelCase.
41+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
42+
type: string
43+
metadata:
44+
type: object
45+
spec:
46+
description: DNSHealthCheckProbeSpec defines the desired state of DNSHealthCheckProbe
47+
properties:
48+
additionalHeadersRef:
49+
description: |-
50+
AdditionalHeadersRef refers to a secret that contains extra headers to send in the probe request, this is primarily useful if an authentication
51+
token is required by the endpoint.
52+
properties:
53+
name:
54+
type: string
55+
required:
56+
- name
57+
type: object
58+
address:
59+
description: Address to connect to the host on (IP Address (A Record)
60+
or hostname (CNAME)).
61+
type: string
62+
allowInsecureCertificate:
63+
description: |-
64+
AllowInsecureCertificate will instruct the health check probe to not fail on a self-signed or otherwise invalid SSL certificate
65+
this is primarily used in development or testing environments and is set by the --insecure-health-checks flag
66+
type: boolean
67+
failureThreshold:
68+
description: FailureThreshold is a limit of consecutive failures that
69+
must occur for a host to be considered unhealthy
70+
type: integer
71+
x-kubernetes-validations:
72+
- message: Failure threshold must be greater than 0
73+
rule: self > 0
74+
hostname:
75+
description: |-
76+
Hostname is the value sent in the host header, to route the request to the correct service
77+
Represents a root host of the parent DNS Record.
78+
type: string
79+
interval:
80+
description: Interval defines how frequently this probe should execute
81+
type: string
82+
path:
83+
description: |-
84+
Path is the path to append to the host to reach the expected health check.
85+
Must start with "?" or "/", contain only valid URL characters and end with alphanumeric char or "/". For example "/" or "/healthz" are common
86+
pattern: ^(?:\?|\/)[\w\-.~:\/?#\[\]@!$&'()*+,;=]+(?:[a-zA-Z0-9]|\/){1}$
87+
type: string
88+
port:
89+
description: Port to connect to the host on. Must be either 80, 443
90+
or 1024-49151
91+
type: integer
92+
x-kubernetes-validations:
93+
- message: Only ports 80, 443, 1024-49151 are allowed
94+
rule: self in [80, 443] || (self >= 1024 && self <= 49151)
95+
protocol:
96+
description: Protocol to use when connecting to the host, valid values
97+
are "HTTP" or "HTTPS"
98+
type: string
99+
x-kubernetes-validations:
100+
- message: Only HTTP or HTTPS protocols are allowed
101+
rule: self in ['HTTP','HTTPS']
102+
type: object
103+
status:
104+
description: DNSHealthCheckProbeStatus defines the observed state of DNSHealthCheckProbe
105+
properties:
106+
consecutiveFailures:
107+
type: integer
108+
healthy:
109+
type: boolean
110+
observedGeneration:
111+
format: int64
112+
type: integer
113+
reason:
114+
type: string
115+
status:
116+
type: integer
117+
required:
118+
- healthy
119+
type: object
120+
type: object
121+
served: true
122+
storage: true
123+
subresources:
124+
status: {}

tests/e2e/main_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func TestKuadrantMetricsAvailable(t *testing.T) {
118118
kuadrantMetrics[params[1]] = append(kuadrantMetrics[params[1]], params)
119119
}
120120
testDNSRecord(t, kuadrantMetrics)
121+
testDNSHealthCheckProbe(t, kuadrantMetrics)
121122
}
122123

123124
func testGatewayClasses(t *testing.T, metrics map[string][][]string) {
@@ -742,6 +743,12 @@ func testDNSRecord(t *testing.T, metrics map[string][][]string) {
742743
}
743744
}
744745

746+
func testDNSHealthCheckProbe(t *testing.T, metrics map[string][][]string) {
747+
probeHealthyMetric := metrics["kuadrant_dnshealthcheckprobe_healthy_status"]
748+
probeHealthyMetric1 := probeHealthyMetric[0]
749+
expectEqual(t, probeHealthyMetric1[3], "1", "kuadrant_dnshealthcheckprobe_healthy_status__1 value")
750+
}
751+
745752
func parseLabels(labelsRaw string) map[string]string {
746753
// simple label parsing assuming no special chars/escaping
747754
// fmt.Printf("labelsRaw=%s\n", labelsRaw)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: kuadrant.io/v1alpha1
2+
kind: DNSHealthCheckProbe
3+
metadata:
4+
labels:
5+
kuadrant.io/health-probes-owner: testdnsrecord1
6+
name: testdnsrecord1-172.32.200.19
7+
namespace: default
8+
spec:
9+
address: 172.32.200.19
10+
allowInsecureCertificate: false
11+
failureThreshold: 3
12+
hostname: eu.klb.test.cb.hcpapps.net
13+
interval: 30s
14+
path: /healthz
15+
port: 80
16+
protocol: HTTP
17+
status:
18+
healthy: true
19+
observedGeneration: 1
20+
status: 200

0 commit comments

Comments
 (0)