Skip to content

Commit cd49f2d

Browse files
committed
Merge remote-tracking branch 'upstream/master' into postgres-query-builder
2 parents 8b47d7c + de7a880 commit cd49f2d

File tree

5 files changed

+97
-51
lines changed

5 files changed

+97
-51
lines changed

docs/sources/http_api/alerting.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,15 @@ Content-Type: application/json
4949
{
5050
"id": 1,
5151
"dashboardId": 1,
52+
"dashboardUId": "ABcdEFghij"
53+
"dashboardSlug": "sensors",
5254
"panelId": 1,
5355
"name": "fire place sensor",
54-
"message": "Someone is trying to break in through the fire place",
5556
"state": "alerting",
57+
"message": "Someone is trying to break in through the fire place",
58+
"newStateDate": "2018-05-14T05:55:20+02:00",
5659
"evalDate": "0001-01-01T00:00:00Z",
57-
"evalData": [
58-
{
59-
"metric": "fire",
60-
"tags": null,
61-
"value": 5.349999999999999
62-
}
63-
"newStateDate": "2016-12-25",
60+
"evalData": null,
6461
"executionError": "",
6562
"url": "http://grafana.com/dashboard/db/sensors"
6663
}
@@ -88,16 +85,35 @@ Content-Type: application/json
8885
{
8986
"id": 1,
9087
"dashboardId": 1,
88+
"dashboardUId": "ABcdEFghij"
89+
"dashboardSlug": "sensors",
9190
"panelId": 1,
9291
"name": "fire place sensor",
93-
"message": "Someone is trying to break in through the fire place",
9492
"state": "alerting",
95-
"newStateDate": "2016-12-25",
93+
"message": "Someone is trying to break in through the fire place",
94+
"newStateDate": "2018-05-14T05:55:20+02:00",
95+
"evalDate": "0001-01-01T00:00:00Z",
96+
"evalData": "evalMatches": [
97+
{
98+
"metric": "movement",
99+
"tags": {
100+
"name": "fireplace_chimney"
101+
},
102+
"value": 98.765
103+
}
104+
],
96105
"executionError": "",
97106
"url": "http://grafana.com/dashboard/db/sensors"
98107
}
99108
```
100109

110+
**Important Note**:
111+
"evalMatches" data is cached in the db when and only when the state of the alert changes
112+
(e.g. transitioning from "ok" to "alerting" state).
113+
114+
If data from one server triggers the alert first and, before that server is seen leaving alerting state,
115+
a second server also enters a state that would trigger the alert, the second server will not be visible in "evalMatches" data.
116+
101117
## Pause alert
102118

103119
`POST /api/alerts/:id/pause`

public/app/features/panel/metrics_panel_ctrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class MetricsPanelCtrl extends PanelCtrl {
312312

313313
getAdditionalMenuItems() {
314314
const items = [];
315-
if (this.datasource.supportsExplore) {
315+
if (this.datasource && this.datasource.supportsExplore) {
316316
items.push({
317317
text: 'Explore',
318318
click: 'ctrl.explore();',
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
jest.mock('app/core/core', () => ({}));
2+
3+
import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
4+
import q from 'q';
5+
import { PanelModel } from 'app/features/dashboard/panel_model';
6+
7+
describe('MetricsPanelCtrl', () => {
8+
let ctrl;
9+
10+
beforeEach(() => {
11+
ctrl = setupController();
12+
});
13+
14+
describe('when getting additional menu items', () => {
15+
let additionalItems;
16+
17+
describe('and has no datasource set', () => {
18+
beforeEach(() => {
19+
additionalItems = ctrl.getAdditionalMenuItems();
20+
});
21+
22+
it('should not return any items', () => {
23+
expect(additionalItems.length).toBe(0);
24+
});
25+
});
26+
27+
describe('and has datasource set that supports explore', () => {
28+
beforeEach(() => {
29+
ctrl.datasource = { supportsExplore: true };
30+
additionalItems = ctrl.getAdditionalMenuItems();
31+
});
32+
33+
it('should not return any items', () => {
34+
expect(additionalItems.length).toBe(1);
35+
});
36+
});
37+
});
38+
});
39+
40+
function setupController() {
41+
const injectorStub = {
42+
get: type => {
43+
switch (type) {
44+
case '$q': {
45+
return q;
46+
}
47+
default: {
48+
return jest.fn();
49+
}
50+
}
51+
},
52+
};
53+
54+
const scope = {
55+
panel: { events: [] },
56+
appEvent: jest.fn(),
57+
onAppEvent: jest.fn(),
58+
$on: jest.fn(),
59+
colors: [],
60+
};
61+
62+
MetricsPanelCtrl.prototype.panel = new PanelModel({ type: 'test' });
63+
64+
return new MetricsPanelCtrl(scope, injectorStub);
65+
}

public/app/plugins/datasource/influxdb/response_parser.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,14 @@ export default class ResponseParser {
1111
return [];
1212
}
1313

14+
var influxdb11format = query.toLowerCase().indexOf('show tag values') >= 0;
15+
1416
var res = {};
1517
_.each(influxResults.series, serie => {
1618
_.each(serie.values, value => {
1719
if (_.isArray(value)) {
18-
// In general, there are 2 possible shapes for the returned value.
19-
// The first one is a two-element array,
20-
// where the first element is somewhat a metadata value:
21-
// the tag name for SHOW TAG VALUES queries,
22-
// the time field for SELECT queries, etc.
23-
// The second shape is an one-element array,
24-
// that is containing an immediate value.
25-
// For example, SHOW FIELD KEYS queries return such shape.
26-
// Note, pre-0.11 versions return
27-
// the second shape for SHOW TAG VALUES queries
28-
// (while the newer versions—first).
29-
if (value[1] !== undefined) {
30-
addUnique(res, value[1]);
20+
if (influxdb11format) {
21+
addUnique(res, value[1] || value[0]);
3122
} else {
3223
addUnique(res, value[0]);
3324
}
@@ -38,7 +29,7 @@ export default class ResponseParser {
3829
});
3930

4031
return _.map(res, value => {
41-
return { text: value.toString() };
32+
return { text: value };
4233
});
4334
}
4435
}

public/app/plugins/datasource/influxdb/specs/response_parser.jest.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,6 @@ describe('influxdb response parser', () => {
8585
});
8686
});
8787

88-
describe('SELECT response', () => {
89-
var query = 'SELECT "usage_iowait" FROM "cpu" LIMIT 10';
90-
var response = {
91-
results: [
92-
{
93-
series: [
94-
{
95-
name: 'cpu',
96-
columns: ['time', 'usage_iowait'],
97-
values: [[1488465190006040638, 0.0], [1488465190006040638, 15.0], [1488465190006040638, 20.2]],
98-
},
99-
],
100-
},
101-
],
102-
};
103-
104-
var result = parser.parse(query, response);
105-
106-
it('should return second column', () => {
107-
expect(_.size(result)).toBe(3);
108-
expect(result[0].text).toBe('0');
109-
expect(result[1].text).toBe('15');
110-
expect(result[2].text).toBe('20.2');
111-
});
112-
});
113-
11488
describe('SHOW FIELD response', () => {
11589
var query = 'SHOW FIELD KEYS FROM "cpu"';
11690
describe('response from 0.10.0', () => {

0 commit comments

Comments
 (0)