diff --git a/docs/sources/http_api/alerting.md b/docs/sources/http_api/alerting.md index 3860ae490b1..4d52105cf3c 100644 --- a/docs/sources/http_api/alerting.md +++ b/docs/sources/http_api/alerting.md @@ -49,18 +49,15 @@ Content-Type: application/json { "id": 1, "dashboardId": 1, + "dashboardUId": "ABcdEFghij" + "dashboardSlug": "sensors", "panelId": 1, "name": "fire place sensor", - "message": "Someone is trying to break in through the fire place", "state": "alerting", + "message": "Someone is trying to break in through the fire place", + "newStateDate": "2018-05-14T05:55:20+02:00", "evalDate": "0001-01-01T00:00:00Z", - "evalData": [ - { - "metric": "fire", - "tags": null, - "value": 5.349999999999999 - } - "newStateDate": "2016-12-25", + "evalData": null, "executionError": "", "url": "http://grafana.com/dashboard/db/sensors" } @@ -88,16 +85,35 @@ Content-Type: application/json { "id": 1, "dashboardId": 1, + "dashboardUId": "ABcdEFghij" + "dashboardSlug": "sensors", "panelId": 1, "name": "fire place sensor", - "message": "Someone is trying to break in through the fire place", "state": "alerting", - "newStateDate": "2016-12-25", + "message": "Someone is trying to break in through the fire place", + "newStateDate": "2018-05-14T05:55:20+02:00", + "evalDate": "0001-01-01T00:00:00Z", + "evalData": "evalMatches": [ + { + "metric": "movement", + "tags": { + "name": "fireplace_chimney" + }, + "value": 98.765 + } + ], "executionError": "", "url": "http://grafana.com/dashboard/db/sensors" } ``` +**Important Note**: +"evalMatches" data is cached in the db when and only when the state of the alert changes +(e.g. transitioning from "ok" to "alerting" state). + +If data from one server triggers the alert first and, before that server is seen leaving alerting state, +a second server also enters a state that would trigger the alert, the second server will not be visible in "evalMatches" data. + ## Pause alert `POST /api/alerts/:id/pause` diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index acf46a193e8..d460b27a679 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -312,7 +312,7 @@ class MetricsPanelCtrl extends PanelCtrl { getAdditionalMenuItems() { const items = []; - if (this.datasource.supportsExplore) { + if (this.datasource && this.datasource.supportsExplore) { items.push({ text: 'Explore', click: 'ctrl.explore();', diff --git a/public/app/features/panel/specs/metrics_panel_ctrl.jest.ts b/public/app/features/panel/specs/metrics_panel_ctrl.jest.ts new file mode 100644 index 00000000000..f2e5199b57d --- /dev/null +++ b/public/app/features/panel/specs/metrics_panel_ctrl.jest.ts @@ -0,0 +1,65 @@ +jest.mock('app/core/core', () => ({})); + +import { MetricsPanelCtrl } from '../metrics_panel_ctrl'; +import q from 'q'; +import { PanelModel } from 'app/features/dashboard/panel_model'; + +describe('MetricsPanelCtrl', () => { + let ctrl; + + beforeEach(() => { + ctrl = setupController(); + }); + + describe('when getting additional menu items', () => { + let additionalItems; + + describe('and has no datasource set', () => { + beforeEach(() => { + additionalItems = ctrl.getAdditionalMenuItems(); + }); + + it('should not return any items', () => { + expect(additionalItems.length).toBe(0); + }); + }); + + describe('and has datasource set that supports explore', () => { + beforeEach(() => { + ctrl.datasource = { supportsExplore: true }; + additionalItems = ctrl.getAdditionalMenuItems(); + }); + + it('should not return any items', () => { + expect(additionalItems.length).toBe(1); + }); + }); + }); +}); + +function setupController() { + const injectorStub = { + get: type => { + switch (type) { + case '$q': { + return q; + } + default: { + return jest.fn(); + } + } + }, + }; + + const scope = { + panel: { events: [] }, + appEvent: jest.fn(), + onAppEvent: jest.fn(), + $on: jest.fn(), + colors: [], + }; + + MetricsPanelCtrl.prototype.panel = new PanelModel({ type: 'test' }); + + return new MetricsPanelCtrl(scope, injectorStub); +} diff --git a/public/app/plugins/datasource/influxdb/response_parser.ts b/public/app/plugins/datasource/influxdb/response_parser.ts index 746a8c0e05a..78ce67e7a37 100644 --- a/public/app/plugins/datasource/influxdb/response_parser.ts +++ b/public/app/plugins/datasource/influxdb/response_parser.ts @@ -11,23 +11,14 @@ export default class ResponseParser { return []; } + var influxdb11format = query.toLowerCase().indexOf('show tag values') >= 0; + var res = {}; _.each(influxResults.series, serie => { _.each(serie.values, value => { if (_.isArray(value)) { - // In general, there are 2 possible shapes for the returned value. - // The first one is a two-element array, - // where the first element is somewhat a metadata value: - // the tag name for SHOW TAG VALUES queries, - // the time field for SELECT queries, etc. - // The second shape is an one-element array, - // that is containing an immediate value. - // For example, SHOW FIELD KEYS queries return such shape. - // Note, pre-0.11 versions return - // the second shape for SHOW TAG VALUES queries - // (while the newer versions—first). - if (value[1] !== undefined) { - addUnique(res, value[1]); + if (influxdb11format) { + addUnique(res, value[1] || value[0]); } else { addUnique(res, value[0]); } @@ -38,7 +29,7 @@ export default class ResponseParser { }); return _.map(res, value => { - return { text: value.toString() }; + return { text: value }; }); } } diff --git a/public/app/plugins/datasource/influxdb/specs/response_parser.jest.ts b/public/app/plugins/datasource/influxdb/specs/response_parser.jest.ts index c0652f5fca3..8ddc0fcdaf1 100644 --- a/public/app/plugins/datasource/influxdb/specs/response_parser.jest.ts +++ b/public/app/plugins/datasource/influxdb/specs/response_parser.jest.ts @@ -85,32 +85,6 @@ describe('influxdb response parser', () => { }); }); - describe('SELECT response', () => { - var query = 'SELECT "usage_iowait" FROM "cpu" LIMIT 10'; - var response = { - results: [ - { - series: [ - { - name: 'cpu', - columns: ['time', 'usage_iowait'], - values: [[1488465190006040638, 0.0], [1488465190006040638, 15.0], [1488465190006040638, 20.2]], - }, - ], - }, - ], - }; - - var result = parser.parse(query, response); - - it('should return second column', () => { - expect(_.size(result)).toBe(3); - expect(result[0].text).toBe('0'); - expect(result[1].text).toBe('15'); - expect(result[2].text).toBe('20.2'); - }); - }); - describe('SHOW FIELD response', () => { var query = 'SHOW FIELD KEYS FROM "cpu"'; describe('response from 0.10.0', () => {