grafana/pkg/models
Ben Tranter b6e46c9eb8 History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.

Goals

1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.

Usage

Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.

Overview of Changes

Backend Changes

- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.

Frontend Changes

- New views
- Methods to pull JSON and HTML from endpoints

New API Endpoints

Each endpoint requires the authorization header to be sent in
the format,

```
Authorization: Bearer <jwt>
```

where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.

`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`

Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:

- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from

`GET "/api/dashboards/db/:dashboardId/versions/:id"`

Get an individual dashboard version by ID, for the given
dashboard ID.

`POST "/api/dashboards/db/:dashboardId/restore"`

Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.

```json
{
  "dashboardId": <int>,
  "version": <int>
}
```

`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`

Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.

Dependencies Added

- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
2017-05-24 19:14:39 -04:00
..
address.go feat(organization): added update org address to http api and to org details settings view, closes #2672 2015-09-08 14:22:44 +02:00
alert_notifications.go tech(notifications): splitt into 3 queries 2016-09-06 08:43:15 +02:00
alert_test.go feat(alerting): add alert message to slack integration 2016-08-12 10:12:04 +02:00
alert.go alerting: dedupe alert notifications when running multiple servers 2017-02-21 16:54:49 +01:00
apikey.go HTTP API: grafana /render calls nows with api keys, Fixes #1649 2015-04-08 08:59:12 +02:00
dashboard_snapshot.go refactor(backend): refactoring management of go routines in backend 2016-09-28 21:06:00 +02:00
dashboard_version.go History and Version Control for Dashboard Updates 2017-05-24 19:14:39 -04:00
dashboards_test.go refactor(): refactoring json usage 2016-03-12 00:13:06 +01:00
dashboards.go History and Version Control for Dashboard Updates 2017-05-24 19:14:39 -04:00
datasource_cache_test.go Config Array Syntax (#8204) 2017-04-25 09:14:29 +02:00
datasource_cache.go Use cache for http.client in tsdb package. (#6833) 2016-12-07 11:10:42 +01:00
datasource.go mysql: improved mysql data source, added test feature when adding data source, fixed cache issue 2017-05-11 10:50:24 +02:00
health.go feat: added api health endpoint that does not require auth and never creates sessions, returns db status as well. #3302 2017-04-25 17:17:45 +02:00
helpflags.go ux(getting started): progress on getting started panel and persited help flag states, #6466 2016-11-09 10:41:39 +01:00
home_dashboard.go Worked on home dashboard 2015-02-03 15:04:35 +01:00
models.go support logging in with grafana.net credentials 2016-09-19 16:48:07 -04:00
notifications.go fix: better error handling / messsage when testing email notification when stmp is not configured, fixes #8093 2017-04-25 13:16:41 +02:00
org_user.go fix(plugins): only add app nav link if it has any pages/dashboards with role matching current user, fixes #4784 2016-04-25 14:00:49 +02:00
org.go feat(organization): added update org address to http api and to org details settings view, closes #2672 2015-09-08 14:22:44 +02:00
playlist.go fix(playlist): fixed sorting issue with playlist playback, fixes #5467 2016-09-22 10:06:03 +02:00
plugin_settings.go refactor(securejsondata): extract to class 2016-11-24 13:22:25 +01:00
preferences.go feat(preferences): theme and home dashbord settings now work work on profile and org settings page 2016-04-02 13:54:06 -07:00
quotas.go move toMap function to be a method on the quota structs 2015-09-15 17:18:26 +08:00
search.go Major refactorings around searching, moved to seperate package, trying to move stuff out of models package, extend search support searching different types of entities and different types of dashboards, #960 2015-05-13 13:36:24 +02:00
server.go tech(server): remove unused code 2017-02-17 10:18:11 +01:00
star.go Added isStarred to search result hit, very inefficient loading right now but can be cached later on 2015-02-05 09:49:00 +01:00
stats.go feat(stats): add alerts to global admin stats 2016-11-11 14:04:38 +01:00
streams.go mergefix(): fixed issue with master merge 2017-01-31 09:00:36 +01:00
temp_user.go feat(signup): progress on new sign up and email verification flow, #2353 2015-08-28 15:14:24 +02:00
test_data.go mysql: minor progress on response processing 2017-03-31 11:45:25 +02:00
user.go use X-Grafana-Org-Id header to ensure backend uses correct org (#8122) 2017-04-14 15:47:39 +02:00