diff --git a/utils/build-validate-quickstart-artifact.ts b/utils/build-validate-quickstart-artifact.ts index 9fc2f89139..9d0b5d2bf1 100644 --- a/utils/build-validate-quickstart-artifact.ts +++ b/utils/build-validate-quickstart-artifact.ts @@ -7,9 +7,8 @@ import DataSource from "./lib/DataSource"; import Alert from "./lib/Alert"; import Dashboard from "./lib/Dashboard"; import Ajv, { type ErrorObject } from 'ajv'; -import { QuickstartConfigAlert } from './types/QuickstartConfig'; import { passedProcessArguments } from './lib/helpers'; -import { ArtifactDataSourceConfig, ArtifactDashboardConfig, ArtifactQuickstartConfig } from './types/Artifact'; +import { ArtifactDataSourceConfig, ArtifactDashboardConfig, ArtifactQuickstartConfig, ArtifactAlertConfig } from './types/Artifact'; type ArtifactSchema = Record; @@ -22,7 +21,7 @@ type InvalidItem = { type ArtifactComponents = { quickstarts: ArtifactQuickstartConfig[], dataSources: ArtifactDataSourceConfig[], - alerts: QuickstartConfigAlert[][], + alerts: ArtifactAlertConfig, dashboards: ArtifactDashboardConfig[] } @@ -44,8 +43,13 @@ export const getArtifactComponents = (): ArtifactComponents => { const dataSources = DataSource.getAll().map((dataSource) => dataSource.transformForArtifact()); console.log(`[*] Found ${dataSources.length} dataSources`); - const alerts = Alert.getAll().map((alert) => alert.config); - console.log(`[*] Found ${alerts.length} alerts`); + const alerts = Alert.getAll().reduce((acc, alert) => { + const conditions = alert.transformForArtifact() + + return { ...acc, ...conditions } + + }, {}); + console.log(`[*] Found ${Object.keys(alerts).length} alerts`); const dashboards = Dashboard.getAll().map((dashboard) => dashboard.transformForArtifact()); console.log(`[*] Found ${dashboards.length} dashboards`); diff --git a/utils/lib/Alert.ts b/utils/lib/Alert.ts index 11c81c0524..a83f50223d 100644 --- a/utils/lib/Alert.ts +++ b/utils/lib/Alert.ts @@ -134,6 +134,22 @@ class Alert extends Component { } } + public transformForArtifact() { + const alertPolicy = this.config.map((condition) => { + const { description, name, type } = condition; + + return { + description: description && description.trim(), + displayName: name && name.trim(), + rawConfiguration: JSON.stringify(condition), + sourceUrl: Component.getAssetSourceUrl(this.configPath), + type: type && (type.trim() as AlertType), + }; + }); + + return { [this.identifier]: alertPolicy } + } + getMutationVariables() { if (!this.isValid) { console.error( diff --git a/utils/lib/Quickstart.ts b/utils/lib/Quickstart.ts index 1a0089473e..c1c531cfd1 100644 --- a/utils/lib/Quickstart.ts +++ b/utils/lib/Quickstart.ts @@ -212,6 +212,8 @@ class Quickstart { dataSourceIds, id, level, + dashboards = [], + alertPolicies = [], } = this.config; @@ -236,6 +238,8 @@ class Quickstart { summary: summary && summary.trim(), supportLevel: SUPPORT_LEVEL_ENUMS[level], dataSourceIds: dataSourceIds, + dashboards, + alertPolicies, }; diff --git a/utils/schema/artifact.json b/utils/schema/artifact.json index 75bf858d7f..8a04187430 100644 --- a/utils/schema/artifact.json +++ b/utils/schema/artifact.json @@ -15,9 +15,11 @@ } }, "alerts": { - "type": "array", - "items": { - "$ref": "#/definitions/alert" + "type": "object", + "patternProperties": { + ".*": { + "$ref": "#/definitions/alert" + } } }, "dashboards": { @@ -211,73 +213,34 @@ "items": { "type": "object", "properties": { - "name": { - "type": "string" - }, - "description": { - "type": "string", - "nullable": true - }, "type": { "enum": ["BASELINE", "STATIC"], "type": "string", "nullable": true }, - "nrql": { - "type": "object", - "properties": { - "query": { - "type": "string" - } - }, - "required": ["query"], - "additionalProperties": true - }, - "runbookUrl": { - "type": "string", - "nullable": true - }, - "violationTimeLimitSeconds": { - "type": "number" + "displayName": { + "type": "string" }, - "enabled": { - "type": "boolean" + "description": { + "type": ["string", "null"] }, - "terms": { + "rawConfiguration": { "type": "string" }, + "sourceUrl": { "type": "string" }, + "screenshots": { "type": "array", - "minItems": 1, "items": { "type": "object", "properties": { - "duration": { - "type": "number", - "minimum": 5, - "maximum": 120 - }, - "priority": { - "enum": ["CRITICAL", "WARNING"] - }, - "operator": { - "enum": ["ABOVE", "BELOW", "EQUALS"] - }, - "threshold": { - "type": "number", - "minimum": 0 - }, - "thresholdDuration": { - "type": "number", - "minimum": 0 - }, - "thresholdOccurances": { - "enum": ["ALL", "AT_LEAST_ONCE"] + "url": { + "type": "string" } }, - "additionalProperties": true + "required": ["url"] } } }, - "required": ["name", "description", "type"], - "additionalProperties": true + "required": ["displayName", "rawConfiguration"], + "additionalProperties": false } }, "dashboard": { diff --git a/utils/types/Artifact.ts b/utils/types/Artifact.ts index d35a52dac8..ad8c2ba6f7 100644 --- a/utils/types/Artifact.ts +++ b/utils/types/Artifact.ts @@ -73,3 +73,17 @@ type QuickstartConfig = { export interface ArtifactQuickstartConfig extends QuickstartConfig { authors: Array<{ name: string; }> } + +type AlertType = 'BASELINE' | 'STATIC'; + +type ArtifactAlert = { + description?: string; + displayName: string; + rawConfiguration: string; + sourceUrl?: string; + type: AlertType; +} + +export interface ArtifactAlertConfig { + [id: string]: ArtifactAlert[] +}