vectordotdev / vector

A high-performance observability data pipeline.
https://vector.dev
Mozilla Public License 2.0
17.08k stars 1.48k forks source link

Vector graph should support mermaidJS format #14082

Open bencooper222 opened 1 year ago

bencooper222 commented 1 year ago

A note for the community

Use Cases

MermaidJS graphing is natively supported by GitHub. Ex:

graph TD;
a --> b
b --> c
c --> a

It doesn't support the same syntax as graphviz unfortunately (see https://github.com/mermaid-js/mermaid/issues/5). Seeing as GitHub is a major place where these graphs are useful (i.e. in READMEs for documentation), vector graph should get a flag to specify output format.

Attempted Solutions

I wrote a basic remapping between DOT and MermaidJS's language:

const final = `graph TD;\n${str
  .slice()
  .split('\n')
  .filter(line => line.includes('->'))
  .join('\n')
  .replaceAll(`"`, '')
  .replaceAll('->', '-->')}`;

That's not perfect (it doesn't capture the shapes of each node) but it's pretty good for 5 minutes of effort and I think shows that adding this feature wouldn't be super hard.

Proposal

vector graph -> outputs in DOT vector graph --format DOT -> output in DOT vector graph --format mermaid -> outputs in mermaid vector graph --format not-real-format -> exit with error

References

No response

Version

vector 0.20.1 (aarch64-unknown-linux-gnu 38b806e 2022-04-07)

bencooper222 commented 1 year ago

(I'd be willing to work on this if there was some guarantee a good implementation would be accepted)

jszwedko commented 1 year ago

Hey @bencooper222 !

Thanks for the proposal! We'd be happy to accept this enhancement. I think the UX you laid-out makes sense: add a --format flag that defaults to dot.