Skip to content

Commit

Permalink
add health check probe metric test
Browse files Browse the repository at this point in the history
Signed-off-by: Phil Brookes <[email protected]>
  • Loading branch information
philbrookes committed Dec 12, 2024
1 parent 48bd400 commit 3012a92
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
19 changes: 19 additions & 0 deletions config/examples/kube-prometheus/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
124 changes: 124 additions & 0 deletions config/kuadrant/crd/kuadrant.io_dnshealthcheckprobes.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
7 changes: 7 additions & 0 deletions tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions tests/manifests/testdnshealthcheckprobe.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3012a92

Please sign in to comment.