mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge remote-tracking branch 'upstream/master' into postgres-query-builder
This commit is contained in:
commit
cd49f2d425
@ -49,18 +49,15 @@ Content-Type: application/json
|
|||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"dashboardId": 1,
|
"dashboardId": 1,
|
||||||
|
"dashboardUId": "ABcdEFghij"
|
||||||
|
"dashboardSlug": "sensors",
|
||||||
"panelId": 1,
|
"panelId": 1,
|
||||||
"name": "fire place sensor",
|
"name": "fire place sensor",
|
||||||
"message": "Someone is trying to break in through the fire place",
|
|
||||||
"state": "alerting",
|
"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",
|
"evalDate": "0001-01-01T00:00:00Z",
|
||||||
"evalData": [
|
"evalData": null,
|
||||||
{
|
|
||||||
"metric": "fire",
|
|
||||||
"tags": null,
|
|
||||||
"value": 5.349999999999999
|
|
||||||
}
|
|
||||||
"newStateDate": "2016-12-25",
|
|
||||||
"executionError": "",
|
"executionError": "",
|
||||||
"url": "http://grafana.com/dashboard/db/sensors"
|
"url": "http://grafana.com/dashboard/db/sensors"
|
||||||
}
|
}
|
||||||
@ -88,16 +85,35 @@ Content-Type: application/json
|
|||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"dashboardId": 1,
|
"dashboardId": 1,
|
||||||
|
"dashboardUId": "ABcdEFghij"
|
||||||
|
"dashboardSlug": "sensors",
|
||||||
"panelId": 1,
|
"panelId": 1,
|
||||||
"name": "fire place sensor",
|
"name": "fire place sensor",
|
||||||
"message": "Someone is trying to break in through the fire place",
|
|
||||||
"state": "alerting",
|
"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": "",
|
"executionError": "",
|
||||||
"url": "http://grafana.com/dashboard/db/sensors"
|
"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
|
## Pause alert
|
||||||
|
|
||||||
`POST /api/alerts/:id/pause`
|
`POST /api/alerts/:id/pause`
|
||||||
|
@ -312,7 +312,7 @@ class MetricsPanelCtrl extends PanelCtrl {
|
|||||||
|
|
||||||
getAdditionalMenuItems() {
|
getAdditionalMenuItems() {
|
||||||
const items = [];
|
const items = [];
|
||||||
if (this.datasource.supportsExplore) {
|
if (this.datasource && this.datasource.supportsExplore) {
|
||||||
items.push({
|
items.push({
|
||||||
text: 'Explore',
|
text: 'Explore',
|
||||||
click: 'ctrl.explore();',
|
click: 'ctrl.explore();',
|
||||||
|
65
public/app/features/panel/specs/metrics_panel_ctrl.jest.ts
Normal file
65
public/app/features/panel/specs/metrics_panel_ctrl.jest.ts
Normal file
@ -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);
|
||||||
|
}
|
@ -11,23 +11,14 @@ export default class ResponseParser {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var influxdb11format = query.toLowerCase().indexOf('show tag values') >= 0;
|
||||||
|
|
||||||
var res = {};
|
var res = {};
|
||||||
_.each(influxResults.series, serie => {
|
_.each(influxResults.series, serie => {
|
||||||
_.each(serie.values, value => {
|
_.each(serie.values, value => {
|
||||||
if (_.isArray(value)) {
|
if (_.isArray(value)) {
|
||||||
// In general, there are 2 possible shapes for the returned value.
|
if (influxdb11format) {
|
||||||
// The first one is a two-element array,
|
addUnique(res, value[1] || value[0]);
|
||||||
// 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]);
|
|
||||||
} else {
|
} else {
|
||||||
addUnique(res, value[0]);
|
addUnique(res, value[0]);
|
||||||
}
|
}
|
||||||
@ -38,7 +29,7 @@ export default class ResponseParser {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return _.map(res, value => {
|
return _.map(res, value => {
|
||||||
return { text: value.toString() };
|
return { text: value };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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', () => {
|
describe('SHOW FIELD response', () => {
|
||||||
var query = 'SHOW FIELD KEYS FROM "cpu"';
|
var query = 'SHOW FIELD KEYS FROM "cpu"';
|
||||||
describe('response from 0.10.0', () => {
|
describe('response from 0.10.0', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user