Updated rules for variable name (#13106)

* updated rules for variable name and fixed files that didn't follow new rules

* fixed test so it uses new rule

* made exceptions to rule in interval_variable
This commit is contained in:
Patrick O'Carroll
2018-09-03 11:00:46 +02:00
committed by Torkel Ödegaard
parent 0d25aa08fa
commit 7837ee4466
26 changed files with 246 additions and 239 deletions

View File

@@ -57,9 +57,9 @@ export class ElasticDatasource {
private get(url) {
const range = this.timeSrv.timeRange();
const index_list = this.indexPattern.getIndexList(range.from.valueOf(), range.to.valueOf());
if (_.isArray(index_list) && index_list.length) {
return this.request('GET', index_list[0] + url).then(function(results) {
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) {
results.data.$$config = results.config;
return results.data;
});
@@ -229,15 +229,15 @@ export class ElasticDatasource {
}
getQueryHeader(searchType, timeFrom, timeTo) {
const query_header: any = {
const queryHeader: any = {
search_type: searchType,
ignore_unavailable: true,
index: this.indexPattern.getIndexList(timeFrom, timeTo),
};
if (this.esVersion >= 56) {
query_header['max_concurrent_shard_requests'] = this.maxConcurrentShardRequests;
queryHeader['max_concurrent_shard_requests'] = this.maxConcurrentShardRequests;
}
return angular.toJson(query_header);
return angular.toJson(queryHeader);
}
query(options) {

View File

@@ -67,8 +67,8 @@ export class ElasticMetricAggCtrl {
}
switch ($scope.agg.type) {
case 'cardinality': {
const precision_threshold = $scope.agg.settings.precision_threshold || '';
$scope.settingsLinkText = 'Precision threshold: ' + precision_threshold;
const precisionThreshold = $scope.agg.settings.precision_threshold || '';
$scope.settingsLinkText = 'Precision threshold: ' + precisionThreshold;
break;
}
case 'percentiles': {

View File

@@ -19,12 +19,12 @@ describe('ElasticQueryBuilder', () => {
});
it('with defaults on es5.x', () => {
const builder_5x = new ElasticQueryBuilder({
const builder5x = new ElasticQueryBuilder({
timeField: '@timestamp',
esVersion: 5,
});
const query = builder_5x.build({
const query = builder5x.build({
metrics: [{ type: 'Count', id: '0' }],
timeField: '@timestamp',
bucketAggs: [{ type: 'date_histogram', field: '@timestamp', id: '1' }],
@@ -134,11 +134,11 @@ describe('ElasticQueryBuilder', () => {
});
it('with filters aggs on es5.x', () => {
const builder_5x = new ElasticQueryBuilder({
const builder5x = new ElasticQueryBuilder({
timeField: '@timestamp',
esVersion: 5,
});
const query = builder_5x.build({
const query = builder5x.build({
metrics: [{ type: 'count', id: '1' }],
timeField: '@timestamp',
bucketAggs: [

View File

@@ -490,8 +490,8 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
this._seriesRefLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
this.buildGraphiteParams = function(options, scopedVars) {
const graphite_options = ['from', 'until', 'rawData', 'format', 'maxDataPoints', 'cacheTimeout'];
const clean_options = [],
const graphiteOptions = ['from', 'until', 'rawData', 'format', 'maxDataPoints', 'cacheTimeout'];
const cleanOptions = [],
targets = {};
let target, targetValue, i;
const regex = /\#([A-Z])/g;
@@ -535,16 +535,16 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
if (!target.hide) {
hasTargets = true;
clean_options.push('target=' + encodeURIComponent(targetValue));
cleanOptions.push('target=' + encodeURIComponent(targetValue));
}
}
_.each(options, function(value, key) {
if (_.indexOf(graphite_options, key) === -1) {
if (_.indexOf(graphiteOptions, key) === -1) {
return;
}
if (value) {
clean_options.push(key + '=' + encodeURIComponent(value));
cleanOptions.push(key + '=' + encodeURIComponent(value));
}
});
@@ -552,7 +552,7 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
return [];
}
return clean_options;
return cleanOptions;
};
}

View File

@@ -277,35 +277,35 @@ export default class OpenTsDatasource {
});
};
const metrics_regex = /metrics\((.*)\)/;
const tag_names_regex = /tag_names\((.*)\)/;
const tag_values_regex = /tag_values\((.*?),\s?(.*)\)/;
const tag_names_suggest_regex = /suggest_tagk\((.*)\)/;
const tag_values_suggest_regex = /suggest_tagv\((.*)\)/;
const metricsRegex = /metrics\((.*)\)/;
const tagNamesRegex = /tag_names\((.*)\)/;
const tagValuesRegex = /tag_values\((.*?),\s?(.*)\)/;
const tagNamesSuggestRegex = /suggest_tagk\((.*)\)/;
const tagValuesSuggestRegex = /suggest_tagv\((.*)\)/;
const metrics_query = interpolated.match(metrics_regex);
if (metrics_query) {
return this._performSuggestQuery(metrics_query[1], 'metrics').then(responseTransform);
const metricsQuery = interpolated.match(metricsRegex);
if (metricsQuery) {
return this._performSuggestQuery(metricsQuery[1], 'metrics').then(responseTransform);
}
const tag_names_query = interpolated.match(tag_names_regex);
if (tag_names_query) {
return this._performMetricKeyLookup(tag_names_query[1]).then(responseTransform);
const tagNamesQuery = interpolated.match(tagNamesRegex);
if (tagNamesQuery) {
return this._performMetricKeyLookup(tagNamesQuery[1]).then(responseTransform);
}
const tag_values_query = interpolated.match(tag_values_regex);
if (tag_values_query) {
return this._performMetricKeyValueLookup(tag_values_query[1], tag_values_query[2]).then(responseTransform);
const tagValuesQuery = interpolated.match(tagValuesRegex);
if (tagValuesQuery) {
return this._performMetricKeyValueLookup(tagValuesQuery[1], tagValuesQuery[2]).then(responseTransform);
}
const tag_names_suggest_query = interpolated.match(tag_names_suggest_regex);
if (tag_names_suggest_query) {
return this._performSuggestQuery(tag_names_suggest_query[1], 'tagk').then(responseTransform);
const tagNamesSuggestQuery = interpolated.match(tagNamesSuggestRegex);
if (tagNamesSuggestQuery) {
return this._performSuggestQuery(tagNamesSuggestQuery[1], 'tagk').then(responseTransform);
}
const tag_values_suggest_query = interpolated.match(tag_values_suggest_regex);
if (tag_values_suggest_query) {
return this._performSuggestQuery(tag_values_suggest_query[1], 'tagv').then(responseTransform);
const tagValuesSuggestQuery = interpolated.match(tagValuesSuggestRegex);
if (tagValuesSuggestQuery) {
return this._performSuggestQuery(tagValuesSuggestQuery[1], 'tagv').then(responseTransform);
}
return this.$q.when([]);
@@ -440,9 +440,9 @@ export default class OpenTsDatasource {
if (target.filters && target.filters.length > 0) {
query.filters = angular.copy(target.filters);
if (query.filters) {
for (const filter_key in query.filters) {
query.filters[filter_key].filter = this.templateSrv.replace(
query.filters[filter_key].filter,
for (const filterKey in query.filters) {
query.filters[filterKey].filter = this.templateSrv.replace(
query.filters[filterKey].filter,
options.scopedVars,
'pipe'
);
@@ -451,8 +451,8 @@ export default class OpenTsDatasource {
} else {
query.tags = angular.copy(target.tags);
if (query.tags) {
for (const tag_key in query.tags) {
query.tags[tag_key] = this.templateSrv.replace(query.tags[tag_key], options.scopedVars, 'pipe');
for (const tagKey in query.tags) {
query.tags[tagKey] = this.templateSrv.replace(query.tags[tagKey], options.scopedVars, 'pipe');
}
}
}

View File

@@ -12,27 +12,27 @@ export default class PrometheusMetricFindQuery {
}
process() {
const label_values_regex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]+)\)\s*$/;
const metric_names_regex = /^metrics\((.+)\)\s*$/;
const query_result_regex = /^query_result\((.+)\)\s*$/;
const labelValuesRegex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]+)\)\s*$/;
const metricNamesRegex = /^metrics\((.+)\)\s*$/;
const queryResultRegex = /^query_result\((.+)\)\s*$/;
const label_values_query = this.query.match(label_values_regex);
if (label_values_query) {
if (label_values_query[1]) {
return this.labelValuesQuery(label_values_query[2], label_values_query[1]);
const labelValuesQuery = this.query.match(labelValuesRegex);
if (labelValuesQuery) {
if (labelValuesQuery[1]) {
return this.labelValuesQuery(labelValuesQuery[2], labelValuesQuery[1]);
} else {
return this.labelValuesQuery(label_values_query[2], null);
return this.labelValuesQuery(labelValuesQuery[2], null);
}
}
const metric_names_query = this.query.match(metric_names_regex);
if (metric_names_query) {
return this.metricNameQuery(metric_names_query[1]);
const metricNamesQuery = this.query.match(metricNamesRegex);
if (metricNamesQuery) {
return this.metricNameQuery(metricNamesQuery[1]);
}
const query_result_query = this.query.match(query_result_regex);
if (query_result_query) {
return this.queryResultQuery(query_result_query[1]);
const queryResultQuery = this.query.match(queryResultRegex);
if (queryResultQuery) {
return this.queryResultQuery(queryResultQuery[1]);
}
// if query contains full metric name, return metric name and label list

View File

@@ -45,9 +45,9 @@ export class ResultTransformer {
}
for (const value of metricData.values) {
let dp_value = parseFloat(value[1]);
if (_.isNaN(dp_value)) {
dp_value = null;
let dpValue = parseFloat(value[1]);
if (_.isNaN(dpValue)) {
dpValue = null;
}
const timestamp = parseFloat(value[0]) * 1000;
@@ -55,7 +55,7 @@ export class ResultTransformer {
dps.push([null, t]);
}
baseTimestamp = timestamp + stepMs;
dps.push([dp_value, timestamp]);
dps.push([dpValue, timestamp]);
}
const endTimestamp = end * 1000;