diff --git a/modules/common/prometheus_recording_rule/standard/1.0/any-resource-0.1.0.tgz b/modules/common/prometheus_recording_rule/standard/1.0/any-resource-0.1.0.tgz new file mode 100644 index 00000000..e0c23bb6 Binary files /dev/null and b/modules/common/prometheus_recording_rule/standard/1.0/any-resource-0.1.0.tgz differ diff --git a/modules/common/prometheus_recording_rule/standard/1.0/facets.yaml b/modules/common/prometheus_recording_rule/standard/1.0/facets.yaml new file mode 100644 index 00000000..636a5527 --- /dev/null +++ b/modules/common/prometheus_recording_rule/standard/1.0/facets.yaml @@ -0,0 +1,78 @@ +intent: prometheus-recording-rule +version: '1.0' +title: Prometheus Recording Rule +description: Module to create Prometheus recording rules using Helm chart. +flavor: default +clouds: +- aws +- azure +- gcp +- kubernetes +metadata: + type: object + properties: + name: + title: Name + type: string + description: Name of the Prometheus recording rule resource. + namespace: + title: Namespace + type: string + description: Kubernetes namespace where the recording rule will be deployed. +spec: + type: object + properties: + group_name: + tilte: Group Name + type: string + description: Name of the recording rule group. + interval: + tilte: Evaluation Interval + type: string + description: Evaluation interval for the recording rules. + recording_rules: + title: Recording Rules + type: object + description: Map of recording rules where each key is the rule name and the + value is an object containing 'expr' (required), 'labels' (optional), and + 'disabled' (optional) properties. + patternProperties: + ^[a-zA-Z0-9_.-]*$: + type: object + title: Recording Rule + properties: + expr: + title: Expression + type: string + description: PromQL expression for the recording rule. + disabled: + title: Disabled + type: boolean + description: Whether the recording rule is disabled. + default: false +inputs: + prometheus_details: + type: '@facets/prometheus' + displayName: Prometheus + optional: true + default: + resource_type: configuration + resource_name: prometheus + kubernetes_details: + type: '@facets/kubernetes-details' + displayName: Kubernetes Cluster + optional: false + default: + resource_type: kubernetes_cluster + resource_name: default + providers: + - kubernetes + - kubernetes-alpha + - helm +sample: + flavor: default + version: '1.0' + kind: prometheus-recording-rule + description: Sample configuration for Prometheus Recording Rule module. + spec: + rules: {} diff --git a/modules/common/prometheus_recording_rule/standard/1.0/locals.tf b/modules/common/prometheus_recording_rule/standard/1.0/locals.tf new file mode 100644 index 00000000..28e11a9e --- /dev/null +++ b/modules/common/prometheus_recording_rule/standard/1.0/locals.tf @@ -0,0 +1,65 @@ +locals { + spec_json = var.instance.spec + userspecified_rules = lookup(local.spec_json, "recording_rules", {}) + metadata = lookup(var.instance, "metadata", {}) + name = lookup(local.metadata, "name", var.instance_name) + group_interval = lookup(local.spec_json, "interval", "5m") + group_name = lookup(local.spec_json, "group_name", "${var.instance_name}-recording-rules") + all_metadata = { + name = lookup(local.metadata, "name", "${var.instance_name}-recording-rules") + namespace = var.environment.namespace + labels = merge( + { + recording_group_name = lookup(local.metadata, "name", "${var.instance_name}-recording-rules") + role = "recording-rules" + }, lookup(var.instance.metadata, "labels", {}) + ) + annotations = merge( + { + owner = "facets" + + }, lookup(var.instance.metadata, "annotations", {}) + ) + } + # All recording rules + all_recording_rules = [ + for rule_name, rule_object in local.userspecified_rules : { + record = rule_name + expr = rule_object.expr + labels = merge( + { + "resourceType" = "prometheus-recording-rule" + "resourceName" = local.name + "resource_type" = "prometheus-recording-rule" + "resource_name" = local.name + + }, lookup(rule_object, "labels", {}) + ) + } if !lookup(rule_object, "disabled", false) + ] + # Manifest for the actual PrometheusRule resource + recording_manifest = { + apiVersion = "monitoring.coreos.com/v1" + kind = "PrometheusRule" + metadata = local.all_metadata + spec = { + groups = [ + { + name = local.group_name + interval = local.group_interval + rules = local.all_recording_rules + + } + ] + } + } + # Manifest to be used after yamlencode for parsing + recording_manifest_yaml = yamlencode(local.recording_manifest) + # Manifest clubed with anyResources object for rendering + helm_values = { + anyResources = { + facets_recording = local.recording_manifest_yaml + } + } + helm_values_yaml = yamlencode(local.helm_values) +} \ No newline at end of file diff --git a/modules/common/prometheus_recording_rule/standard/1.0/main.tf b/modules/common/prometheus_recording_rule/standard/1.0/main.tf new file mode 100644 index 00000000..f26b6050 --- /dev/null +++ b/modules/common/prometheus_recording_rule/standard/1.0/main.tf @@ -0,0 +1,16 @@ +resource "helm_release" "prometheus_recording_rules_helm" { + name = "recording-rules-${var.instance_name}" + chart = "${path.module}/any-resource-0.1.0.tgz" + repository = "kiwigrid" + namespace = var.environment.namespace + version = "0.1.0" + cleanup_on_fail = true + timeout = 720 + atomic = false + values = [ + <