Skip to content

Commit

Permalink
feat: Update alert artifact and schema
Browse files Browse the repository at this point in the history
  • Loading branch information
josephgregoryii committed Oct 8, 2024
1 parent db839fe commit 1b1462b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 59 deletions.
14 changes: 9 additions & 5 deletions utils/build-validate-quickstart-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;

Expand All @@ -22,7 +21,7 @@ type InvalidItem = {
type ArtifactComponents = {
quickstarts: ArtifactQuickstartConfig[],
dataSources: ArtifactDataSourceConfig[],
alerts: QuickstartConfigAlert[][],
alerts: ArtifactAlertConfig,
dashboards: ArtifactDashboardConfig[]
}

Expand All @@ -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`);
Expand Down
16 changes: 16 additions & 0 deletions utils/lib/Alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ class Alert extends Component<QuickstartConfigAlert[], QuickstartAlertInput[]> {
}
}

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(
Expand Down
4 changes: 4 additions & 0 deletions utils/lib/Quickstart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class Quickstart {
dataSourceIds,
id,
level,
dashboards = [],
alertPolicies = [],
} = this.config;


Expand All @@ -236,6 +238,8 @@ class Quickstart {
summary: summary && summary.trim(),
supportLevel: SUPPORT_LEVEL_ENUMS[level],
dataSourceIds: dataSourceIds,
dashboards,
alertPolicies,
};


Expand Down
71 changes: 17 additions & 54 deletions utils/schema/artifact.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
}
},
"alerts": {
"type": "array",
"items": {
"$ref": "#/definitions/alert"
"type": "object",
"patternProperties": {
".*": {
"$ref": "#/definitions/alert"
}
}
},
"dashboards": {
Expand Down Expand Up @@ -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": {
Expand Down
14 changes: 14 additions & 0 deletions utils/types/Artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}

0 comments on commit 1b1462b

Please sign in to comment.