Commit f44d6e06 by Torkel Ödegaard

Merge branch 'master' into variable-value-formatting-rethink

parents 4ef79d25 113509a4
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* **Prometheus**: Prometheus annotation support, closes[#2883](https://github.com/grafana/grafana/pull/2883) * **Prometheus**: Prometheus annotation support, closes[#2883](https://github.com/grafana/grafana/pull/2883)
* **Cli**: New cli tool for downloading and updating plugins * **Cli**: New cli tool for downloading and updating plugins
* **Annotations**: Annotations can now contain links that can be clicked (you can navigate on to annotation popovers), closes [#1588](https://github.com/grafana/grafana/issues/1588) * **Annotations**: Annotations can now contain links that can be clicked (you can navigate on to annotation popovers), closes [#1588](https://github.com/grafana/grafana/issues/1588)
* **Opentsdb**: Opentsdb 2.2 filters support, closes[#3077](https://github.com/grafana/grafana/issues/3077)
### Breaking changes ### Breaking changes
* **Plugin API**: Both datasource and panel plugin api (and plugin.json schema) have been updated, requiring an update to plugins. See [plugin api](https://github.com/grafana/grafana/blob/master/public/app/plugins/plugin_api.md) for more info. * **Plugin API**: Both datasource and panel plugin api (and plugin.json schema) have been updated, requiring an update to plugins. See [plugin api](https://github.com/grafana/grafana/blob/master/public/app/plugins/plugin_api.md) for more info.
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
* **Admin**: Admin can now have global overview of Grafana setup, closes [#3812](https://github.com/grafana/grafana/issues/3812) * **Admin**: Admin can now have global overview of Grafana setup, closes [#3812](https://github.com/grafana/grafana/issues/3812)
* **graph**: Right side legend height is now fixed at row height, closes [#1277](https://github.com/grafana/grafana/issues/1277) * **graph**: Right side legend height is now fixed at row height, closes [#1277](https://github.com/grafana/grafana/issues/1277)
* **Table**: All content in table panel is now html escaped, closes [#3673](https://github.com/grafana/grafana/issues/3673) * **Table**: All content in table panel is now html escaped, closes [#3673](https://github.com/grafana/grafana/issues/3673)
* **graph**: Template variables can now be used in TimeShift and TimeFrom, closes[#1960](https://github.com/grafana/grafana/issues/1960)
### Bug fixes ### Bug fixes
* **Playlist**: Fix for memory leak when running a playlist, closes [#3794](https://github.com/grafana/grafana/pull/3794) * **Playlist**: Fix for memory leak when running a playlist, closes [#3794](https://github.com/grafana/grafana/pull/3794)
......
script.inline: on
script.indexed: on
...@@ -4,3 +4,5 @@ elasticsearch: ...@@ -4,3 +4,5 @@ elasticsearch:
ports: ports:
- "9200:9200" - "9200:9200"
- "9300:9300" - "9300:9300"
volumes:
- ./blocks/elastic/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
...@@ -23,6 +23,7 @@ Name | The data source name, important that this is the same as in Grafana v1.x ...@@ -23,6 +23,7 @@ Name | The data source name, important that this is the same as in Grafana v1.x
Default | Default data source means that it will be pre-selected for new panels. Default | Default data source means that it will be pre-selected for new panels.
Url | The http protocol, ip and port of you opentsdb server (default port is usually 4242) Url | The http protocol, ip and port of you opentsdb server (default port is usually 4242)
Access | Proxy = access via Grafana backend, Direct = access directory from browser. Access | Proxy = access via Grafana backend, Direct = access directory from browser.
Version | Version = opentsdb version, either <=2.1 or 2.2
## Query editor ## Query editor
Open a graph in edit mode by click the title. Open a graph in edit mode by click the title.
......
...@@ -43,8 +43,9 @@ func Register(r *macaron.Macaron) { ...@@ -43,8 +43,9 @@ func Register(r *macaron.Macaron) {
r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, Index) r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, Index)
r.Get("/admin/stats", reqGrafanaAdmin, Index) r.Get("/admin/stats", reqGrafanaAdmin, Index)
r.Get("/apps", reqSignedIn, Index) r.Get("/plugins", reqSignedIn, Index)
r.Get("/apps/edit/*", reqSignedIn, Index) r.Get("/plugins/:id/edit", reqSignedIn, Index)
r.Get("/plugins/:id/page/:page", reqSignedIn, Index)
r.Get("/dashboard/*", reqSignedIn, Index) r.Get("/dashboard/*", reqSignedIn, Index)
r.Get("/dashboard-solo/*", reqSignedIn, Index) r.Get("/dashboard-solo/*", reqSignedIn, Index)
......
...@@ -85,13 +85,13 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { ...@@ -85,13 +85,13 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
if plugin.Pinned { if plugin.Pinned {
pageLink := &dtos.NavLink{ pageLink := &dtos.NavLink{
Text: plugin.Name, Text: plugin.Name,
Url: setting.AppSubUrl + "/apps/" + plugin.Id + "/edit", Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/edit",
Img: plugin.Info.Logos.Small, Img: plugin.Info.Logos.Small,
} }
for _, page := range plugin.Pages { for _, page := range plugin.Pages {
pageLink.Children = append(pageLink.Children, &dtos.NavLink{ pageLink.Children = append(pageLink.Children, &dtos.NavLink{
Url: setting.AppSubUrl + "/apps/" + plugin.Id + "/page/" + page.Slug, Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/page/" + page.Slug,
Text: page.Name, Text: page.Name,
}) })
} }
......
...@@ -77,7 +77,7 @@ func NewEngine() { ...@@ -77,7 +77,7 @@ func NewEngine() {
log.Fatal(3, "Sqlstore: Fail to connect to database: %v", err) log.Fatal(3, "Sqlstore: Fail to connect to database: %v", err)
} }
err = SetEngine(x, true) err = SetEngine(x, setting.Env == setting.DEV)
if err != nil { if err != nil {
log.Fatal(3, "fail to initialize orm engine: %v", err) log.Fatal(3, "fail to initialize orm engine: %v", err)
...@@ -105,14 +105,6 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) { ...@@ -105,14 +105,6 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
return fmt.Errorf("sqlstore.init(fail to create xorm.log): %v", err) return fmt.Errorf("sqlstore.init(fail to create xorm.log): %v", err)
} }
x.Logger = xorm.NewSimpleLogger(f) x.Logger = xorm.NewSimpleLogger(f)
if setting.Env == setting.DEV {
x.ShowSQL = false
x.ShowInfo = false
x.ShowDebug = false
x.ShowErr = true
x.ShowWarn = true
}
} }
return nil return nil
......
...@@ -47,6 +47,9 @@ function (coreModule, kbn, rangeUtil) { ...@@ -47,6 +47,9 @@ function (coreModule, kbn, rangeUtil) {
if (ctrl.$isEmpty(modelValue)) { if (ctrl.$isEmpty(modelValue)) {
return true; return true;
} }
if (viewValue.indexOf('$') === 0) {
return true; // allow template variable
}
var info = rangeUtil.describeTextRange(viewValue); var info = rangeUtil.describeTextRange(viewValue);
return info.invalid !== true; return info.invalid !== true;
}; };
......
...@@ -14,6 +14,41 @@ export function exportSeriesListToCsv(seriesList) { ...@@ -14,6 +14,41 @@ export function exportSeriesListToCsv(seriesList) {
saveSaveBlob(text, 'grafana_data_export.csv'); saveSaveBlob(text, 'grafana_data_export.csv');
}; };
export function exportSeriesListToCsvColumns(seriesList) {
var text = 'Time;';
// add header
_.each(seriesList, function(series) {
text += series.alias + ';';
});
text = text.substring(0,text.length-1);
text += '\n';
// process data
var dataArr = [[]];
var sIndex = 1;
_.each(seriesList, function(series) {
var cIndex = 0;
dataArr.push([]);
_.each(series.datapoints, function(dp) {
dataArr[0][cIndex] = new Date(dp[1]).toISOString();
dataArr[sIndex][cIndex] = dp[0];
cIndex++;
});
sIndex++;
});
// make text
for (var i = 0; i < dataArr[0].length; i++) {
text += dataArr[0][i] + ';';
for (var j = 1; j < dataArr.length; j++) {
text += dataArr[j][i] + ';';
}
text = text.substring(0,text.length-1);
text += '\n';
}
saveSaveBlob(text, 'grafana_data_export.csv');
};
export function exportTableDataToCsv(table) { export function exportTableDataToCsv(table) {
var text = ''; var text = '';
// add header // add header
......
...@@ -12,39 +12,66 @@ function($, _) { ...@@ -12,39 +12,66 @@ function($, _) {
kbn.round_interval = function(interval) { kbn.round_interval = function(interval) {
switch (true) { switch (true) {
// 0.5s // 0.3s
case (interval <= 500): case (interval <= 300):
return 100; // 0.1s return 100; // 0.1s
// 5s // 0.75s
case (interval <= 5000): case (interval <= 750):
return 500; // 0.5s
// 1.5s
case (interval <= 1500):
return 1000; // 1s return 1000; // 1s
// 3.5s
case (interval <= 3500):
return 2000; // 2s
// 7.5s // 7.5s
case (interval <= 7500): case (interval <= 7500):
return 5000; // 5s return 5000; // 5s
// 15s // 12.5s
case (interval <= 15000): case (interval <= 12500):
return 10000; // 10s return 10000; // 10s
// 17.5s
case (interval <= 17500):
return 15000; // 15s
// 25s
case (interval <= 25000):
return 20000; // 20s
// 45s // 45s
case (interval <= 45000): case (interval <= 45000):
return 30000; // 30s return 30000; // 30s
// 3m // 1.5m
case (interval <= 180000): case (interval <= 90000):
return 60000; // 1m return 60000; // 1m
// 9m // 3.5m
case (interval <= 210000):
return 120000; // 2m
// 7.5m
case (interval <= 450000): case (interval <= 450000):
return 300000; // 5m return 300000; // 5m
// 20m // 12.5m
case (interval <= 1200000): case (interval <= 750000):
return 600000; // 10m return 600000; // 10m
// 12.5m
case (interval <= 1050000):
return 900000; // 15m
// 25m
case (interval <= 1500000):
return 1200000; // 20m
// 45m // 45m
case (interval <= 2700000): case (interval <= 2700000):
return 1800000; // 30m return 1800000; // 30m
// 2h // 1.5h
case (interval <= 7200000): case (interval <= 5400000):
return 3600000; // 1h return 3600000; // 1h
// 6h // 2.5h
case (interval <= 21600000): case (interval <= 9000000):
return 7200000; // 2h
// 4.5h
case (interval <= 16200000):
return 10800000; // 3h return 10800000; // 3h
// 9h
case (interval <= 32400000):
return 21600000; // 6h
// 24h // 24h
case (interval <= 86400000): case (interval <= 86400000):
return 43200000; // 12h return 43200000; // 12h
......
...@@ -12,10 +12,7 @@ function (angular, _, $) { ...@@ -12,10 +12,7 @@ function (angular, _, $) {
var annotationDefaults = { var annotationDefaults = {
name: '', name: '',
datasource: null, datasource: null,
showLine: true, iconColor: 'rgba(255, 96, 96, 1)',
iconColor: '#C0C6BE',
lineColor: 'rgba(255, 96, 96, 0.592157)',
iconSize: 13,
enable: true enable: true
}; };
......
...@@ -76,8 +76,8 @@ ...@@ -76,8 +76,8 @@
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label"> <label class="gf-form-label">
<span>Color</span> <span>Color</span>
<spectrum-picker ng-model="currentAnnotation.iconColor"></spectrum-picker>
</label> </label>
<spectrum-picker class="gf-form-input" ng-model="currentAnnotation.iconColor"></spectrum-picker>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -16,4 +16,5 @@ define([ ...@@ -16,4 +16,5 @@ define([
'./graphiteImportCtrl', './graphiteImportCtrl',
'./dynamicDashboardSrv', './dynamicDashboardSrv',
'./importCtrl', './importCtrl',
'./impressionStore',
], function () {}); ], function () {});
...@@ -5,8 +5,9 @@ define([ ...@@ -5,8 +5,9 @@ define([
'jquery', 'jquery',
'app/core/utils/kbn', 'app/core/utils/kbn',
'app/core/utils/datemath', 'app/core/utils/datemath',
'./impressionStore',
], ],
function (angular, moment, _, $, kbn, dateMath) { function (angular, moment, _, $, kbn, dateMath, impressionStore) {
'use strict'; 'use strict';
var module = angular.module('grafana.services'); var module = angular.module('grafana.services');
...@@ -24,19 +25,27 @@ function (angular, moment, _, $, kbn, dateMath) { ...@@ -24,19 +25,27 @@ function (angular, moment, _, $, kbn, dateMath) {
}; };
this.loadDashboard = function(type, slug) { this.loadDashboard = function(type, slug) {
if (type === 'script') { var promise;
return this._loadScriptedDashboard(slug);
}
if (type === 'snapshot') { if (type === 'script') {
return backendSrv.get('/api/snapshots/' + $routeParams.slug).catch(function() { promise = this._loadScriptedDashboard(slug);
} else if (type === 'snapshot') {
promise = backendSrv.get('/api/snapshots/' + $routeParams.slug).catch(function() {
return {meta:{isSnapshot: true, canSave: false, canEdit: false}, dashboard: {title: 'Snapshot not found'}}; return {meta:{isSnapshot: true, canSave: false, canEdit: false}, dashboard: {title: 'Snapshot not found'}};
}); });
} else {
promise = backendSrv.getDashboard($routeParams.type, $routeParams.slug)
.catch(function() {
return self._dashboardLoadFailed("Not found");
});
} }
return backendSrv.getDashboard($routeParams.type, $routeParams.slug).catch(function() { promise.then(function(result) {
return self._dashboardLoadFailed("Not found"); impressionStore.impressions.addDashboardImpression(slug);
return result;
}); });
return promise;
}; };
this._loadScriptedDashboard = function(file) { this._loadScriptedDashboard = function(file) {
......
...@@ -140,7 +140,11 @@ function (angular, $, _, moment) { ...@@ -140,7 +140,11 @@ function (angular, $, _, moment) {
}; };
p.isSubmenuFeaturesEnabled = function() { p.isSubmenuFeaturesEnabled = function() {
return this.templating.list.length > 0 || this.annotations.list.length > 0 || this.links.length > 0; var visableTemplates = _.filter(this.templating.list, function(template) {
return template.hideVariable === undefined || template.hideVariable === false;
});
return visableTemplates.length > 0 || this.annotations.list.length > 0 || this.links.length > 0;
}; };
p.getPanelInfoById = function(panelId) { p.getPanelInfoById = function(panelId) {
......
///<reference path="../../headers/common.d.ts" />
import store from 'app/core/store';
import _ from 'lodash';
export class ImpressionsStore {
constructor() {}
addDashboardImpression(slug) {
var impressions = [];
if (store.exists("dashboard_impressions")) {
impressions = JSON.parse(store.get("dashboard_impressions"));
if (!_.isArray(impressions)) {
impressions = [];
}
}
var exists = impressions.indexOf(slug);
if (exists >= 0) {
impressions.splice(exists, 1);
}
impressions.unshift(slug);
if (impressions.length > 20) {
impressions.shift();
}
store.set("dashboard_impressions", JSON.stringify(impressions));
}
getDashboardOpened() {
var k = store.get("dashboard_impressions");
return JSON.parse(k);
}
}
var impressions = new ImpressionsStore();
export {
impressions
};
<div class="submenu-controls"> <div class="submenu-controls">
<ul ng-if="ctrl.dashboard.templating.list.length > 0"> <ul ng-if="ctrl.dashboard.templating.list.length > 0">
<li ng-repeat="variable in ctrl.variables" class="submenu-item"> <li ng-repeat="variable in ctrl.variables" ng-show="!variable.hideVariable" class="submenu-item">
<span class="submenu-item-label template-variable " ng-show="!variable.hideLabel"> <span class="submenu-item-label template-variable " ng-show="!variable.hideLabel">
{{variable.label || variable.name}}: {{variable.label || variable.name}}:
</span> </span>
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<thead> <thead>
<tr> <tr>
<th><strong>name</strong></th> <th><strong>name</strong></th>
<th><strong>type</strong></th>
<th><strong>url</strong></th> <th><strong>url</strong></th>
<th style="width: 60px;"></th> <th style="width: 60px;"></th>
<th style="width: 85px;"></th> <th style="width: 85px;"></th>
...@@ -37,7 +38,10 @@ ...@@ -37,7 +38,10 @@
</a> </a>
</td> </td>
<td> <td>
<span class="ellipsis">{{ds.url}}</span> <span>{{ds.type}}</span>
</td>
<td>
<span>{{ds.url}}</span>
</td> </td>
<td class="text-center"> <td class="text-center">
<span ng-if="ds.isDefault"> <span ng-if="ds.isDefault">
......
...@@ -17,6 +17,7 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -17,6 +17,7 @@ class MetricsPanelCtrl extends PanelCtrl {
$timeout: any; $timeout: any;
datasourceSrv: any; datasourceSrv: any;
timeSrv: any; timeSrv: any;
templateSrv: any;
timing: any; timing: any;
range: any; range: any;
rangeRaw: any; rangeRaw: any;
...@@ -34,6 +35,7 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -34,6 +35,7 @@ class MetricsPanelCtrl extends PanelCtrl {
this.$q = $injector.get('$q'); this.$q = $injector.get('$q');
this.datasourceSrv = $injector.get('datasourceSrv'); this.datasourceSrv = $injector.get('datasourceSrv');
this.timeSrv = $injector.get('timeSrv'); this.timeSrv = $injector.get('timeSrv');
this.templateSrv = $injector.get('templateSrv');
if (!this.panel.targets) { if (!this.panel.targets) {
this.panel.targets = [{}]; this.panel.targets = [{}];
...@@ -119,7 +121,8 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -119,7 +121,8 @@ class MetricsPanelCtrl extends PanelCtrl {
// check panel time overrrides // check panel time overrrides
if (this.panel.timeFrom) { if (this.panel.timeFrom) {
var timeFromInfo = rangeUtil.describeTextRange(this.panel.timeFrom); var timeFromInterpolated = this.templateSrv.replace(this.panel.timeFrom, this.panel.scopedVars);
var timeFromInfo = rangeUtil.describeTextRange(timeFromInterpolated);
if (timeFromInfo.invalid) { if (timeFromInfo.invalid) {
this.timeInfo = 'invalid time override'; this.timeInfo = 'invalid time override';
return; return;
...@@ -136,13 +139,14 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -136,13 +139,14 @@ class MetricsPanelCtrl extends PanelCtrl {
} }
if (this.panel.timeShift) { if (this.panel.timeShift) {
var timeShiftInfo = rangeUtil.describeTextRange(this.panel.timeShift); var timeShiftInterpolated = this.templateSrv.replace(this.panel.timeShift, this.panel.scopedVars);
var timeShiftInfo = rangeUtil.describeTextRange(timeShiftInterpolated);
if (timeShiftInfo.invalid) { if (timeShiftInfo.invalid) {
this.timeInfo = 'invalid timeshift'; this.timeInfo = 'invalid timeshift';
return; return;
} }
var timeShift = '-' + this.panel.timeShift; var timeShift = '-' + timeShiftInterpolated;
this.timeInfo += ' timeshift ' + timeShift; this.timeInfo += ' timeshift ' + timeShift;
this.range.from = dateMath.parseDateMath(timeShift, this.range.from, false); this.range.from = dateMath.parseDateMath(timeShift, this.range.from, false);
this.range.to = dateMath.parseDateMath(timeShift, this.range.to, true); this.range.to = dateMath.parseDateMath(timeShift, this.range.to, true);
......
...@@ -31,7 +31,6 @@ var panelTemplate = ` ...@@ -31,7 +31,6 @@ var panelTemplate = `
<div class="tabbed-view tabbed-view--panel-edit"> <div class="tabbed-view tabbed-view--panel-edit">
<div class="tabbed-view-header"> <div class="tabbed-view-header">
<h2 class="tabbed-view-title"> <h2 class="tabbed-view-title">
<i ng-class="ctrl.icon"></i>
{{ctrl.pluginName}} {{ctrl.pluginName}}
</h2> </h2>
......
...@@ -5,14 +5,13 @@ import _ from 'lodash'; ...@@ -5,14 +5,13 @@ import _ from 'lodash';
export class AppPageCtrl { export class AppPageCtrl {
page: any; page: any;
appId: any; pluginId: any;
appModel: any; appModel: any;
/** @ngInject */ /** @ngInject */
constructor(private backendSrv, private $routeParams: any, private $rootScope) { constructor(private backendSrv, private $routeParams: any, private $rootScope) {
this.appId = $routeParams.appId; this.pluginId = $routeParams.pluginId;
this.backendSrv.get(`/api/org/plugins/${this.pluginId}/settings`).then(app => {
this.backendSrv.get(`/api/org/apps/${this.appId}/settings`).then(app => {
this.appModel = app; this.appModel = app;
this.page = _.findWhere(app.pages, {slug: this.$routeParams.slug}); this.page = _.findWhere(app.pages, {slug: this.$routeParams.slug});
if (!this.page) { if (!this.page) {
......
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
{{ds.name}} {{ds.name}}
</li> </li>
<li ng-repeat="page in ctrl.model.pages"> <li ng-repeat="page in ctrl.model.pages">
<a href="apps/{{ctrl.appId}}/page/{{page.slug}}" class="external-link">{{page.name}}</a> <a href="plugins/{{ctrl.pluginId}}/page/{{page.slug}}" class="external-link">{{page.name}}</a>
</li> </li>
</ul> </ul>
</section> </section>
......
<navbar icon="icon-gf icon-gf-apps" title="{{ctrl.appModel.name}}" title-url="apps/{{ctrl.appId}}/edit"> <navbar icon="icon-gf icon-gf-apps" title="{{ctrl.appModel.name}}" title-url="plugins/{{ctrl.pluginId}}/edit">
</navbar> </navbar>
<div class="page-container"> <div class="page-container">
......
...@@ -91,11 +91,17 @@ ...@@ -91,11 +91,17 @@
</div> </div>
</div> </div>
</div> </div>
<div class="gf-form-inline">
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-7">Label</span> <span class="gf-form-label width-7">Label</span>
<input type="text" class="gf-form-input max-width-14" ng-model='current.label' placeholder="optional display name"></input> <input type="text" class="gf-form-input max-width-14" ng-model='current.label' placeholder="optional display name"></input>
<editor-checkbox class="width-13" text="Hide label" model="current.hideLabel" change="runQuery()"></editor-checkbox>
</div> </div>
<div class="gf-form">
<editor-checkbox class="width-10" text="Hide label" model="current.hideLabel" change="runQuery()"></editor-checkbox>
<editor-checkbox class="width-11" text="Hide variable" model="current.hideVariable" change="runQuery()"></editor-checkbox>
</div>
</div>
</div> </div>
<h5 class="section-heading">Value Options</h5> <h5 class="section-heading">Value Options</h5>
...@@ -109,9 +115,15 @@ ...@@ -109,9 +115,15 @@
<span class="gf-form-label" ng-show="current.auto"> <span class="gf-form-label" ng-show="current.auto">
Auto interval steps <tip>How many times should the current time range be divided to calculate the value</tip> Auto interval steps <tip>How many times should the current time range be divided to calculate the value</tip>
</span> </span>
<div class="gf-form-select-wrapper max-width-10"> <div class="gf-form-select-wrapper max-width-10" ng-show="current.auto">
<select class="gf-form-input" ng-model="current.auto_count" ng-options="f for f in [3,5,10,30,50,100,200]" ng-change="runQuery()"></select> <select class="gf-form-input" ng-model="current.auto_count" ng-options="f for f in [2,3,4,5,10,20,30,40,50,100,200,300,400,500]" ng-change="runQuery()"></select>
</div>
</div> </div>
<div class="gf-form">
<span class="gf-form-label" ng-show="current.auto">
Auto interval min value <tip>The calculated value will not go below this threshold</tip>
</span>
<input type="text" class="gf-form-input max-width-10" ng-show="current.auto" ng-model="current.auto_min" ng-change="runQuery()"></input>
</div> </div>
</div> </div>
......
...@@ -60,7 +60,7 @@ function (angular, _, kbn) { ...@@ -60,7 +60,7 @@ function (angular, _, kbn) {
variable.options.unshift({ text: 'auto', value: '$__auto_interval' }); variable.options.unshift({ text: 'auto', value: '$__auto_interval' });
} }
var interval = kbn.calculateInterval(timeSrv.timeRange(), variable.auto_count); var interval = kbn.calculateInterval(timeSrv.timeRange(), variable.auto_count, (variable.auto_min ? ">"+variable.auto_min : null));
templateSrv.setGrafanaVariable('$__auto_interval', interval); templateSrv.setGrafanaVariable('$__auto_interval', interval);
}; };
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
<div class="gf-box-body"> <div class="gf-box-body">
<div ng-if="editor.index == 0"> <div ng-if="editor.index == 0">
<h5>Request details</h5> <h5 class="section-heading">Request details</h5>
<table class="table table-striped small inspector-request-table"> <table class="filter-table gf-form-group">
<tr> <tr>
<td>Url</td> <td>Url</td>
<td>{{inspector.error.config.url}}</td> <td>{{inspector.error.config.url}}</td>
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
</tr> </tr>
</table> </table>
<h5>Request parameters</h5> <h5 class="section-heading">Request parameters</h5>
<table class="table table-striped small inspector-request-table"> <table class="filter-table">
<tr ng-repeat="param in request_parameters"> <tr ng-repeat="param in request_parameters">
<td> <td>
{{param.key}} {{param.key}}
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</div> </div>
<div class="editor-row" style="margin-top: 30px"> <div class="editor-row">
<div class="pull-right dropdown" style="margin-right: 10px;"> <div class="pull-right dropdown" style="margin-right: 10px;">
<button class="btn btn-inverse dropdown-toggle" data-toggle="dropdown" bs-tooltip="'Datasource'"> <button class="btn btn-inverse dropdown-toggle" data-toggle="dropdown" bs-tooltip="'Datasource'">
......
///<reference path="../../../headers/common.d.ts" />
import angular from 'angular';
import _ from 'lodash';
export class OpenTsConfigCtrl {
static templateUrl = 'public/app/plugins/datasource/opentsdb/partials/config.html';
current: any;
/** @ngInject */
constructor($scope) {
this.current.jsonData = this.current.jsonData || {};
this.current.jsonData.tsdbVersion = this.current.jsonData.tsdbVersion || 1;
}
tsdbVersions = [
{name: '<=2.1', value: 1},
{name: '2.2', value: 2},
];
}
...@@ -14,6 +14,8 @@ function (angular, _, dateMath) { ...@@ -14,6 +14,8 @@ function (angular, _, dateMath) {
this.name = instanceSettings.name; this.name = instanceSettings.name;
this.withCredentials = instanceSettings.withCredentials; this.withCredentials = instanceSettings.withCredentials;
this.basicAuth = instanceSettings.basicAuth; this.basicAuth = instanceSettings.basicAuth;
instanceSettings.jsonData = instanceSettings.jsonData || {};
this.tsdbVersion = instanceSettings.jsonData.tsdbVersion || 1;
this.supportMetrics = true; this.supportMetrics = true;
this.tagKeys = {}; this.tagKeys = {};
...@@ -39,9 +41,15 @@ function (angular, _, dateMath) { ...@@ -39,9 +41,15 @@ function (angular, _, dateMath) {
var groupByTags = {}; var groupByTags = {};
_.each(queries, function(query) { _.each(queries, function(query) {
if (query.filters && query.filters.length > 0) {
_.each(query.filters, function(val) {
groupByTags[val.tagk] = true;
});
} else {
_.each(query.tags, function(val, key) { _.each(query.tags, function(val, key) {
groupByTags[key] = true; groupByTags[key] = true;
}); });
}
}); });
return this.performTimeSeriesQuery(queries, start, end).then(function(response) { return this.performTimeSeriesQuery(queries, start, end).then(function(response) {
...@@ -88,6 +96,7 @@ function (angular, _, dateMath) { ...@@ -88,6 +96,7 @@ function (angular, _, dateMath) {
// In case the backend is 3rd-party hosted and does not suport OPTIONS, urlencoded requests // In case the backend is 3rd-party hosted and does not suport OPTIONS, urlencoded requests
// go as POST rather than OPTIONS+POST // go as POST rather than OPTIONS+POST
options.headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; options.headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
return backendSrv.datasourceRequest(options); return backendSrv.datasourceRequest(options);
}; };
...@@ -224,6 +233,19 @@ function (angular, _, dateMath) { ...@@ -224,6 +233,19 @@ function (angular, _, dateMath) {
return aggregatorsPromise; return aggregatorsPromise;
}; };
var filterTypesPromise = null;
this.getFilterTypes = function() {
if (filterTypesPromise) { return filterTypesPromise; }
filterTypesPromise = this._get('/api/config/filters').then(function(result) {
if (result.data) {
return Object.keys(result.data).sort();
}
return [];
});
return filterTypesPromise;
};
function transformMetricData(md, groupByTags, target, options) { function transformMetricData(md, groupByTags, target, options) {
var metricLabel = createMetricLabel(md, target, groupByTags, options); var metricLabel = createMetricLabel(md, target, groupByTags, options);
var dps = []; var dps = [];
...@@ -307,12 +329,16 @@ function (angular, _, dateMath) { ...@@ -307,12 +329,16 @@ function (angular, _, dateMath) {
} }
} }
if (target.filters && target.filters.length > 0) {
query.filters = angular.copy(target.filters);
} else {
query.tags = angular.copy(target.tags); query.tags = angular.copy(target.tags);
if(query.tags){ if(query.tags){
for(var key in query.tags){ for(var key in query.tags){
query.tags[key] = templateSrv.replace(query.tags[key], options.scopedVars); query.tags[key] = templateSrv.replace(query.tags[key], options.scopedVars);
} }
} }
}
return query; return query;
} }
...@@ -321,11 +347,18 @@ function (angular, _, dateMath) { ...@@ -321,11 +347,18 @@ function (angular, _, dateMath) {
var interpolatedTagValue; var interpolatedTagValue;
return _.map(metrics, function(metricData) { return _.map(metrics, function(metricData) {
return _.findIndex(options.targets, function(target) { return _.findIndex(options.targets, function(target) {
if (target.filters && target.filters.length > 0) {
return target.metric === metricData.metric &&
_.all(target.filters, function(filter) {
return filter.tagk === interpolatedTagValue === "*";
});
} else {
return target.metric === metricData.metric && return target.metric === metricData.metric &&
_.all(target.tags, function(tagV, tagK) { _.all(target.tags, function(tagV, tagK) {
interpolatedTagValue = templateSrv.replace(tagV, options.scopedVars); interpolatedTagValue = templateSrv.replace(tagV, options.scopedVars);
return metricData.tags[tagK] === interpolatedTagValue || interpolatedTagValue === "*"; return metricData.tags[tagK] === interpolatedTagValue || interpolatedTagValue === "*";
}); });
}
}); });
}); });
} }
......
import {OpenTsDatasource} from './datasource'; import {OpenTsDatasource} from './datasource';
import {OpenTsQueryCtrl} from './query_ctrl'; import {OpenTsQueryCtrl} from './query_ctrl';
import {OpenTsConfigCtrl} from './config_ctrl';
class OpenTsConfigCtrl {
static templateUrl = 'partials/config.html';
}
export { export {
OpenTsDatasource as Datasource, OpenTsDatasource as Datasource,
......
<datasource-http-settings current="ctrl.current"></datasource-http-settings> <datasource-http-settings current="ctrl.current"></datasource-http-settings>
<br>
<h5>Opentsdb settings</h5>
<div class="gf-form">
<span class="gf-form-label width-7">
Version
</span>
<span class="gf-form-select-wrapper">
<select class="gf-form-input gf-size-auto" ng-model="ctrl.current.jsonData.tsdbVersion" ng-options="v.value as v.name for v in ctrl.tsdbVersions"></select>
</span>
<div class="clearfix"></div>
</div>
...@@ -63,12 +63,11 @@ ...@@ -63,12 +63,11 @@
</select> </select>
</li> </li>
<li class="tight-form-item query-keyword" style="width: 59px"> <li class="tight-form-item query-keyword" style="width: 59px" ng-if="ctrl.tsdbVersion == 2">
Fill Fill
<tip>Available since OpenTSDB 2.2</tip>
</li> </li>
<li> <li ng-if="ctrl.tsdbVersion == 2">
<select ng-model="ctrl.target.downsampleFillPolicy" class="tight-form-input input-small" <select ng-model="ctrl.target.downsampleFillPolicy" class="tight-form-input input-small"
ng-options="agg for agg in ctrl.fillPolicies" ng-options="agg for agg in ctrl.fillPolicies"
ng-change="ctrl.targetBlur()"> ng-change="ctrl.targetBlur()">
...@@ -83,10 +82,67 @@ ...@@ -83,10 +82,67 @@
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div class="tight-form" ng-if="ctrl.tsdbVersion == 2">
<ul class="tight-form-list" role="menu">
<li class="tight-form-item tight-form-align query-keyword" style="width: 100px">
Filters
<tip ng-if="ctrl.tsdbVersion == 2">Filters does not work with tags, either of the two will work but not both.</tip>
</li>
<li ng-repeat="fil in ctrl.target.filters track by $index" class="tight-form-item">
{{fil.tagk}}&nbsp;=&nbsp;{{fil.type}}&#40;{{fil.filter}}&#41;&nbsp;&#44&nbsp;groupBy&nbsp;=&nbsp;{{fil.groupBy}}
<a ng-click="ctrl.editFilter(fil, $index)">
<i class="fa fa-pencil"></i>
</a>
<a ng-click="ctrl.removeFilter($index)">
<i class="fa fa-remove"></i>
</a>
</li>
<li class="tight-form-item query-keyword" ng-hide="ctrl.addFilterMode">
<a ng-click="ctrl.addFilter()">
<i class="fa fa-plus"></i>
</a>
</li>
<li class="query-keyword" ng-show="ctrl.addFilterMode">
<input type="text" class="input-small tight-form-input" spellcheck='false'
bs-typeahead="ctrl.suggestTagKeys" data-min-length=0 data-items=100
ng-model="ctrl.target.currentFilterKey" placeholder="key"></input>
Type <select ng-model="ctrl.target.currentFilterType"
class="tight-form-input input-small"
ng-options="filType for filType in ctrl.filterTypes">
</select>
<input type="text" class="input-small tight-form-input"
spellcheck='false' bs-typeahead="ctrl.suggestTagValues"
data-min-length=0 data-items=100 ng-model="ctrl.target.currentFilterValue" placeholder="filter">
</input>
groupBy <editor-checkbox text="" model="ctrl.target.currentFilterGroupBy"></editor-checkbox>
<a bs-tooltip="ctrl.errors.filters"
style="color: rgb(229, 189, 28)"
ng-show="ctrl.errors.filters">
<i class="fa fa-warning"></i>
</a>
<a ng-click="ctrl.addFilter()" ng-hide="ctrl.errors.filters">
add filter
</a>
<a ng-click="ctrl.closeAddFilterMode()">
<i class="fa fa-remove"></i>
</a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="tight-form"> <div class="tight-form">
<ul class="tight-form-list" role="menu"> <ul class="tight-form-list" role="menu">
<li class="tight-form-item tight-form-align query-keyword" style="width: 100px"> <li class="tight-form-item tight-form-align query-keyword" style="width: 100px">
Tags Tags
<tip ng-if="ctrl.tsdbVersion == 2">Please use filters, tags are deprecated in opentsdb 2.2</tip>
</li> </li>
<li ng-repeat="(key, value) in ctrl.target.tags track by $index" class="tight-form-item"> <li ng-repeat="(key, value) in ctrl.target.tags track by $index" class="tight-form-item">
{{key}}&nbsp;=&nbsp;{{value}} {{key}}&nbsp;=&nbsp;{{value}}
...@@ -113,14 +169,20 @@ ...@@ -113,14 +169,20 @@
spellcheck='false' bs-typeahead="ctrl.suggestTagValues" spellcheck='false' bs-typeahead="ctrl.suggestTagValues"
data-min-length=0 data-items=100 ng-model="ctrl.target.currentTagValue" placeholder="value"> data-min-length=0 data-items=100 ng-model="ctrl.target.currentTagValue" placeholder="value">
</input> </input>
<a ng-click="ctrl.addTag()">
add tag
</a>
<a bs-tooltip="ctrl.errors.tags" <a bs-tooltip="ctrl.errors.tags"
style="color: rgb(229, 189, 28)" style="color: rgb(229, 189, 28)"
ng-show="target.errors.tags"> ng-show="ctrl.errors.tags">
<i class="fa fa-warning"></i> <i class="fa fa-warning"></i>
</a> </a>
<a ng-click="ctrl.addTag()" ng-hide="ctrl.errors.tags">
add tag
</a>
<a ng-click="ctrl.closeAddTagMode()">
<i class="fa fa-remove"></i>
</a>
</li> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
......
...@@ -8,6 +8,8 @@ export class OpenTsQueryCtrl extends QueryCtrl { ...@@ -8,6 +8,8 @@ export class OpenTsQueryCtrl extends QueryCtrl {
static templateUrl = 'partials/query.editor.html'; static templateUrl = 'partials/query.editor.html';
aggregators: any; aggregators: any;
fillPolicies: any; fillPolicies: any;
filterTypes: any;
tsdbVersion: any;
aggregator: any; aggregator: any;
downsampleInterval: any; downsampleInterval: any;
downsampleAggregator: any; downsampleAggregator: any;
...@@ -17,6 +19,7 @@ export class OpenTsQueryCtrl extends QueryCtrl { ...@@ -17,6 +19,7 @@ export class OpenTsQueryCtrl extends QueryCtrl {
suggestTagKeys: any; suggestTagKeys: any;
suggestTagValues: any; suggestTagValues: any;
addTagMode: boolean; addTagMode: boolean;
addFilterMode: boolean;
/** @ngInject **/ /** @ngInject **/
constructor($scope, $injector) { constructor($scope, $injector) {
...@@ -25,6 +28,9 @@ export class OpenTsQueryCtrl extends QueryCtrl { ...@@ -25,6 +28,9 @@ export class OpenTsQueryCtrl extends QueryCtrl {
this.errors = this.validateTarget(); this.errors = this.validateTarget();
this.aggregators = ['avg', 'sum', 'min', 'max', 'dev', 'zimsum', 'mimmin', 'mimmax']; this.aggregators = ['avg', 'sum', 'min', 'max', 'dev', 'zimsum', 'mimmin', 'mimmax'];
this.fillPolicies = ['none', 'nan', 'null', 'zero']; this.fillPolicies = ['none', 'nan', 'null', 'zero'];
this.filterTypes = ['wildcard','iliteral_or','not_iliteral_or','not_literal_or','iwildcard','literal_or','regexp'];
this.tsdbVersion = this.datasource.tsdbVersion;
if (!this.target.aggregator) { if (!this.target.aggregator) {
this.target.aggregator = 'sum'; this.target.aggregator = 'sum';
...@@ -38,8 +44,16 @@ export class OpenTsQueryCtrl extends QueryCtrl { ...@@ -38,8 +44,16 @@ export class OpenTsQueryCtrl extends QueryCtrl {
this.target.downsampleFillPolicy = 'none'; this.target.downsampleFillPolicy = 'none';
} }
this.datasource.getAggregators().then(function(aggs) { this.datasource.getAggregators().then((aggs) => {
if (aggs.length !== 0) {
this.aggregators = aggs; this.aggregators = aggs;
}
});
this.datasource.getFilterTypes().then((filterTypes) => {
if (filterTypes.length !== 0) {
this.filterTypes = filterTypes;
}
}); });
// needs to be defined here as it is called from typeahead // needs to be defined here as it is called from typeahead
...@@ -70,6 +84,11 @@ export class OpenTsQueryCtrl extends QueryCtrl { ...@@ -70,6 +84,11 @@ export class OpenTsQueryCtrl extends QueryCtrl {
} }
addTag() { addTag() {
if (this.target.filters && this.target.filters.length > 0) {
this.errors.tags = "Please remove filters to use tags, tags and filters are mutually exclusive.";
}
if (!this.addTagMode) { if (!this.addTagMode) {
this.addTagMode = true; this.addTagMode = true;
return; return;
...@@ -103,6 +122,73 @@ export class OpenTsQueryCtrl extends QueryCtrl { ...@@ -103,6 +122,73 @@ export class OpenTsQueryCtrl extends QueryCtrl {
this.addTag(); this.addTag();
} }
closeAddTagMode() {
this.addTagMode = false;
return;
}
addFilter() {
if (this.target.tags && _.size(this.target.tags) > 0) {
this.errors.filters = "Please remove tags to use filters, tags and filters are mutually exclusive.";
}
if (!this.addFilterMode) {
this.addFilterMode = true;
return;
}
if (!this.target.filters) {
this.target.filters = [];
}
if (!this.target.currentFilterType) {
this.target.currentFilterType = 'iliteral_or';
}
if (!this.target.currentFilterGroupBy) {
this.target.currentFilterGroupBy = false;
}
this.errors = this.validateTarget();
if (!this.errors.filters) {
var currentFilter = {
type: this.target.currentFilterType,
tagk: this.target.currentFilterKey,
filter: this.target.currentFilterValue,
groupBy: this.target.currentFilterGroupBy
};
this.target.filters.push(currentFilter);
this.target.currentFilterType = 'literal_or';
this.target.currentFilterKey = '';
this.target.currentFilterValue = '';
this.target.currentFilterGroupBy = false;
this.targetBlur();
}
this.addFilterMode = false;
}
removeFilter(index) {
this.target.filters.splice(index, 1);
this.targetBlur();
}
editFilter(fil, index) {
this.removeFilter(index);
this.target.currentFilterKey = fil.tagk;
this.target.currentFilterValue = fil.filter;
this.target.currentFilterType = fil.type;
this.target.currentFilterGroupBy = fil.groupBy;
this.addFilter();
}
closeAddFilterMode() {
this.addFilterMode = false;
return;
}
validateTarget() { validateTarget() {
var errs: any = {}; var errs: any = {};
......
...@@ -4,7 +4,7 @@ import {OpenTsDatasource} from "../datasource"; ...@@ -4,7 +4,7 @@ import {OpenTsDatasource} from "../datasource";
describe('opentsdb', function() { describe('opentsdb', function() {
var ctx = new helpers.ServiceTestContext(); var ctx = new helpers.ServiceTestContext();
var instanceSettings = {url: '' }; var instanceSettings = {url: '', jsonData: { tsdbVersion: 1 }};
beforeEach(angularMocks.module('grafana.core')); beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services')); beforeEach(angularMocks.module('grafana.services'));
......
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
import helpers from 'test/specs/helpers';
import {OpenTsQueryCtrl} from "../query_ctrl";
describe('OpenTsQueryCtrl', function() {
var ctx = new helpers.ControllerTestContext();
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(ctx.providePhase(['backendSrv','templateSrv']));
beforeEach(ctx.providePhase());
beforeEach(angularMocks.inject(($rootScope, $controller, $q) => {
ctx.$q = $q;
ctx.scope = $rootScope.$new();
ctx.target = {target: ''};
ctx.panelCtrl = {panel: {}};
ctx.panelCtrl.refresh = sinon.spy();
ctx.datasource.getAggregators = sinon.stub().returns(ctx.$q.when([]));
ctx.datasource.getFilterTypes = sinon.stub().returns(ctx.$q.when([]));
ctx.ctrl = $controller(OpenTsQueryCtrl, {$scope: ctx.scope}, {
panelCtrl: ctx.panelCtrl,
datasource: ctx.datasource,
target: ctx.target,
});
ctx.scope.$digest();
}));
describe('init query_ctrl variables', function() {
it('filter types should be initialized', function() {
expect(ctx.ctrl.filterTypes.length).to.be(7);
});
it('aggregators should be initialized', function() {
expect(ctx.ctrl.aggregators.length).to.be(8);
});
it('fill policy options should be initialized', function() {
expect(ctx.ctrl.fillPolicies.length).to.be(4);
});
});
describe('when adding filters and tags', function() {
it('addTagMode should be false when closed', function() {
ctx.ctrl.addTagMode = true;
ctx.ctrl.closeAddTagMode();
expect(ctx.ctrl.addTagMode).to.be(false);
});
it('addFilterMode should be false when closed', function() {
ctx.ctrl.addFilterMode = true;
ctx.ctrl.closeAddFilterMode();
expect(ctx.ctrl.addFilterMode).to.be(false);
});
it('removing a tag from the tags list', function() {
ctx.ctrl.target.tags = {"tagk": "tag_key", "tagk2": "tag_value2"};
ctx.ctrl.removeTag("tagk");
expect(Object.keys(ctx.ctrl.target.tags).length).to.be(1);
});
it('removing a filter from the filters list', function() {
ctx.ctrl.target.filters = [{"tagk": "tag_key", "filter": "tag_value2", "type": "wildcard", "groupBy": true}];
ctx.ctrl.removeFilter(0);
expect(ctx.ctrl.target.filters.length).to.be(0);
});
it('adding a filter when tags exist should generate error', function() {
ctx.ctrl.target.tags = {"tagk": "tag_key", "tagk2": "tag_value2"};
ctx.ctrl.addFilter();
expect(ctx.ctrl.errors.filters).to.be('Please remove tags to use filters, tags and filters are mutually exclusive.');
});
it('adding a tag when filters exist should generate error', function() {
ctx.ctrl.target.filters = [{"tagk": "tag_key", "filter": "tag_value2", "type": "wildcard", "groupBy": true}];
ctx.ctrl.addTag();
expect(ctx.ctrl.errors.tags).to.be('Please remove filters to use tags, tags and filters are mutually exclusive.');
});
});
});
...@@ -11,16 +11,16 @@ function (_, moment) { ...@@ -11,16 +11,16 @@ function (_, moment) {
} }
PrometheusMetricFindQuery.prototype.process = function() { PrometheusMetricFindQuery.prototype.process = function() {
var label_values_regex = /^label_values\(([^,]+)(?:,\s*(.+))?\)$/; var label_values_regex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]+)\)$/;
var metric_names_regex = /^metrics\((.+)\)$/; var metric_names_regex = /^metrics\((.+)\)$/;
var query_result_regex = /^query_result\((.+)\)$/; var query_result_regex = /^query_result\((.+)\)$/;
var label_values_query = this.query.match(label_values_regex); var label_values_query = this.query.match(label_values_regex);
if (label_values_query) { if (label_values_query) {
if (label_values_query[2]) { if (label_values_query[1]) {
return this.labelValuesQuery(label_values_query[2], label_values_query[1]); return this.labelValuesQuery(label_values_query[2], label_values_query[1]);
} else { } else {
return this.labelValuesQuery(label_values_query[1], null); return this.labelValuesQuery(label_values_query[2], null);
} }
} }
......
...@@ -48,6 +48,22 @@ describe('PrometheusMetricFindQuery', function() { ...@@ -48,6 +48,22 @@ describe('PrometheusMetricFindQuery', function() {
ctx.$rootScope.$apply(); ctx.$rootScope.$apply();
expect(results.length).to.be(3); expect(results.length).to.be(3);
}); });
it('label_values(metric{label1="foo", label2="bar", label3="baz"}, resource) should generate series query', function() {
response = {
status: "success",
data: [
{__name__: "metric", resource: "value1"},
{__name__: "metric", resource: "value2"},
{__name__: "metric", resource: "value3"}
]
};
ctx.$httpBackend.expect('GET', 'proxied/api/v1/series?match[]=metric').respond(response);
var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(metric, resource)');
pm.process().then(function(data) { results = data; });
ctx.$httpBackend.flush();
ctx.$rootScope.$apply();
expect(results.length).to.be(3);
});
it('metrics(metric.*) should generate metric name query', function() { it('metrics(metric.*) should generate metric name query', function() {
response = { response = {
status: "success", status: "success",
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{{dash.title}} {{dash.title}}
</span> </span>
<span class="dashlist-star"> <span class="dashlist-star">
<i class="fa" ng-class="{'fa-star': dash.isStarred, 'fa-star-o': !dash.isStarred}"></i> <i class="fa" ng-class="{'fa-star': dash.isStarred, 'fa-star-o': dash.isStarred === false}"></i>
</span> </span>
</a> </a>
</div> </div>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import _ from 'lodash'; import _ from 'lodash';
import config from 'app/core/config'; import config from 'app/core/config';
import {PanelCtrl} from 'app/plugins/sdk'; import {PanelCtrl} from 'app/plugins/sdk';
import {impressions} from 'app/features/dashboard/impressionStore';
// Set and populate defaults // Set and populate defaults
var panelDefaults = { var panelDefaults = {
...@@ -31,7 +32,7 @@ class DashListCtrl extends PanelCtrl { ...@@ -31,7 +32,7 @@ class DashListCtrl extends PanelCtrl {
initEditMode() { initEditMode() {
super.initEditMode(); super.initEditMode();
this.modes = ['starred', 'search']; this.modes = ['starred', 'search', 'last viewed'];
this.icon = "fa fa-star"; this.icon = "fa fa-star";
this.addEditorTab('Options', () => { this.addEditorTab('Options', () => {
return {templateUrl: 'public/app/plugins/panel/dashlist/editor.html'}; return {templateUrl: 'public/app/plugins/panel/dashlist/editor.html'};
...@@ -41,6 +42,19 @@ class DashListCtrl extends PanelCtrl { ...@@ -41,6 +42,19 @@ class DashListCtrl extends PanelCtrl {
refresh() { refresh() {
var params: any = {limit: this.panel.limit}; var params: any = {limit: this.panel.limit};
if (this.panel.mode === 'last viewed') {
var dashListNames = _.first(impressions.getDashboardOpened(), this.panel.limit).map((dashboard) => {
return {
title: dashboard,
uri: 'db/' + dashboard
};
});
this.dashList = dashListNames;
this.renderingCompleted();
return;
}
if (this.panel.mode === 'starred') { if (this.panel.mode === 'starred') {
params.starred = "true"; params.starred = "true";
} else { } else {
......
...@@ -125,7 +125,8 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -125,7 +125,8 @@ class GraphCtrl extends MetricsPanelCtrl {
getExtendedMenu() { getExtendedMenu() {
var menu = super.getExtendedMenu(); var menu = super.getExtendedMenu();
menu.push({text: 'Export CSV', click: 'ctrl.exportCsv()'}); menu.push({text: 'Export CSV (series as rows)', click: 'ctrl.exportCsv()'});
menu.push({text: 'Export CSV (series as columns)', click: 'ctrl.exportCsvColumns()'});
menu.push({text: 'Toggle legend', click: 'ctrl.toggleLegend()'}); menu.push({text: 'Toggle legend', click: 'ctrl.toggleLegend()'});
return menu; return menu;
} }
...@@ -295,6 +296,10 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -295,6 +296,10 @@ class GraphCtrl extends MetricsPanelCtrl {
exportCsv() { exportCsv() {
fileExport.exportSeriesListToCsv(this.seriesList); fileExport.exportSeriesListToCsv(this.seriesList);
} }
exportCsvColumns() {
fileExport.exportSeriesListToCsvColumns(this.seriesList);
}
} }
export {GraphCtrl, GraphCtrl as PanelCtrl} export {GraphCtrl, GraphCtrl as PanelCtrl}
...@@ -167,13 +167,13 @@ ...@@ -167,13 +167,13 @@
<i class="fa fa-remove pointer" ng-click="ctrl.removeValueMap(map)"></i> <i class="fa fa-remove pointer" ng-click="ctrl.removeValueMap(map)"></i>
</li> </li>
<li> <li>
<input type="text" ng-model="ctrl.map.value" placeholder="value" class="input-mini tight-form-input" ng-blur="ctrl.render()"> <input type="text" ng-model="map.value" placeholder="value" class="input-mini tight-form-input" ng-blur="ctrl.render()">
</li> </li>
<li class="tight-form-item"> <li class="tight-form-item">
<i class="fa fa-arrow-right"></i> <i class="fa fa-arrow-right"></i>
</li> </li>
<li ng-repeat-end> <li ng-repeat-end>
<input type="text" placeholder="text" ng-model="ctrl.map.text" class="input-mini tight-form-input" ng-blur="ctrl.render()"> <input type="text" placeholder="text" ng-model="map.text" class="input-mini tight-form-input" ng-blur="ctrl.render()">
</li> </li>
<li> <li>
......
...@@ -50,7 +50,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { ...@@ -50,7 +50,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
unitFormats: any[]; unitFormats: any[];
/** @ngInject */ /** @ngInject */
constructor($scope, $injector, private $location, private linkSrv, private templateSrv) { constructor($scope, $injector, private $location, private linkSrv) {
super($scope, $injector); super($scope, $injector);
_.defaults(this.panel, panelDefaults); _.defaults(this.panel, panelDefaults);
} }
...@@ -213,7 +213,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { ...@@ -213,7 +213,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
// value/number to text mapping // value/number to text mapping
var value = parseFloat(map.value); var value = parseFloat(map.value);
if (value === data.value) { if (value === data.valueRounded) {
data.valueFormated = map.text; data.valueFormated = map.text;
return; return;
} }
......
...@@ -69,14 +69,20 @@ describe('SingleStatCtrl', function() { ...@@ -69,14 +69,20 @@ describe('SingleStatCtrl', function() {
singleStatScenario('When value to text mapping is specified', function(ctx) { singleStatScenario('When value to text mapping is specified', function(ctx) {
ctx.setup(function() { ctx.setup(function() {
ctx.datapoints = [[10,1]]; ctx.datapoints = [[9.9,1]];
ctx.ctrl.panel.valueMaps = [{value: '10', text: 'OK'}]; ctx.ctrl.panel.valueMaps = [{value: '10', text: 'OK'}];
}); });
it('value should remain', function() {
expect(ctx.data.value).to.be(9.9);
});
it('round should be rounded up', function() {
expect(ctx.data.valueRounded).to.be(10);
});
it('Should replace value with text', function() { it('Should replace value with text', function() {
expect(ctx.data.value).to.be(10);
expect(ctx.data.valueFormated).to.be('OK'); expect(ctx.data.valueFormated).to.be('OK');
}); });
}); });
}); });
...@@ -47,11 +47,11 @@ ...@@ -47,11 +47,11 @@
{ {
"id": 3, "id": 3,
"limit": 10, "limit": 10,
"mode": "search", "mode": "last viewed",
"query": "", "query": "",
"span": 6, "span": 6,
"tags": [], "tags": [],
"title": "Dashboards", "title": "Last 10 viewed dashboards",
"type": "dashlist" "type": "dashlist"
} }
], ],
......
...@@ -28,10 +28,6 @@ ...@@ -28,10 +28,6 @@
vertical-align: middle; vertical-align: middle;
} }
.icon-gf-raintank_wordmark:before { .icon-gf-raintank_wordmark:before {
content: "\e600"; content: "\e600";
} }
......
...@@ -131,7 +131,7 @@ mark, ...@@ -131,7 +131,7 @@ mark,
// Unordered and Ordered lists // Unordered and Ordered lists
ul, ol { ul, ol {
padding: 0; padding: 0;
margin: 0 0 $line-height-base / 2 25px; padding-left: $spacer;
} }
ul ul, ul ul,
ul ol, ul ol,
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
width: 15px; width: 15px;
height: 15px; height: 15px;
border: none; border: none;
margin-right: 5px; margin: 0;
float: left; float: left;
z-index: 0; z-index: 0;
} }
...@@ -127,7 +127,7 @@ define([ ...@@ -127,7 +127,7 @@ define([
it('10m 1600 resolution', function() { it('10m 1600 resolution', function() {
var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') }; var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
var str = kbn.calculateInterval(range, 1600, null); var str = kbn.calculateInterval(range, 1600, null);
expect(str).to.be('100ms'); expect(str).to.be('500ms');
}); });
it('fixed user interval', function() { it('fixed user interval', function() {
...@@ -145,7 +145,7 @@ define([ ...@@ -145,7 +145,7 @@ define([
it('large time range and user low limit', function() { it('large time range and user low limit', function() {
var range = { from: dateMath.parse('now-14d'), to: dateMath.parse('now') }; var range = { from: dateMath.parse('now-14d'), to: dateMath.parse('now') };
var str = kbn.calculateInterval(range, 1000, '>10s'); var str = kbn.calculateInterval(range, 1000, '>10s');
expect(str).to.be('30m'); expect(str).to.be('20m');
}); });
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment