Skip to content

Commit

Permalink
chore: Update dasbhoard artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
josephgregoryii committed Oct 7, 2024
1 parent 235dfd1 commit c3163e9
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 80 deletions.
13 changes: 6 additions & 7 deletions utils/build-validate-quickstart-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import get from 'lodash/get';
import Quickstart from "./lib/Quickstart";
import DataSource from "./lib/DataSource";
import Alert from "./lib/Alert";
import Dashboard, { DashboardConfig } from "./lib/Dashboard";
import Dashboard from "./lib/Dashboard";
import Ajv, { type ErrorObject } from 'ajv';
import { QuickstartConfig, QuickstartConfigAlert } from './types/QuickstartConfig';
import { QuickstartConfigAlert } from './types/QuickstartConfig';
import { passedProcessArguments } from './lib/helpers';
import { ArtifactDataSourceConfig } from './types/Artifact';
import { ArtifactDataSourceConfig, ArtifactDashboardConfig, ArtifactQuickstartConfig } from './types/Artifact';

type ArtifactSchema = Record<string, unknown>;

Expand All @@ -20,10 +20,10 @@ type InvalidItem = {
}

type ArtifactComponents = {
quickstarts: QuickstartConfig[],
quickstarts: ArtifactQuickstartConfig[],
dataSources: ArtifactDataSourceConfig[],
alerts: QuickstartConfigAlert[][],
dashboards: DashboardConfig[]
dashboards: ArtifactDashboardConfig[]
}

