Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cert-manager example (community hack session) #21

Merged
merged 6 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions examples/cert-manager/cert-manager.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package polly

import "github.com/pollypkg/polly/schema:pollyschema"

// Enforce that the emit value of this file unifies with the Polly schema
pollyschema.PollyPackage

header: {
name: "cert-manager"
uri: "github.com/pollypkg/polly/examples/cert-manager"
params: {
certManagerCertExpiryDays: int | *21,
certManagerJobLabel: string | *"cert-manager",
// TODO Runbooks are an open question themselves, and not really sure how
// we'd even think about the interpolation-inside-interpolation here
// certManagerRunbookURLPattern: "https://gitlab.com/uneeq-oss/cert-manager-mixin/-/blob/master/RUNBOOK.md#%s",
grafanaExternalUrl: string,
}
}

prometheusAlerts: v0: {
CertManagerCertExpirySoon: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maps! YISSSS! 🎉 🎉

Finally I will be able to stop iterating over the whole thing just to select one alert ^^

group: "certificates"
alert: {
expr: """
avg by (exported_namespace, namespace, name) (
certmanager_certificate_expiration_timestamp_seconds - time()
) < (\(header.params.certManagerCertExpiryDays\) * 24 * 3600)
"""
}
"for": "1h",
labels: {
severity: "warning"
}
annotations: {
summary: "The cert `{{ $labels.name }}` is {{ $value | humanizeDuration }} from expiry, it should have renewed over a week ago.",
description: "The domain that this cert covers will be unavailable after {{ $value | humanizeDuration }}. Clients using endpoints that this cert protects will start to fail in {{ $value | humanizeDuration }}.",
// TODO this is totally broken right now because it relies on a
// hardcoded uid for the particular dashboard. Polly provides the
// necessary namespacing information such that it should no longer be
// necessary to sling around uids like this - instead, this should be
// a reference to the namespaced name of the polly dashboard.
//
// That's the ideal, anyway - we'll have to see what we can actually
// accomplish :)
dashboard_url: header.params.grafanaExternalUrl + "/d/TvuRo2iMk/cert-manager",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set a UID on your dashboard and you can get rid of that randomised string: TvuRo2iMk

}
}
}
15 changes: 14 additions & 1 deletion schema/pollypkg.cue
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,24 @@ PollyPackage: {
v0?: [string]: (_latest & {arg: prometheus.Alert.lineages[0]}).out
}

prometheusAlerts?: {
v0?: [Name=string]: {
group: string
alert: (_latest & {arg: prometheus.Alert.lineages[0]}).out & {
alert: Name
}
}
}

// prometheusRules contains definitions of Prometheus rules that are
// valid with respect to Prometheus rule scuemata specifications.
//
// @doc(metaschema)
prometheusRules?: {
v0?: [string]: (_latest & {arg: prometheus.Rule.lineages[0]}).out
v0?: [string]: {
group: string
rule: (_latest & {arg: prometheus.Alert.lineages[0]}).out & {
sdboyer marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}