From 8167b62af49e98d4e4812091aa75498fe99e19ed Mon Sep 17 00:00:00 2001 From: Phil Brookes Date: Thu, 12 Dec 2024 09:27:46 +0100 Subject: [PATCH] add health check probe metric test --- config/examples/kube-prometheus/bundle.yaml | 19 +++ .../crd/kuadrant.io_dnshealthcheckprobes.yaml | 124 ++++++++++++++++++ tests/e2e/main_test.go | 7 + tests/manifests/testdnshealthcheckprobe.yaml | 20 +++ 4 files changed, 170 insertions(+) create mode 100644 config/kuadrant/crd/kuadrant.io_dnshealthcheckprobes.yaml create mode 100644 tests/manifests/testdnshealthcheckprobe.yaml diff --git a/config/examples/kube-prometheus/bundle.yaml b/config/examples/kube-prometheus/bundle.yaml index c174806..e2f44a0 100644 --- a/config/examples/kube-prometheus/bundle.yaml +++ b/config/examples/kube-prometheus/bundle.yaml @@ -1739,6 +1739,25 @@ data: labelsFromPath: type: ["type"] valueFrom: ["status"] + - groupVersionKind: + group: kuadrant.io + kind: "DNSHealthCheckProbe" + version: "v1alpha1" + metricNamePrefix: kuadrant_dnshealthcheckprobe + labelsFromPath: + name: + - metadata + - name + namespace: + - metadata + - namespace + metrics: + - name: "healthy_status" + help: "DNS Probe current status" + each: + type: Gauge + gauge: + path: [status, healthy] kind: ConfigMap metadata: name: custom-resource-state diff --git a/config/kuadrant/crd/kuadrant.io_dnshealthcheckprobes.yaml b/config/kuadrant/crd/kuadrant.io_dnshealthcheckprobes.yaml new file mode 100644 index 0000000..edb7592 --- /dev/null +++ b/config/kuadrant/crd/kuadrant.io_dnshealthcheckprobes.yaml @@ -0,0 +1,124 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: dnshealthcheckprobes.kuadrant.io +spec: + group: kuadrant.io + names: + kind: DNSHealthCheckProbe + listKind: DNSHealthCheckProbeList + plural: dnshealthcheckprobes + singular: dnshealthcheckprobe + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: DNSHealthCheckProbe healthy. + jsonPath: .status.healthy + name: Healthy + type: boolean + name: v1alpha1 + schema: + openAPIV3Schema: + description: DNSHealthCheckProbe is the Schema for the dnshealthcheckprobes + API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: DNSHealthCheckProbeSpec defines the desired state of DNSHealthCheckProbe + properties: + additionalHeadersRef: + description: |- + AdditionalHeadersRef refers to a secret that contains extra headers to send in the probe request, this is primarily useful if an authentication + token is required by the endpoint. + properties: + name: + type: string + required: + - name + type: object + address: + description: Address to connect to the host on (IP Address (A Record) + or hostname (CNAME)). + type: string + allowInsecureCertificate: + description: |- + AllowInsecureCertificate will instruct the health check probe to not fail on a self-signed or otherwise invalid SSL certificate + this is primarily used in development or testing environments and is set by the --insecure-health-checks flag + type: boolean + failureThreshold: + description: FailureThreshold is a limit of consecutive failures that + must occur for a host to be considered unhealthy + type: integer + x-kubernetes-validations: + - message: Failure threshold must be greater than 0 + rule: self > 0 + hostname: + description: |- + Hostname is the value sent in the host header, to route the request to the correct service + Represents a root host of the parent DNS Record. + type: string + interval: + description: Interval defines how frequently this probe should execute + type: string + path: + description: |- + Path is the path to append to the host to reach the expected health check. + Must start with "?" or "/", contain only valid URL characters and end with alphanumeric char or "/". For example "/" or "/healthz" are common + pattern: ^(?:\?|\/)[\w\-.~:\/?#\[\]@!$&'()*+,;=]+(?:[a-zA-Z0-9]|\/){1}$ + type: string + port: + description: Port to connect to the host on. Must be either 80, 443 + or 1024-49151 + type: integer + x-kubernetes-validations: + - message: Only ports 80, 443, 1024-49151 are allowed + rule: self in [80, 443] || (self >= 1024 && self <= 49151) + protocol: + description: Protocol to use when connecting to the host, valid values + are "HTTP" or "HTTPS" + type: string + x-kubernetes-validations: + - message: Only HTTP or HTTPS protocols are allowed + rule: self in ['HTTP','HTTPS'] + type: object + status: + description: DNSHealthCheckProbeStatus defines the observed state of DNSHealthCheckProbe + properties: + consecutiveFailures: + type: integer + healthy: + type: boolean + observedGeneration: + format: int64 + type: integer + reason: + type: string + status: + type: integer + required: + - healthy + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/tests/e2e/main_test.go b/tests/e2e/main_test.go index 8b3214f..a4c6838 100644 --- a/tests/e2e/main_test.go +++ b/tests/e2e/main_test.go @@ -118,6 +118,7 @@ func TestKuadrantMetricsAvailable(t *testing.T) { kuadrantMetrics[params[1]] = append(kuadrantMetrics[params[1]], params) } testDNSRecord(t, kuadrantMetrics) + testDNSHealthCheckProbe(t, kuadrantMetrics) } func testGatewayClasses(t *testing.T, metrics map[string][][]string) { @@ -742,6 +743,12 @@ func testDNSRecord(t *testing.T, metrics map[string][][]string) { } } +func testDNSHealthCheckProbe(t *testing.T, metrics map[string][][]string) { + probeHealthyMetric := metrics["kuadrant_dnshealthcheckprobe_healthy_status"] + probeHealthyMetric1 := probeHealthyMetric[0] + expectEqual(t, probeHealthyMetric1[3], "1", "kuadrant_dnsrecord_status__1 value") +} + func parseLabels(labelsRaw string) map[string]string { // simple label parsing assuming no special chars/escaping // fmt.Printf("labelsRaw=%s\n", labelsRaw) diff --git a/tests/manifests/testdnshealthcheckprobe.yaml b/tests/manifests/testdnshealthcheckprobe.yaml new file mode 100644 index 0000000..9b9a505 --- /dev/null +++ b/tests/manifests/testdnshealthcheckprobe.yaml @@ -0,0 +1,20 @@ +apiVersion: kuadrant.io/v1alpha1 +kind: DNSHealthCheckProbe +metadata: + labels: + kuadrant.io/health-probes-owner: testdnsrecord1 + name: testdnsrecord1-172.32.200.19 + namespace: default +spec: + address: 172.32.200.19 + allowInsecureCertificate: false + failureThreshold: 3 + hostname: eu.klb.test.cb.hcpapps.net + interval: 30s + path: /healthz + port: 80 + protocol: HTTP +status: + healthy: true + observedGeneration: 1 + status: 200