HTTP & Content Checks
Relevant source files
The following files were used as context for generating this wiki page:
HTTP and Content Checks are specialized synthetic monitoring tools within the Kuberhealthy ecosystem designed to verify the availability, performance, and integrity of web services. These checks function as external checkers, running as isolated pods that perform network requests and report their findings back to the Kuberhealthy operator.
The HTTP Check verifies that a specific URL responds with an expected status code over a series of attempts, while the Content Check validates that a specific string exists within the response body of a target URL. Both checks integrate with Prometheus for metric collection and use the Kuberhealthy status page to report cluster health.
Sources: README.md:1-20, cmd/http-check/README.md:3-8, cmd/http-content-check/README.md:3-7
HTTP Status Check Architecture
The HTTP Status Check is designed to execute multiple requests (GET, POST, PUT, DELETE, PATCH) to a target endpoint and calculate a success rate based on expected HTTP response codes.
Execution Logic
The check initializes by fetching configuration from environment variables, validating the URL protocol (requiring http or https), and waiting for the Kuberhealthy endpoint to become reachable via the nodeCheck package. It then enters a loop to perform the configured number of API calls, using a ticker to manage intervals between requests.
The logic compares the final number of successful attempts against a calculated passingScore (Passing Percent * Total Count).
Sources: cmd/http-check/main.go:61-167
Configuration Parameters
The HTTP Check is highly configurable via environment variables defined in the KuberhealthyCheck spec.
| Variable | Default | Description |
|---|---|---|
CHECK_URL | N/A | The target URL to check. Must include protocol. |
COUNT | "0" | Total number of requests to perform during a single check run. |
SECONDS | "0" | Interval in seconds to wait between individual requests. |
PASSING_PERCENT | "100" | Percentage of successful requests required to mark the check as OK. |
REQUEST_TYPE | "GET" | HTTP method (GET, POST, PUT, DELETE, PATCH, or PATCH). |
REQUEST_BODY | "{}" | JSON body to send with POST/PUT/DELETE/PATCH requests. |
EXPECTED_STATUS_CODE | "200" | The HTTP status code indicating a successful response. |
Sources: cmd/http-check/main.go:23-31, cmd/http-check/README.md:12-87
HTTP Content Check Architecture
The HTTP Content Check focuses on the data returned by a service. It is used to ensure that a web page or API is not just reachable, but is serving the correct content.
Validation Flow
This check utilizes the standard Go http.Client to fetch the body of a target URL, follows redirects by default, and searches for a specific substring within the byte slice of the response body.
Implementation Details
- String Matching: Uses
strings.Containsto perform a basic search within the response body. - Timeout Management: Uses
TIMEOUT_DURATIONto set thehttp.Clienttimeout, ensuring the check does not hang indefinitely. - Reporting: Uses the
checkclientpackage to communicate results. IfReportSuccess()orReportFailure()fails to communicate with the operator, the process exits with status code 1.
Sources: cmd/http-content-check/main.go:92-127
Technical Specifications
Resource Requirements
Both checks are lightweight synthetic tests. Default configurations typically request minimal CPU and memory.
resources:
requests:
cpu: 15m
memory: 15Mi
limits:
cpu: 25m
Sources: cmd/http-check/http-check.yaml:22-26, cmd/http-content-check/http-content-check.yaml:18-22
API Request Implementation
The HTTP check uses a custom APIRequest struct to abstract the request details.
type APIRequest struct {
URL *url.URL
Type string
Body io.Reader
}
Sources: cmd/http-check/main.go:34-38
The callAPI function handles the specific HTTP methods:
- GET: Uses
http.Get(url). - Others: Uses
http.NewRequest(type, url, body)followed byhttp.DefaultClient.Do(req).
Sources: cmd/http-check/main.go:183-211
Conclusion
HTTP and Content Checks provide a robust mechanism for verifying external dependencies and internal services from within the Kubernetes cluster. By allowing configurable success thresholds and content validation, they ensure that applications are functional beyond simple connectivity, directly contributing to the Kuberhealthy JSON status page and Prometheus metrics.
Sources: README.md:65-79, cmd/http-check/README.md:3-10