@pulumiverse/grafana
Version:
A Pulumi package for creating and managing grafana.
302 lines • 11 kB
JavaScript
"use strict";
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromRuleFile = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* 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 }}"
* ```
*/
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, id, state, opts) {
return new PromRuleFile(name, state, { ...opts, id: id });
}
/**
* 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) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === PromRuleFile.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["active"] = state?.active;
resourceInputs["groups"] = state?.groups;
resourceInputs["name"] = state?.name;
}
else {
const args = argsOrState;
if (args?.groups === undefined && !opts.urn) {
throw new Error("Missing required property 'groups'");
}
resourceInputs["active"] = args?.active;
resourceInputs["groups"] = args?.groups;
resourceInputs["name"] = args?.name;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(PromRuleFile.__pulumiType, name, resourceInputs, opts);
}
}
exports.PromRuleFile = PromRuleFile;
/** @internal */
PromRuleFile.__pulumiType = 'grafana:assert/promRuleFile:PromRuleFile';
//# sourceMappingURL=promRuleFile.js.map