UNPKG

@pulumiverse/grafana

Version:

A Pulumi package for creating and managing grafana.

321 lines (320 loc) 12.1 kB
import * as pulumi from "@pulumi/pulumi"; import * as inputs from "../types/input"; import * as outputs from "../types/output"; /** * Manages Prometheus Rules configurations through Grafana Asserts API. Allows creation and management of custom Prometheus recording and alerting rules. * * ## Example Usage * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as grafana from "@pulumiverse/grafana"; * * // Basic recording rule for latency metrics * const latencyMetrics = new grafana.assert.PromRuleFile("latency_metrics", { * name: "custom-latency-metrics", * active: true, * groups: [{ * name: "latency_recording_rules", * interval: "30s", * rules: [ * { * record: "custom:latency:p95", * expr: "histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))", * labels: { * source: "custom_instrumentation", * severity: "info", * }, * }, * { * record: "custom:latency:p99", * expr: "histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m]))", * labels: { * source: "custom_instrumentation", * severity: "info", * }, * }, * ], * }], * }); * // Alert rules for high latency * const latencyAlerts = new grafana.assert.PromRuleFile("latency_alerts", { * name: "custom-latency-alerts", * active: true, * groups: [{ * name: "latency_alerting", * interval: "30s", * rules: [ * { * alert: "HighLatency", * expr: "histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 0.5", * duration: "5m", * labels: { * severity: "warning", * category: "Latency", * }, * annotations: { * summary: "High latency detected", * description: "P99 latency is above 500ms for 5 minutes", * }, * }, * { * alert: "VeryHighLatency", * expr: "histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 1.0", * duration: "2m", * labels: { * severity: "critical", * category: "Latency", * }, * annotations: { * summary: "Very high latency detected", * description: "P99 latency is above 1 second", * }, * }, * ], * }], * }); * // Comprehensive monitoring rules with multiple groups * const comprehensiveMonitoring = new grafana.assert.PromRuleFile("comprehensive_monitoring", { * name: "custom-comprehensive-monitoring", * active: true, * groups: [ * { * name: "latency_monitoring", * interval: "30s", * rules: [ * { * record: "custom:latency:p99", * expr: "histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m]))", * labels: { * source: "custom", * }, * }, * { * alert: "HighLatency", * expr: "custom:latency:p99 > 0.5", * duration: "5m", * labels: { * severity: "warning", * }, * annotations: { * summary: "High latency detected", * }, * }, * ], * }, * { * name: "error_monitoring", * interval: "1m", * rules: [ * { * record: "custom:error:rate", * expr: "rate(http_requests_total{status=~\"5..\"}[5m])", * labels: { * source: "custom", * }, * }, * { * alert: "HighErrorRate", * expr: "custom:error:rate > 0.1", * duration: "10m", * labels: { * severity: "critical", * category: "Errors", * }, * annotations: { * summary: "High error rate detected", * description: "Error rate is above 10%", * }, * }, * ], * }, * { * name: "throughput_monitoring", * interval: "1m", * rules: [ * { * record: "custom:throughput:total", * expr: "sum(rate(http_requests_total[5m]))", * labels: { * source: "custom", * }, * }, * { * alert: "LowThroughput", * expr: "custom:throughput:total < 10", * duration: "5m", * labels: { * severity: "warning", * category: "Throughput", * }, * annotations: { * summary: "Low throughput detected", * description: "Request throughput is below 10 requests/second", * }, * }, * ], * }, * ], * }); * // Rules with conditional enablement * const conditionalRules = new grafana.assert.PromRuleFile("conditional_rules", { * name: "custom-conditional-rules", * active: true, * groups: [{ * name: "environment_specific_rules", * interval: "30s", * rules: [ * { * alert: "TestAlert", * expr: "up == 0", * duration: "1m", * labels: { * severity: "info", * }, * annotations: { * summary: "Test alert that is disabled in production", * }, * disableInGroups: ["production"], * }, * { * alert: "CriticalAlert", * expr: "up == 0", * duration: "30s", * labels: { * severity: "critical", * }, * annotations: { * summary: "Critical alert that fires in all environments", * }, * }, * ], * }], * }); * // Inactive rules (for staging/testing) * const stagingRules = new grafana.assert.PromRuleFile("staging_rules", { * name: "custom-staging-rules", * active: false, * groups: [{ * name: "staging_tests", * interval: "1m", * rules: [{ * record: "staging:test:metric", * expr: "up", * labels: { * environment: "staging", * }, * }], * }], * }); * // SLO-based alerting * const sloAlerts = new grafana.assert.PromRuleFile("slo_alerts", { * name: "custom-slo-alerts", * active: true, * groups: [{ * name: "slo_monitoring", * interval: "1m", * rules: [ * { * record: "custom:slo:availability", * expr: "sum(rate(http_requests_total{status!~\"5..\"}[5m])) / sum(rate(http_requests_total[5m]))", * labels: { * slo_type: "availability", * }, * }, * { * alert: "SLOAvailabilityBreach", * expr: "custom:slo:availability < 0.995", * duration: "5m", * labels: { * severity: "critical", * category: "SLO", * }, * annotations: { * summary: "SLO availability breach", * description: "Availability is below 99.5% SLO target", * runbook_url: "https://docs.example.com/runbooks/availability-breach", * }, * }, * ], * }], * }); * ``` * * ## Import * * ```sh * terraform import grafana_asserts_prom_rule_file.name "{{ name }}" * ``` */ export declare class PromRuleFile extends pulumi.CustomResource { /** * Get an existing PromRuleFile resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name: string, id: pulumi.Input<pulumi.ID>, state?: PromRuleFileState, opts?: pulumi.CustomResourceOptions): PromRuleFile; /** * Returns true if the given object is an instance of PromRuleFile. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj: any): obj is PromRuleFile; /** * Whether the rules file is active. Inactive rules are not evaluated. Defaults to `true`. */ readonly active: pulumi.Output<boolean | undefined>; /** * List of Prometheus rule groups. Each group contains one or more rules and can have its own evaluation interval. */ readonly groups: pulumi.Output<outputs.assert.PromRuleFileGroup[]>; /** * The name of the Prometheus rules file. This will be stored with a .custom extension. Must follow naming validation rules (alphanumeric, hyphens, underscores). */ readonly name: pulumi.Output<string>; /** * Create a PromRuleFile resource with the given unique name, arguments, and options. * * @param name The _unique_ name of the resource. * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ constructor(name: string, args: PromRuleFileArgs, opts?: pulumi.CustomResourceOptions); } /** * Input properties used for looking up and filtering PromRuleFile resources. */ export interface PromRuleFileState { /** * Whether the rules file is active. Inactive rules are not evaluated. Defaults to `true`. */ active?: pulumi.Input<boolean>; /** * List of Prometheus rule groups. Each group contains one or more rules and can have its own evaluation interval. */ groups?: pulumi.Input<pulumi.Input<inputs.assert.PromRuleFileGroup>[]>; /** * The name of the Prometheus rules file. This will be stored with a .custom extension. Must follow naming validation rules (alphanumeric, hyphens, underscores). */ name?: pulumi.Input<string>; } /** * The set of arguments for constructing a PromRuleFile resource. */ export interface PromRuleFileArgs { /** * Whether the rules file is active. Inactive rules are not evaluated. Defaults to `true`. */ active?: pulumi.Input<boolean>; /** * List of Prometheus rule groups. Each group contains one or more rules and can have its own evaluation interval. */ groups: pulumi.Input<pulumi.Input<inputs.assert.PromRuleFileGroup>[]>; /** * The name of the Prometheus rules file. This will be stored with a .custom extension. Must follow naming validation rules (alphanumeric, hyphens, underscores). */ name?: pulumi.Input<string>; }