How metrico/grafana-flow works
1. What this repository is
- The repo is centered on a Grafana 10+ panel plugin called grafana-flow.
- Its main job is to take query results from Grafana and render them as an interactive flow diagram / transaction flow view.
- The codebase also contains an Angular workspace (ngx-flow/) that appears to be a companion implementation/demo/legacy build path alongside the main Grafana plugin.
2. Main application boundary
- The primary production boundary is the root src/ tree, which is the Grafana plugin implementation.
- It is a frontend-only plugin: it runs inside Grafana’s panel runtime and uses Grafana plugin APIs rather than owning its own backend service.
- The plugin is declared via src/plugin.json and wired through src/module.ts.
3. Data flow into the plugin
- Grafana sends data frames / query results into the panel.
- Those results are transformed by helper code under src/helpers/dataProcessors/ into a list of flow items:
- parsing fields
- filtering items
- sorting/formatting items
- The resulting normalized data becomes the model consumed by the visualization and modal/detail views.
4. Visualization and interaction layer
- The main UI is split into focused components under src/components/:
- FlowPanel.tsx is the top-level panel renderer.
- FlowModal/ handles detailed drill-down for a selected flow item.
- FilterPanel/ provides user filtering and collapse/menu controls.
- CopyText/ handles copy-to-clipboard style interaction.
- PluginSettings/ provides Grafana editor controls for panel configuration.
- This separation suggests a clear architecture: panel rendering, selection/drill-down, filtering, and configuration are handled independently.
5. Domain model and packet logic
- The plugin includes domain-specific packet helpers in src/helpers/packets/:
- Ethernet
- IP
- TCP
- UDP
- This indicates the visualization is not just generic charting; it can interpret and present network/message flow semantics.
- Supporting utilities such as hash, uuid, and labelFormatter suggest stable identity, grouping, and human-readable labeling of flow elements.
6. Export and persistence helpers
- src/helpers/exporters/ contains exporters for:
- text
- pcap
- That means the plugin can convert displayed flow data into external formats for analysis or archival.
- saveAs.ts and date filename helpers support client-side file generation/download, so exporting is handled entirely in the browser/plugin layer.
7. Plugin settings architecture
- The panel exposes Grafana configuration via custom editors in src/components/PluginSettings/.
- MultiSelectEditor and TemplateEditor imply the plugin allows users to tune field mappings, labels, or template-driven behavior.
- This is important for the diagram because the plugin is partly schema/config-driven, not hardcoded to one data shape.
8. Angular subproject (ngx-flow/)
- ngx-flow/ is a separate Angular workspace with:
- a library package under projects/ngx-flow
- an application/demo under src/app
- an elements project for building custom elements/web components
- The library contains its own flow UI (tab-flow, transaction-filter, ngx-flow.service, message-details.service) and model types.
- Architecturally, this is a parallel UI stack to the React/Grafana plugin, likely used for standalone rendering or older integration paths.
9. Build and packaging
- The root plugin uses TypeScript + React with custom webpack configuration under .config/webpack/.
- The Angular workspace has its own Angular CLI/ng-package setup and custom build scripts (buildElements.sh, compileElements.js, elements-webpack.config.js).
- This repo therefore has two build systems: one for the Grafana plugin and one for the Angular workspace.
10. Testing and verification
- There is Jest setup for unit-style testing and Cypress smoke testing under cypress/integration/01-smoke.spec.ts.
- The presence of both suggests the repository validates:
- core data transformation logic
- UI behavior in-browser
- Mock files and test setup live at the repo root and under .config/, showing shared test infrastructure.
11. Deployment/runtime support
- docker-compose.yaml, root Docker/config files, and .github/workflows/ indicate the project supports containerized local development and CI/CD release automation.
- The README also documents installation as an unsigned Grafana plugin, which is a key operational constraint for deployment.
12. Grafana provisioning
- provisioning/datasources/ and provisioning/dashboards/ provide preset Grafana environment assets.
- This means the repo is designed not just as a plugin package, but also as a reproducible Grafana test/demo environment.
13. How to draw the architecture
- A good diagram would show:
- Grafana panel host on the left
- the React plugin UI in the center
- a data transformation layer between query results and rendering
- side paths for filtering, modal drill-down, settings, and export
- a separate, lower-priority box for the Angular ngx-flow workspace
- and supporting boxes for tests, build tooling, and Grafana provisioning
- The central flow is: Grafana query data → normalize/parse/filter → render flow diagram → interact/filter/drill down/export.
Main entry points: FlowPanel.tsx Flow panel · index.ts Data processors · formatAndSortFlowItems.ts Sort format · module.ts Module entry
Components 27
Grafana plugin
Main React/Grafana panel plugin runtime
- Plugin manifest · Declares the panel plugin to Grafana
src/plugin.json - Module entry · Registers the panel and wires plugin setup
src/module.ts - Flow panel · Top-level panel renderer for the flow diagram
src/components/FlowPanel.tsx - Data processors · Normalizes Grafana frames into flow items
src/helpers/dataProcessors/index.ts - Parse fields · Extracts fields from query results
src/helpers/dataProcessors/parseDataIntoListOfFields.ts - Filter items · Applies item-level filtering before render
src/helpers/dataProcessors/filterFlowItems.ts - Sort format · Formats and orders flow items for display
src/helpers/dataProcessors/formatAndSortFlowItems.ts - Flow modal · Detailed view for a selected flow item
src/components/FlowModal/FlowModal.tsx - Parsed view · Structured breakdown of parsed data and fields
src/components/FlowModal/ParsedView/ParsedView.tsx - Filter panel · User controls for filtering and collapsing flow views
src/components/FilterPanel/FilterPanel.tsx - Copy text · Copy-to-clipboard interaction for displayed content
src/components/CopyText/CopyText.tsx - Plugin settings · Grafana configuration editors for panel options
src/components/PluginSettings/index.ts - Exporters · Converts flow data into text or PCAP outputs
src/helpers/exporters/index.ts - Packet helpers · Ethernet, IP, TCP, and UDP helpers for network semantics
src/helpers/packets/ethernetPacket.ts - Shared utils · Hashing, UUIDs, labels, filenames, and save helpers
src/helpers/hash.ts
Angular workspace
Standalone companion UI/build path
- Library API · Exports the ngx-flow Angular package surface
ngx-flow/projects/ngx-flow/src/public-api.ts - Flow service · Central service for standalone Angular flow state
ngx-flow/projects/ngx-flow/src/lib/ngx-flow.service.ts - Ngx component · Library component wrapper for ngx-flow rendering
ngx-flow/projects/ngx-flow/src/lib/ngx-flow.component.ts - Tab flow · Standalone tabbed flow presentation
ngx-flow/projects/ngx-flow/src/tab-flow/tab-flow.component.ts - Txn filter · Transaction filtering UI and logic
ngx-flow/projects/ngx-flow/src/transaction-filter/transaction-filter.component.ts - Elements build · Compiles Angular elements into distributable outputs
ngx-flow/projects/elements/src/main.ts
Tooling
Build, test, CI, and provisioning support
- Webpack config · Custom webpack configuration for the Grafana plugin
.config/webpack/webpack.config.ts - Jest setup · Shared Jest configuration and mocks
.config/jest-setup.js - Smoke test · Browser smoke coverage for the plugin UI
cypress/integration/01-smoke.spec.ts - CI workflow · Automated build and verification workflow
.github/workflows/ci.yml - Provisioning · Prebuilt datasources and dashboards for local Grafana
provisioning/dashboards/default.yaml
Other components
- Grafana host · Grafana provides query results and panel lifecycle
Connections 31
- Grafana host → Plugin manifest: loads · Grafana discovers the panel plugin from its manifest
- Plugin manifest → Module entry: boots · Plugin metadata points to the module entry
- Module entry → Flow panel: renders · Module registers the panel UI
- Grafana host → Data processors: passes frames · Query results arrive as Grafana data frames
- Data processors → Parse fields: parse · Extract fields from incoming query data
- Data processors → Filter items: filter · Drop items that do not match current criteria
- Data processors → Sort format: shape · Format and order flow items for rendering
- Parse fields → Sort format: normalize · Parsed fields feed downstream shaping
- Filter items → Sort format: refine · Filtering constrains the final displayed list
- Sort format → Flow panel: feed · Normalized items drive the main visualization
- Flow panel → Flow modal: drill down · Selecting an item opens the detail modal
- Flow modal → Parsed view: inspect · Modal exposes structured parsed content
- Flow panel → Filter panel: controls · Panel exposes filtering and collapse controls
- Flow panel → Copy text: copy · Rendered content can be copied to clipboard
- Flow panel → Plugin settings: configure · Editor controls tune panel behavior
- Flow panel → Exporters: export · Displayed flow data can be exported
- Exporters → Shared utils: write files · Export flows use filename and save helpers
- Packet helpers → Exporters: pcap format · Packet helpers support PCAP generation semantics
- Module entry → Packet helpers: uses · Plugin logic interprets network packet semantics
- Library API → Ngx component: exports · Library API exposes the main component
- Library API → Flow service: exports · Library API exposes the shared service
- Ngx component → Tab flow: hosts · Library component organizes the flow view
- Tab flow → Txn filter: filters · Standalone Angular UI includes transaction filtering
- Flow service → Tab flow: serves state · Shared service coordinates flow view data
- Elements build → Library API: packages · Elements build compiles the Angular flow library
- Webpack config → Flow panel: bundles · Webpack builds the React plugin bundle
- Jest setup → Data processors: tests · Unit test harness supports transformation logic
- Smoke test → Flow panel: smokes · E2E smoke tests exercise the panel UI
- CI workflow → Webpack config: builds · CI runs the plugin build pipeline
- CI workflow → Jest setup: verifies · CI executes unit test infrastructure
- Provisioning → Grafana host: seeds · Provisioned dashboards and datasources create a demo Grafana environment