meshnet-cni icon indicating copy to clipboard operation
meshnet-cni copied to clipboard

Add a read-only data api for external and cluster.local tools

Open Cerebus opened this issue 2 years ago • 11 comments

This is an initial implementation, but wanted to expose it here for comment and expansion.

The need I had was to dynamically visualize the meshnet topology, and since I already had Grafana deployed I wanted to use the Node Graph panel.

The quick and dirty way to approach this without writing my own complete datasource was to expose the list of topologies (by namespace) at a service API. The fastest way to do that was to just dump the JSON over a REST API, and use the JSON datasource to read and reshape it into something the Node Graph panel can read.

The examples/grafana/ directory has a simple dashboard that massages the TopologyList data and visualizes the result. The datasource simply taps http://meshnet:51112/v1/meshnet. The dashboard variable $namespace selects the namespace from which topos will be read. The "nodes" and "edges" queries provide the two required data frames, using path /topos/${namespace}.

Currently the only thing being visualized is the topology and the Pod status (via containerId; red for no container assigned; green for container assigned). Data is not cached (otherwise the colors don't update right).

A couple screenshots. A 4-node network (in a line, don't ask) at initial deployment: Screen Shot 2023-05-22 at 12 51 21 PM And again, after deleting pod lf1 (but not the topology): Screen Shot 2023-05-22 at 12 51 53 PM

This can be merged as-is, or hidden behind a feature flag, or refactored (see below) depending how you want to approach it.

I can also take this a different way; there's a generic gRPC data source. Using this would be more efficient (grpc-gateway not required) but has a bit more code to implement.

Cerebus avatar May 22 '23 17:05 Cerebus