diff --git a/public/app/core/components/grafana_app.ts b/public/app/core/components/grafana_app.ts index 286c3f743c7..6c7b8cf3bf7 100644 --- a/public/app/core/components/grafana_app.ts +++ b/public/app/core/components/grafana_app.ts @@ -28,7 +28,7 @@ export class GrafanaCtrl { setBackendSrv(backendSrv); createStore({ backendSrv, datasourceSrv }); - $scope.init = function() { + $scope.init = () => { $scope.contextSrv = contextSrv; $scope.appSubUrl = config.appSubUrl; $scope._ = _; @@ -43,7 +43,7 @@ export class GrafanaCtrl { $rootScope.colors = colors; - $scope.initDashboard = function(dashboardData, viewScope) { + $scope.initDashboard = (dashboardData, viewScope) => { $scope.appEvent('dashboard-fetch-end', dashboardData); $controller('DashboardCtrl', { $scope: viewScope }).init(dashboardData); }; @@ -60,7 +60,7 @@ export class GrafanaCtrl { callerScope.$on('$destroy', unbind); }; - $rootScope.appEvent = function(name, payload) { + $rootScope.appEvent = (name, payload) => { $rootScope.$emit(name, payload); appEvents.emit(name, payload); }; @@ -103,7 +103,7 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop const body = $('body'); // see https://github.com/zenorocha/clipboard.js/issues/155 - $.fn.modal.Constructor.prototype.enforceFocus = function() {}; + $.fn.modal.Constructor.prototype.enforceFocus = () => {}; $('.preloader').remove(); @@ -123,9 +123,12 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop body.toggleClass('sidemenu-hidden'); }); - scope.$watch(() => playlistSrv.isPlaying, function(newValue) { - elem.toggleClass('view-mode--playlist', newValue === true); - }); + scope.$watch( + () => playlistSrv.isPlaying, + newValue => { + elem.toggleClass('view-mode--playlist', newValue === true); + } + ); // check if we are in server side render if (document.cookie.indexOf('renderKey') !== -1) { @@ -135,7 +138,7 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop // tooltip removal fix // manage page classes let pageClass; - scope.$on('$routeChangeSuccess', function(evt, data) { + scope.$on('$routeChangeSuccess', (evt, data) => { if (pageClass) { body.removeClass(pageClass); } @@ -236,7 +239,7 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop }); // handle document clicks that should hide things - body.click(function(evt) { + body.click(evt => { const target = $(evt.target); if (target.parents().length === 0) { return; @@ -248,7 +251,7 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop if (clickAutoHide.length) { const clickAutoHideParent = clickAutoHide.parent(); clickAutoHide.detach(); - setTimeout(function() { + setTimeout(() => { clickAutoHideParent.append(clickAutoHide); }, 100); } @@ -260,7 +263,7 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop // hide search if (body.find('.search-container').length > 0) { if (target.parents('.search-results-container, .search-field-wrapper').length === 0) { - scope.$apply(function() { + scope.$apply(() => { scope.appEvent('hide-dash-search'); }); } diff --git a/public/app/core/components/info_popover.ts b/public/app/core/components/info_popover.ts index ae4feeec701..2ada91b09f1 100644 --- a/public/app/core/components/info_popover.ts +++ b/public/app/core/components/info_popover.ts @@ -7,7 +7,7 @@ export function infoPopover() { restrict: 'E', template: '', transclude: true, - link: function(scope, elem, attrs, ctrl, transclude) { + link: (scope, elem, attrs, ctrl, transclude) => { const offset = attrs.offset || '0 -10px'; const position = attrs.position || 'right middle'; let classes = 'drop-help drop-hide-out-of-bounds'; @@ -23,7 +23,7 @@ export function infoPopover() { elem.addClass('gf-form-help-icon--' + attrs.mode); } - transclude(function(clone, newScope) { + transclude((clone, newScope) => { const content = document.createElement('div'); content.className = 'markdown-html'; @@ -54,7 +54,7 @@ export function infoPopover() { scope.$applyAsync(() => { const drop = new Drop(dropOptions); - const unbind = scope.$on('$destroy', function() { + const unbind = scope.$on('$destroy', () => { drop.destroy(); unbind(); }); diff --git a/public/app/core/components/layout_selector/layout_selector.ts b/public/app/core/components/layout_selector/layout_selector.ts index 6fcc768c846..b3f3cdc14d1 100644 --- a/public/app/core/components/layout_selector/layout_selector.ts +++ b/public/app/core/components/layout_selector/layout_selector.ts @@ -50,7 +50,7 @@ export function layoutMode($rootScope) { return { restrict: 'A', scope: {}, - link: function(scope, elem) { + link: (scope, elem) => { const layout = store.get('grafana.list.layout.mode') || 'grid'; let className = 'card-list-layout-' + layout; elem.addClass(className); diff --git a/public/app/core/components/navbar/navbar.ts b/public/app/core/components/navbar/navbar.ts index 7e95be72458..db0924738ed 100644 --- a/public/app/core/components/navbar/navbar.ts +++ b/public/app/core/components/navbar/navbar.ts @@ -30,7 +30,7 @@ export function navbarDirective() { scope: { model: '=', }, - link: function(scope, elem) {}, + link: (scope, elem) => {}, }; } diff --git a/public/app/core/components/query_part/query_part_editor.ts b/public/app/core/components/query_part/query_part_editor.ts index d45c6532364..6181d020471 100644 --- a/public/app/core/components/query_part/query_part_editor.ts +++ b/public/app/core/components/query_part/query_part_editor.ts @@ -89,20 +89,20 @@ export function queryPartEditorDirective($compile, templateSrv) { return; } - const typeaheadSource = function(query, callback) { + const typeaheadSource = (query, callback) => { if (param.options) { let options = param.options; if (param.type === 'int') { - options = _.map(options, function(val) { + options = _.map(options, val => { return val.toString(); }); } return options; } - $scope.$apply(function() { - $scope.handleEvent({ $event: { name: 'get-param-options' } }).then(function(result) { - const dynamicOptions = _.map(result, function(op) { + $scope.$apply(() => { + $scope.handleEvent({ $event: { name: 'get-param-options' } }).then(result => { + const dynamicOptions = _.map(result, op => { return op.value; }); callback(dynamicOptions); @@ -116,8 +116,8 @@ export function queryPartEditorDirective($compile, templateSrv) { source: typeaheadSource, minLength: 0, items: 1000, - updater: function(value) { - setTimeout(function() { + updater: value => { + setTimeout(() => { inputBlur.call($input[0], paramIndex); }, 0); return value; @@ -136,18 +136,18 @@ export function queryPartEditorDirective($compile, templateSrv) { } } - $scope.showActionsMenu = function() { + $scope.showActionsMenu = () => { $scope.handleEvent({ $event: { name: 'get-part-actions' } }).then(res => { $scope.partActions = res; }); }; - $scope.triggerPartAction = function(action) { + $scope.triggerPartAction = action => { $scope.handleEvent({ $event: { name: 'action', action: action } }); }; function addElementsAndCompile() { - _.each(partDef.params, function(param, index) { + _.each(partDef.params, (param, index) => { if (param.optional && part.params.length <= index) { return; } diff --git a/public/app/core/controllers/inspect_ctrl.ts b/public/app/core/controllers/inspect_ctrl.ts index c55a0d50902..d106b42da16 100644 --- a/public/app/core/controllers/inspect_ctrl.ts +++ b/public/app/core/controllers/inspect_ctrl.ts @@ -28,7 +28,7 @@ export class InspectCtrl { } if (model.error.config && model.error.config.params) { - $scope.request_parameters = _.map(model.error.config.params, function(value, key) { + $scope.request_parameters = _.map(model.error.config.params, (value, key) => { return { key: key, value: value }; }); } @@ -45,7 +45,7 @@ export class InspectCtrl { if (_.isString(model.error.config.data)) { $scope.request_parameters = this.getParametersFromQueryString(model.error.config.data); } else { - $scope.request_parameters = _.map(model.error.config.data, function(value, key) { + $scope.request_parameters = _.map(model.error.config.data, (value, key) => { return { key: key, value: angular.toJson(value, true) }; }); } diff --git a/public/app/core/controllers/json_editor_ctrl.ts b/public/app/core/controllers/json_editor_ctrl.ts index 3260f6ff537..9c3f9d9e98d 100644 --- a/public/app/core/controllers/json_editor_ctrl.ts +++ b/public/app/core/controllers/json_editor_ctrl.ts @@ -8,7 +8,7 @@ export class JsonEditorCtrl { $scope.canUpdate = $scope.updateHandler !== void 0 && $scope.contextSrv.isEditor; $scope.canCopy = $scope.enableCopy; - $scope.update = function() { + $scope.update = () => { const newObject = angular.fromJson($scope.json); $scope.updateHandler(newObject, $scope.object); }; diff --git a/public/app/core/directives/array_join.ts b/public/app/core/directives/array_join.ts index f3416f43576..c906319e985 100644 --- a/public/app/core/directives/array_join.ts +++ b/public/app/core/directives/array_join.ts @@ -7,7 +7,7 @@ export function arrayJoin() { return { restrict: 'A', require: 'ngModel', - link: function(scope, element, attr, ngModel) { + link: (scope, element, attr, ngModel) => { function split_array(text) { return (text || '').split(','); } diff --git a/public/app/features/annotations/annotation_tooltip.ts b/public/app/features/annotations/annotation_tooltip.ts index 6da6fc4f66d..7e626bc5860 100644 --- a/public/app/features/annotations/annotation_tooltip.ts +++ b/public/app/features/annotations/annotation_tooltip.ts @@ -20,7 +20,7 @@ export function annotationTooltipDirective($sanitize, dashboardSrv, contextSrv, event: '=', onEdit: '&', }, - link: function(scope, element) { + link: (scope, element) => { const event = scope.event; let title = event.title; let text = event.text; diff --git a/public/app/features/panellinks/link_srv.ts b/public/app/features/panellinks/link_srv.ts index 9f18a76bf61..f9ad40c50da 100644 --- a/public/app/features/panellinks/link_srv.ts +++ b/public/app/features/panellinks/link_srv.ts @@ -26,14 +26,14 @@ export class LinkSrv { addParamsToUrl(url, params) { const paramsArray = []; - _.each(params, function(value, key) { + _.each(params, (value, key) => { if (value === null) { return; } if (value === true) { paramsArray.push(key); } else if (_.isArray(value)) { - _.each(value, function(instance) { + _.each(value, instance => { paramsArray.push(key + '=' + encodeURIComponent(instance)); }); } else { diff --git a/public/app/features/plugins/datasource_srv.ts b/public/app/features/plugins/datasource_srv.ts index b73c91ddb2b..7ef82519668 100644 --- a/public/app/features/plugins/datasource_srv.ts +++ b/public/app/features/plugins/datasource_srv.ts @@ -77,7 +77,7 @@ export class DatasourceSrv { this.addDataSourceVariables(sources); - _.each(config.datasources, function(value) { + _.each(config.datasources, value => { if (value.meta && value.meta.annotations) { sources.push(value); } @@ -97,7 +97,7 @@ export class DatasourceSrv { getMetricSources(options) { const metricSources = []; - _.each(config.datasources, function(value, key) { + _.each(config.datasources, (value, key) => { if (value.meta && value.meta.metrics) { let metricSource = { value: key, name: key, meta: value.meta, sort: key }; @@ -121,7 +121,7 @@ export class DatasourceSrv { this.addDataSourceVariables(metricSources); } - metricSources.sort(function(a, b) { + metricSources.sort((a, b) => { if (a.sort.toLowerCase() > b.sort.toLowerCase()) { return 1; } diff --git a/public/app/features/plugins/plugin_loader.ts b/public/app/features/plugins/plugin_loader.ts index e227dbb910c..bc3c719917c 100644 --- a/public/app/features/plugins/plugin_loader.ts +++ b/public/app/features/plugins/plugin_loader.ts @@ -65,7 +65,7 @@ System.config({ }); function exposeToPlugin(name: string, component: any) { - System.registerDynamic(name, [], true, function(require, exports, module) { + System.registerDynamic(name, [], true, (require, exports, module) => { module.exports = component; }); } diff --git a/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.ts b/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.ts index 065a7100b09..4f4b2961761 100644 --- a/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.ts +++ b/public/app/plugins/datasource/cloudwatch/query_parameter_ctrl.ts @@ -19,7 +19,7 @@ export class CloudWatchQueryParameter { export class CloudWatchQueryParameterCtrl { /** @ngInject */ constructor($scope, templateSrv, uiSegmentSrv, datasourceSrv, $q) { - $scope.init = function() { + $scope.init = () => { const target = $scope.target; target.namespace = target.namespace || ''; target.metricName = target.metricName || ''; @@ -38,7 +38,7 @@ export class CloudWatchQueryParameterCtrl { $scope.dimSegments = _.reduce( $scope.target.dimensions, - function(memo, value, key) { + (memo, value, key) => { memo.push(uiSegmentSrv.newKey(key)); memo.push(uiSegmentSrv.newOperator('=')); memo.push(uiSegmentSrv.newKeyValue(value)); @@ -47,7 +47,7 @@ export class CloudWatchQueryParameterCtrl { [] ); - $scope.statSegments = _.map($scope.target.statistics, function(stat) { + $scope.statSegments = _.map($scope.target.statistics, stat => { return uiSegmentSrv.getSegmentForValue(stat); }); @@ -67,15 +67,15 @@ export class CloudWatchQueryParameterCtrl { } if (!$scope.onChange) { - $scope.onChange = function() {}; + $scope.onChange = () => {}; } }; - $scope.getStatSegments = function() { + $scope.getStatSegments = () => { return $q.when( _.flatten([ angular.copy($scope.removeStatSegment), - _.map($scope.datasource.standardStatistics, function(s) { + _.map($scope.datasource.standardStatistics, s => { return uiSegmentSrv.getSegmentForValue(s); }), uiSegmentSrv.getSegmentForValue('pNN.NN'), @@ -83,7 +83,7 @@ export class CloudWatchQueryParameterCtrl { ); }; - $scope.statSegmentChanged = function(segment, index) { + $scope.statSegmentChanged = (segment, index) => { if (segment.value === $scope.removeStatSegment.value) { $scope.statSegments.splice(index, 1); } else { @@ -92,7 +92,7 @@ export class CloudWatchQueryParameterCtrl { $scope.target.statistics = _.reduce( $scope.statSegments, - function(memo, seg) { + (memo, seg) => { if (!seg.fake) { memo.push(seg.value); } @@ -105,7 +105,7 @@ export class CloudWatchQueryParameterCtrl { $scope.onChange(); }; - $scope.ensurePlusButton = function(segments) { + $scope.ensurePlusButton = segments => { const count = segments.length; const lastSegment = segments[Math.max(count - 1, 0)]; @@ -114,7 +114,7 @@ export class CloudWatchQueryParameterCtrl { } }; - $scope.getDimSegments = function(segment, $index) { + $scope.getDimSegments = (segment, $index) => { if (segment.type === 'operator') { return $q.when([]); } @@ -135,7 +135,7 @@ export class CloudWatchQueryParameterCtrl { ); } - return query.then($scope.transformToSegments(true)).then(function(results) { + return query.then($scope.transformToSegments(true)).then(results => { if (segment.type === 'key') { results.splice(0, 0, angular.copy($scope.removeDimSegment)); } @@ -143,7 +143,7 @@ export class CloudWatchQueryParameterCtrl { }); }; - $scope.dimSegmentChanged = function(segment, index) { + $scope.dimSegmentChanged = (segment, index) => { $scope.dimSegments[index] = segment; if (segment.value === $scope.removeDimSegment.value) { @@ -160,7 +160,7 @@ export class CloudWatchQueryParameterCtrl { $scope.onChange(); }; - $scope.syncDimSegmentsWithModel = function() { + $scope.syncDimSegmentsWithModel = () => { const dims = {}; const length = $scope.dimSegments.length; @@ -175,44 +175,44 @@ export class CloudWatchQueryParameterCtrl { $scope.target.dimensions = dims; }; - $scope.getRegions = function() { + $scope.getRegions = () => { return $scope.datasource .metricFindQuery('regions()') - .then(function(results) { + .then(results => { results.unshift({ text: 'default' }); return results; }) .then($scope.transformToSegments(true)); }; - $scope.getNamespaces = function() { + $scope.getNamespaces = () => { return $scope.datasource.metricFindQuery('namespaces()').then($scope.transformToSegments(true)); }; - $scope.getMetrics = function() { + $scope.getMetrics = () => { return $scope.datasource .metricFindQuery('metrics(' + $scope.target.namespace + ',' + $scope.target.region + ')') .then($scope.transformToSegments(true)); }; - $scope.regionChanged = function() { + $scope.regionChanged = () => { $scope.target.region = $scope.regionSegment.value; $scope.onChange(); }; - $scope.namespaceChanged = function() { + $scope.namespaceChanged = () => { $scope.target.namespace = $scope.namespaceSegment.value; $scope.onChange(); }; - $scope.metricChanged = function() { + $scope.metricChanged = () => { $scope.target.metricName = $scope.metricSegment.value; $scope.onChange(); }; - $scope.transformToSegments = function(addTemplateVars) { - return function(results) { - const segments = _.map(results, function(segment) { + $scope.transformToSegments = addTemplateVars => { + return results => { + const segments = _.map(results, segment => { return uiSegmentSrv.newSegment({ value: segment.text, expandable: segment.expandable, @@ -220,7 +220,7 @@ export class CloudWatchQueryParameterCtrl { }); if (addTemplateVars) { - _.each(templateSrv.variables, function(variable) { + _.each(templateSrv.variables, variable => { segments.unshift( uiSegmentSrv.newSegment({ type: 'template', diff --git a/public/app/plugins/datasource/elasticsearch/bucket_agg.ts b/public/app/plugins/datasource/elasticsearch/bucket_agg.ts index 8c8e00b34ec..e17a34778ee 100644 --- a/public/app/plugins/datasource/elasticsearch/bucket_agg.ts +++ b/public/app/plugins/datasource/elasticsearch/bucket_agg.ts @@ -23,36 +23,36 @@ export class ElasticBucketAggCtrl { $scope.orderByOptions = []; - $scope.getBucketAggTypes = function() { + $scope.getBucketAggTypes = () => { return queryDef.bucketAggTypes; }; - $scope.getOrderOptions = function() { + $scope.getOrderOptions = () => { return queryDef.orderOptions; }; - $scope.getSizeOptions = function() { + $scope.getSizeOptions = () => { return queryDef.sizeOptions; }; $rootScope.onAppEvent( 'elastic-query-updated', - function() { + () => { $scope.validateModel(); }, $scope ); - $scope.init = function() { + $scope.init = () => { $scope.agg = bucketAggs[$scope.index]; $scope.validateModel(); }; - $scope.onChangeInternal = function() { + $scope.onChangeInternal = () => { $scope.onChange(); }; - $scope.onTypeChanged = function() { + $scope.onTypeChanged = () => { $scope.agg.settings = {}; $scope.showOptions = false; @@ -79,7 +79,7 @@ export class ElasticBucketAggCtrl { $scope.onChange(); }; - $scope.validateModel = function() { + $scope.validateModel = () => { $scope.index = _.indexOf(bucketAggs, $scope.agg); $scope.isFirst = $scope.index === 0; $scope.bucketAggCount = bucketAggs.length; @@ -114,7 +114,7 @@ export class ElasticBucketAggCtrl { settings.filters = settings.filters || [{ query: '*' }]; settingsLinkText = _.reduce( settings.filters, - function(memo, value, index) { + (memo, value, index) => { memo += 'Q' + (index + 1) + ' = ' + value.query + ' '; return memo; }, @@ -168,23 +168,23 @@ export class ElasticBucketAggCtrl { return true; }; - $scope.addFiltersQuery = function() { + $scope.addFiltersQuery = () => { $scope.agg.settings.filters.push({ query: '*' }); }; - $scope.removeFiltersQuery = function(filter) { + $scope.removeFiltersQuery = filter => { $scope.agg.settings.filters = _.without($scope.agg.settings.filters, filter); }; - $scope.toggleOptions = function() { + $scope.toggleOptions = () => { $scope.showOptions = !$scope.showOptions; }; - $scope.getOrderByOptions = function() { + $scope.getOrderByOptions = () => { return queryDef.getOrderByOptions($scope.target); }; - $scope.getFieldsInternal = function() { + $scope.getFieldsInternal = () => { if ($scope.agg.type === 'date_histogram') { return $scope.getFields({ $fieldType: 'date' }); } else { @@ -192,11 +192,11 @@ export class ElasticBucketAggCtrl { } }; - $scope.getIntervalOptions = function() { + $scope.getIntervalOptions = () => { return $q.when(uiSegmentSrv.transformToSegments(true, 'interval')(queryDef.intervalOptions)); }; - $scope.addBucketAgg = function() { + $scope.addBucketAgg = () => { // if last is date histogram add it before const lastBucket = bucketAggs[bucketAggs.length - 1]; let addIndex = bucketAggs.length - 1; @@ -207,7 +207,7 @@ export class ElasticBucketAggCtrl { const id = _.reduce( $scope.target.bucketAggs.concat($scope.target.metrics), - function(max, val) { + (max, val) => { return parseInt(val.id) > max ? parseInt(val.id) : max; }, 0 @@ -217,7 +217,7 @@ export class ElasticBucketAggCtrl { $scope.onChange(); }; - $scope.removeBucketAgg = function() { + $scope.removeBucketAgg = () => { bucketAggs.splice($scope.index, 1); $scope.onChange(); }; diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index f1e7bf78514..c2f2364d49d 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -59,12 +59,12 @@ export class ElasticDatasource { const range = this.timeSrv.timeRange(); const indexList = this.indexPattern.getIndexList(range.from.valueOf(), range.to.valueOf()); if (_.isArray(indexList) && indexList.length) { - return this.request('GET', indexList[0] + url).then(function(results) { + return this.request('GET', indexList[0] + url).then(results => { results.data.$$config = results.config; return results.data; }); } else { - return this.request('GET', this.indexPattern.getIndexForToday() + url).then(function(results) { + return this.request('GET', this.indexPattern.getIndexForToday() + url).then(results => { results.data.$$config = results.config; return results.data; }); @@ -73,7 +73,7 @@ export class ElasticDatasource { private post(url, data) { return this.request('POST', url, data) - .then(function(results) { + .then(results => { results.data.$$config = results.config; return results.data; }) @@ -145,7 +145,7 @@ export class ElasticDatasource { const list = []; const hits = res.responses[0].hits.hits; - const getFieldFromSource = function(source, fieldName) { + const getFieldFromSource = (source, fieldName) => { if (!fieldName) { return; } @@ -213,7 +213,7 @@ export class ElasticDatasource { } return { status: 'success', message: 'Index OK. Time field name OK.' }; }, - function(err) { + err => { console.log(err); if (err.data && err.data.error) { let message = angular.toJson(err.data.error); @@ -274,13 +274,13 @@ export class ElasticDatasource { payload = payload.replace(/\$timeTo/g, options.range.to.valueOf()); payload = this.templateSrv.replace(payload, options.scopedVars); - return this.post('_msearch', payload).then(function(res) { + return this.post('_msearch', payload).then(res => { return new ElasticResponse(sentTargets, res).getTimeSeries(); }); } getFields(query) { - return this.get('/_mapping').then(function(result) { + return this.get('/_mapping').then(result => { const typeMap = { float: 'number', double: 'number', @@ -352,7 +352,7 @@ export class ElasticDatasource { } // transform to array - return _.map(fields, function(value) { + return _.map(fields, value => { return value; }); }); @@ -368,13 +368,13 @@ export class ElasticDatasource { esQuery = esQuery.replace(/\$timeTo/g, range.to.valueOf()); esQuery = header + '\n' + esQuery + '\n'; - return this.post('_msearch?search_type=' + searchType, esQuery).then(function(res) { + return this.post('_msearch?search_type=' + searchType, esQuery).then(res => { if (!res.responses[0].aggregations) { return []; } const buckets = res.responses[0].aggregations['1'].buckets; - return _.map(buckets, function(bucket) { + return _.map(buckets, bucket => { return { text: bucket.key_as_string || bucket.key, value: bucket.key, diff --git a/public/app/plugins/datasource/elasticsearch/elastic_response.ts b/public/app/plugins/datasource/elasticsearch/elastic_response.ts index 2be97423176..7adec22c545 100644 --- a/public/app/plugins/datasource/elasticsearch/elastic_response.ts +++ b/public/app/plugins/datasource/elasticsearch/elastic_response.ts @@ -227,7 +227,7 @@ export class ElasticResponse { if (target.alias) { const regex = /\{\{([\s\S]+?)\}\}/g; - return target.alias.replace(regex, function(match, g1, g2) { + return target.alias.replace(regex, (match, g1, g2) => { const group = g1 || g2; if (group.indexOf('term ') === 0) { diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.ts b/public/app/plugins/datasource/elasticsearch/metric_agg.ts index 08af5ab825e..7e5300b43e1 100644 --- a/public/app/plugins/datasource/elasticsearch/metric_agg.ts +++ b/public/app/plugins/datasource/elasticsearch/metric_agg.ts @@ -25,19 +25,19 @@ export class ElasticMetricAggCtrl { $scope.pipelineAggOptions = []; $scope.modelSettingsValues = {}; - $scope.init = function() { + $scope.init = () => { $scope.agg = metricAggs[$scope.index]; $scope.validateModel(); $scope.updatePipelineAggOptions(); }; - $scope.updatePipelineAggOptions = function() { + $scope.updatePipelineAggOptions = () => { $scope.pipelineAggOptions = queryDef.getPipelineAggOptions($scope.target); }; $rootScope.onAppEvent( 'elastic-query-updated', - function() { + () => { $scope.index = _.indexOf(metricAggs, $scope.agg); $scope.updatePipelineAggOptions(); $scope.validateModel(); @@ -45,7 +45,7 @@ export class ElasticMetricAggCtrl { $scope ); - $scope.validateModel = function() { + $scope.validateModel = () => { $scope.isFirst = $scope.index === 0; $scope.isSingle = metricAggs.length === 1; $scope.settingsLinkText = ''; @@ -57,7 +57,7 @@ export class ElasticMetricAggCtrl { const pipelineOptions = queryDef.getPipelineOptions($scope.agg); if (pipelineOptions.length > 0) { - _.each(pipelineOptions, function(opt) { + _.each(pipelineOptions, opt => { $scope.agg.settings[opt.text] = $scope.agg.settings[opt.text] || opt.default; }); $scope.settingsLinkText = 'Options'; @@ -84,7 +84,7 @@ export class ElasticMetricAggCtrl { const stats = _.reduce( $scope.agg.meta, - function(memo, val, key) { + (memo, val, key) => { if (val) { const def = _.find($scope.extendedStats, { value: key }); memo.push(def.text); @@ -128,16 +128,16 @@ export class ElasticMetricAggCtrl { } }; - $scope.toggleOptions = function() { + $scope.toggleOptions = () => { $scope.showOptions = !$scope.showOptions; $scope.updatePipelineAggOptions(); }; - $scope.onChangeInternal = function() { + $scope.onChangeInternal = () => { $scope.onChange(); }; - $scope.updateMovingAvgModelSettings = function() { + $scope.updateMovingAvgModelSettings = () => { const modelSettingsKeys = []; const modelSettings = queryDef.getMovingAvgSettings($scope.agg.settings.model, false); for (let i = 0; i < modelSettings.length; i++) { @@ -151,12 +151,12 @@ export class ElasticMetricAggCtrl { } }; - $scope.onChangeClearInternal = function() { + $scope.onChangeClearInternal = () => { delete $scope.agg.settings.minimize; $scope.onChange(); }; - $scope.onTypeChange = function() { + $scope.onTypeChange = () => { $scope.agg.settings = {}; $scope.agg.meta = {}; $scope.showOptions = false; @@ -164,19 +164,19 @@ export class ElasticMetricAggCtrl { $scope.onChange(); }; - $scope.getFieldsInternal = function() { + $scope.getFieldsInternal = () => { if ($scope.agg.type === 'cardinality') { return $scope.getFields(); } return $scope.getFields({ $fieldType: 'number' }); }; - $scope.addMetricAgg = function() { + $scope.addMetricAgg = () => { const addIndex = metricAggs.length; const id = _.reduce( $scope.target.bucketAggs.concat($scope.target.metrics), - function(max, val) { + (max, val) => { return parseInt(val.id) > max ? parseInt(val.id) : max; }, 0 @@ -186,12 +186,12 @@ export class ElasticMetricAggCtrl { $scope.onChange(); }; - $scope.removeMetricAgg = function() { + $scope.removeMetricAgg = () => { metricAggs.splice($scope.index, 1); $scope.onChange(); }; - $scope.toggleShowMetric = function() { + $scope.toggleShowMetric = () => { $scope.agg.hide = !$scope.agg.hide; if (!$scope.agg.hide) { delete $scope.agg.hide; diff --git a/public/app/plugins/datasource/elasticsearch/query_def.ts b/public/app/plugins/datasource/elasticsearch/query_def.ts index eec219d0065..dd65a8b373e 100644 --- a/public/app/plugins/datasource/elasticsearch/query_def.ts +++ b/public/app/plugins/datasource/elasticsearch/query_def.ts @@ -145,7 +145,7 @@ export const movingAvgModelSettings = { }; export function getMetricAggTypes(esVersion) { - return _.filter(metricAggTypes, function(f) { + return _.filter(metricAggTypes, f => { if (f.minVersion) { return f.minVersion <= esVersion; } else { @@ -173,7 +173,7 @@ export function isPipelineAgg(metricType) { export function getPipelineAggOptions(targets) { const result = []; - _.each(targets.metrics, function(metric) { + _.each(targets.metrics, metric => { if (!isPipelineAgg(metric.type)) { result.push({ text: describeMetric(metric), value: metric.id }); } @@ -185,7 +185,7 @@ export function getPipelineAggOptions(targets) { export function getMovingAvgSettings(model, filtered) { const filteredResult = []; if (filtered) { - _.each(movingAvgModelSettings[model], function(setting) { + _.each(movingAvgModelSettings[model], setting => { if (!setting.isCheckbox) { filteredResult.push(setting); } @@ -197,7 +197,7 @@ export function getMovingAvgSettings(model, filtered) { export function getOrderByOptions(target) { const metricRefs = []; - _.each(target.metrics, function(metric) { + _.each(target.metrics, metric => { if (metric.type !== 'count') { metricRefs.push({ text: describeMetric(metric), value: metric.id }); } diff --git a/public/app/plugins/datasource/graphite/graphite_query.ts b/public/app/plugins/datasource/graphite/graphite_query.ts index 20179e0e509..ab137a6a299 100644 --- a/public/app/plugins/datasource/graphite/graphite_query.ts +++ b/public/app/plugins/datasource/graphite/graphite_query.ts @@ -73,7 +73,7 @@ export default class GraphiteQuery { return _.reduce( arr, - function(result, segment) { + (result, segment) => { return result ? result + '.' + segment.value : segment.value; }, '' @@ -133,7 +133,7 @@ export default class GraphiteQuery { } moveAliasFuncLast() { - const aliasFunc = _.find(this.functions, function(func) { + const aliasFunc = _.find(this.functions, func => { return func.def.name.startsWith('alias'); }); diff --git a/public/app/plugins/datasource/graphite/lexer.ts b/public/app/plugins/datasource/graphite/lexer.ts index 1f2da854991..0d72116a217 100644 --- a/public/app/plugins/datasource/graphite/lexer.ts +++ b/public/app/plugins/datasource/graphite/lexer.ts @@ -1370,7 +1370,7 @@ Lexer.prototype = { }; }, - isPunctuator: function(ch1) { + isPunctuator: ch1 => { switch (ch1) { case '.': case '(': diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index d9fd1a3605d..ec995de630a 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -23,7 +23,7 @@ export default class InfluxDatasource { /** @ngInject */ constructor(instanceSettings, private $q, private backendSrv, private templateSrv) { this.type = 'influxdb'; - this.urls = _.map(instanceSettings.url.split(','), function(url) { + this.urls = _.map(instanceSettings.url.split(','), url => { return url.trim(); }); @@ -274,7 +274,7 @@ export default class InfluxDatasource { result => { return result.data; }, - function(err) { + err => { if (err.status !== 0 || err.status >= 300) { if (err.data && err.data.error) { throw { diff --git a/public/app/plugins/datasource/influxdb/influx_query.ts b/public/app/plugins/datasource/influxdb/influx_query.ts index e9158739327..60eac1d3f2b 100644 --- a/public/app/plugins/datasource/influxdb/influx_query.ts +++ b/public/app/plugins/datasource/influxdb/influx_query.ts @@ -27,15 +27,15 @@ export default class InfluxQuery { } updateProjection() { - this.selectModels = _.map(this.target.select, function(parts: any) { + this.selectModels = _.map(this.target.select, (parts: any) => { return _.map(parts, queryPart.create); }); this.groupByParts = _.map(this.target.groupBy, queryPart.create); } updatePersistedParts() { - this.target.select = _.map(this.selectModels, function(selectParts) { - return _.map(selectParts, function(part: any) { + this.target.select = _.map(this.selectModels, selectParts => { + return _.map(selectParts, (part: any) => { return { type: part.def.type, params: part.params }; }); }); diff --git a/public/app/plugins/datasource/influxdb/influx_series.ts b/public/app/plugins/datasource/influxdb/influx_series.ts index a9268979592..d2a8482eced 100644 --- a/public/app/plugins/datasource/influxdb/influx_series.ts +++ b/public/app/plugins/datasource/influxdb/influx_series.ts @@ -22,7 +22,7 @@ export default class InfluxSeries { _.each(this.series, series => { const columns = series.columns.length; - const tags = _.map(series.tags, function(value, key) { + const tags = _.map(series.tags, (value, key) => { return key + ': ' + value; }); @@ -57,7 +57,7 @@ export default class InfluxSeries { const regex = /\$(\w+)|\[\[([\s\S]+?)\]\]/g; const segments = series.name.split('.'); - return this.alias.replace(regex, function(match, g1, g2) { + return this.alias.replace(regex, (match, g1, g2) => { const group = g1 || g2; const segIndex = parseInt(group, 10); @@ -124,10 +124,10 @@ export default class InfluxSeries { // Remove empty values, then split in different tags for comma separated values tags: _.flatten( tagsCol - .filter(function(t) { + .filter(t => { return value[t]; }) - .map(function(t) { + .map(t => { return value[t].split(','); }) ), @@ -158,7 +158,7 @@ export default class InfluxSeries { table.columns.push({ text: 'Time', type: 'time' }); j++; } - _.each(_.keys(series.tags), function(key) { + _.each(_.keys(series.tags), key => { table.columns.push({ text: key }); }); for (; j < series.columns.length; j++) { diff --git a/public/app/plugins/datasource/influxdb/query_builder.ts b/public/app/plugins/datasource/influxdb/query_builder.ts index 3d5ce476c69..a61216787d3 100644 --- a/public/app/plugins/datasource/influxdb/query_builder.ts +++ b/public/app/plugins/datasource/influxdb/query_builder.ts @@ -84,7 +84,7 @@ export class InfluxQueryBuilder { if (this.target.tags && this.target.tags.length > 0) { const whereConditions = _.reduce( this.target.tags, - function(memo, tag) { + (memo, tag) => { // do not add a condition for the key we want to explore for if (tag.key === withKey) { return memo; diff --git a/public/app/plugins/datasource/influxdb/query_ctrl.ts b/public/app/plugins/datasource/influxdb/query_ctrl.ts index 4a9310c63d1..f531fe6c4d9 100644 --- a/public/app/plugins/datasource/influxdb/query_ctrl.ts +++ b/public/app/plugins/datasource/influxdb/query_ctrl.ts @@ -70,7 +70,7 @@ export class InfluxQueryCtrl extends QueryCtrl { const categories = queryPart.getCategories(); this.selectMenu = _.reduce( categories, - function(memo, cat, key) { + (memo, cat, key) => { const menu = { text: key, submenu: cat.map(item => { diff --git a/public/app/plugins/datasource/influxdb/query_part.ts b/public/app/plugins/datasource/influxdb/query_part.ts index 22cac9bb608..4bc92bcfe72 100644 --- a/public/app/plugins/datasource/influxdb/query_part.ts +++ b/public/app/plugins/datasource/influxdb/query_part.ts @@ -126,7 +126,7 @@ function addAliasStrategy(selectParts, partModel) { function addFieldStrategy(selectParts, partModel, query) { // copy all parts - const parts = _.map(selectParts, function(part: any) { + const parts = _.map(selectParts, (part: any) => { return createPart({ type: part.def.type, params: _.clone(part.params) }); }); @@ -453,7 +453,7 @@ register({ export default { create: createPart, - getCategories: function() { + getCategories: () => { return categories; }, replaceAggregationAdd: replaceAggregationAddStrategy, diff --git a/public/app/plugins/datasource/mixed/datasource.ts b/public/app/plugins/datasource/mixed/datasource.ts index bfdfcd61c77..6018329093e 100644 --- a/public/app/plugins/datasource/mixed/datasource.ts +++ b/public/app/plugins/datasource/mixed/datasource.ts @@ -13,14 +13,14 @@ class MixedDatasource { return this.$q([]); } - return this.datasourceSrv.get(dsName).then(function(ds) { + return this.datasourceSrv.get(dsName).then(ds => { const opt = angular.copy(options); opt.targets = targets; return ds.query(opt); }); }); - return this.$q.all(promises).then(function(results) { + return this.$q.all(promises).then(results => { return { data: _.flatten(_.map(results, 'data')) }; }); } diff --git a/public/app/plugins/datasource/mssql/datasource.ts b/public/app/plugins/datasource/mssql/datasource.ts index fc497b2c274..4b67252632a 100644 --- a/public/app/plugins/datasource/mssql/datasource.ts +++ b/public/app/plugins/datasource/mssql/datasource.ts @@ -26,7 +26,7 @@ export class MssqlDatasource { return value; } - const quotedValues = _.map(value, function(val) { + const quotedValues = _.map(value, val => { if (typeof value === 'number') { return value; } diff --git a/public/app/plugins/datasource/mysql/datasource.ts b/public/app/plugins/datasource/mysql/datasource.ts index eca223f2d6d..6303dbb2c6d 100644 --- a/public/app/plugins/datasource/mysql/datasource.ts +++ b/public/app/plugins/datasource/mysql/datasource.ts @@ -26,7 +26,7 @@ export class MysqlDatasource { return value; } - const quotedValues = _.map(value, function(val) { + const quotedValues = _.map(value, val => { if (typeof value === 'number') { return value; } diff --git a/public/app/plugins/datasource/opentsdb/datasource.ts b/public/app/plugins/datasource/opentsdb/datasource.ts index 843b36a5dc0..08bd1585b42 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.ts +++ b/public/app/plugins/datasource/opentsdb/datasource.ts @@ -56,19 +56,19 @@ export default class OpenTsDatasource { } const groupByTags = {}; - _.each(queries, function(query) { + _.each(queries, query => { if (query.filters && query.filters.length > 0) { - _.each(query.filters, function(val) { + _.each(query.filters, val => { groupByTags[val.tagk] = true; }); } else { - _.each(query.tags, function(val, key) { + _.each(query.tags, (val, key) => { groupByTags[key] = true; }); } }); - options.targets = _.filter(options.targets, function(query) { + options.targets = _.filter(options.targets, query => { return query.hide !== true; }); @@ -97,28 +97,26 @@ export default class OpenTsDatasource { const queries = _.compact(qs); - return this.performTimeSeriesQuery(queries, start, end).then( - function(results) { - if (results.data[0]) { - let annotationObject = results.data[0].annotations; - if (options.annotation.isGlobal) { - annotationObject = results.data[0].globalAnnotations; - } - if (annotationObject) { - _.each(annotationObject, function(annotation) { - const event = { - text: annotation.description, - time: Math.floor(annotation.startTime) * 1000, - annotation: options.annotation, - }; - - eventList.push(event); - }); - } + return this.performTimeSeriesQuery(queries, start, end).then(results => { + if (results.data[0]) { + let annotationObject = results.data[0].annotations; + if (options.annotation.isGlobal) { + annotationObject = results.data[0].globalAnnotations; } - return eventList; - }.bind(this) - ); + if (annotationObject) { + _.each(annotationObject, annotation => { + const event = { + text: annotation.description, + time: Math.floor(annotation.startTime) * 1000, + annotation: options.annotation, + }; + + eventList.push(event); + }); + } + } + return eventList; + }); } targetContainsTemplate(target) { @@ -177,7 +175,7 @@ export default class OpenTsDatasource { _saveTagKeys(metricData) { const tagKeys = Object.keys(metricData.tags); - _.each(metricData.aggregateTags, function(tag) { + _.each(metricData.aggregateTags, tag => { tagKeys.push(tag); }); @@ -185,7 +183,7 @@ export default class OpenTsDatasource { } _performSuggestQuery(query, type) { - return this._get('/api/suggest', { type: type, q: query, max: 1000 }).then(function(result) { + return this._get('/api/suggest', { type: type, q: query, max: 1000 }).then(result => { return result.data; }); } @@ -195,7 +193,7 @@ export default class OpenTsDatasource { return this.$q.when([]); } - const keysArray = keys.split(',').map(function(key) { + const keysArray = keys.split(',').map(key => { return key.trim(); }); const key = keysArray[0]; @@ -207,10 +205,10 @@ export default class OpenTsDatasource { const m = metric + '{' + keysQuery + '}'; - return this._get('/api/search/lookup', { m: m, limit: 3000 }).then(function(result) { + return this._get('/api/search/lookup', { m: m, limit: 3000 }).then(result => { result = result.data.results; const tagvs = []; - _.each(result, function(r) { + _.each(result, r => { if (tagvs.indexOf(r.tags[key]) === -1) { tagvs.push(r.tags[key]); } @@ -224,11 +222,11 @@ export default class OpenTsDatasource { return this.$q.when([]); } - return this._get('/api/search/lookup', { m: metric, limit: 1000 }).then(function(result) { + return this._get('/api/search/lookup', { m: metric, limit: 1000 }).then(result => { result = result.data.results; const tagks = []; - _.each(result, function(r) { - _.each(r.tags, function(tagv, tagk) { + _.each(result, r => { + _.each(r.tags, (tagv, tagk) => { if (tagks.indexOf(tagk) === -1) { tagks.push(tagk); } @@ -271,8 +269,8 @@ export default class OpenTsDatasource { return this.$q.reject(err); } - const responseTransform = function(result) { - return _.map(result, function(value) { + const responseTransform = result => { + return _.map(result, value => { return { text: value }; }); }; @@ -312,7 +310,7 @@ export default class OpenTsDatasource { } testDatasource() { - return this._performSuggestQuery('cpu', 'metrics').then(function() { + return this._performSuggestQuery('cpu', 'metrics').then(() => { return { status: 'success', message: 'Data source is working' }; }); } @@ -322,7 +320,7 @@ export default class OpenTsDatasource { return this.aggregatorsPromise; } - this.aggregatorsPromise = this._get('/api/aggregators').then(function(result) { + this.aggregatorsPromise = this._get('/api/aggregators').then(result => { if (result.data && _.isArray(result.data)) { return result.data.sort(); } @@ -336,7 +334,7 @@ export default class OpenTsDatasource { return this.filterTypesPromise; } - this.filterTypesPromise = this._get('/api/config/filters').then(function(result) { + this.filterTypesPromise = this._get('/api/config/filters').then(result => { if (result.data) { return Object.keys(result.data).sort(); } @@ -351,7 +349,7 @@ export default class OpenTsDatasource { // TSDB returns datapoints has a hash of ts => value. // Can't use _.pairs(invert()) because it stringifies keys/values - _.each(md.dps, function(v, k) { + _.each(md.dps, (v, k) => { if (tsdbResolution === 2) { dps.push([v, k * 1]); } else { @@ -365,7 +363,7 @@ export default class OpenTsDatasource { createMetricLabel(md, target, groupByTags, options) { if (target.alias) { const scopedVars = _.clone(options.scopedVars || {}); - _.each(md.tags, function(value, key) { + _.each(md.tags, (value, key) => { scopedVars['tag_' + key] = { value: value }; }); return this.templateSrv.replace(target.alias, scopedVars); @@ -375,7 +373,7 @@ export default class OpenTsDatasource { const tagData = []; if (!_.isEmpty(md.tags)) { - _.each(_.toPairs(md.tags), function(tag) { + _.each(_.toPairs(md.tags), tag => { if (_.has(groupByTags, tag[0])) { tagData.push(tag[0] + '=' + tag[1]); } diff --git a/public/app/plugins/datasource/opentsdb/query_ctrl.ts b/public/app/plugins/datasource/opentsdb/query_ctrl.ts index 4c8a0ed8d12..2e6f1d54302 100644 --- a/public/app/plugins/datasource/opentsdb/query_ctrl.ts +++ b/public/app/plugins/datasource/opentsdb/query_ctrl.ts @@ -88,7 +88,7 @@ export class OpenTsQueryCtrl extends QueryCtrl { } getTextValues(metricFindResult) { - return _.map(metricFindResult, function(value) { + return _.map(metricFindResult, value => { return value.text; }); } diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 356322cf369..4d4da0a415b 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -526,13 +526,13 @@ export class PrometheusDatasource { const query = this.createQuery({ expr, interval: step }, queryOptions, start, end); const self = this; - return this.performTimeSeriesQuery(query, query.start, query.end).then(function(results) { + return this.performTimeSeriesQuery(query, query.start, query.end).then(results => { const eventList = []; tagKeys = tagKeys.split(','); - _.each(results.data.data.result, function(series) { + _.each(results.data.data.result, series => { const tags = _.chain(series.metric) - .filter(function(v, k) { + .filter((v, k) => { return _.includes(tagKeys, k); }) .value(); diff --git a/public/app/plugins/datasource/prometheus/metric_find_query.ts b/public/app/plugins/datasource/prometheus/metric_find_query.ts index 8e15541ce62..feada28deea 100644 --- a/public/app/plugins/datasource/prometheus/metric_find_query.ts +++ b/public/app/plugins/datasource/prometheus/metric_find_query.ts @@ -46,8 +46,8 @@ export default class PrometheusMetricFindQuery { // return label values globally url = '/api/v1/label/' + label + '/values'; - return this.datasource.metadataRequest(url).then(function(result) { - return _.map(result.data.data, function(value) { + return this.datasource.metadataRequest(url).then(result => { + return _.map(result.data.data, value => { return { text: value }; }); }); @@ -56,14 +56,14 @@ export default class PrometheusMetricFindQuery { const end = this.datasource.getPrometheusTime(this.range.to, true); url = '/api/v1/series?match[]=' + encodeURIComponent(metric) + '&start=' + start + '&end=' + end; - return this.datasource.metadataRequest(url).then(function(result) { - const _labels = _.map(result.data.data, function(metric) { + return this.datasource.metadataRequest(url).then(result => { + const _labels = _.map(result.data.data, metric => { return metric[label] || ''; - }).filter(function(label) { + }).filter(label => { return label !== ''; }); - return _.uniq(_labels).map(function(metric) { + return _.uniq(_labels).map(metric => { return { text: metric, expandable: true, @@ -76,13 +76,13 @@ export default class PrometheusMetricFindQuery { metricNameQuery(metricFilterPattern) { const url = '/api/v1/label/__name__/values'; - return this.datasource.metadataRequest(url).then(function(result) { + return this.datasource.metadataRequest(url).then(result => { return _.chain(result.data.data) - .filter(function(metricName) { + .filter(metricName => { const r = new RegExp(metricFilterPattern); return r.test(metricName); }) - .map(function(matchedMetricName) { + .map(matchedMetricName => { return { text: matchedMetricName, expandable: true, @@ -94,13 +94,13 @@ export default class PrometheusMetricFindQuery { queryResultQuery(query) { const end = this.datasource.getPrometheusTime(this.range.to, true); - return this.datasource.performInstantQuery({ expr: query }, end).then(function(result) { - return _.map(result.data.data.result, function(metricData) { + return this.datasource.performInstantQuery({ expr: query }, end).then(result => { + return _.map(result.data.data.result, metricData => { let text = metricData.metric.__name__ || ''; delete metricData.metric.__name__; text += '{' + - _.map(metricData.metric, function(v, k) { + _.map(metricData.metric, (v, k) => { return k + '="' + v + '"'; }).join(',') + '}'; @@ -120,7 +120,7 @@ export default class PrometheusMetricFindQuery { const url = '/api/v1/series?match[]=' + encodeURIComponent(query) + '&start=' + start + '&end=' + end; const self = this; - return this.datasource.metadataRequest(url).then(function(result) { + return this.datasource.metadataRequest(url).then(result => { return _.map(result.data.data, metric => { return { text: self.datasource.getOriginalMetricName(metric), diff --git a/public/app/plugins/datasource/prometheus/query_ctrl.ts b/public/app/plugins/datasource/prometheus/query_ctrl.ts index 36c3b35a817..66038cb5ca4 100644 --- a/public/app/plugins/datasource/prometheus/query_ctrl.ts +++ b/public/app/plugins/datasource/prometheus/query_ctrl.ts @@ -27,7 +27,7 @@ class PrometheusQueryCtrl extends QueryCtrl { target.format = target.format || this.getDefaultFormat(); this.metric = ''; - this.resolutions = _.map([1, 2, 3, 4, 5, 10], function(f) { + this.resolutions = _.map([1, 2, 3, 4, 5, 10], f => { return { factor: f, label: '1/' + f }; }); diff --git a/public/app/plugins/datasource/prometheus/result_transformer.ts b/public/app/plugins/datasource/prometheus/result_transformer.ts index 3f4e4592a2d..96b8e0d4137 100644 --- a/public/app/plugins/datasource/prometheus/result_transformer.ts +++ b/public/app/plugins/datasource/prometheus/result_transformer.ts @@ -81,7 +81,7 @@ export class ResultTransformer { } // Collect all labels across all metrics - _.each(md, function(series) { + _.each(md, series => { for (const label in series.metric) { if (!metricLabels.hasOwnProperty(label)) { metricLabels[label] = 1; @@ -92,7 +92,7 @@ export class ResultTransformer { // Sort metric labels, create columns for them and record their index const sortedLabels = _.keys(metricLabels).sort(); table.columns.push({ text: 'Time', type: 'time' }); - _.each(sortedLabels, function(label, labelIndex) { + _.each(sortedLabels, (label, labelIndex) => { metricLabels[label] = labelIndex + 1; table.columns.push({ text: label, filterable: !label.startsWith('__') }); }); @@ -100,7 +100,7 @@ export class ResultTransformer { table.columns.push({ text: valueText }); // Populate rows, set value to empty string when label not present. - _.each(md, function(series) { + _.each(md, series => { if (series.value) { series.values = [series.value]; } @@ -150,7 +150,7 @@ export class ResultTransformer { renderTemplate(aliasPattern, aliasData) { const aliasRegex = /\{\{\s*(.+?)\s*\}\}/g; - return aliasPattern.replace(aliasRegex, function(match, g1) { + return aliasPattern.replace(aliasRegex, (match, g1) => { if (aliasData[g1]) { return aliasData[g1]; } @@ -161,7 +161,7 @@ export class ResultTransformer { getOriginalMetricName(labelData) { const metricName = labelData.__name__ || ''; delete labelData.__name__; - const labelPart = _.map(_.toPairs(labelData), function(label) { + const labelPart = _.map(_.toPairs(labelData), label => { return label[0] + '="' + label[1] + '"'; }).join(','); return metricName + '{' + labelPart + '}'; diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index 8e871566877..33db0e7220a 100755 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -464,7 +464,7 @@ class GraphElement { } addXSeriesAxis(options) { - const ticks = _.map(this.data, function(series, index) { + const ticks = _.map(this.data, (series, index) => { return [index + 1, series.alias]; }); @@ -533,8 +533,8 @@ class GraphElement { } addXTableAxis(options) { - let ticks = _.map(this.data, function(series, seriesIndex) { - return _.map(series.datapoints, function(point, pointIndex) { + let ticks = _.map(this.data, (series, seriesIndex) => { + return _.map(series.datapoints, (point, pointIndex) => { const tickIndex = seriesIndex * series.datapoints.length + pointIndex; return [tickIndex + 1, point[1]]; }); @@ -627,10 +627,10 @@ class GraphElement { } } - axis.transform = function(v) { + axis.transform = v => { return v < Number.MIN_VALUE ? null : Math.log(v) / Math.log(axis.logBase); }; - axis.inverseTransform = function(v) { + axis.inverseTransform = v => { return Math.pow(axis.logBase, v); }; @@ -701,7 +701,7 @@ class GraphElement { } configureAxisMode(axis, format) { - axis.tickFormatter = function(val, axis) { + axis.tickFormatter = (val, axis) => { if (!kbn.valueFormats[format]) { throw new Error(`Unit '${format}' is not supported`); } diff --git a/public/app/plugins/panel/graph/graph_tooltip.ts b/public/app/plugins/panel/graph/graph_tooltip.ts index 53b646b4442..aeba9fa6ed3 100644 --- a/public/app/plugins/panel/graph/graph_tooltip.ts +++ b/public/app/plugins/panel/graph/graph_tooltip.ts @@ -8,11 +8,11 @@ export default function GraphTooltip(this: any, elem, dashboard, scope, getSerie const $tooltip = $('