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

Dashboard arm #718

Merged
merged 9 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .changeset/warm-wasps-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@azure-tools/cadl-ranch-coverage-sdk": minor
"@azure-tools/cadl-ranch-dashboard": minor
"@azure-tools/cadl-ranch": minor
---

Add dashboard for Azure Resource Manager.
5 changes: 4 additions & 1 deletion packages/cadl-ranch-coverage-sdk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const GeneratorMode: string[] = ["azure", "standard"];
export enum GeneratorMode {
azure = "azure",
standard = "standard",
}
6 changes: 3 additions & 3 deletions packages/cadl-ranch-dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
## Dev

```bash
npm start
npm run start
# or
npm dev
npm run dev
```

## Show the test generator

Add `?showtest=true` query parameter to url https://localhost:5173/?showtest=true
Add `?showtest=true` query parameter to url http://localhost:5173/?showtest=true
54 changes: 32 additions & 22 deletions packages/cadl-ranch-dashboard/src/apis.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
CadlRanchCoverageClient,
GeneratorMode,
ResolvedCoverageReport,
ScenarioData,
ScenarioManifest,
GeneratorMode,
} from "@azure-tools/cadl-ranch-coverage-sdk";
import { TableConfig, TableConfigs } from "./constants.js";

const storageAccountName = "azuresdkcadlranch";

Expand Down Expand Up @@ -35,7 +37,7 @@ const generatorNames: GeneratorNames[] = [
export interface CoverageSummary {
manifest: ScenarioManifest;
generatorReports: Record<GeneratorNames, ResolvedCoverageReport | undefined>;
mode: string;
tableConfig: TableConfig;
}

let client: CadlRanchCoverageClient | undefined;
Expand All @@ -57,34 +59,42 @@ export async function getCoverageSummaries(): Promise<CoverageSummary[]> {
coverageClient.manifest.get(),
loadReports(coverageClient, generatorNames),
]);
return GeneratorMode.map((mode) => ({
manifest,
generatorReports: generatorReports[mode],
mode,
}));
return TableConfigs.map((config) => {
const copiedManifest: ScenarioManifest = JSON.parse(JSON.stringify(manifest));
copiedManifest.scenarios = manifest.scenarios.filter((scenarioData: ScenarioData) =>
config.scenarioFilter ? config.scenarioFilter(scenarioData.name) : () => true,
);
return {
manifest: copiedManifest,
generatorReports: generatorReports[config.mode],
tableConfig: config,
};
});
}

async function loadReports(
coverageClient: CadlRanchCoverageClient,
generatorNames: GeneratorNames[],
): Promise<{ [mode: string]: Record<GeneratorNames, ResolvedCoverageReport | undefined> }> {
const results = await Promise.all(
GeneratorMode.map(async (mode): Promise<[string, Record<GeneratorNames, ResolvedCoverageReport | undefined>]> => {
const items = await Promise.all(
generatorNames.map(async (generatorName): Promise<[GeneratorNames, ResolvedCoverageReport | undefined]> => {
try {
const report = await coverageClient.coverage.getLatestCoverageFor(generatorName, mode);
return [generatorName, report];
} catch (error) {
// eslint-disable-next-line no-console
console.error("Error resolving report", error);
Object.keys(GeneratorMode).map(
async (mode): Promise<[string, Record<GeneratorNames, ResolvedCoverageReport | undefined>]> => {
const items = await Promise.all(
generatorNames.map(async (generatorName): Promise<[GeneratorNames, ResolvedCoverageReport | undefined]> => {
try {
const report = await coverageClient.coverage.getLatestCoverageFor(generatorName, mode);
return [generatorName, report];
} catch (error) {
// eslint-disable-next-line no-console
console.error("Error resolving report", error);

return [generatorName, undefined];
}
}),
);
return [mode, Object.fromEntries(items) as any];
}),
return [generatorName, undefined];
}
}),
);
return [mode, Object.fromEntries(items) as any];
},
),
);

return results.reduce<{ [mode: string]: Record<GeneratorNames, ResolvedCoverageReport | undefined> }>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,15 @@ const DashboardHeaderRow: FunctionComponent<DashboardHeaderRowProps> = ({ covera
}
return [language, getCompletedRatio(coverageSummary.manifest.scenarios, report), report];
});
let tableHeader;
if (coverageSummary.tableConfig.name) {
tableHeader = <th>Scenario name ({coverageSummary.tableConfig.name})</th>;
} else {
tableHeader = <th>Scenario name ({coverageSummary.tableConfig.mode})</th>;
}
return (
<tr>
<th>Scenario name (mode: {coverageSummary.mode})</th>
{tableHeader}
{data.map(([lang, status, report]) => (
<GeneratorHeaderCell key={lang} status={status} report={report} language={lang} />
))}
Expand Down Expand Up @@ -286,5 +292,19 @@ function createTree(manifest: ScenarioManifest): ManifestTreeNode {

current.scenario = scenario;
}
return root;

return cutTillMultipleChildren(root);
XiaofeiCao marked this conversation as resolved.
Show resolved Hide resolved
}

function cutTillMultipleChildren(node: ManifestTreeNode): ManifestTreeNode {
let newRoot: ManifestTreeNode = node;
while (newRoot.children) {
if (Object.keys(newRoot.children).length === 1) {
newRoot = Object.values(newRoot.children)[0];
} else {
break;
}
}

return newRoot;
}
21 changes: 21 additions & 0 deletions packages/cadl-ranch-dashboard/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GeneratorMode } from "@azure-tools/cadl-ranch-coverage-sdk";

export const Colors = {
bgSubtle: "#f7f7f7",
borderDefault: "#f0f0f0",
Expand Down Expand Up @@ -38,3 +40,22 @@ export const ScenarioStatusColors = {
notSupported: Colors.borderDefault,
fail: Colors.error,
};

export const TableConfigs: TableConfig[] = [
{
mode: GeneratorMode.azure,
scenarioFilter: (name) => !name.startsWith("Azure_ResourceManager_"),
name: "Azure DPG",
},
{ mode: GeneratorMode.azure, scenarioFilter: (name) => name.startsWith("Azure_ResourceManager_"), name: "Azure MPG" },
{
mode: GeneratorMode.standard,
scenarioFilter: (name) => !name.startsWith("Azure_ResourceManager_"),
},
];

export interface TableConfig {
mode: GeneratorMode;
scenarioFilter?: (scenarioName: string) => boolean;
name?: string;
}
2 changes: 1 addition & 1 deletion packages/cadl-ranch/src/coverage/scenario-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export function createScenarioManifest(
};
return { name, scenarioDoc, location };
}),
modes: GeneratorMode,
modes: Object.values(GeneratorMode),
};
}
Loading