Grafana

@webship.co/workspace-grafana 1.0.0 · github.com/webship/workspace-grafana · npm

Grafana logo

Grafana for the Webship Workspace dashboard. It brings:

  • a builder that runs Grafana, the open-source observability platform, from its official image in a container of its own, and gives its admin the workspace's password;
  • the Grafana step pack wired into the testing setup of that app;
  • its AI items: two agents, a skill, a command and two prompts for building and testing Grafana apps, each listed in the workspace folder of its kind.

An app runs Grafana's official image, pinned by digest:

  • 13.3.2, the latest, by default;
  • 12.4.16, the last of 12.x, with --release 12.4.16.

Its data is the project's data/ folder and its provisioning the project's provisioning/ folder: what Grafana's own docs call /var/lib/grafana and /etc/grafana/provisioning. Nothing of Grafana runs on the machine: what the builder asks of the app (its admin's password, its checks) runs in the app's own container, and its database is copied and checked in a short-lived container of Python's official image, since Grafana's image has no SQLite tool.

The workspace is container-based (DDEV by default). An app is a row like any other, so the row menus the core draws (start, stop, launch, backup, restore, remove, tests) work on it. Its Backup and Restore go through the plugin's own database hook, with a consistent copy of its SQLite database.

The builder builds on DDEV by default, and with --runtime on Docker Compose, Podman or a Kubernetes cluster: see Runtimes. It needs Webship Workspace 1.0.42 or newer, the core with the database hook (webship/workspace#937), and says so on an older one before it makes anything.

Use it

cd ~/workspace
bash core/scripts/plugins.sh --require grafana --with-needs     # npm install into the dashboard
bash core/scripts/plugins.sh --activate grafana --with-needs    # plugins.grafana in settings.yml
bash core/scripts/plugins.sh --install grafana                  # the builder, functions, args, AI items, its settings file
bash core/scripts/plugins.sh --configure grafana                # its settings: TestData, analytics, the preinstalled plugins

The same four steps are buttons on the dashboard's Settings → Plugins page. --install is idempotent. --uninstall removes what it placed; an AI item you edited stays.

Everything the plugin carries lands in the folder it belongs to, when that folder is an active workspace folder:

What Lands in
cmd-grafana-project.sh every active sites folder: dev/, test/, sandboxes/, demos/
The agents grafana-app-builder, grafana-tester ai-agents/
The skill grafana-scenarios ai-skills/
The command /grafana-test ai-commands/
The prompts grafana-build-and-test, grafana-scenarios-for-an-app ai-prompts/
Its settings, plugin.grafana.settings.yml core/config/ (once; never overwritten)

There they are listed like any other item of the folder, and installed into Claude Code from there.

What it needs

A workspace starts empty, so the manifest says what else this plugin needs (needs):

  • One sites folder, for the builder: dev, test, sandboxes or demos (dev is the one added when none is there). The folder also carries cmd-tools-testing.sh, the Users tools and the backup script this plugin's hooks answer to.
  • ai-agents, ai-skills, ai-commands and ai-prompts: the AI folders its agents, its skill, its command and its prompts are placed in.

--require says so, --activate and --install stop until the workspace has them, and --with-needs adds what is missing first:

bash core/scripts/plugins.sh --activate grafana --with-needs   # dev and the four AI folders are required, activated and installed first
bash core/scripts/plugins.sh --install grafana

Everything the builder runs for an app runs in containers, through the container tool the workspace already needs; the plugin asks for no command of its own on the machine.

What the package holds

Path What it is
commands/cmd-grafana-project.sh The builder, in the Build list as Grafana (observability), installed into every sites folder
scripts/functions/fun-grafana.sh The bash functions behind it, sourced by bootstrap once installed. They hold the names the core's tools look for (set_grafana_users, add_grafana_users, cancel_grafana_users, testing_configure_grafana) and the database hook (grafana_is_project, grafana_export_db, grafana_import_db, grafana_db_extension).
scripts/args/arg-grafana.sh Its argparse; the Build form draws the builder's flags from it
scripts/docker-compose.grafana.yaml On DDEV, the app's service, copied into the project's .ddev/
scripts/grafana-db.py The copy and the check of the app's database, run in the short-lived container of Python's official image: VACUUM INTO while the app runs, the app's release marked on the copy, integrity_check, Grafana's tables, never a copy of a newer Grafana
config/plugin.grafana.settings.yml The template of its settings file
testing/site.feature The first feature an app gets when testing is set up
ai/agents/grafana-app-builder.md The agent that builds and fixes apps: their container, their data and provisioning, their database, their admin
ai/agents/grafana-tester.md The agent that writes and runs scenarios with the step pack
ai/skills/grafana-scenarios/ The skill: the step pack's phrases, the traps, four example features
ai/commands/grafana-test.md The slash command /grafana-test <app>: set up when missing, match every step, run, report
ai/prompts/grafana-build-and-test.md, grafana-scenarios-for-an-app.md Two prompts: whole launch commands for a new session
src/index.ts register(api): what the assistant is told about Grafana here
features/grafana.feature, features/grafana-runtimes.feature Scenarios for the dashboard's own browser suite

The workspacePlugin block in package.json is the manifest the installer reads. Its functions and its claim on a project are named grafana: cmd-tools-add-users.sh <name> grafana.

What is different from a platform

WordPress (a platform) Grafana
What is built A WordPress site A Grafana app, 13.3.2 (or 12.4.16), with its admin and the TestData data source
Project --project-type=wordpress --project-type=generic --webserver-type=generic, DDEV's database omitted: Grafana's own server serves it, on its own SQLite database
The image The container tool's Grafana's official image, pinned by digest, with its own start (/run.sh)
Its data — The project's data/ folder (its SQLite database, its search index) and provisioning/ folder, so they go with the project's backup
Recognised by The project type On DDEV a file the builder writes, .ddev/config.grafana.yaml; on another runtime its claim, platform: grafana in the x-webship block of compose.yaml
Accounts WP-CLI Grafana's own admin, its password given through Grafana's own command line
Backup and Restore DDEV's export-db and import-db The plugin's database hook: a consistent copy by SQLite (VACUUM INTO), checked before it is put back with the app stopped
Testing The WordPress pack The Grafana pack, which reads dashboards by their panels, sets their time range and variables, and waits on the app's own state

The commands

Run it from a sites folder. --help is safe.

Build and serve an app

cd ~/workspace/dev
bash cmd-grafana-project.sh graphs --install --add-users                     # Grafana 13.3.2, started, its admin given the workspace's password
bash cmd-grafana-project.sh graphs --install --add-users --release 12.4.16   # the last of 12.x
bash cmd-grafana-project.sh graphs --install --add-users --runtime docker    # on Docker Compose instead of DDEV
bash cmd-grafana-project.sh graphs --install --runtime kubernetes            # on the workspace's Kubernetes cluster
Flag What it does
--install Start the app (its first start makes its database and its admin, see below) and check that its database answers at its address (https://<name>.ddev.site on DDEV)
--add-users Give its admin the workspace's password too (see Its admin)
--release 13.3.2|12.4.16 The release to run, each from its official image pinned by digest (default: 13.3.2)
--runtime ddev|docker|podman|kubernetes The container runtime to build on (default: DDEV, or container.runtime of settings.yml); see Runtimes
--launch Open the app in a browser when it is ready

The builder works in this order:

  1. It deletes a project of the same name first: its containers and its data.
  2. It makes the project with its empty data/ folder and configures it.
  3. It writes its own folder, .webship-grafana/ (only you can read it): the release it runs and the script the database is copied with. It writes provisioning/ with Grafana's folders in it and, as the plugin's settings say, provisioning/datasources/testdata.yaml: the TestData data source, the default one, editable in the app's pages.
  4. With --install, it starts the app and waits until its health check says its database is ok. Its first start makes its database (data/grafana.db) and its admin, and reads the provisioning.
  5. With --add-users, it gives the admin the workspace's password, then checks the app: the admin signs in with it, and the TestData data source is there.

Its data and its database

The data is the project's data/ folder: /var/www/html/data in the app's container on every runtime. It holds Grafana's SQLite database (grafana.db: its dashboards, data sources, alert rules, accounts, annotations), its search index (unified-search/) and the plugins it installs (plugins/, empty with the preinstalled plugins off). On DDEV the app runs as the project's user, so these are the project's own files. On the other runtimes the web container runs it as the same user.

The row's Backup archives the project's folder, so the archive holds data/ and provisioning/. Its grafana.db is the live file, taken as it was mid-write: a file copied while Grafana writes it can hold half of a change. So the plugin declares the core's database hook (webship/workspace#937, core 1.0.42), which the row's Backup and Restore ask first, on every runtime:

  • Backup writes a consistent copy of the database beside the archive (<archive>-db.db.gz): SQLite's own VACUUM INTO, run in a short-lived container of Python's official image (pinned by digest), with the project's data/ mounted, as the project's user, without a network, removed after the run. VACUUM INTO reads the database in one transaction while the app runs: Grafana's SQLite is in rollback-journal mode, so a write of the app waits the moment the copy reads, and the copy waits for a write in progress. Grafana's database does not say which Grafana wrote it, so the copy carries the app's release in its header (SQLite's user_version, which Grafana leaves at 0). The copy is checked (integrity_check, Grafana's tables) and gzipped. The app need not run for it.
  • Restore from the backups list puts the archive back, starts the project, then imports that copy, over the archive's grafana.db. The row's Import does the same with a copy you choose. Either works in this order:
    1. It checks the copy: gzipped, SQLite's, then by the script in the short-lived container: whole, Grafana's, and not a copy of a newer Grafana than the app, by the release it carries (Grafana migrates an older one as it starts; a database with no release on it, not the plugin's copy, is taken as it is). The mark is taken off then, so the app gets its database as Grafana keeps it. A copy that is not one to put back leaves everything as it was.
    2. It stops the app, so nothing has its database open, and keeps the old database and the search index built from it aside.
    3. The copy takes grafana.db's place, and the app starts on it (and builds its search index again).
    4. Once its health check says its database is ok, the old files go; when it does not, they are put back and the app starts on them again.

A name ending in .sql.gz (the safety dump the core takes before a remove or a clone) gets the same copy: the plugin's import reads it under any name.

On a terminal, in the project's folder:

cd ~/workspace/dev/graphs
bash ~/workspace/core/scripts/runtime-verb.sh export-db --file=../graphs-before.db.gz
bash ~/workspace/core/scripts/runtime-verb.sh import-db --file=../graphs-before.db.gz

Proven with the row's own actions: the Backup and the Import on all four runtimes, the Restore from the backups list on DDEV and Docker Compose:

  • Backup: the archive (136 to 160K) held data/ with grafana.db; the plugin's copy beside it (104K) held the dashboard made before it. No copy was left in data/, nor a container of the copy.
  • The row's Import: a dashboard added after the Backup, the Import put the copy back, with the core's export of the app as it was taken first (it held both dashboards). The app then listed the one dashboard. It took 6 to 8 s on Docker Compose, Podman and Kubernetes, and 26 s on DDEV, which stops and starts the whole project.
  • The Restore from the backups list ends with the plugin's copy, not with the archive's database:
    • a dashboard was added after a Backup, and a second Backup taken;
    • the copy beside the second archive was then made the first Backup's, so the archive's own grafana.db held both dashboards and the copy beside it one;
    • after the row's Remove, the Restore of the second archive from the backups list ended with the copy's one dashboard.
  • Across the lines (DDEV): a copy of a 13.3.2 app is refused by a 12.4.16 app ("It is a copy of Grafana 13.3.2, newer than this app's 12.4.16: an app takes a copy of its own release or an older one."), which keeps its database. A copy of the 12.4.16 app goes into a 13.3.2 app: Grafana migrates it as it starts and lists the 12.4.16 app's dashboard.
  • A stop (the runtime menu's Stop): Grafana's own shutdown ("Shutdown started", reason "System signal: terminated") ends within a tenth of a second, its database passes integrity_check after it, and the next start answers. The runtimes' own stop takes 0.1 to 0.8 s off DDEV (DDEV's stops the whole project, in about 10 s).

Its settings: TestData, analytics and the preinstalled plugins

core/config/plugin.grafana.settings.yml holds three settings the builder applies to each app it makes:

Setting Default here Grafana's default What it is
testdata "on" none The TestData data source, the default one: made-up data (random walks, CSV values, logs, traces) that needs nothing outside the app, which the step pack's scenarios read. "off" makes an app with only the data sources added to it.
analytics "off" on Grafana's usage reports, its checks for updates of itself and of its plugins, and its news feed call out of the app. Off here: no call out of a test workspace. "on" turns them on.
preinstall "off" on At its first start Grafana downloads plugins from its catalogue into data/plugins, and takes the latest minor version of each again at every start: on 13.3.2 eight, 248 MB (the drilldown apps for logs, metrics, traces and profiles, the advisor, and newer CloudWatch, Prometheus and Tempo data sources); on 12.4.16 the four drilldown apps, 48 MB. Off leaves out the drilldown apps and the advisor; every data source type the image bundles stays (Prometheus, Loki, Tempo, Jaeger, CloudWatch, Elasticsearch, MySQL, PostgreSQL, TestData and the others). The app runs what its image holds, the same at every start, and the row's Backup stays 250 MB smaller. "on" downloads them again, for the drilldown apps and the advisor.

They are applied when an app is built: build it again to change them (provisioning/datasources/testdata.yaml, and .ddev/.env on DDEV, show what an app has).

Test an app

bash cmd-tools-testing.sh graphs                                  # webship-js, the step pack, the account, a first feature
bash cmd-tools-testing.sh graphs --run --path tests/features/site.feature

The testing setup does five things:

  • adds @webship-js/grafana-steps to the project, with webship-js 2.0.20 or newer, and lists the pack's step definitions in cucumber.js;
  • gives the suite the app's address;
  • adds the account the scenarios name: admin, its password from GRAFANA_ADMIN_PASSWORD (the workspace's by default), as the pack's own tests take it;
  • leaves out the browser's errors for the requests Grafana makes and expects to fail, by their address (javascript.ignore, as the pack's own suite does): 13.3's user storage before it holds anything (404), its quotas' usage on a server without quotas (501), the plugin catalogue's version of a built-in plugin (404), and a refused sign-in (401). Any other error is still reported. An ignore the project has of its own is left as it is;
  • writes tests/features/site.feature.

It changes nothing in a project that is not an app of this builder.

Every page of the app needs JavaScript. Its HTTP API answers without it.

Feature: The first dashboard
  Scenario: A dashboard made from JSON shows its panel
    Given I am signed in to the observability platform as "admin"
    When I make the dashboard "Webship test first" from this JSON:
      """
      { "uid": "webship-test-first", "panels": [ { "id": 1, "type": "stat", "title": "Orders total",
        "datasource": { "type": "grafana-testdata-datasource", "uid": "testdata" },
        "targets": [ { "refId": "A", "scenarioId": "csv_content", "csvContent": "orders\n49" } ] } ] }
      """
    And I open the observability platform's dashboard "Webship test first"
    Then the panel "Orders total" should show "49"
    When I delete the observability platform's dashboard "Webship test first"
    Then the dashboards should not list "Webship test first"

Runtimes

The commands are the same on every runtime. The builder speaks DDEV's verbs, and on another runtime the core's layer gives each verb its meaning there (webship/workspace#694 and #841):

  • the app's image is the stack, its entrypoint cleared (ENTRYPOINT []): the runtime's own start runs as it is;
  • the web container runs the image's own start, /run.sh, as the host user, on the project's data/ and provisioning/, with the plugin's settings.
Runtime The address of the app Where the data is Proven with this builder
DDEV (the default) https://<name>.ddev.site <project>/data (the app's /var/www/html/data) Built and served in 50 to 58 s with the image already pulled, the app a service of the project and DDEV's db omitted; its admin given the workspace's password, TestData the default data source; data/ 1.7 MB, no plugin downloaded; its files the project user's, the server run as that user with the plugin's settings in its environment; a stop and the database after it; the row's Backup and Import, and the Restore from the backups list; a copy of 13.3.2 refused by a 12.4.16 app (built in 52 s), and one of 12.4.16 taken by 13.3.2; the testing setup from npm (grafana-steps 2.0.1, webship-js 2.0.20) and its first feature (4 scenarios, 15 steps), twice; the skill's four examples (8 scenarios, 51 steps)
Docker Compose (--runtime docker) http://127.0.0.1:<port>, a free port kept in compose.yaml <project>/data (in the web container: /var/www/html/data) Built in 11 to 21 s, the web image built on the app's; the same checks, the server run as www-data, the host user; a stop in 0.6 s; the row's menu with Export, Import and Backup, the same Backup and Import, and the Restore from the backups list; the testing setup and its first feature, twice; the skill's four examples, twice
Podman (--runtime podman) http://127.0.0.1:<port> <project>/data Built in 4 min, the image taken into Podman's own storage on that first build; the same checks; a stop in 0.8 s; the row's menu, the same Backup and Import, the copy made with Podman as the project's user (--userns=keep-id)
Kubernetes (--runtime kubernetes) http://<node address>:<NodePort> <project>/data too: the web pod mounts the project's folder by hostPath (see below) On kind: built in about 3 min (the web image built by Docker on the app's image and loaded into the node), served at the node's address; the same checks; a stop and the database after it, the pod's log read through the cluster; the row's menu, the same Backup and Import, the copy made on this machine from the folder the pod writes; the testing setup on the cluster and its first feature, twice

On Kubernetes the data is in the project too. The web pod mounts the project's folder at /var/www/html by hostPath, and the app's data is its data/. The workspace's kind cluster has /home mounted into its node at the same path (and the workspace's root when it lives elsewhere), so the hostPath is the project's folder on this machine: the database the app writes in its pod is <project>/data/grafana.db here, and the row's Backup and the plugin's copy read it, as on the other runtimes. On a cluster of your own (WORKSPACE_KUBE_CONTEXT), the hostPath is a folder of the node the pod runs on: the data is in this machine's project only when that node sees this machine's folder at the same path.

A project of the builder is known by DDEV's file on DDEV and by its claim on another runtime. So the testing setup, the Users tools, the database hook and the dashboard's row work the same on each. Lando and Docksal are runtimes of the workspace too, not proven with this builder yet: it says so and stops, before anything is made.

Its admin

Account Made by
admin Grafana itself, at its first start; --add-users, or cmd-tools-add-users.sh <name> grafana, gives it the workspace's password through Grafana's own command line

The admin gets the workspace's password, which the builder never prints: it reaches Grafana's command line on its input, never on a command line, and the check after it gives it to curl on its input too. Built without --add-users, the admin has Grafana's own first password, which Grafana asks to change at the first sign-in.

cmd-tools-cancel-users.sh <name> grafana changes nothing: the admin stays, and it says so.

The AI items

Item Kind What it is for
grafana-app-builder agent Builds and fixes Grafana apps: their container, their data and provisioning, their database and its copies, their admin, their settings, what to read when one does not answer
grafana-tester agent Writes and runs scenarios with the step pack: signing in, dashboards by their titles and panels, the time range and variables, data sources, Explore, alert rules, the API, test content deleted, never a fixed wait
grafana-scenarios skill The step pack's phrases, the traps of the two lines, four example features
/grafana-test <app> command Sets the pack up when missing, matches every step, runs, reports
grafana-build-and-test prompt Builds an app and proves it with its first feature
grafana-scenarios-for-an-app prompt Writes and runs the scenarios of an app of the workspace: its dashboards, its data sources, Explore, its alert rules, its API

Every item says the workspace is container-based (DDEV by default), and the agents and the skill send the reader to the book Automated Functional Testing Recipes first.

Develop it

npm install
npm test        # builds, then the unit tests: the manifest, the scripts (run with stand-ins), the AI items, the needs
npm run lint    # the TypeScript compiler, no output

CI runs the same on Node.js 24 and 26, and checks that every shell script parses. It also runs the plugin's webship-js features against a dashboard with the plugin installed (the reusable workflow webship/workspace/.github/workflows/plugin-browser-suite.yml):

  • before the features it builds the app the manifest names (featuresSite: cmd-grafana-project.sh ci-grafana --install --add-users --runtime docker);
  • so the scenarios of features/grafana-runtimes.feature tagged @needs-runtime-docker drive a real app on Docker Compose;
  • the Podman and Kubernetes ones run where such an app is.

tests/fixtures/step-definitions.txt holds the step definitions of the step pack and of webship-js, read from their packages: every phrase an AI item shows must match one of them.

License

ISC (see LICENSE).

The logo is Grafana's mark from Simple Icons (grafana, CC0-1.0), filled with the colour Simple Icons lists for the brand, #F46800, so it reads on a light and a dark page. Grafana and its mark are Grafana Labs': the logo names the software the plugin builds. It is not covered by this package's licence.