Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to artifact to conform to service structs #2583

Merged
merged 25 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ca107fa
feat: Tweak artifact for better compatiblity (WIP)
Oct 2, 2024
235dfd1
WIP
Oct 4, 2024
8761b56
Merge branch 'main' of https://github.com/newrelic/newrelic-quickstar…
mickeyryan42 Oct 4, 2024
c258063
Merge https://github.com/newrelic/newrelic-quickstarts into tweak-art…
mickeyryan42 Oct 7, 2024
6f2c054
chore: Update dasbhoard artifact
josephgregoryii Oct 7, 2024
7c8f58d
Merge branch 'tweak-artifact' of https://github.com/newrelic/newrelic…
mickeyryan42 Oct 7, 2024
c3163e9
chore: Update dasbhoard artifact
josephgregoryii Oct 7, 2024
10e7560
chore: Resolve conflicts
mickeyryan42 Oct 7, 2024
db839fe
fix: Quickstart schema
josephgregoryii Oct 7, 2024
c9d1d6f
Merge branch 'tweak-artifact' of https://github.com/newrelic/newrelic…
mickeyryan42 Oct 8, 2024
1b1462b
feat: Update alert artifact and schema
josephgregoryii Oct 8, 2024
12bc1a5
feat: Update dashboard to reflrect alert schema
josephgregoryii Oct 8, 2024
8591bc7
Merge branch 'tweak-artifact' of https://github.com/newrelic/newrelic…
mickeyryan42 Oct 9, 2024
20eddc1
chore: Cleanup classes and add jsdocs
josephgregoryii Oct 9, 2024
be33c35
chore: formatting
josephgregoryii Oct 9, 2024
9f6149c
chore: Remove data source ids from schema artifact
josephgregoryii Oct 9, 2024
0c04dba
chore: Add public signature to class method
josephgregoryii Oct 9, 2024
324d2fa
Merge branch 'tweak-artifact' of https://github.com/newrelic/newrelic…
mickeyryan42 Oct 9, 2024
2169e87
test: Update tests
josephgregoryii Oct 9, 2024
bcddaae
feat: Update alertPolicies to alertConditions
mickeyryan42 Oct 11, 2024
13f3515
Merge branch 'tweak-artifact' of https://github.com/newrelic/newrelic…
mickeyryan42 Oct 11, 2024
1028159
fix: Change alert type to undercase
josephgregoryii Oct 14, 2024
ad0308c
chore: Comments and cleanup
josephgregoryii Oct 15, 2024
e2a8020
fix: Lowercase support level for quickstart artifact
josephgregoryii Oct 15, 2024
0e28386
fix: Change authors to be a list of strings
josephgregoryii Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions utils/build-validate-quickstart-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Alert from "./lib/Alert";
import Dashboard, { DashboardConfig } from "./lib/Dashboard";
import Ajv, { type ErrorObject } from 'ajv';
import { QuickstartConfig, QuickstartConfigAlert } from './types/QuickstartConfig';
import { DataSourceConfig } from './types/DataSourceConfig';
import { passedProcessArguments } from './lib/helpers';
import { ArtifactDataSourceConfig } from './types/Artifact';

type ArtifactSchema = Record<string, unknown>;

Expand All @@ -21,7 +21,7 @@ type InvalidItem = {

type ArtifactComponents = {
quickstarts: QuickstartConfig[],
dataSources: DataSourceConfig[],
dataSources: ArtifactDataSourceConfig[],
alerts: QuickstartConfigAlert[][],
dashboards: DashboardConfig[]
}
Expand All @@ -38,10 +38,10 @@ const getSchema = (filepath: string): ArtifactSchema => {

// NOTE: we could run these in parallel to speed up the script
export const getArtifactComponents = (): ArtifactComponents => {
const quickstarts = Quickstart.getAll().map((quickstart) => quickstart.config);
const quickstarts = Quickstart.getAll().map((quickstart) => quickstart.transformForArtifact());
console.log(`[*] Found ${quickstarts.length} quickstarts`);

const dataSources = DataSource.getAll().map((dataSource) => dataSource.config);
const dataSources = DataSource.getAll().map((dataSource) => dataSource.transformForArtifact());
console.log(`[*] Found ${dataSources.length} dataSources`);

const alerts = Alert.getAll().map((alert) => alert.config);
Expand All @@ -51,14 +51,15 @@ export const getArtifactComponents = (): ArtifactComponents => {
console.log(`[*] Found ${dashboards.length} dashboards`);

return {
// @ts-ignore
quickstarts,
dataSources,
alerts,
dashboards
}
};

export const getDataSourceIds = (filepath: string, communityDataSources: DataSourceConfig[]): string[] => {
export const getDataSourceIds = (filepath: string, communityDataSources: ArtifactComponents['dataSources']): string[] => {
const coreDataSourceIds = yaml.load(
fs.readFileSync(filepath).toString('utf8')
) as string[];
Expand Down
51 changes: 51 additions & 0 deletions utils/lib/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
DataSourceInstallDirectiveInput,
DataSourceMutationVariable,
} from '../types/DataSourceMutationVariable';
import { ArtifactInstall, ArtifactInstallDirective } from '../types/Artifact';

export interface DataSourceMutationResponse {
dataSource: {
Expand Down Expand Up @@ -73,6 +74,29 @@ class DataSource extends Component<DataSourceConfig, string> {
return this._getYamlConfigContent();
}

public transformForArtifact() {
const { keywords, description, categoryTerms, icon, ...rest } = this.config;

return {
...rest,
iconUrl: this._getIconUrl(),
install: this._parseInstallsForArtifact(),
categoryTerms: categoryTerms ? categoryTerms.map((t) => t.trim()) : [],
keywords: keywords ? keywords.map((k) => k.trim()) : [],
description: description && description.trim(),
};
}

private _parseInstallsForArtifact() {
const { install } = this.config;

return {
primary: this._parseInstallDirectiveForArtifact(install.primary),
fallback:
install.fallback && this._parseInstallDirectiveForArtifact(install.fallback),
};
}

/**
* Get the variables for the **Quickstart** mutation.
*
Expand Down Expand Up @@ -189,6 +213,33 @@ class DataSource extends Component<DataSourceConfig, string> {
return directive;
}

/**
* Helper method that returns the directive, based on its type.
*/
private _parseInstallDirectiveForArtifact(
directive: DataSourceConfigInstallDirective
): ArtifactInstall {
if ('link' in directive) {
const { url } = directive.link;

return {
url: url?.trim() ?? '',
};
}

if ('nerdlet' in directive) {
const { nerdletId, nerdletState, requiresAccount } = directive.nerdlet;

return {
nerdletId: nerdletId?.trim() ?? '',
nerdletState: nerdletState,
requiresAccount: requiresAccount,
};
}

return directive;
}

static isDataSource(x: DataSource | undefined): x is DataSource {
return x !== undefined;
}
Expand Down
14 changes: 14 additions & 0 deletions utils/lib/Quickstart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ class Quickstart {
};
}

public transformForArtifact(): QuickstartConfig | { authors: { name: string }[] } {
josephgregoryii marked this conversation as resolved.
Show resolved Hide resolved
const config = {
...this.config,
// @ts-ignore
displayName: this.config.title,
icon: this._constructIconUrl(this.config.icon),
authors: this.config.authors.map((author) => ({ name: author })),
}

// @ts-ignore
delete config.title;
return config;
}

public async submitMutation(dryRun = true) {
logger.info(`Submitting mutation for ${this.identifier}`, { dryRun });
const { data, errors } = await fetchNRGraphqlResults<
Expand Down
Loading
Loading