浏览代码

noImplicitAny: Datasource files, under 2500 (#17959)

* noImplicitAny on Graphite

* More noImplicitAny
Tobias Skarhed 6 年之前
父节点
当前提交
9b468caea4

+ 10 - 7
public/app/plugins/datasource/grafana/datasource.ts

@@ -1,10 +1,13 @@
 import _ from 'lodash';
 import _ from 'lodash';
+import { BackendSrv } from 'app/core/services/backend_srv';
+import { IQService } from 'angular';
+import { TemplateSrv } from 'app/features/templating/template_srv';
 
 
 class GrafanaDatasource {
 class GrafanaDatasource {
   /** @ngInject */
   /** @ngInject */
-  constructor(private backendSrv, private $q, private templateSrv) {}
+  constructor(private backendSrv: BackendSrv, private $q: IQService, private templateSrv: TemplateSrv) {}
 
 
-  query(options) {
+  query(options: any) {
     return this.backendSrv
     return this.backendSrv
       .get('/api/tsdb/testdata/random-walk', {
       .get('/api/tsdb/testdata/random-walk', {
         from: options.range.from.valueOf(),
         from: options.range.from.valueOf(),
@@ -12,8 +15,8 @@ class GrafanaDatasource {
         intervalMs: options.intervalMs,
         intervalMs: options.intervalMs,
         maxDataPoints: options.maxDataPoints,
         maxDataPoints: options.maxDataPoints,
       })
       })
-      .then(res => {
-        const data = [];
+      .then((res: any) => {
+        const data: any[] = [];
 
 
         if (res.results) {
         if (res.results) {
           _.forEach(res.results, queryRes => {
           _.forEach(res.results, queryRes => {
@@ -30,11 +33,11 @@ class GrafanaDatasource {
       });
       });
   }
   }
 
 
-  metricFindQuery(options) {
+  metricFindQuery(options: any) {
     return this.$q.when({ data: [] });
     return this.$q.when({ data: [] });
   }
   }
 
 
-  annotationQuery(options) {
+  annotationQuery(options: any) {
     const params: any = {
     const params: any = {
       from: options.range.from.valueOf(),
       from: options.range.from.valueOf(),
       to: options.range.to.valueOf(),
       to: options.range.to.valueOf(),
@@ -60,7 +63,7 @@ class GrafanaDatasource {
       const delimiter = '__delimiter__';
       const delimiter = '__delimiter__';
       const tags = [];
       const tags = [];
       for (const t of params.tags) {
       for (const t of params.tags) {
-        const renderedValues = this.templateSrv.replace(t, {}, value => {
+        const renderedValues = this.templateSrv.replace(t, {}, (value: any) => {
           if (typeof value === 'string') {
           if (typeof value === 'string') {
             return value;
             return value;
           }
           }

+ 7 - 6
public/app/plugins/datasource/grafana/specs/datasource.test.ts

@@ -1,12 +1,13 @@
 import { GrafanaDatasource } from '../datasource';
 import { GrafanaDatasource } from '../datasource';
+// @ts-ignore
 import q from 'q';
 import q from 'q';
 import { dateTime } from '@grafana/ui/src/utils/moment_wrapper';
 import { dateTime } from '@grafana/ui/src/utils/moment_wrapper';
 
 
 describe('grafana data source', () => {
 describe('grafana data source', () => {
   describe('when executing an annotations query', () => {
   describe('when executing an annotations query', () => {
-    let calledBackendSrvParams;
+    let calledBackendSrvParams: any;
     const backendSrvStub = {
     const backendSrvStub = {
-      get: (url: string, options) => {
+      get: (url: string, options: any) => {
         calledBackendSrvParams = options;
         calledBackendSrvParams = options;
         return q.resolve([]);
         return q.resolve([]);
       },
       },
@@ -18,7 +19,7 @@ describe('grafana data source', () => {
       },
       },
     };
     };
 
 
-    const ds = new GrafanaDatasource(backendSrvStub, q, templateSrvStub);
+    const ds = new GrafanaDatasource(backendSrvStub as any, q, templateSrvStub as any);
 
 
     describe('with tags that have template variables', () => {
     describe('with tags that have template variables', () => {
       const options = setupAnnotationQueryOptions({ tags: ['tag1:$var'] });
       const options = setupAnnotationQueryOptions({ tags: ['tag1:$var'] });
@@ -65,10 +66,10 @@ describe('grafana data source', () => {
   });
   });
 });
 });
 
 
-function setupAnnotationQueryOptions(annotation, dashboard?) {
+function setupAnnotationQueryOptions(annotation: { tags: string[]; type?: string }, dashboard?: { id: number }) {
   return {
   return {
-    annotation: annotation,
-    dashboard: dashboard,
+    annotation,
+    dashboard,
     range: {
     range: {
       from: dateTime(1432288354),
       from: dateTime(1432288354),
       to: dateTime(1432288401),
       to: dateTime(1432288401),

+ 2 - 1
public/app/plugins/datasource/graphite/FunctionEditor.tsx

@@ -1,5 +1,6 @@
 import React from 'react';
 import React from 'react';
 import { PopperController, Popper } from '@grafana/ui';
 import { PopperController, Popper } from '@grafana/ui';
+// @ts-ignore
 import rst2html from 'rst2html';
 import rst2html from 'rst2html';
 import { FunctionDescriptor, FunctionEditorControlsProps, FunctionEditorControls } from './FunctionEditorControls';
 import { FunctionDescriptor, FunctionEditorControlsProps, FunctionEditorControls } from './FunctionEditorControls';
 
 
@@ -22,7 +23,7 @@ class FunctionEditor extends React.PureComponent<FunctionEditorProps, FunctionEd
     };
     };
   }
   }
 
 
-  renderContent = ({ updatePopperPosition }) => {
+  renderContent = ({ updatePopperPosition }: any) => {
     const {
     const {
       onMoveLeft,
       onMoveLeft,
       onMoveRight,
       onMoveRight,

+ 10 - 7
public/app/plugins/datasource/graphite/add_graphite_func.ts

@@ -1,11 +1,14 @@
 import _ from 'lodash';
 import _ from 'lodash';
 import $ from 'jquery';
 import $ from 'jquery';
+// @ts-ignore
 import rst2html from 'rst2html';
 import rst2html from 'rst2html';
+// @ts-ignore
 import Drop from 'tether-drop';
 import Drop from 'tether-drop';
 import coreModule from 'app/core/core_module';
 import coreModule from 'app/core/core_module';
+import { FuncDef } from './gfunc';
 
 
 /** @ngInject */
 /** @ngInject */
-export function graphiteAddFunc($compile) {
+export function graphiteAddFunc($compile: any) {
   const inputTemplate =
   const inputTemplate =
     '<input type="text"' + ' class="gf-form-input"' + ' spellcheck="false" style="display:none"></input>';
     '<input type="text"' + ' class="gf-form-input"' + ' spellcheck="false" style="display:none"></input>';
 
 
@@ -15,7 +18,7 @@ export function graphiteAddFunc($compile) {
     '<i class="fa fa-plus"></i></a>';
     '<i class="fa fa-plus"></i></a>';
 
 
   return {
   return {
-    link: function($scope, elem) {
+    link: function($scope: any, elem: JQuery) {
       const ctrl = $scope.ctrl;
       const ctrl = $scope.ctrl;
 
 
       const $input = $(inputTemplate);
       const $input = $(inputTemplate);
@@ -24,7 +27,7 @@ export function graphiteAddFunc($compile) {
       $input.appendTo(elem);
       $input.appendTo(elem);
       $button.appendTo(elem);
       $button.appendTo(elem);
 
 
-      ctrl.datasource.getFuncDefs().then(funcDefs => {
+      ctrl.datasource.getFuncDefs().then((funcDefs: FuncDef[]) => {
         const allFunctions = _.map(funcDefs, 'name').sort();
         const allFunctions = _.map(funcDefs, 'name').sort();
 
 
         $scope.functionMenu = createFunctionDropDownMenu(funcDefs);
         $scope.functionMenu = createFunctionDropDownMenu(funcDefs);
@@ -34,7 +37,7 @@ export function graphiteAddFunc($compile) {
           source: allFunctions,
           source: allFunctions,
           minLength: 1,
           minLength: 1,
           items: 10,
           items: 10,
-          updater: value => {
+          updater: (value: any) => {
             let funcDef: any = ctrl.datasource.getFuncDef(value);
             let funcDef: any = ctrl.datasource.getFuncDef(value);
             if (!funcDef) {
             if (!funcDef) {
               // try find close match
               // try find close match
@@ -81,7 +84,7 @@ export function graphiteAddFunc($compile) {
         $compile(elem.contents())($scope);
         $compile(elem.contents())($scope);
       });
       });
 
 
-      let drop;
+      let drop: any;
       const cleanUpDrop = () => {
       const cleanUpDrop = () => {
         if (drop) {
         if (drop) {
           drop.destroy();
           drop.destroy();
@@ -132,8 +135,8 @@ export function graphiteAddFunc($compile) {
 
 
 coreModule.directive('graphiteAddFunc', graphiteAddFunc);
 coreModule.directive('graphiteAddFunc', graphiteAddFunc);
 
 
-function createFunctionDropDownMenu(funcDefs) {
-  const categories = {};
+function createFunctionDropDownMenu(funcDefs: FuncDef[]) {
+  const categories: any = {};
 
 
   _.forEach(funcDefs, funcDef => {
   _.forEach(funcDefs, funcDef => {
     if (!funcDef.category) {
     if (!funcDef.category) {

+ 5 - 3
public/app/plugins/datasource/graphite/config_ctrl.ts

@@ -1,10 +1,12 @@
+import DatasourceSrv from 'app/features/plugins/datasource_srv';
+
 export class GraphiteConfigCtrl {
 export class GraphiteConfigCtrl {
   static templateUrl = 'public/app/plugins/datasource/graphite/partials/config.html';
   static templateUrl = 'public/app/plugins/datasource/graphite/partials/config.html';
   datasourceSrv: any;
   datasourceSrv: any;
   current: any;
   current: any;
 
 
   /** @ngInject */
   /** @ngInject */
-  constructor($scope, datasourceSrv) {
+  constructor($scope: any, datasourceSrv: DatasourceSrv) {
     this.datasourceSrv = datasourceSrv;
     this.datasourceSrv = datasourceSrv;
     this.current.jsonData = this.current.jsonData || {};
     this.current.jsonData = this.current.jsonData || {};
     this.current.jsonData.graphiteVersion = this.current.jsonData.graphiteVersion || '0.9';
     this.current.jsonData.graphiteVersion = this.current.jsonData.graphiteVersion || '0.9';
@@ -18,10 +20,10 @@ export class GraphiteConfigCtrl {
 
 
     this.datasourceSrv
     this.datasourceSrv
       .loadDatasource(this.current.name)
       .loadDatasource(this.current.name)
-      .then(ds => {
+      .then((ds: any) => {
         return ds.getVersion();
         return ds.getVersion();
       })
       })
-      .then(version => {
+      .then((version: any) => {
         this.graphiteVersions.push({ name: version, value: version });
         this.graphiteVersions.push({ name: version, value: version });
         this.current.jsonData.graphiteVersion = version;
         this.current.jsonData.graphiteVersion = version;
       });
       });

+ 8 - 8
public/app/plugins/datasource/graphite/datasource.ts

@@ -15,8 +15,8 @@ export class GraphiteDatasource {
   supportsTags: boolean;
   supportsTags: boolean;
   cacheTimeout: any;
   cacheTimeout: any;
   withCredentials: boolean;
   withCredentials: boolean;
-  funcDefs = null;
-  funcDefsPromise = null;
+  funcDefs: any = null;
+  funcDefsPromise: Promise<any> = null;
   _seriesRefLetters: string;
   _seriesRefLetters: string;
 
 
   /** @ngInject */
   /** @ngInject */
@@ -107,7 +107,7 @@ export class GraphiteDatasource {
   }
   }
 
 
   parseTags(tagString: string) {
   parseTags(tagString: string) {
-    let tags = [];
+    let tags: string[] = [];
     tags = tagString.split(',');
     tags = tagString.split(',');
     if (tags.length === 1) {
     if (tags.length === 1) {
       tags = tagString.split(' ');
       tags = tagString.split(' ');
@@ -154,7 +154,7 @@ export class GraphiteDatasource {
     } else {
     } else {
       // Graphite event as annotation
       // Graphite event as annotation
       const tags = this.templateSrv.replace(options.annotation.tags);
       const tags = this.templateSrv.replace(options.annotation.tags);
-      return this.events({ range: options.rangeRaw, tags: tags }).then(results => {
+      return this.events({ range: options.rangeRaw, tags: tags }).then((results: any) => {
         const list = [];
         const list = [];
         for (let i = 0; i < results.data.length; i++) {
         for (let i = 0; i < results.data.length; i++) {
           const e = results.data[i];
           const e = results.data[i];
@@ -309,7 +309,7 @@ export class GraphiteDatasource {
       httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
       httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
     }
     }
 
 
-    return this.doGraphiteRequest(httpOptions).then(results => {
+    return this.doGraphiteRequest(httpOptions).then((results: any) => {
       return _.map(results.data, tag => {
       return _.map(results.data, tag => {
         return {
         return {
           text: tag.tag,
           text: tag.tag,
@@ -372,7 +372,7 @@ export class GraphiteDatasource {
       httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
       httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
     }
     }
 
 
-    return this.doGraphiteRequest(httpOptions).then(results => {
+    return this.doGraphiteRequest(httpOptions).then((results: any) => {
       if (results.data) {
       if (results.data) {
         return _.map(results.data, tag => {
         return _.map(results.data, tag => {
           return { text: tag };
           return { text: tag };
@@ -478,7 +478,7 @@ export class GraphiteDatasource {
         }
         }
         return this.funcDefs;
         return this.funcDefs;
       })
       })
-      .catch(err => {
+      .catch((err: any) => {
         console.log('Fetching graphite functions error', err);
         console.log('Fetching graphite functions error', err);
         this.funcDefs = gfunc.getFuncDefs(this.graphiteVersion);
         this.funcDefs = gfunc.getFuncDefs(this.graphiteVersion);
         return this.funcDefs;
         return this.funcDefs;
@@ -524,7 +524,7 @@ export class GraphiteDatasource {
   buildGraphiteParams(options: any, scopedVars: ScopedVars) {
   buildGraphiteParams(options: any, scopedVars: ScopedVars) {
     const graphiteOptions = ['from', 'until', 'rawData', 'format', 'maxDataPoints', 'cacheTimeout'];
     const graphiteOptions = ['from', 'until', 'rawData', 'format', 'maxDataPoints', 'cacheTimeout'];
     const cleanOptions = [],
     const cleanOptions = [],
-      targets = {};
+      targets: any = {};
     let target, targetValue, i;
     let target, targetValue, i;
     const regex = /\#([A-Z])/g;
     const regex = /\#([A-Z])/g;
     const intervalFormatFixRegex = /'(\d+)m'/gi;
     const intervalFormatFixRegex = /'(\d+)m'/gi;

+ 14 - 13
public/app/plugins/datasource/graphite/func_editor.ts

@@ -1,9 +1,10 @@
 import _ from 'lodash';
 import _ from 'lodash';
 import $ from 'jquery';
 import $ from 'jquery';
 import coreModule from 'app/core/core_module';
 import coreModule from 'app/core/core_module';
+import { TemplateSrv } from 'app/features/templating/template_srv';
 
 
 /** @ngInject */
 /** @ngInject */
-export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
+export function graphiteFuncEditor($compile: any, templateSrv: TemplateSrv) {
   const funcSpanTemplate = `
   const funcSpanTemplate = `
     <function-editor
     <function-editor
       func="func"
       func="func"
@@ -17,27 +18,27 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
 
 
   return {
   return {
     restrict: 'A',
     restrict: 'A',
-    link: function postLink($scope, elem) {
+    link: function postLink($scope: any, elem: JQuery) {
       const $funcLink = $(funcSpanTemplate);
       const $funcLink = $(funcSpanTemplate);
       const ctrl = $scope.ctrl;
       const ctrl = $scope.ctrl;
       const func = $scope.func;
       const func = $scope.func;
       let scheduledRelink = false;
       let scheduledRelink = false;
       let paramCountAtLink = 0;
       let paramCountAtLink = 0;
-      let cancelBlur = null;
+      let cancelBlur: any = null;
 
 
-      ctrl.handleRemoveFunction = func => {
+      ctrl.handleRemoveFunction = (func: any) => {
         ctrl.removeFunction(func);
         ctrl.removeFunction(func);
       };
       };
 
 
-      ctrl.handleMoveLeft = func => {
+      ctrl.handleMoveLeft = (func: any) => {
         ctrl.moveFunction(func, -1);
         ctrl.moveFunction(func, -1);
       };
       };
 
 
-      ctrl.handleMoveRight = func => {
+      ctrl.handleMoveRight = (func: any) => {
         ctrl.moveFunction(func, 1);
         ctrl.moveFunction(func, 1);
       };
       };
 
 
-      function clickFuncParam(this: any, paramIndex) {
+      function clickFuncParam(this: any, paramIndex: any) {
         /*jshint validthis:true */
         /*jshint validthis:true */
 
 
         const $link = $(this);
         const $link = $(this);
@@ -73,7 +74,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
         }
         }
       }
       }
 
 
-      function paramDef(index) {
+      function paramDef(index: number) {
         if (index < func.def.params.length) {
         if (index < func.def.params.length) {
           return func.def.params[index];
           return func.def.params[index];
         }
         }
@@ -83,7 +84,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
         return {};
         return {};
       }
       }
 
 
-      function switchToLink(inputElem, paramIndex) {
+      function switchToLink(inputElem: HTMLElement, paramIndex: any) {
         /*jshint validthis:true */
         /*jshint validthis:true */
         const $input = $(inputElem);
         const $input = $(inputElem);
 
 
@@ -117,7 +118,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
       }
       }
 
 
       // this = input element
       // this = input element
-      function inputBlur(this: any, paramIndex) {
+      function inputBlur(this: any, paramIndex: any) {
         /*jshint validthis:true */
         /*jshint validthis:true */
         const inputElem = this;
         const inputElem = this;
         // happens long before the click event on the typeahead options
         // happens long before the click event on the typeahead options
@@ -127,7 +128,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
         }, 200);
         }, 200);
       }
       }
 
 
-      function inputKeyPress(this: any, paramIndex, e) {
+      function inputKeyPress(this: any, paramIndex: any, e: any) {
         /*jshint validthis:true */
         /*jshint validthis:true */
         if (e.which === 13) {
         if (e.which === 13) {
           $(this).blur();
           $(this).blur();
@@ -139,7 +140,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
         this.style.width = (3 + this.value.length) * 8 + 'px';
         this.style.width = (3 + this.value.length) * 8 + 'px';
       }
       }
 
 
-      function addTypeahead($input, paramIndex) {
+      function addTypeahead($input: any, paramIndex: any) {
         $input.attr('data-provide', 'typeahead');
         $input.attr('data-provide', 'typeahead');
 
 
         let options = paramDef(paramIndex).options;
         let options = paramDef(paramIndex).options;
@@ -153,7 +154,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
           source: options,
           source: options,
           minLength: 0,
           minLength: 0,
           items: 20,
           items: 20,
-          updater: value => {
+          updater: (value: any) => {
             $input.val(value);
             $input.val(value);
             switchToLink($input[0], paramIndex);
             switchToLink($input[0], paramIndex);
             return value;
             return value;

+ 26 - 15
public/app/plugins/datasource/graphite/gfunc.ts

@@ -2,9 +2,20 @@ import _ from 'lodash';
 import { isVersionGtOrEq } from 'app/core/utils/version';
 import { isVersionGtOrEq } from 'app/core/utils/version';
 import { InterpolateFunction } from '@grafana/ui';
 import { InterpolateFunction } from '@grafana/ui';
 
 
-const index = {};
+const index: any = {};
+
+export interface FuncDef {
+  name: any;
+  category?: string;
+  params?: any;
+  defaultParams?: any;
+  shortName?: any;
+  fake?: boolean;
+  version?: string;
+  description?: string;
+}
 
 
-function addFuncDef(funcDef) {
+function addFuncDef(funcDef: FuncDef) {
   funcDef.params = funcDef.params || [];
   funcDef.params = funcDef.params || [];
   funcDef.defaultParams = funcDef.defaultParams || [];
   funcDef.defaultParams = funcDef.defaultParams || [];
 
 
@@ -941,7 +952,7 @@ addFuncDef({
   version: '1.1',
   version: '1.1',
 });
 });
 
 
-function isVersionRelatedFunction(obj, graphiteVersion) {
+function isVersionRelatedFunction(obj: { version: string }, graphiteVersion: string) {
   return !obj.version || isVersionGtOrEq(graphiteVersion, obj.version);
   return !obj.version || isVersionGtOrEq(graphiteVersion, obj.version);
 }
 }
 
 
@@ -951,7 +962,7 @@ export class FuncInstance {
   text: any;
   text: any;
   added: boolean;
   added: boolean;
 
 
-  constructor(funcDef, options) {
+  constructor(funcDef: any, options: { withDefaultParams: any }) {
     this.def = funcDef;
     this.def = funcDef;
     this.params = [];
     this.params = [];
 
 
@@ -1002,7 +1013,7 @@ export class FuncInstance {
     return str + parameters.join(', ') + ')';
     return str + parameters.join(', ') + ')';
   }
   }
 
 
-  _hasMultipleParamsInString(strValue, index) {
+  _hasMultipleParamsInString(strValue: any, index: number) {
     if (strValue.indexOf(',') === -1) {
     if (strValue.indexOf(',') === -1) {
       return false;
       return false;
     }
     }
@@ -1018,7 +1029,7 @@ export class FuncInstance {
     return false;
     return false;
   }
   }
 
 
-  updateParam(strValue, index) {
+  updateParam(strValue: any, index: any) {
     // handle optional parameters
     // handle optional parameters
     // if string contains ',' and next param is optional, split and update both
     // if string contains ',' and next param is optional, split and update both
     if (this._hasMultipleParamsInString(strValue, index)) {
     if (this._hasMultipleParamsInString(strValue, index)) {
@@ -1050,22 +1061,22 @@ export class FuncInstance {
   }
   }
 }
 }
 
 
-function createFuncInstance(funcDef, options?, idx?) {
+function createFuncInstance(funcDef: any, options?: { withDefaultParams: any }, idx?: any) {
   if (_.isString(funcDef)) {
   if (_.isString(funcDef)) {
     funcDef = getFuncDef(funcDef, idx);
     funcDef = getFuncDef(funcDef, idx);
   }
   }
   return new FuncInstance(funcDef, options);
   return new FuncInstance(funcDef, options);
 }
 }
 
 
-function getFuncDef(name, idx?) {
+function getFuncDef(name: string, idx?: any) {
   if (!(idx || index)[name]) {
   if (!(idx || index)[name]) {
     throw { message: 'Method not found ' + name };
     throw { message: 'Method not found ' + name };
   }
   }
   return (idx || index)[name];
   return (idx || index)[name];
 }
 }
 
 
-function getFuncDefs(graphiteVersion, idx?) {
-  const funcs = {};
+function getFuncDefs(graphiteVersion: string, idx?: any) {
+  const funcs: any = {};
   _.forEach(idx || index, funcDef => {
   _.forEach(idx || index, funcDef => {
     if (isVersionRelatedFunction(funcDef, graphiteVersion)) {
     if (isVersionRelatedFunction(funcDef, graphiteVersion)) {
       funcs[funcDef.name] = _.assign({}, funcDef, {
       funcs[funcDef.name] = _.assign({}, funcDef, {
@@ -1079,8 +1090,8 @@ function getFuncDefs(graphiteVersion, idx?) {
 }
 }
 
 
 // parse response from graphite /functions endpoint into internal format
 // parse response from graphite /functions endpoint into internal format
-function parseFuncDefs(rawDefs) {
-  const funcDefs = {};
+function parseFuncDefs(rawDefs: any) {
+  const funcDefs: any = {};
 
 
   _.forEach(rawDefs || {}, (funcDef, funcName) => {
   _.forEach(rawDefs || {}, (funcDef, funcName) => {
     // skip graphite graph functions
     // skip graphite graph functions
@@ -1097,9 +1108,9 @@ function parseFuncDefs(rawDefs) {
         .replace(/.. code-block *:: *none/g, '.. code-block::');
         .replace(/.. code-block *:: *none/g, '.. code-block::');
     }
     }
 
 
-    const func = {
+    const func: FuncDef = {
       name: funcDef.name,
       name: funcDef.name,
-      description: description,
+      description,
       category: funcDef.group,
       category: funcDef.group,
       params: [],
       params: [],
       defaultParams: [],
       defaultParams: [],
@@ -1122,7 +1133,7 @@ function parseFuncDefs(rawDefs) {
     }
     }
 
 
     _.forEach(funcDef.params, rawParam => {
     _.forEach(funcDef.params, rawParam => {
-      const param = {
+      const param: any = {
         name: rawParam.name,
         name: rawParam.name,
         type: 'string',
         type: 'string',
         optional: !rawParam.required,
         optional: !rawParam.required,

+ 19 - 17
public/app/plugins/datasource/graphite/graphite_query.ts

@@ -1,5 +1,7 @@
 import _ from 'lodash';
 import _ from 'lodash';
 import { Parser } from './parser';
 import { Parser } from './parser';
+import { TemplateSrv } from 'app/features/templating/template_srv';
+import { ScopedVars } from '@grafana/ui';
 
 
 export default class GraphiteQuery {
 export default class GraphiteQuery {
   datasource: any;
   datasource: any;
@@ -15,7 +17,7 @@ export default class GraphiteQuery {
   scopedVars: any;
   scopedVars: any;
 
 
   /** @ngInject */
   /** @ngInject */
-  constructor(datasource, target, templateSrv?, scopedVars?) {
+  constructor(datasource: any, target: any, templateSrv?: TemplateSrv, scopedVars?: ScopedVars) {
     this.datasource = datasource;
     this.datasource = datasource;
     this.target = target;
     this.target = target;
     this.templateSrv = templateSrv;
     this.templateSrv = templateSrv;
@@ -60,7 +62,7 @@ export default class GraphiteQuery {
     this.checkOtherSegmentsIndex = this.segments.length - 1;
     this.checkOtherSegmentsIndex = this.segments.length - 1;
   }
   }
 
 
-  getSegmentPathUpTo(index) {
+  getSegmentPathUpTo(index: number) {
     const arr = this.segments.slice(0, index);
     const arr = this.segments.slice(0, index);
 
 
     return _.reduce(
     return _.reduce(
@@ -72,7 +74,7 @@ export default class GraphiteQuery {
     );
     );
   }
   }
 
 
-  parseTargetRecursive(astNode, func) {
+  parseTargetRecursive(astNode: any, func: any): any {
     if (astNode === null) {
     if (astNode === null) {
       return null;
       return null;
     }
     }
@@ -119,7 +121,7 @@ export default class GraphiteQuery {
     }
     }
   }
   }
 
 
-  updateSegmentValue(segment, index) {
+  updateSegmentValue(segment: any, index: number) {
     this.segments[index].value = segment.value;
     this.segments[index].value = segment.value;
   }
   }
 
 
@@ -127,28 +129,28 @@ export default class GraphiteQuery {
     this.segments.push({ value: 'select metric' });
     this.segments.push({ value: 'select metric' });
   }
   }
 
 
-  addFunction(newFunc) {
+  addFunction(newFunc: any) {
     this.functions.push(newFunc);
     this.functions.push(newFunc);
   }
   }
 
 
-  addFunctionParameter(func, value) {
+  addFunctionParameter(func: any, value: string) {
     if (func.params.length >= func.def.params.length && !_.get(_.last(func.def.params), 'multiple', false)) {
     if (func.params.length >= func.def.params.length && !_.get(_.last(func.def.params), 'multiple', false)) {
       throw { message: 'too many parameters for function ' + func.def.name };
       throw { message: 'too many parameters for function ' + func.def.name };
     }
     }
     func.params.push(value);
     func.params.push(value);
   }
   }
 
 
-  removeFunction(func) {
+  removeFunction(func: any) {
     this.functions = _.without(this.functions, func);
     this.functions = _.without(this.functions, func);
   }
   }
 
 
-  moveFunction(func, offset) {
+  moveFunction(func: any, offset: number) {
     const index = this.functions.indexOf(func);
     const index = this.functions.indexOf(func);
     // @ts-ignore
     // @ts-ignore
     _.move(this.functions, index, index + offset);
     _.move(this.functions, index, index + offset);
   }
   }
 
 
-  updateModelTarget(targets) {
+  updateModelTarget(targets: any) {
     const wrapFunction = (target: string, func: any) => {
     const wrapFunction = (target: string, func: any) => {
       return func.render(target, (value: string) => {
       return func.render(target, (value: string) => {
         return this.templateSrv.replace(value, this.scopedVars);
         return this.templateSrv.replace(value, this.scopedVars);
@@ -170,7 +172,7 @@ export default class GraphiteQuery {
     }
     }
   }
   }
 
 
-  updateRenderedTarget(target, targets) {
+  updateRenderedTarget(target: { refId: string | number; target: any; targetFull: any }, targets: any) {
     // render nested query
     // render nested query
     const targetsByRefId = _.keyBy(targets, 'refId');
     const targetsByRefId = _.keyBy(targets, 'refId');
 
 
@@ -181,7 +183,7 @@ export default class GraphiteQuery {
     let targetWithNestedQueries = target.target;
     let targetWithNestedQueries = target.target;
 
 
     // Use ref count to track circular references
     // Use ref count to track circular references
-    function countTargetRefs(targetsByRefId, refId) {
+    function countTargetRefs(targetsByRefId: any, refId: string) {
       let refCount = 0;
       let refCount = 0;
       _.each(targetsByRefId, (t, id) => {
       _.each(targetsByRefId, (t, id) => {
         if (id !== refId) {
         if (id !== refId) {
@@ -199,7 +201,7 @@ export default class GraphiteQuery {
     // Keep interpolating until there are no query references
     // Keep interpolating until there are no query references
     // The reason for the loop is that the referenced query might contain another reference to another query
     // The reason for the loop is that the referenced query might contain another reference to another query
     while (targetWithNestedQueries.match(nestedSeriesRefRegex)) {
     while (targetWithNestedQueries.match(nestedSeriesRefRegex)) {
-      const updated = targetWithNestedQueries.replace(nestedSeriesRefRegex, (match, g1) => {
+      const updated = targetWithNestedQueries.replace(nestedSeriesRefRegex, (match: string, g1: string) => {
         const t = targetsByRefId[g1];
         const t = targetsByRefId[g1];
         if (!t) {
         if (!t) {
           return match;
           return match;
@@ -227,7 +229,7 @@ export default class GraphiteQuery {
     }
     }
   }
   }
 
 
-  splitSeriesByTagParams(func) {
+  splitSeriesByTagParams(func: { params: any }) {
     const tagPattern = /([^\!=~]+)(\!?=~?)(.*)/;
     const tagPattern = /([^\!=~]+)(\!?=~?)(.*)/;
     return _.flatten(
     return _.flatten(
       _.map(func.params, (param: string) => {
       _.map(func.params, (param: string) => {
@@ -260,18 +262,18 @@ export default class GraphiteQuery {
     }
     }
   }
   }
 
 
-  addTag(tag) {
+  addTag(tag: { key: any; operator: string; value: string }) {
     const newTagParam = renderTagString(tag);
     const newTagParam = renderTagString(tag);
     this.getSeriesByTagFunc().params.push(newTagParam);
     this.getSeriesByTagFunc().params.push(newTagParam);
     this.tags.push(tag);
     this.tags.push(tag);
   }
   }
 
 
-  removeTag(index) {
+  removeTag(index: number) {
     this.getSeriesByTagFunc().params.splice(index, 1);
     this.getSeriesByTagFunc().params.splice(index, 1);
     this.tags.splice(index, 1);
     this.tags.splice(index, 1);
   }
   }
 
 
-  updateTag(tag, tagIndex) {
+  updateTag(tag: { key: string }, tagIndex: number) {
     this.error = null;
     this.error = null;
 
 
     if (tag.key === this.removeTagValue) {
     if (tag.key === this.removeTagValue) {
@@ -296,6 +298,6 @@ export default class GraphiteQuery {
   }
   }
 }
 }
 
 
-function renderTagString(tag) {
+function renderTagString(tag: { key: any; operator?: any; value?: any }) {
   return tag.key + tag.operator + tag.value;
   return tag.key + tag.operator + tag.value;
 }
 }

+ 43 - 33
public/app/plugins/datasource/graphite/query_ctrl.ts

@@ -5,6 +5,8 @@ import _ from 'lodash';
 import GraphiteQuery from './graphite_query';
 import GraphiteQuery from './graphite_query';
 import { QueryCtrl } from 'app/plugins/sdk';
 import { QueryCtrl } from 'app/plugins/sdk';
 import appEvents from 'app/core/app_events';
 import appEvents from 'app/core/app_events';
+import { auto } from 'angular';
+import { TemplateSrv } from 'app/features/templating/template_srv';
 
 
 const GRAPHITE_TAG_OPERATORS = ['=', '!=', '=~', '!=~'];
 const GRAPHITE_TAG_OPERATORS = ['=', '!=', '=~', '!=~'];
 const TAG_PREFIX = 'tag: ';
 const TAG_PREFIX = 'tag: ';
@@ -20,7 +22,13 @@ export class GraphiteQueryCtrl extends QueryCtrl {
   paused: boolean;
   paused: boolean;
 
 
   /** @ngInject */
   /** @ngInject */
-  constructor($scope, $injector, private uiSegmentSrv, private templateSrv, $timeout) {
+  constructor(
+    $scope: any,
+    $injector: auto.IInjectorService,
+    private uiSegmentSrv: any,
+    private templateSrv: TemplateSrv,
+    $timeout: any
+  ) {
     super($scope, $injector);
     super($scope, $injector);
     this.supportsTags = this.datasource.supportsTags;
     this.supportsTags = this.datasource.supportsTags;
     this.paused = false;
     this.paused = false;
@@ -62,7 +70,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     this.segments.push(this.uiSegmentSrv.newSelectMetric());
     this.segments.push(this.uiSegmentSrv.newSelectMetric());
   }
   }
 
 
-  checkOtherSegments(fromIndex) {
+  checkOtherSegments(fromIndex: number) {
     if (this.queryModel.segments.length === 1 && this.queryModel.segments[0].type === 'series-ref') {
     if (this.queryModel.segments.length === 1 && this.queryModel.segments[0].type === 'series-ref') {
       return;
       return;
     }
     }
@@ -79,7 +87,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
 
 
     return this.datasource
     return this.datasource
       .metricFindQuery(path)
       .metricFindQuery(path)
-      .then(segments => {
+      .then((segments: any) => {
         if (segments.length === 0) {
         if (segments.length === 0) {
           if (path !== '') {
           if (path !== '') {
             this.queryModel.segments = this.queryModel.segments.splice(0, fromIndex);
             this.queryModel.segments = this.queryModel.segments.splice(0, fromIndex);
@@ -94,18 +102,18 @@ export class GraphiteQueryCtrl extends QueryCtrl {
           }
           }
         }
         }
       })
       })
-      .catch(err => {
+      .catch((err: any) => {
         appEvents.emit('alert-error', ['Error', err]);
         appEvents.emit('alert-error', ['Error', err]);
       });
       });
   }
   }
 
 
-  setSegmentFocus(segmentIndex) {
+  setSegmentFocus(segmentIndex: any) {
     _.each(this.segments, (segment, index) => {
     _.each(this.segments, (segment, index) => {
       segment.focus = segmentIndex === index;
       segment.focus = segmentIndex === index;
     });
     });
   }
   }
 
 
-  getAltSegments(index, prefix) {
+  getAltSegments(index: number, prefix: string) {
     let query = prefix && prefix.length > 0 ? '*' + prefix + '*' : '*';
     let query = prefix && prefix.length > 0 ? '*' + prefix + '*' : '*';
     if (index > 0) {
     if (index > 0) {
       query = this.queryModel.getSegmentPathUpTo(index) + '.' + query;
       query = this.queryModel.getSegmentPathUpTo(index) + '.' + query;
@@ -117,7 +125,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
 
 
     return this.datasource
     return this.datasource
       .metricFindQuery(query, options)
       .metricFindQuery(query, options)
-      .then(segments => {
+      .then((segments: any[]) => {
         const altSegments = _.map(segments, segment => {
         const altSegments = _.map(segments, segment => {
           return this.uiSegmentSrv.newSegment({
           return this.uiSegmentSrv.newSegment({
             value: segment.text,
             value: segment.text,
@@ -167,13 +175,15 @@ export class GraphiteQueryCtrl extends QueryCtrl {
           return altSegments;
           return altSegments;
         }
         }
       })
       })
-      .catch(err => {
-        return [];
-      });
+      .catch(
+        (err: any): any[] => {
+          return [];
+        }
+      );
   }
   }
 
 
-  addAltTagSegments(prefix, altSegments) {
-    return this.getTagsAsSegments(prefix).then(tagSegments => {
+  addAltTagSegments(prefix: string, altSegments: any[]) {
+    return this.getTagsAsSegments(prefix).then((tagSegments: any[]) => {
       tagSegments = _.map(tagSegments, segment => {
       tagSegments = _.map(tagSegments, segment => {
         segment.value = TAG_PREFIX + segment.value;
         segment.value = TAG_PREFIX + segment.value;
         return segment;
         return segment;
@@ -186,7 +196,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     altSegments = _.remove(altSegments, s => s.value === '_tagged');
     altSegments = _.remove(altSegments, s => s.value === '_tagged');
   }
   }
 
 
-  segmentValueChanged(segment, segmentIndex) {
+  segmentValueChanged(segment: { type: string; value: string; expandable: any }, segmentIndex: number) {
     this.error = null;
     this.error = null;
     this.queryModel.updateSegmentValue(segment, segmentIndex);
     this.queryModel.updateSegmentValue(segment, segmentIndex);
 
 
@@ -214,7 +224,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     this.targetChanged();
     this.targetChanged();
   }
   }
 
 
-  spliceSegments(index) {
+  spliceSegments(index: any) {
     this.segments = this.segments.splice(0, index);
     this.segments = this.segments.splice(0, index);
     this.queryModel.segments = this.queryModel.segments.splice(0, index);
     this.queryModel.segments = this.queryModel.segments.splice(0, index);
   }
   }
@@ -246,7 +256,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     }
     }
   }
   }
 
 
-  addFunction(funcDef) {
+  addFunction(funcDef: any) {
     const newFunc = this.datasource.createFuncInstance(funcDef, {
     const newFunc = this.datasource.createFuncInstance(funcDef, {
       withDefaultParams: true,
       withDefaultParams: true,
     });
     });
@@ -267,17 +277,17 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     }
     }
   }
   }
 
 
-  removeFunction(func) {
+  removeFunction(func: any) {
     this.queryModel.removeFunction(func);
     this.queryModel.removeFunction(func);
     this.targetChanged();
     this.targetChanged();
   }
   }
 
 
-  moveFunction(func, offset) {
+  moveFunction(func: any, offset: any) {
     this.queryModel.moveFunction(func, offset);
     this.queryModel.moveFunction(func, offset);
     this.targetChanged();
     this.targetChanged();
   }
   }
 
 
-  addSeriesByTagFunc(tag) {
+  addSeriesByTagFunc(tag: string) {
     const newFunc = this.datasource.createFuncInstance('seriesByTag', {
     const newFunc = this.datasource.createFuncInstance('seriesByTag', {
       withDefaultParams: false,
       withDefaultParams: false,
     });
     });
@@ -291,7 +301,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     this.parseTarget();
     this.parseTarget();
   }
   }
 
 
-  smartlyHandleNewAliasByNode(func) {
+  smartlyHandleNewAliasByNode(func: { def: { name: string }; params: number[]; added: boolean }) {
     if (func.def.name !== 'aliasByNode') {
     if (func.def.name !== 'aliasByNode') {
       return;
       return;
     }
     }
@@ -307,25 +317,25 @@ export class GraphiteQueryCtrl extends QueryCtrl {
   }
   }
 
 
   getAllTags() {
   getAllTags() {
-    return this.datasource.getTags().then(values => {
+    return this.datasource.getTags().then((values: any[]) => {
       const altTags = _.map(values, 'text');
       const altTags = _.map(values, 'text');
       altTags.splice(0, 0, this.removeTagValue);
       altTags.splice(0, 0, this.removeTagValue);
       return mapToDropdownOptions(altTags);
       return mapToDropdownOptions(altTags);
     });
     });
   }
   }
 
 
-  getTags(index, tagPrefix) {
+  getTags(index: number, tagPrefix: any) {
     const tagExpressions = this.queryModel.renderTagExpressions(index);
     const tagExpressions = this.queryModel.renderTagExpressions(index);
-    return this.datasource.getTagsAutoComplete(tagExpressions, tagPrefix).then(values => {
+    return this.datasource.getTagsAutoComplete(tagExpressions, tagPrefix).then((values: any) => {
       const altTags = _.map(values, 'text');
       const altTags = _.map(values, 'text');
       altTags.splice(0, 0, this.removeTagValue);
       altTags.splice(0, 0, this.removeTagValue);
       return mapToDropdownOptions(altTags);
       return mapToDropdownOptions(altTags);
     });
     });
   }
   }
 
 
-  getTagsAsSegments(tagPrefix) {
+  getTagsAsSegments(tagPrefix: string) {
     const tagExpressions = this.queryModel.renderTagExpressions();
     const tagExpressions = this.queryModel.renderTagExpressions();
-    return this.datasource.getTagsAutoComplete(tagExpressions, tagPrefix).then(values => {
+    return this.datasource.getTagsAutoComplete(tagExpressions, tagPrefix).then((values: any) => {
       return _.map(values, val => {
       return _.map(values, val => {
         return this.uiSegmentSrv.newSegment({
         return this.uiSegmentSrv.newSegment({
           value: val.text,
           value: val.text,
@@ -340,18 +350,18 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     return mapToDropdownOptions(GRAPHITE_TAG_OPERATORS);
     return mapToDropdownOptions(GRAPHITE_TAG_OPERATORS);
   }
   }
 
 
-  getAllTagValues(tag) {
+  getAllTagValues(tag: { key: any }) {
     const tagKey = tag.key;
     const tagKey = tag.key;
-    return this.datasource.getTagValues(tagKey).then(values => {
+    return this.datasource.getTagValues(tagKey).then((values: any[]) => {
       const altValues = _.map(values, 'text');
       const altValues = _.map(values, 'text');
       return mapToDropdownOptions(altValues);
       return mapToDropdownOptions(altValues);
     });
     });
   }
   }
 
 
-  getTagValues(tag, index, valuePrefix) {
+  getTagValues(tag: { key: any }, index: number, valuePrefix: any) {
     const tagExpressions = this.queryModel.renderTagExpressions(index);
     const tagExpressions = this.queryModel.renderTagExpressions(index);
     const tagKey = tag.key;
     const tagKey = tag.key;
-    return this.datasource.getTagValuesAutoComplete(tagExpressions, tagKey, valuePrefix).then(values => {
+    return this.datasource.getTagValuesAutoComplete(tagExpressions, tagKey, valuePrefix).then((values: any[]) => {
       const altValues = _.map(values, 'text');
       const altValues = _.map(values, 'text');
       // Add template variables as additional values
       // Add template variables as additional values
       _.eachRight(this.templateSrv.variables, variable => {
       _.eachRight(this.templateSrv.variables, variable => {
@@ -361,12 +371,12 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     });
     });
   }
   }
 
 
-  tagChanged(tag, tagIndex) {
+  tagChanged(tag: any, tagIndex: any) {
     this.queryModel.updateTag(tag, tagIndex);
     this.queryModel.updateTag(tag, tagIndex);
     this.targetChanged();
     this.targetChanged();
   }
   }
 
 
-  addNewTag(segment) {
+  addNewTag(segment: { value: any }) {
     const newTagKey = segment.value;
     const newTagKey = segment.value;
     const newTag = { key: newTagKey, operator: '=', value: '' };
     const newTag = { key: newTagKey, operator: '=', value: '' };
     this.queryModel.addTag(newTag);
     this.queryModel.addTag(newTag);
@@ -374,7 +384,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     this.fixTagSegments();
     this.fixTagSegments();
   }
   }
 
 
-  removeTag(index) {
+  removeTag(index: any) {
     this.queryModel.removeTag(index);
     this.queryModel.removeTag(index);
     this.targetChanged();
     this.targetChanged();
   }
   }
@@ -384,7 +394,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     this.addTagSegments = [this.uiSegmentSrv.newPlusButton()];
     this.addTagSegments = [this.uiSegmentSrv.newPlusButton()];
   }
   }
 
 
-  showDelimiter(index) {
+  showDelimiter(index: number) {
     return index !== this.queryModel.tags.length - 1;
     return index !== this.queryModel.tags.length - 1;
   }
   }
 
 
@@ -402,7 +412,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
   }
   }
 }
 }
 
 
-function mapToDropdownOptions(results) {
+function mapToDropdownOptions(results: any[]) {
   return _.map(results, value => {
   return _.map(results, value => {
     return { text: value, value: value };
     return { text: value, value: value };
   });
   });

+ 30 - 25
public/app/plugins/datasource/graphite/specs/datasource.test.ts

@@ -1,5 +1,6 @@
 import { GraphiteDatasource } from '../datasource';
 import { GraphiteDatasource } from '../datasource';
 import _ from 'lodash';
 import _ from 'lodash';
+// @ts-ignore
 import $q from 'q';
 import $q from 'q';
 import { TemplateSrvStub } from 'test/specs/helpers';
 import { TemplateSrvStub } from 'test/specs/helpers';
 import { dateTime } from '@grafana/ui/src/utils/moment_wrapper';
 import { dateTime } from '@grafana/ui/src/utils/moment_wrapper';
@@ -7,13 +8,15 @@ import { dateTime } from '@grafana/ui/src/utils/moment_wrapper';
 describe('graphiteDatasource', () => {
 describe('graphiteDatasource', () => {
   const ctx: any = {
   const ctx: any = {
     backendSrv: {},
     backendSrv: {},
-    $q: $q,
+    $q,
+    // @ts-ignore
     templateSrv: new TemplateSrvStub(),
     templateSrv: new TemplateSrvStub(),
     instanceSettings: { url: 'url', name: 'graphiteProd', jsonData: {} },
     instanceSettings: { url: 'url', name: 'graphiteProd', jsonData: {} },
   };
   };
 
 
   beforeEach(() => {
   beforeEach(() => {
     ctx.instanceSettings.url = '/api/datasources/proxy/1';
     ctx.instanceSettings.url = '/api/datasources/proxy/1';
+    // @ts-ignore
     ctx.ds = new GraphiteDatasource(ctx.instanceSettings, ctx.$q, ctx.backendSrv, ctx.templateSrv);
     ctx.ds = new GraphiteDatasource(ctx.instanceSettings, ctx.$q, ctx.backendSrv, ctx.templateSrv);
   });
   });
 
 
@@ -26,18 +29,18 @@ describe('graphiteDatasource', () => {
       maxDataPoints: 500,
       maxDataPoints: 500,
     };
     };
 
 
-    let results;
-    let requestOptions;
+    let results: any;
+    let requestOptions: any;
 
 
     beforeEach(async () => {
     beforeEach(async () => {
-      ctx.backendSrv.datasourceRequest = options => {
+      ctx.backendSrv.datasourceRequest = (options: any) => {
         requestOptions = options;
         requestOptions = options;
         return ctx.$q.when({
         return ctx.$q.when({
           data: [{ target: 'prod1.count', datapoints: [[10, 1], [12, 1]] }],
           data: [{ target: 'prod1.count', datapoints: [[10, 1], [12, 1]] }],
         });
         });
       };
       };
 
 
-      await ctx.ds.query(query).then(data => {
+      await ctx.ds.query(query).then((data: any) => {
         results = data;
         results = data;
       });
       });
     });
     });
@@ -79,7 +82,7 @@ describe('graphiteDatasource', () => {
   });
   });
 
 
   describe('when fetching Graphite Events as annotations', () => {
   describe('when fetching Graphite Events as annotations', () => {
-    let results;
+    let results: any;
 
 
     const options = {
     const options = {
       annotation: {
       annotation: {
@@ -106,11 +109,11 @@ describe('graphiteDatasource', () => {
       };
       };
 
 
       beforeEach(async () => {
       beforeEach(async () => {
-        ctx.backendSrv.datasourceRequest = options => {
+        ctx.backendSrv.datasourceRequest = (options: any) => {
           return ctx.$q.when(response);
           return ctx.$q.when(response);
         };
         };
 
 
-        await ctx.ds.annotationQuery(options).then(data => {
+        await ctx.ds.annotationQuery(options).then((data: any) => {
           results = data;
           results = data;
         });
         });
       });
       });
@@ -136,11 +139,11 @@ describe('graphiteDatasource', () => {
         ],
         ],
       };
       };
       beforeEach(() => {
       beforeEach(() => {
-        ctx.backendSrv.datasourceRequest = options => {
+        ctx.backendSrv.datasourceRequest = (options: any) => {
           return ctx.$q.when(response);
           return ctx.$q.when(response);
         };
         };
 
 
-        ctx.ds.annotationQuery(options).then(data => {
+        ctx.ds.annotationQuery(options).then((data: any) => {
           results = data;
           results = data;
         });
         });
         // ctx.$rootScope.$apply();
         // ctx.$rootScope.$apply();
@@ -218,11 +221,11 @@ describe('graphiteDatasource', () => {
   });
   });
 
 
   describe('querying for template variables', () => {
   describe('querying for template variables', () => {
-    let results;
-    let requestOptions;
+    let results: any;
+    let requestOptions: any;
 
 
     beforeEach(() => {
     beforeEach(() => {
-      ctx.backendSrv.datasourceRequest = options => {
+      ctx.backendSrv.datasourceRequest = (options: any) => {
         requestOptions = options;
         requestOptions = options;
         return ctx.$q.when({
         return ctx.$q.when({
           data: ['backend_01', 'backend_02'],
           data: ['backend_01', 'backend_02'],
@@ -231,7 +234,7 @@ describe('graphiteDatasource', () => {
     });
     });
 
 
     it('should generate tags query', () => {
     it('should generate tags query', () => {
-      ctx.ds.metricFindQuery('tags()').then(data => {
+      ctx.ds.metricFindQuery('tags()').then((data: any) => {
         results = data;
         results = data;
       });
       });
 
 
@@ -241,7 +244,7 @@ describe('graphiteDatasource', () => {
     });
     });
 
 
     it('should generate tags query with a filter expression', () => {
     it('should generate tags query with a filter expression', () => {
-      ctx.ds.metricFindQuery('tags(server=backend_01)').then(data => {
+      ctx.ds.metricFindQuery('tags(server=backend_01)').then((data: any) => {
         results = data;
         results = data;
       });
       });
 
 
@@ -251,7 +254,7 @@ describe('graphiteDatasource', () => {
     });
     });
 
 
     it('should generate tags query for an expression with whitespace after', () => {
     it('should generate tags query for an expression with whitespace after', () => {
-      ctx.ds.metricFindQuery('tags(server=backend_01 )').then(data => {
+      ctx.ds.metricFindQuery('tags(server=backend_01 )').then((data: any) => {
         results = data;
         results = data;
       });
       });
 
 
@@ -261,7 +264,7 @@ describe('graphiteDatasource', () => {
     });
     });
 
 
     it('should generate tag values query for one tag', () => {
     it('should generate tag values query for one tag', () => {
-      ctx.ds.metricFindQuery('tag_values(server)').then(data => {
+      ctx.ds.metricFindQuery('tag_values(server)').then((data: any) => {
         results = data;
         results = data;
       });
       });
 
 
@@ -272,7 +275,7 @@ describe('graphiteDatasource', () => {
     });
     });
 
 
     it('should generate tag values query for a tag and expression', () => {
     it('should generate tag values query for a tag and expression', () => {
-      ctx.ds.metricFindQuery('tag_values(server,server=~backend*)').then(data => {
+      ctx.ds.metricFindQuery('tag_values(server,server=~backend*)').then((data: any) => {
         results = data;
         results = data;
       });
       });
 
 
@@ -283,7 +286,7 @@ describe('graphiteDatasource', () => {
     });
     });
 
 
     it('should generate tag values query for a tag with whitespace after', () => {
     it('should generate tag values query for a tag with whitespace after', () => {
-      ctx.ds.metricFindQuery('tag_values(server )').then(data => {
+      ctx.ds.metricFindQuery('tag_values(server )').then((data: any) => {
         results = data;
         results = data;
       });
       });
 
 
@@ -294,7 +297,7 @@ describe('graphiteDatasource', () => {
     });
     });
 
 
     it('should generate tag values query for a tag and expression with whitespace after', () => {
     it('should generate tag values query for a tag and expression with whitespace after', () => {
-      ctx.ds.metricFindQuery('tag_values(server , server=~backend* )').then(data => {
+      ctx.ds.metricFindQuery('tag_values(server , server=~backend* )').then((data: any) => {
         results = data;
         results = data;
       });
       });
 
 
@@ -306,7 +309,7 @@ describe('graphiteDatasource', () => {
 
 
     it('/metrics/find should be POST', () => {
     it('/metrics/find should be POST', () => {
       ctx.templateSrv.setGrafanaVariable('foo', 'bar');
       ctx.templateSrv.setGrafanaVariable('foo', 'bar');
-      ctx.ds.metricFindQuery('[[foo]]').then(data => {
+      ctx.ds.metricFindQuery('[[foo]]').then((data: any) => {
         results = data;
         results = data;
       });
       });
       expect(requestOptions.url).toBe('/api/datasources/proxy/1/metrics/find');
       expect(requestOptions.url).toBe('/api/datasources/proxy/1/metrics/find');
@@ -318,11 +321,12 @@ describe('graphiteDatasource', () => {
   });
   });
 });
 });
 
 
-function accessScenario(name, url, fn) {
+function accessScenario(name: string, url: string, fn: any) {
   describe('access scenario ' + name, () => {
   describe('access scenario ' + name, () => {
     const ctx: any = {
     const ctx: any = {
       backendSrv: {},
       backendSrv: {},
-      $q: $q,
+      $q,
+      // @ts-ignore
       templateSrv: new TemplateSrvStub(),
       templateSrv: new TemplateSrvStub(),
       instanceSettings: { url: 'url', name: 'graphiteProd', jsonData: {} },
       instanceSettings: { url: 'url', name: 'graphiteProd', jsonData: {} },
     };
     };
@@ -336,6 +340,7 @@ function accessScenario(name, url, fn) {
 
 
       it('tracing headers should be added', () => {
       it('tracing headers should be added', () => {
         ctx.instanceSettings.url = url;
         ctx.instanceSettings.url = url;
+        // @ts-ignore
         const ds = new GraphiteDatasource(ctx.instanceSettings, ctx.$q, ctx.backendSrv, ctx.templateSrv);
         const ds = new GraphiteDatasource(ctx.instanceSettings, ctx.$q, ctx.backendSrv, ctx.templateSrv);
         ds.addTracingHeaders(httpOptions, options);
         ds.addTracingHeaders(httpOptions, options);
         fn(httpOptions);
         fn(httpOptions);
@@ -344,12 +349,12 @@ function accessScenario(name, url, fn) {
   });
   });
 }
 }
 
 
-accessScenario('with proxy access', '/api/datasources/proxy/1', httpOptions => {
+accessScenario('with proxy access', '/api/datasources/proxy/1', (httpOptions: any) => {
   expect(httpOptions.headers['X-Dashboard-Id']).toBe(1);
   expect(httpOptions.headers['X-Dashboard-Id']).toBe(1);
   expect(httpOptions.headers['X-Panel-Id']).toBe(2);
   expect(httpOptions.headers['X-Panel-Id']).toBe(2);
 });
 });
 
 
-accessScenario('with direct access', 'http://localhost:8080', httpOptions => {
+accessScenario('with direct access', 'http://localhost:8080', (httpOptions: any) => {
   expect(httpOptions.headers['X-Dashboard-Id']).toBe(undefined);
   expect(httpOptions.headers['X-Dashboard-Id']).toBe(undefined);
   expect(httpOptions.headers['X-Panel-Id']).toBe(undefined);
   expect(httpOptions.headers['X-Panel-Id']).toBe(undefined);
 });
 });

+ 1 - 1
public/app/plugins/datasource/graphite/specs/query_ctrl.test.ts

@@ -29,7 +29,7 @@ describe('GraphiteQueryCtrl', () => {
 
 
     ctx.ctrl = new GraphiteQueryCtrl(
     ctx.ctrl = new GraphiteQueryCtrl(
       {},
       {},
-      {},
+      {} as any,
       //@ts-ignore
       //@ts-ignore
       new uiSegmentSrv({ trustAsHtml: html => html }, { highlightVariablesAsHtml: () => {} }),
       new uiSegmentSrv({ trustAsHtml: html => html }, { highlightVariablesAsHtml: () => {} }),
       //@ts-ignore
       //@ts-ignore