Skip to main content

HTTP

This check performs queries on HTTP endpoints, and HTTP Namespaces to monitor their activity.

apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-check
spec:
interval: 30
http:
- name: http pass response 200 status code
endpoint: https://httpbin.demo.aws.flanksource.com/status/200
thresholdMillis: 3000
responseCodes: [201, 200, 301]
maxSSLExpiry: 7
FieldDescriptionScheme
name*

Name of the check, must be unique within the canary

string

url*

HTTP URL

string

body

Request Body Contents

string

body

Request Body Contents

string

headers

Header fields

[]EnvVar

maxSSLExpiry

Max SSL expiry days

integer

method

HTTP Request method. Defaults to GET

string

responseCodes

Expected response codes

[]int

responseContent

Expected response content

string

templateBody

If true body will be templated

boolean

thresholdMillis

Request timeout. Defaults to 5000

integer

tlsConfig

TLS Config

TLSConfig

description

Description for the check

string

display

Expression to change the formatting of the display

Expression

icon

Icon for overwriting default icon on the dashboard

Icon

labels

Labels for check

map[string]string

metrics

Metrics to export from

[]Metrics

test

Evaluate whether a check is healthy

Expression

transform

Transform data from a check into multiple individual checks

Expression

username

EnvVar

password

EnvVar

TLS Config

FieldDescriptionScheme
ca

PEM encoded certificate of the CA to verify the server certificate

EnvVar

cert

PEM encoded client certificate

EnvVar

handshakeTimeout

Timeout for SSL Handshake (defaults to 10 seconds)

integer

insecureSkipVerify

Controls whether a client verifies the server's certificate chain and host name

boolean

key

PEM encoded client private key

EnvVar

You can specify either the ca or the pair of client cert & key

Example
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-check
spec:
interval: 30
http:
- name: http pass response 200 status code
url: https://httpbin.demo.aws.flanksource.com/status/200
tlsConfig:
ca:
valueFrom:
secretKeyRef:
name: ca-cert
key: ca.pem

Result Variables

Result variables can be used in test, display and transform expressions

NameDescriptionScheme
codeHTTP response codeint
headersHTTP response headersmap[string]string
elapsedHTTP Request durationtime.Duration
sslAgeTime until SSL certificate expirestime.Duration
contentHTTP Response bodystring
jsonIf Content-Type=application/json response body converted into JSON objectJSON

The above canary (http-check.yaml) is functionally equivalent to http-check-expr.yaml below

apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-check-expr
spec:
interval: 30
http:
- name: http pass response 200 status code
endpoint: https://httpbin.demo.aws.flanksource.com/status/200
test:
expr: "code in [200,201,301] and sslAge > Duration('7d')"

Authentication

Basic Authentication
http_auth.yaml
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-basic-auth
spec:
http:
- name: "basic auth fail"
endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [401]
- name: "basic auth pass"
endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [200]
username:
value: hello
password:
value: world

OAuth

Template Body Variables

NameScheme
metadata.namestring
metadata.metadata.namespacestring
metadata.labelsmap[string]string
{fields from []env}any

Variables defined in env will be available to template with the name that's configured on the spec. Eg: In the following spec, the vars my_secret_path and my_secret_var, defined in env, are available during templating.

Templating request body from env variables
http_template.yaml
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: templated-http
spec:
interval: 30
http:
- name: templated-http
endpoint: https://webhook.site/#!/9f1392a6-718a-4ef5-a8e2-bfb55b08afca/f93d307b-0aaf-4a38-b9b3-db5daaae5657/1
responseCodes: [200]
templateBody: true
envVar:
- name: db
valueFrom:
secretKeyRef:
name: db-user-pass
key: username
body: |
{
"canary": "{{.canary.name}}",
"secret": "{{.db}}"
}

See Escaping variables

Metrics

HTTP Check Metrics
canary_check_http_response_status{status, statusClass, url}CounterResponse code counter for each endpoint
canary_check_http_ssl_expiry{url}Gauge

Status class is one of 1xx, 2xx, 3xx, 4xx, 5xx

Adding custom metrics
metrics.yaml
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-pass-single
spec:
interval: 30
http:
- name: http-minimal-check
url: https://httpbin.demo.aws.flanksource.com/status/200
metrics:
- name: httpbin_count
type: counter
value: "1"
labels:
- name: check_name
valueExpr: check.name
- name: code
valueExpr: code
- name: httpbin_2xx_duration
type: counter
value: elapsed.getMilliseconds()
labels:
- name: check_name
valueExpr: check.name
Transforming metrics into individual checks
metrics.yaml
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: exchange-rates
annotations:
trace: "true"
spec:
schedule: "every 30 @minutes"
http:
- name: exchange-rates
url: https://api.frankfurter.app/latest?from=USD&to=GBP,EUR,ILS
transform:
expr: |
{
'metrics': json.rates.keys().map(k, {
'name': "exchange_rate",
'type': "gauge",
'value': json.rates[k],
'labels': {
"from": json.base,
"to": k
}
})
}.toJSON()
metrics:
- name: exchange_rate_api
type: histogram
value: elapsed.getMilliseconds()