Commit Graph

30 Commits

Author SHA1 Message Date
Serge Zaitsev
18e93c7077
Chore: Remove bus (#47511)
* Chore: Remove bus

* remove unused const
2022-04-08 16:15:06 +02:00
idafurjes
7936c4c522
Rename AddHandlerCtx to AddHandler (#43557) 2021-12-28 16:08:07 +01:00
idafurjes
bb01f8c4cf
Chore: Add context dashboard version (#41672)
* Add context dashboard version

* Fix codeql
2021-11-17 10:57:37 +01:00
Arve Knudsen
b5379c5335
Chore: Fix SQL related Go variable naming (#28887)
* Chore: Fix variable naming

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2020-11-11 06:21:08 +01:00
Dan Cech
2ecc7f22b9
delete old dashboard versions in multiple batches (#23348) 2020-04-06 11:44:14 -04:00
Carl Bergquist
f9962eabff
chore: avoid aliasing imports in services (#22499) 2020-02-29 13:35:15 +01:00
Marcus Efraimsson
f845a3b841
upgrade xorm packages to latest versions 2019-03-05 21:11:23 +01:00
Alexander Zobnin
0ffcea08c7 dashboard version cleanup: more tests and refactor 2018-03-22 15:18:05 +03:00
Alexander Zobnin
2ade0881b1 minor refactor of dashboard version cleanup 2018-03-21 22:48:17 +03:00
Alexander Zobnin
3f85fcce2d refactor: dashboard version cleanup 2018-03-21 21:01:15 +03:00
Alexander Zobnin
f976b690ca limit number of rows deleted by dashboard version cleanup 2018-03-21 20:26:27 +03:00
Alexander Zobnin
fc2d1d6ca9 fix dashboard version cleanup on large datasets 2018-03-21 17:23:05 +03:00
Daniel Lee
fe49182b9d snapshots: fixes cleanup of old snapshots
Snapshot cleanup did not work due to time.Now syntax error. Added test
for it as well to catch any future errors.

Added error and debug logging so that it is possible to see any errors in the future.

Removed an unused configuration value and deprecated the remove expired snapshots
setting.
2018-02-22 16:12:16 +01:00
Torkel Ödegaard
0e44fe082b Merge branch 'master' into develop 2017-11-17 15:49:17 +01:00
Torkel Ödegaard
98b4074c16 refactoring: minor refactor of clean up dashboard history PR #9882 2017-11-17 14:41:44 +01:00
Alexander Zobnin
a55be07ea5 dashboard history clean up: avoid potential SQL injections 2017-11-17 10:51:50 +03:00
Alexander Zobnin
a0a1f4aacd dashboard history: refactor after review 2017-11-15 13:36:36 +03:00
Alexander Zobnin
08e2bbef83 dashboard history: clean up dashboard version history 2017-11-14 18:22:18 +03:00
Torkel Ödegaard
cbbbccf12a refactoring dashoard folder guardian 2017-06-17 18:24:38 -04:00
Torkel Ödegaard
08b37186a5 fix: fixed failing sql unit test 2017-06-07 15:42:48 +02:00
Torkel Ödegaard
46412c8475 dasboard_history: security fix, added orgId filter to dashboard version lookup 2017-06-07 14:21:40 +02:00
Torkel Ödegaard
7b5f7ed553 dashboard_history: SQL did not work when using MySQL, fixes to dashboard version numbering, so inserts start at 1, added migration to fix old dashboards with version 0 2017-06-06 15:40:10 +02:00
Torkel Ödegaard
e2061312f5 refactoring: moved compare dashboard version command out of sqlstore, the code in this command did not use any sql operations and was more high level, could be moved out and use existing queries to get the versions 2017-06-06 00:15:40 +02:00
Torkel Ödegaard
746d6cdc88 refactoring: changed name on compare command to make properties more explainatory 2017-06-05 23:29:25 +02:00
Torkel Ödegaard
c87418d060 refactoring: Dashboard history restore operation is now reusing existing
operations instead of duplicating a bunch of get & save logic.
2017-06-05 17:45:27 +02:00
Torkel Ödegaard
c296ae1178 refactoring: fixing unit tests broken in last commit 2017-06-05 16:52:36 +02:00
Torkel Ödegaard
e18007153d refactoring: Renamed dashboard version queries that wrongly had Command suffix, added missing OrgId to dashboard history commands and queries 2017-06-05 16:34:32 +02:00
sanchitraizada
77c046aac6 Implement review feedback 2017-06-01 17:57:09 -04:00
Ben Tranter
a927b893ae Use DBSession for getMaxVersion 2017-05-25 23:04:00 -04:00
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