AlgoViz

Grafana

easy 26 min

Grafana is a web application that queries many kinds of stores, draws the answers on dashboards and evaluates alert rules on them.

See it run

A dashboard opens, a step is chosen, a variable changes, a rule runs, and screens make load.

Operations

A dashboard opens

One panel on Prometheus, one on PostgreSQL.

Step 1 of 5

Load the page

Our systemBrowserGrafanaIts own databasedashboard JSONPrometheusPostgreSQL

The dashboard comes from Grafana's own database. There are no measurements in it.

Step 1: Load the page

def open_dashboard(uid):    dash = own_db.load(uid)    for panel in dash.panels:        q = fill(panel.query, variables, time_range)        frame = source(panel).query(q, credentials)        browser.draw(transform(frame))
When
At each refresh
Who does the work
The stores

An empty panel is a question for the store first.

In the real world

The same grafana doing real jobs. Pick one and step through it.

Prometheus stops during an incident.

Step 1 of 3

Both answer

Our systemBrowser2 panelsGrafanaIts own databasePrometheusPostgreSQL

Metrics on the left, orders on the right.

Step 1: Both answer

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Trusting the Viewer role with secrets

    critical

    By default any user can send any query to any data source of the organization.

    Wrong
    data source user: adminrole of people: Viewer
    Right
    data source user: read only,only the tables all may see
  • Two servers on SQLite

    major

    Each has its own file: dashboards and sessions differ.

    Wrong
    [database]type = sqlite3   # on both
    Right
    [database]type = postgres  # one, shared
  • A fixed short rate window

    major

    With slower scrapes or a longer range the panel has gaps or misses peaks.

    Wrong
    rate(x_total[30s])
    Right
    rate(x_total[$__rate_interval])
  • Refresh every five seconds

    major

    Panels times screens makes load that nobody reads.

    Wrong
    refresh: 5s  # hourly data
    Right
    refresh: 5mmin_refresh_interval = 30s
  • A copy for every service

    minor

    Twelve copies drift apart and each fix is made twelve times.

    Wrong
    cart, pay, search: 3 copies
    Right
    one dashboard, $service

Interview tips

  • How to explain it

    • It asks other stores.
    • It draws what they answer.
    • It keeps only its own settings.
  • Where state lives

    • Measurements: the stores.
    • Dashboards, users, rules: its database.
    • Secrets: encrypted with secret_key.
  • Reach for it when

    • Several stores need one view.
    • Dashboards should be code.
    • Prometheus needs a screen.
  • Before production

    • Change admin / admin.
    • PostgreSQL instead of SQLite.
    • Read-only accounts for data sources.