mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tslint: autofix of let -> const (#13033)
This commit is contained in:
@@ -210,8 +210,8 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
};
|
||||
|
||||
this.metricFindQuery = function(query, optionalOptions) {
|
||||
let options = optionalOptions || {};
|
||||
let interpolatedQuery = templateSrv.replace(query);
|
||||
const options = optionalOptions || {};
|
||||
const interpolatedQuery = templateSrv.replace(query);
|
||||
|
||||
// special handling for tag_values(<tag>[,<expression>]*), this is used for template variables
|
||||
let matches = interpolatedQuery.match(/^tag_values\(([^,]+)((, *[^,]+)*)\)$/);
|
||||
@@ -242,7 +242,7 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
return this.getTagsAutoComplete(expressions, undefined, options);
|
||||
}
|
||||
|
||||
let httpOptions: any = {
|
||||
const httpOptions: any = {
|
||||
method: 'GET',
|
||||
url: '/metrics/find',
|
||||
params: {
|
||||
@@ -268,9 +268,9 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
};
|
||||
|
||||
this.getTags = function(optionalOptions) {
|
||||
let options = optionalOptions || {};
|
||||
const options = optionalOptions || {};
|
||||
|
||||
let httpOptions: any = {
|
||||
const httpOptions: any = {
|
||||
method: 'GET',
|
||||
url: '/tags',
|
||||
// for cancellations
|
||||
@@ -293,9 +293,9 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
};
|
||||
|
||||
this.getTagValues = function(tag, optionalOptions) {
|
||||
let options = optionalOptions || {};
|
||||
const options = optionalOptions || {};
|
||||
|
||||
let httpOptions: any = {
|
||||
const httpOptions: any = {
|
||||
method: 'GET',
|
||||
url: '/tags/' + templateSrv.replace(tag),
|
||||
// for cancellations
|
||||
@@ -322,9 +322,9 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
};
|
||||
|
||||
this.getTagsAutoComplete = (expressions, tagPrefix, optionalOptions) => {
|
||||
let options = optionalOptions || {};
|
||||
const options = optionalOptions || {};
|
||||
|
||||
let httpOptions: any = {
|
||||
const httpOptions: any = {
|
||||
method: 'GET',
|
||||
url: '/tags/autoComplete/tags',
|
||||
params: {
|
||||
@@ -357,9 +357,9 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
};
|
||||
|
||||
this.getTagValuesAutoComplete = (expressions, tag, valuePrefix, optionalOptions) => {
|
||||
let options = optionalOptions || {};
|
||||
const options = optionalOptions || {};
|
||||
|
||||
let httpOptions: any = {
|
||||
const httpOptions: any = {
|
||||
method: 'GET',
|
||||
url: '/tags/autoComplete/values',
|
||||
params: {
|
||||
@@ -393,9 +393,9 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
};
|
||||
|
||||
this.getVersion = function(optionalOptions) {
|
||||
let options = optionalOptions || {};
|
||||
const options = optionalOptions || {};
|
||||
|
||||
let httpOptions = {
|
||||
const httpOptions = {
|
||||
method: 'GET',
|
||||
url: '/version',
|
||||
requestId: options.requestId,
|
||||
@@ -404,7 +404,7 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
return this.doGraphiteRequest(httpOptions)
|
||||
.then(results => {
|
||||
if (results.data) {
|
||||
let semver = new SemVersion(results.data);
|
||||
const semver = new SemVersion(results.data);
|
||||
return semver.isValid() ? results.data : '';
|
||||
}
|
||||
return '';
|
||||
@@ -437,7 +437,7 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
return this.funcDefsPromise;
|
||||
}
|
||||
|
||||
let httpOptions = {
|
||||
const httpOptions = {
|
||||
method: 'GET',
|
||||
url: '/functions',
|
||||
};
|
||||
@@ -461,7 +461,7 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
|
||||
};
|
||||
|
||||
this.testDatasource = function() {
|
||||
let query = {
|
||||
const query = {
|
||||
panelId: 3,
|
||||
rangeRaw: { from: 'now-1h', to: 'now' },
|
||||
targets: [{ target: 'constantLine(100)' }],
|
||||
|
||||
@@ -59,11 +59,11 @@ export default class GraphiteQuery {
|
||||
}
|
||||
|
||||
checkForSeriesByTag() {
|
||||
let seriesByTagFunc = _.find(this.functions, func => func.def.name === 'seriesByTag');
|
||||
const seriesByTagFunc = _.find(this.functions, func => func.def.name === 'seriesByTag');
|
||||
if (seriesByTagFunc) {
|
||||
this.seriesByTagUsed = true;
|
||||
seriesByTagFunc.hidden = true;
|
||||
let tags = this.splitSeriesByTagParams(seriesByTagFunc);
|
||||
const tags = this.splitSeriesByTagParams(seriesByTagFunc);
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
||||
@@ -186,8 +186,8 @@ export default class GraphiteQuery {
|
||||
let refCount = 0;
|
||||
_.each(targetsByRefId, (t, id) => {
|
||||
if (id !== refId) {
|
||||
let match = nestedSeriesRefRegex.exec(t.target);
|
||||
let count = match && match.length ? match.length - 1 : 0;
|
||||
const match = nestedSeriesRefRegex.exec(t.target);
|
||||
const count = match && match.length ? match.length - 1 : 0;
|
||||
refCount += count;
|
||||
}
|
||||
});
|
||||
@@ -232,9 +232,9 @@ export default class GraphiteQuery {
|
||||
const tagPattern = /([^\!=~]+)(\!?=~?)(.*)/;
|
||||
return _.flatten(
|
||||
_.map(func.params, (param: string) => {
|
||||
let matches = tagPattern.exec(param);
|
||||
const matches = tagPattern.exec(param);
|
||||
if (matches) {
|
||||
let tag = matches.slice(1);
|
||||
const tag = matches.slice(1);
|
||||
if (tag.length === 3) {
|
||||
return {
|
||||
key: tag[0],
|
||||
@@ -253,7 +253,7 @@ export default class GraphiteQuery {
|
||||
}
|
||||
|
||||
getSeriesByTagFunc() {
|
||||
let seriesByTagFuncIndex = this.getSeriesByTagFuncIndex();
|
||||
const seriesByTagFuncIndex = this.getSeriesByTagFuncIndex();
|
||||
if (seriesByTagFuncIndex >= 0) {
|
||||
return this.functions[seriesByTagFuncIndex];
|
||||
} else {
|
||||
@@ -262,7 +262,7 @@ export default class GraphiteQuery {
|
||||
}
|
||||
|
||||
addTag(tag) {
|
||||
let newTagParam = renderTagString(tag);
|
||||
const newTagParam = renderTagString(tag);
|
||||
this.getSeriesByTagFunc().params.push(newTagParam);
|
||||
this.tags.push(tag);
|
||||
}
|
||||
@@ -280,7 +280,7 @@ export default class GraphiteQuery {
|
||||
return;
|
||||
}
|
||||
|
||||
let newTagParam = renderTagString(tag);
|
||||
const newTagParam = renderTagString(tag);
|
||||
this.getSeriesByTagFunc().params[tagIndex] = newTagParam;
|
||||
this.tags[tagIndex] = tag;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
return this.uiSegmentSrv.newSegment(segment);
|
||||
});
|
||||
|
||||
let checkOtherSegmentsIndex = this.queryModel.checkOtherSegmentsIndex || 0;
|
||||
const checkOtherSegmentsIndex = this.queryModel.checkOtherSegmentsIndex || 0;
|
||||
this.checkOtherSegments(checkOtherSegmentsIndex);
|
||||
|
||||
if (this.queryModel.seriesByTagUsed) {
|
||||
@@ -195,7 +195,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
if (segment.type === 'tag') {
|
||||
let tag = removeTagPrefix(segment.value);
|
||||
const tag = removeTagPrefix(segment.value);
|
||||
this.pause();
|
||||
this.addSeriesByTagFunc(tag);
|
||||
return;
|
||||
@@ -273,10 +273,10 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
addSeriesByTagFunc(tag) {
|
||||
let newFunc = this.datasource.createFuncInstance('seriesByTag', {
|
||||
const newFunc = this.datasource.createFuncInstance('seriesByTag', {
|
||||
withDefaultParams: false,
|
||||
});
|
||||
let tagParam = `${tag}=`;
|
||||
const tagParam = `${tag}=`;
|
||||
newFunc.params = [tagParam];
|
||||
this.queryModel.addFunction(newFunc);
|
||||
newFunc.added = true;
|
||||
@@ -303,23 +303,23 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
|
||||
getAllTags() {
|
||||
return this.datasource.getTags().then(values => {
|
||||
let altTags = _.map(values, 'text');
|
||||
const altTags = _.map(values, 'text');
|
||||
altTags.splice(0, 0, this.removeTagValue);
|
||||
return mapToDropdownOptions(altTags);
|
||||
});
|
||||
}
|
||||
|
||||
getTags(index, tagPrefix) {
|
||||
let tagExpressions = this.queryModel.renderTagExpressions(index);
|
||||
const tagExpressions = this.queryModel.renderTagExpressions(index);
|
||||
return this.datasource.getTagsAutoComplete(tagExpressions, tagPrefix).then(values => {
|
||||
let altTags = _.map(values, 'text');
|
||||
const altTags = _.map(values, 'text');
|
||||
altTags.splice(0, 0, this.removeTagValue);
|
||||
return mapToDropdownOptions(altTags);
|
||||
});
|
||||
}
|
||||
|
||||
getTagsAsSegments(tagPrefix) {
|
||||
let tagExpressions = this.queryModel.renderTagExpressions();
|
||||
const tagExpressions = this.queryModel.renderTagExpressions();
|
||||
return this.datasource.getTagsAutoComplete(tagExpressions, tagPrefix).then(values => {
|
||||
return _.map(values, val => {
|
||||
return this.uiSegmentSrv.newSegment({
|
||||
@@ -336,18 +336,18 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
getAllTagValues(tag) {
|
||||
let tagKey = tag.key;
|
||||
const tagKey = tag.key;
|
||||
return this.datasource.getTagValues(tagKey).then(values => {
|
||||
let altValues = _.map(values, 'text');
|
||||
const altValues = _.map(values, 'text');
|
||||
return mapToDropdownOptions(altValues);
|
||||
});
|
||||
}
|
||||
|
||||
getTagValues(tag, index, valuePrefix) {
|
||||
let tagExpressions = this.queryModel.renderTagExpressions(index);
|
||||
let tagKey = tag.key;
|
||||
const tagExpressions = this.queryModel.renderTagExpressions(index);
|
||||
const tagKey = tag.key;
|
||||
return this.datasource.getTagValuesAutoComplete(tagExpressions, tagKey, valuePrefix).then(values => {
|
||||
let altValues = _.map(values, 'text');
|
||||
const altValues = _.map(values, 'text');
|
||||
// Add template variables as additional values
|
||||
_.eachRight(this.templateSrv.variables, variable => {
|
||||
altValues.push('${' + variable.name + ':regex}');
|
||||
@@ -362,8 +362,8 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
addNewTag(segment) {
|
||||
let newTagKey = segment.value;
|
||||
let newTag = { key: newTagKey, operator: '=', value: '' };
|
||||
const newTagKey = segment.value;
|
||||
const newTag = { key: newTagKey, operator: '=', value: '' };
|
||||
this.queryModel.addTag(newTag);
|
||||
this.targetChanged();
|
||||
this.fixTagSegments();
|
||||
|
||||
@@ -5,7 +5,7 @@ import $q from 'q';
|
||||
import { TemplateSrvStub } from 'test/specs/helpers';
|
||||
|
||||
describe('graphiteDatasource', () => {
|
||||
let ctx: any = {
|
||||
const ctx: any = {
|
||||
backendSrv: {},
|
||||
$q: $q,
|
||||
templateSrv: new TemplateSrvStub(),
|
||||
@@ -18,7 +18,7 @@ describe('graphiteDatasource', () => {
|
||||
});
|
||||
|
||||
describe('When querying graphite with one target using query editor target spec', function() {
|
||||
let query = {
|
||||
const query = {
|
||||
panelId: 3,
|
||||
dashboardId: 5,
|
||||
rangeRaw: { from: 'now-1h', to: 'now' },
|
||||
@@ -56,7 +56,7 @@ describe('graphiteDatasource', () => {
|
||||
});
|
||||
|
||||
it('should query correctly', function() {
|
||||
let params = requestOptions.data.split('&');
|
||||
const params = requestOptions.data.split('&');
|
||||
expect(params).toContain('target=prod1.count');
|
||||
expect(params).toContain('target=prod2.count');
|
||||
expect(params).toContain('from=-1h');
|
||||
@@ -64,7 +64,7 @@ describe('graphiteDatasource', () => {
|
||||
});
|
||||
|
||||
it('should exclude undefined params', function() {
|
||||
let params = requestOptions.data.split('&');
|
||||
const params = requestOptions.data.split('&');
|
||||
expect(params).not.toContain('cacheTimeout=undefined');
|
||||
});
|
||||
|
||||
@@ -157,28 +157,28 @@ describe('graphiteDatasource', () => {
|
||||
|
||||
describe('building graphite params', function() {
|
||||
it('should return empty array if no targets', function() {
|
||||
let results = ctx.ds.buildGraphiteParams({
|
||||
const results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{}],
|
||||
});
|
||||
expect(results.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should uri escape targets', function() {
|
||||
let results = ctx.ds.buildGraphiteParams({
|
||||
const results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{ target: 'prod1.{test,test2}' }, { target: 'prod2.count' }],
|
||||
});
|
||||
expect(results).toContain('target=prod1.%7Btest%2Ctest2%7D');
|
||||
});
|
||||
|
||||
it('should replace target placeholder', function() {
|
||||
let results = ctx.ds.buildGraphiteParams({
|
||||
const results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{ target: 'series1' }, { target: 'series2' }, { target: 'asPercent(#A,#B)' }],
|
||||
});
|
||||
expect(results[2]).toBe('target=asPercent(series1%2Cseries2)');
|
||||
});
|
||||
|
||||
it('should replace target placeholder for hidden series', function() {
|
||||
let results = ctx.ds.buildGraphiteParams({
|
||||
const results = ctx.ds.buildGraphiteParams({
|
||||
targets: [
|
||||
{ target: 'series1', hide: true },
|
||||
{ target: 'sumSeries(#A)', hide: true },
|
||||
@@ -189,28 +189,28 @@ describe('graphiteDatasource', () => {
|
||||
});
|
||||
|
||||
it('should replace target placeholder when nesting query references', function() {
|
||||
let results = ctx.ds.buildGraphiteParams({
|
||||
const results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{ target: 'series1' }, { target: 'sumSeries(#A)' }, { target: 'asPercent(#A,#B)' }],
|
||||
});
|
||||
expect(results[2]).toBe('target=' + encodeURIComponent('asPercent(series1,sumSeries(series1))'));
|
||||
});
|
||||
|
||||
it('should fix wrong minute interval parameters', function() {
|
||||
let results = ctx.ds.buildGraphiteParams({
|
||||
const results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{ target: "summarize(prod.25m.count, '25m', 'sum')" }],
|
||||
});
|
||||
expect(results[0]).toBe('target=' + encodeURIComponent("summarize(prod.25m.count, '25min', 'sum')"));
|
||||
});
|
||||
|
||||
it('should fix wrong month interval parameters', function() {
|
||||
let results = ctx.ds.buildGraphiteParams({
|
||||
const results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{ target: "summarize(prod.5M.count, '5M', 'sum')" }],
|
||||
});
|
||||
expect(results[0]).toBe('target=' + encodeURIComponent("summarize(prod.5M.count, '5mon', 'sum')"));
|
||||
});
|
||||
|
||||
it('should ignore empty targets', function() {
|
||||
let results = ctx.ds.buildGraphiteParams({
|
||||
const results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{ target: 'series1' }, { target: '' }],
|
||||
});
|
||||
expect(results.length).toBe(2);
|
||||
@@ -308,19 +308,19 @@ describe('graphiteDatasource', () => {
|
||||
|
||||
function accessScenario(name, url, fn) {
|
||||
describe('access scenario ' + name, function() {
|
||||
let ctx: any = {
|
||||
const ctx: any = {
|
||||
backendSrv: {},
|
||||
$q: $q,
|
||||
templateSrv: new TemplateSrvStub(),
|
||||
instanceSettings: { url: 'url', name: 'graphiteProd', jsonData: {} },
|
||||
};
|
||||
|
||||
let httpOptions = {
|
||||
const httpOptions = {
|
||||
headers: {},
|
||||
};
|
||||
|
||||
describe('when using proxy mode', () => {
|
||||
let options = { dashboardId: 1, panelId: 2 };
|
||||
const options = { dashboardId: 1, panelId: 2 };
|
||||
|
||||
it('tracing headers should be added', () => {
|
||||
ctx.instanceSettings.url = url;
|
||||
|
||||
@@ -2,7 +2,7 @@ import gfunc from '../gfunc';
|
||||
import GraphiteQuery from '../graphite_query';
|
||||
|
||||
describe('Graphite query model', () => {
|
||||
let ctx: any = {
|
||||
const ctx: any = {
|
||||
datasource: {
|
||||
getFuncDef: gfunc.getFuncDef,
|
||||
getFuncDefs: jest.fn().mockReturnValue(Promise.resolve(gfunc.getFuncDefs('1.0'))),
|
||||
|
||||
@@ -3,7 +3,7 @@ import gfunc from '../gfunc';
|
||||
import { GraphiteQueryCtrl } from '../query_ctrl';
|
||||
|
||||
describe('GraphiteQueryCtrl', () => {
|
||||
let ctx = <any>{
|
||||
const ctx = <any>{
|
||||
datasource: {
|
||||
metricFindQuery: jest.fn(() => Promise.resolve([])),
|
||||
getFuncDefs: jest.fn(() => Promise.resolve(gfunc.getFuncDefs('1.0'))),
|
||||
|
||||
Reference in New Issue
Block a user