type Artifact = ArtifactComponents | {
Expand All @@ -47,11 +47,10 @@ export const getArtifactComponents = (): ArtifactComponents => {
const alerts = Alert.getAll().map((alert) => alert.config);
console.log(`[*] Found ${alerts.length} alerts`);

const dashboards = Dashboard.getAll().map((dashboard) => dashboard.config);
const dashboards = Dashboard.getAll().map((dashboard) => dashboard.transformForArtifact());
console.log(`[*] Found ${dashboards.length} dashboards`);

return {
// @ts-ignore
quickstarts,
dataSources,
alerts,
Expand Down
15 changes: 15 additions & 0 deletions utils/lib/Dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ class Dashboard extends Component<DashboardConfig, QuickstartDashboardInput> {
}
}

public transformForArtifact() {
const { name, description } = this.config;
const screenshotPaths = this.getScreenshotPaths();

return {
id: this.identifier,
description: description && description.trim(),
displayName: name && name.trim(),
rawConfiguration: JSON.stringify(this.config),
sourceUrl: Component.getAssetSourceUrl(this.configPath),
screenshots:
screenshotPaths && screenshotPaths.map((s) => this.getScreenshotUrl(s)),
};
}

/**
* Get mutation variables from dashboard config
* @returns - mutation variables for dashboard.
Expand Down
2 changes: 1 addition & 1 deletion utils/lib/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
DataSourceInstallDirectiveInput,
DataSourceMutationVariable,
} from '../types/DataSourceMutationVariable';
import { ArtifactInstall, ArtifactInstallDirective } from '../types/Artifact';
import { ArtifactInstall } from '../types/Artifact';

export interface DataSourceMutationResponse {
dataSource: {
Expand Down
3 changes: 2 additions & 1 deletion utils/lib/Quickstart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
QuickstartSupportLevel,
} from '../types/QuickstartMutationVariable';
import type { QuickstartConfig } from '../types/QuickstartConfig';
import {ArtifactQuickstartConfig} from '../types/Artifact';

export interface QuickstartMutationResponse {
quickstart: {
Expand Down Expand Up @@ -198,7 +199,7 @@ class Quickstart {
};
}

public transformForArtifact(): QuickstartConfig | { authors: { name: string }[] } {
public transformForArtifact(): ArtifactQuickstartConfig {
const config = {
...this.config,
// @ts-ignore
Expand Down
102 changes: 31 additions & 71 deletions utils/schema/artifact.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,12 @@
"type": "string"
}
},
"required": [
"name",
"description",
"url"
],
"required": ["name", "description", "url"],
"additionalProperties": false
}
},
"level": {
"enum": [
"New Relic",
"Community",
"Verified"
]
"enum": ["New Relic", "Community", "Verified"]
},
"icon": {
"type": "string"
Expand Down Expand Up @@ -129,13 +121,7 @@
}
}
},
"required": [
"description",
"summary",
"displayName",
"authors",
"icon"
],
"required": ["description", "summary", "displayName", "authors", "icon"],
"additionalProperties": false
},
"dataSource": {
Expand All @@ -160,9 +146,7 @@
"$ref": "#/definitions/installDirective"
}
},
"required": [
"primary"
],
"required": ["primary"],
"additionalProperties": false
},
"keywords": {
Expand All @@ -181,11 +165,7 @@
"type": "string"
}
},
"required": [
"id",
"displayName",
"install"
],
"required": ["id", "displayName", "install"],
"additionalProperties": false
},
"installDirective": {
Expand All @@ -198,9 +178,7 @@
"type": "string"
}
},
"required": [
"url"
],
"required": ["url"],
"additionalProperties": false
},
{
Expand All @@ -216,10 +194,7 @@
"type": "boolean"
}
},
"required": [
"nerdletId",
"requiresAccount"
],
"required": ["nerdletId", "requiresAccount"],
"additionalProperties": false
}
]
Expand All @@ -237,10 +212,7 @@
"nullable": true
},
"type": {
"enum": [
"BASELINE",
"STATIC"
],
"enum": ["BASELINE", "STATIC"],
"type": "string",
"nullable": true
},
Expand All @@ -251,9 +223,7 @@
"type": "string"
}
},
"required": [
"query"
],
"required": ["query"],
"additionalProperties": true
},
"runbookUrl": {
Expand All @@ -278,17 +248,10 @@
"maximum": 120
},
"priority": {
"enum": [
"CRITICAL",
"WARNING"
]
"enum": ["CRITICAL", "WARNING"]
},
"operator": {
"enum": [
"ABOVE",
"BELOW",
"EQUALS"
]
"enum": ["ABOVE", "BELOW", "EQUALS"]
},
"threshold": {
"type": "number",
Expand All @@ -299,48 +262,45 @@
"minimum": 0
},
"thresholdOccurances": {
"enum": [
"ALL",
"AT_LEAST_ONCE"
]
"enum": ["ALL", "AT_LEAST_ONCE"]
}
},
"additionalProperties": true
}
}
},
"required": [
"name",
"description",
"type"
],
"required": ["name", "description", "type"],
"additionalProperties": true
}
},
"dashboard": {
"type": "object",
"properties": {
"name": {
"id": {
"type": "string"
},
"pages": {
"type": "array",
"minItems": 1
"displayName": {
"type": "string"
},
"description": {
"type": [
"string",
"null"
]
"type": ["string", "null"]
},
"variables": {
"type": "array"
"rawConfiguration": { "type": "string" },
"sourceUrl": { "type": "string" },
"screenshots": {
"type": "array",
"items": {
"type": "object",
"properties": {
"url": {
"type": "string"
}
},
"required": ["url"]
}
}
},
"required": [
"name",
"pages"
],
"required": ["id", "displayName", "rawConfiguration"],
"additionalProperties": false
},
"dataSourceIds": {
Expand Down
42 changes: 42 additions & 0 deletions utils/types/Artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,45 @@ interface ArtifactDataSourceConfigNerdletDirective {
nerdletState: Record<string, string>;
requiresAccount: boolean;
}

type DashboardScreenshot = {
url: string;
}

export interface ArtifactDashboardConfig {
description?: string;
displayName: string;
rawConfiguration: string;
sourceUrl?: string;
screenshots?: DashboardScreenshot[];
}

type QuickstartConfigDocumentation = {
name: string;
description: string;
url: string;
}

export type QuickstartConfigSupportLevel =
| 'New Relic'
| 'Community'
| 'Verified';

type QuickstartConfig = {
id: string;
description: string;
title: string;
slug?: string;
documentation: QuickstartConfigDocumentation[];
icon: string;
keywords?: string[];
summary: string;
level: QuickstartConfigSupportLevel;
alertPolicies?: string[];
dashboards?: string[];
dataSourceIds?: string[];
}

export interface ArtifactQuickstartConfig extends QuickstartConfig {
authors: Array<{ name: string; }>
}

0 comments on commit c3163e9

Please sign in to comment.