Skip to content

Conversation

tombrk
Copy link
Contributor

@tombrk tombrk commented Aug 26, 2021

Rather large PR implementing a (very basic) interactive editing flow.

Usage:

# run Grafana locally
$ docker run -p 3000:3000 grafana/grafana
$ export GRAFANA_URL=http://localhost:3000
$ export GRAFANA_TOKEN=<token>

# start the react ui (currently standalone)
$ cd pkg/edit/ui && yarn install && yarn start

# interactively edit the 'cert-manager' pop:
$ go run ./cmd/pop edit ./examples/cert-manager

Then visit http://localhost:3001 and edit the one dashboard. Changes made in Grafana will be reflected on disk.

Warning: Because the schema currently in main seems to lack the stat panel (ping @sdboyer), above actually leads to a CUE error. So either fix that schema, or revert to the previous one: git revert 9ab7ea1360a379c65df6199539f97ba3ca92bce1

Packages

  • pkg/api/grafana: intermediary Grafana client (wrapping https://github.com/grafana/grafana-api-golang-client) until we actually have a stable API client. Adds grafana.Watcher type for subscribing to change events
  • pkg/coord: utility package for coordinating shutdown of components using a context.Context.
  • pkg/edit: Editing in general
    • edit.Editor, edit.Grafana: Go structs performing editing sessions (e.g. subscribing to events, plumbing, etc)
    • edit.Server: gRPC-web server to expose edit.Editor capabilities to the frontend
    • edit.Check(): enforces dashboards are in their separate files, so that they can safely be replaced
  • pkg/edit/ui: React UI using gRPC-web to communicate with the Go server

Internals

Grafana pushes notifications over a special WebSocket API using centrifuge, when dashboards are saved. edit.Grafana uses a grafana.Watcher to be notified by that, queries the current dashboard model using the deprecated (but only) API client and saves it to disk.

edit.Server and edit.DashboardService implement a gRPC (and gRPC-web) server for interacting with this exact edit.Grafana, allowing easy control of the edit session.

Both the frontend and the backend use strongly typed gRPC messages, which fits nicely with the overall schema awareness of Polly

tombrk added 17 commits August 6, 2021 00:23
Adds initial and highly experimental support for converting pops to
mixins for somewhat easy integration into current pipelines.

Usage:
$ pop mix ./path/to/pop [-o yaml|json] [-s alerts|rules|grafana]
When invoked with `-s rules|alerts` we now include the `groups:` prefix
so that the output can directly be piped into Prometheus rule files
To overwrite changed dashboards safely these need to be in their
separate files.

pop edit now enforces that with information-rich error messages.
Makes `pop edit` create the (currently one and only) dashboard on some
Grafana instance (using a temp uid) and subscribes for change events.

Once exited (SIGINT), all temporary dashboards are cleaned up
Adds pkg/coord for coordinating graceful shutdown of
components (including cleanup) on actions like CTRL-C (SIGINT)
adds a http based interface to the edit package, so that a browser UI
can perform those actions
initially bootstraps a react based UI that lists the dashboards in the
Polly package and displays a respective Edit link (which actually works)
for each.
adds actually usable support for prometheus rules
@tombrk tombrk requested a review from sdboyer August 26, 2021 23:05
@tombrk tombrk marked this pull request as draft August 26, 2021 23:05
@tombrk tombrk marked this pull request as ready for review August 26, 2021 23:08
@sdboyer
Copy link
Member

sdboyer commented Sep 2, 2021

Because the schema currently in main seems to lack the stat panel (ping @sdboyer)

Quick note that i am actively working on a fix for this in grafana/grafana#38727 which will unblock a pile of things, this included. Right now it's looking rosy that i deal with a bunch of the fugly awkwardness around using scuemata from CUE, in fact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants