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

Prettify provenance output #72

Merged
merged 1 commit into from
Sep 14, 2023
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
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"typescript.tsc.autoDetect": "off",
"cSpell.words": [
"eopa",
"norc",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Author Note: ensure VS Code cspell does not complain about the name of the table style used.

"picomatch",
"tsandall"
]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![slack](https://img.shields.io/badge/slack-styra-24b6e0.svg?logo=slack)](https://styracommunity.slack.com/)
[![Apache License](https://img.shields.io/badge/license-Apache%202.0-orange.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/Styra.vscode-styra?color=24b6e0)](#)
[![Coverage](https://img.shields.io/badge/Coverage-74%25-brightgreen)](#)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing this happened automatically. Interesting setup.

[![Coverage](https://img.shields.io/badge/Coverage-73%25-brightgreen)](#)
[![CI status](https://github.com/StyraInc/vscode-styra/actions/workflows/main.yaml/badge.svg)](https://github.com/StyraInc/vscode-styra/actions/workflows/main.yaml)
[![closed PRs](https://img.shields.io/github/issues-pr-closed-raw/StyraInc/vscode-styra)](https://github.com/StyraInc/vscode-styra/pulls?q=is%3Apr+is%3Aclosed)
<!--
Expand Down
29 changes: 25 additions & 4 deletions src/lib/eopaPreview/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,20 @@ export function formatResults(results: object, selection:boolean, raw?: boolean)
if (raw) {
return JSON.stringify(results, null, 2);
}
const r = results as {result: object, metrics: {[key: string]: number}, printed: string, provenance: object};
const r = results as {result: object, metrics: {[key: string]: number}, printed: string, provenance: {[key: string]: string | {[key: string]: object}}};

let output = '';

if (r.provenance) {
output += `PROVENANCE\n==========\n${JSON.stringify(r.provenance, null, 2)}\n\n`;
output += `PROVENANCE\n==========\n${getPrettyProvenance(r.provenance)}`;
}

if (r.metrics?.timer_query_compile_stage_resolve_refs_ns) {
output += `METRICS\n=======\n${metricTables(r.metrics)}`;
// output += `METRICS\n=======\n${Object.keys(r.metrics).map((k: string) => formatMetric(k, r.metrics[k])).join('\n')}\n\n`;
}

if (r.printed) {
output += `PRINTED\n=======\n${r.printed}\n\n`;
output += `PRINTED\n=======\n${r.printed}\n`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Bonus: There was an extra line added after printed lines because each ends with a new-line character. This cause three new lines instead of 2.

}

output += 'RESULT\n======\n';
Expand Down Expand Up @@ -353,6 +352,28 @@ export function getPrettyTime(ns: number): string {
return (ns / 1e3).toString() + 'µs';
}

function getPrettyProvenance(provenance: {[key: string]: string | {[key: string]: object}}): string {
let output = '';
Object.keys(provenance).forEach((k: string) => {
if (typeof provenance[k] !== 'string') {
return;
}
const niceKey = k.split('_').map((part: string) => part[0].toUpperCase() + part.substring(1)).join(' ');
output += `${niceKey}: ${provenance[k]}\n`;
});
output += '\n';

if (provenance.bundles && typeof provenance.bundles === 'object' && Object.keys(provenance.bundles).length > 0) {
const bundleData: Array<[string, string]> = [['Name', 'Revision']];
Object.keys(provenance.bundles).forEach((bundle) => {
const revision = (provenance.bundles as {[key: string]: {revision?: string}})[bundle].revision;
bundleData.push([bundle, revision || '']);
});
output += table(bundleData, {border: getBorderCharacters('norc'), columns: [{}, {width: 65, wrapWord: true}], header: {alignment: 'center', content: 'BUNDLES'}}) + '\n';
}
return output;
}

/**
* Reports a result to the Enterprise OPA Preview pane
*/
Expand Down