-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rebased from rizkybiz/circonus-irondb-datasource.git b64-fixes-final #36
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d119a56
Added tslib to resolve some linting issues
3424439
Adding .prettierrc.js because the grafana toolkit implemented it
14de46b
updated gitignore with some IDE linting and testing artifact ignores
41747f3
Adding .eslintrc.json, grafana toolkit now uses eslint instead of tslint
b67d364
resolving cherry-pick conflicts
3e28302
resolving more cherry-pick conflicts
a5316c1
Adding Riley's changes to both tag related lookup functions
cc92282
removing some debug code
4b50ad7
updated changelog
dc7bbb7
adding \n to end of .gitignore at githubs request
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"extends": ["@grafana/eslint-config"], | ||
"parserOptions": { | ||
"tsconfigRootDir": "./" | ||
}, | ||
"rules": { | ||
"strict": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ npm-debug.log | |
.DS_Store | ||
*.swp | ||
package-lock.json | ||
yarn.lock | ||
coverage | ||
jest* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
...require('@grafana/toolkit/src/config/prettier.plugin.config.json'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,26 +7,23 @@ import memoize from 'memoizee'; | |
import { Memoized } from 'memoizee'; | ||
import { | ||
metaInterpolateLabel, | ||
decodeNameAndTags, | ||
isStatsdCounter, | ||
taglessName, | ||
taglessNameAndTags, | ||
decodeTag, | ||
encodeTag, | ||
splitTags, | ||
mergeTags, | ||
TagSet, | ||
decodeTagsInLabel, | ||
SegmentType, | ||
} from './irondb_query'; | ||
|
||
import { | ||
ArrayVector, | ||
DataFrame, | ||
Field, | ||
FieldType, | ||
formatLabels, | ||
Labels, | ||
MutableField, | ||
ScopedVars, | ||
TIME_SERIES_TIME_FIELD_NAME, | ||
TIME_SERIES_VALUE_FIELD_NAME, | ||
DataSourceApi, | ||
|
@@ -39,15 +36,11 @@ import { | |
AnnotationQueryRequest, | ||
AnnotationEvent, | ||
LoadingState, | ||
TimeSeries, | ||
isTableData, | ||
} from '@grafana/data'; | ||
import * as Mustache from 'mustache'; | ||
|
||
const log = Log('IrondbDatasource'); | ||
|
||
import { map } from 'rxjs/operators'; | ||
|
||
const DURATION_UNITS_DEFAULT = 's'; | ||
const DURATION_UNITS = { | ||
ms: 1, | ||
|
@@ -311,7 +304,7 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
options.method = 'GET'; | ||
options.url = options.url + '/alert'; | ||
const alertId = this.templateSrv.replace(query.annotation['alertId']); | ||
const alertQuery = this.templateSrv.replace(query.annotation['annotationQueryText']); | ||
const alertQuery = this.templateSrv.replace(query.annotation['annotationQueryText'], null, this.interpolateExpr); | ||
if (alertId !== '') { | ||
options.url = options.url + '/' + alertId; | ||
} else { | ||
|
@@ -396,7 +389,7 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
let notes = | ||
rule !== undefined && rule !== null && rule['notes'] !== null && rule['notes'] !== '' | ||
? rule['notes'] | ||
: 'Oh no!'; | ||
: ''; | ||
|
||
notes = Mustache.render(notes, tags); | ||
|
||
|
@@ -469,28 +462,23 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
} | ||
|
||
interpolateExpr(value: string | string[] = [], variable: any) { | ||
if (typeof value === 'string') { | ||
value = encodeTag(SegmentType.TagVal, value, false); | ||
} else { | ||
for (let i in value) { | ||
value[i] = encodeTag(SegmentType.TagVal, value[i], false); | ||
} | ||
} | ||
// if no multi or include all do not regexEscape | ||
if (!variable.multi && !variable.includeAll) { | ||
return value; | ||
} | ||
|
||
if (typeof value === 'string') { | ||
return value; | ||
} else { | ||
return value.join(','); | ||
} | ||
|
||
if (value.length === 1) { | ||
return value[0]; | ||
} | ||
|
||
let q = ''; | ||
for (let i = 0; i < value.length; i++) { | ||
if (i > 0) { | ||
q = q + ','; | ||
} | ||
q = q + value[i]; | ||
i = i + 1; | ||
} | ||
return q; | ||
} | ||
|
||
// This is used by the Dashboard Admin Variable Setup function | ||
|
@@ -528,7 +516,7 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
if (tagCat !== '') { | ||
return this.metricFindTagValsQuery(metricQuery, tagCat, from, to).then((results) => { | ||
return _.map(results.data, (result) => { | ||
return { value: result }; | ||
return { value: decodeTag(result) }; | ||
}); | ||
}); | ||
} else { | ||
|
@@ -546,7 +534,7 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
return this.irondbType === 'standalone' ? '/' + this.accountId : ''; | ||
} | ||
|
||
metricTagsQuery(query: string, allowEmptyWildcard = false, from?: number = null, to?: number = null) { | ||
metricTagsQuery(query: string, allowEmptyWildcard = false, from: number = null, to: number = null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might not want or need this change |
||
if (query === '' || query === undefined || (!allowEmptyWildcard && query === 'and(__name:*)')) { | ||
return Promise.resolve({ data: [] }); | ||
} | ||
|
@@ -797,7 +785,8 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
end += interval; | ||
const caqlQuery = this.templateSrv.replace( | ||
irondbOptions['caql']['names'][i].leaf_name, | ||
irondbOptions['scopedVars'] | ||
irondbOptions['scopedVars'], | ||
this.interpolateExpr | ||
); | ||
options.url = options.url + '/caql_v1?format=DF4&start=' + start.toFixed(3); | ||
options.url = options.url + '&end=' + end.toFixed(3); | ||
|
@@ -829,7 +818,11 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
} | ||
options.method = 'GET'; | ||
options.url = options.url + '/alert'; | ||
const alertQuery = this.templateSrv.replace(irondbOptions['alert']['names'][i], irondbOptions['scopedVars']); | ||
const alertQuery = this.templateSrv.replace( | ||
irondbOptions['alert']['names'][i], | ||
irondbOptions['scopedVars'], | ||
this.interpolateExpr | ||
); | ||
if (alertQuery.startsWith('alert_id:')) { | ||
options.url = options.url + '/' + alertQuery.split(':')[1]; | ||
} else { | ||
|
@@ -1328,7 +1321,7 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
} | ||
|
||
buildFetchParamsAsync(cleanOptions, target, start, end) { | ||
const rawQuery = this.templateSrv.replace(target['query'], cleanOptions['scopedVars']); | ||
const rawQuery = this.templateSrv.replace(target['query'], cleanOptions['scopedVars'], this.interpolateExpr); | ||
|
||
return this.metricTagsQuery(rawQuery, false, start, end) | ||
.then((result) => { | ||
|
@@ -1347,13 +1340,13 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
} | ||
|
||
buildAlertQueryAsync(cleanOptions, target, start, end) { | ||
let rawQuery = this.templateSrv.replace(target['query'], cleanOptions['scopedVars']); | ||
let rawQuery = this.templateSrv.replace(target['query'], cleanOptions['scopedVars'], this.interpolateExpr); | ||
if (target['alert_id'] !== '') { | ||
rawQuery = 'alert_id:' + this.templateSrv.replace(target['alert_id'], cleanOptions['scopedVars']); | ||
} | ||
cleanOptions['alert']['names'].push(rawQuery); | ||
cleanOptions['alert']['local_filters'].push( | ||
this.templateSrv.replace(target['local_filter'], cleanOptions['scopedVars']) | ||
this.templateSrv.replace(target['local_filter'], cleanOptions['scopedVars'], this.interpolateExpr) | ||
); | ||
cleanOptions['alert']['local_filter_matches'].push(target['local_filter_match']); | ||
cleanOptions['alert']['counts_only'] = target.querytype === 'alert_counts'; | ||
|
@@ -1637,7 +1630,13 @@ export default class IrondbDatasource extends DataSourceApi<IrondbQueryInterface | |
vstr = v.toString(); | ||
const tsstr = ts.toString(); | ||
if (_.isUndefined(lookaside[vstr])) { | ||
lookaside[vstr] = { target: vstr, title: vstr, tags: labels, datapoints: [], _ts: {} }; | ||
lookaside[vstr] = { | ||
target: vstr, | ||
title: vstr, | ||
tags: labels, | ||
datapoints: [], | ||
_ts: {}, | ||
}; | ||
dataFrames.push(lookaside[vstr]); | ||
} | ||
if (_.isUndefined(lookaside[vstr]._ts[tsstr])) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is just replacing a longhand form of
value.join(',')