Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
418dba4b
Commit
418dba4b
authored
Jul 05, 2019
by
Tobias Skarhed
Committed by
Torkel Ödegaard
Jul 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
noImplicitAnys: Fix InfluxDB type issues #17937)
parent
de71875e
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
126 additions
and
98 deletions
+126
-98
public/app/plugins/datasource/graphite/specs/query_ctrl.test.ts
+3
-1
public/app/plugins/datasource/influxdb/components/InfluxLogsQueryField.tsx
+7
-5
public/app/plugins/datasource/influxdb/datasource.ts
+14
-14
public/app/plugins/datasource/influxdb/influx_query_model.ts
+13
-11
public/app/plugins/datasource/influxdb/influx_series.ts
+11
-11
public/app/plugins/datasource/influxdb/query_builder.ts
+2
-2
public/app/plugins/datasource/influxdb/query_ctrl.ts
+23
-16
public/app/plugins/datasource/influxdb/query_part.ts
+11
-11
public/app/plugins/datasource/influxdb/response_parser.ts
+2
-2
public/app/plugins/datasource/influxdb/specs/datasource.test.ts
+10
-7
public/app/plugins/datasource/influxdb/specs/influx_query_model.test.ts
+1
-1
public/app/plugins/datasource/influxdb/specs/query_ctrl.test.ts
+5
-4
public/app/plugins/datasource/mssql/config_ctrl.ts
+1
-1
public/app/plugins/datasource/mssql/datasource.ts
+19
-9
public/app/plugins/datasource/mssql/query_ctrl.ts
+4
-3
No files found.
public/app/plugins/datasource/graphite/specs/query_ctrl.test.ts
View file @
418dba4b
...
...
@@ -30,7 +30,9 @@ describe('GraphiteQueryCtrl', () => {
ctx
.
ctrl
=
new
GraphiteQueryCtrl
(
{},
{},
//@ts-ignore
new
uiSegmentSrv
({
trustAsHtml
:
html
=>
html
},
{
highlightVariablesAsHtml
:
()
=>
{}
}),
//@ts-ignore
new
TemplateSrvStub
(),
{}
);
...
...
@@ -121,7 +123,7 @@ describe('GraphiteQueryCtrl', () => {
ctx
.
ctrl
.
target
.
target
=
'test.count'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([]);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
getAltSegments
(
1
).
then
(
results
=>
{
ctx
.
ctrl
.
getAltSegments
(
1
).
then
(
(
results
:
any
)
=>
{
ctx
.
altSegments
=
results
;
});
});
...
...
public/app/plugins/datasource/influxdb/components/InfluxLogsQueryField.tsx
View file @
418dba4b
...
...
@@ -48,11 +48,13 @@ export class InfluxLogsQueryField extends React.PureComponent<Props, State> {
const
queryBuilder
=
new
InfluxQueryBuilder
({
measurement
:
measurementObj
.
text
,
tags
:
[]
},
datasource
.
database
);
const
fieldsQuery
=
queryBuilder
.
buildExploreQuery
(
'FIELDS'
);
const
influxFields
=
await
datasource
.
metricFindQuery
(
fieldsQuery
);
const
fields
=
influxFields
.
map
((
field
:
any
)
=>
({
label
:
field
.
text
,
value
:
field
.
text
,
children
:
[],
}));
const
fields
:
any
[]
=
influxFields
.
map
(
(
field
:
any
):
any
=>
({
label
:
field
.
text
,
value
:
field
.
text
,
children
:
[],
})
);
measurements
.
push
({
label
:
measurementObj
.
text
,
value
:
measurementObj
.
text
,
...
...
public/app/plugins/datasource/influxdb/datasource.ts
View file @
418dba4b
...
...
@@ -49,12 +49,12 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
this
.
responseParser
=
new
ResponseParser
();
}
query
(
options
)
{
query
(
options
:
any
)
{
let
timeFilter
=
this
.
getTimeFilter
(
options
);
const
scopedVars
=
options
.
scopedVars
;
const
targets
=
_
.
cloneDeep
(
options
.
targets
);
const
queryTargets
=
[];
let
queryModel
;
const
queryTargets
:
any
[]
=
[];
let
queryModel
:
InfluxQueryModel
;
let
i
,
y
;
let
allQueries
=
_
.
map
(
targets
,
target
=>
{
...
...
@@ -93,7 +93,7 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
allQueries
=
this
.
templateSrv
.
replace
(
allQueries
,
scopedVars
);
return
this
.
_seriesQuery
(
allQueries
,
options
).
then
(
(
data
):
any
=>
{
(
data
:
any
):
any
=>
{
if
(
!
data
||
!
data
.
results
)
{
return
[];
}
...
...
@@ -136,7 +136,7 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
);
}
annotationQuery
(
options
)
{
annotationQuery
(
options
:
any
)
{
if
(
!
options
.
annotation
.
query
)
{
return
this
.
$q
.
reject
({
message
:
'Query missing in annotation definition'
,
...
...
@@ -147,7 +147,7 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
let
query
=
options
.
annotation
.
query
.
replace
(
'$timeFilter'
,
timeFilter
);
query
=
this
.
templateSrv
.
replace
(
query
,
null
,
'regex'
);
return
this
.
_seriesQuery
(
query
,
options
).
then
(
data
=>
{
return
this
.
_seriesQuery
(
query
,
options
).
then
(
(
data
:
any
)
=>
{
if
(
!
data
||
!
data
.
results
||
!
data
.
results
[
0
])
{
throw
{
message
:
'No results in response from InfluxDB'
};
}
...
...
@@ -158,7 +158,7 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
});
}
targetContainsTemplate
(
target
)
{
targetContainsTemplate
(
target
:
any
)
{
for
(
const
group
of
target
.
groupBy
)
{
for
(
const
param
of
group
.
params
)
{
if
(
this
.
templateSrv
.
variableExists
(
param
))
{
...
...
@@ -207,7 +207,7 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
return
this
.
_influxRequest
(
this
.
httpMode
,
'/query'
,
{
q
:
query
,
epoch
:
'ms'
},
options
);
}
serializeParams
(
params
)
{
serializeParams
(
params
:
any
)
{
if
(
!
params
)
{
return
''
;
}
...
...
@@ -230,14 +230,14 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
const
query
=
queryBuilder
.
buildExploreQuery
(
'RETENTION POLICIES'
);
return
this
.
_seriesQuery
(
query
)
.
then
(
res
=>
{
.
then
(
(
res
:
any
)
=>
{
const
error
=
_
.
get
(
res
,
'results[0].error'
);
if
(
error
)
{
return
{
status
:
'error'
,
message
:
error
};
}
return
{
status
:
'success'
,
message
:
'Data source is working'
};
})
.
catch
(
err
=>
{
.
catch
(
(
err
:
any
)
=>
{
return
{
status
:
'error'
,
message
:
err
.
message
};
});
}
...
...
@@ -292,10 +292,10 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
}
return
this
.
backendSrv
.
datasourceRequest
(
req
).
then
(
result
=>
{
(
result
:
any
)
=>
{
return
result
.
data
;
},
err
=>
{
(
err
:
any
)
=>
{
if
(
err
.
status
!==
0
||
err
.
status
>=
300
)
{
if
(
err
.
data
&&
err
.
data
.
error
)
{
throw
{
...
...
@@ -315,7 +315,7 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
);
}
getTimeFilter
(
options
)
{
getTimeFilter
(
options
:
any
)
{
const
from
=
this
.
getInfluxTime
(
options
.
rangeRaw
.
from
,
false
,
options
.
timezone
);
const
until
=
this
.
getInfluxTime
(
options
.
rangeRaw
.
to
,
true
,
options
.
timezone
);
const
fromIsAbsolute
=
from
[
from
.
length
-
1
]
===
'ms'
;
...
...
@@ -327,7 +327,7 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
return
'time >= '
+
from
+
' and time <= '
+
until
;
}
getInfluxTime
(
date
,
roundUp
,
timezone
)
{
getInfluxTime
(
date
:
any
,
roundUp
:
any
,
timezone
:
any
)
{
if
(
_
.
isString
(
date
))
{
if
(
date
===
'now'
)
{
return
'now()'
;
...
...
public/app/plugins/datasource/influxdb/influx_query_model.ts
View file @
418dba4b
import
_
from
'lodash'
;
import
queryPart
from
'./query_part'
;
import
kbn
from
'app/core/utils/kbn'
;
import
{
InfluxQuery
}
from
'./types'
;
import
{
InfluxQuery
,
InfluxQueryTag
}
from
'./types'
;
import
{
ScopedVars
}
from
'@grafana/ui'
;
import
{
TemplateSrv
}
from
'app/features/templating/template_srv'
;
export
default
class
InfluxQueryModel
{
target
:
InfluxQuery
;
...
...
@@ -13,7 +15,7 @@ export default class InfluxQueryModel {
refId
:
string
;
/** @ngInject */
constructor
(
target
:
InfluxQuery
,
templateSrv
?
,
scopedVars
?
)
{
constructor
(
target
:
InfluxQuery
,
templateSrv
?
:
TemplateSrv
,
scopedVars
?:
ScopedVars
)
{
this
.
target
=
target
;
this
.
templateSrv
=
templateSrv
;
this
.
scopedVars
=
scopedVars
;
...
...
@@ -51,7 +53,7 @@ export default class InfluxQueryModel {
return
_
.
find
(
this
.
target
.
groupBy
,
(
g
:
any
)
=>
g
.
type
===
'fill'
);
}
addGroupBy
(
value
)
{
addGroupBy
(
value
:
string
)
{
const
stringParts
=
value
.
match
(
/^
(\w
+
)\((
.*
)\)
$/
);
const
typePart
=
stringParts
[
1
];
const
arg
=
stringParts
[
2
];
...
...
@@ -75,7 +77,7 @@ export default class InfluxQueryModel {
this
.
updateProjection
();
}
removeGroupByPart
(
part
,
index
)
{
removeGroupByPart
(
part
:
{
def
:
{
type
:
string
}
},
index
:
number
)
{
const
categories
=
queryPart
.
getCategories
();
if
(
part
.
def
.
type
===
'time'
)
{
...
...
@@ -105,7 +107,7 @@ export default class InfluxQueryModel {
this
.
updateProjection
();
}
removeSelectPart
(
selectParts
,
part
)
{
removeSelectPart
(
selectParts
:
any
[],
part
:
any
)
{
// if we remove the field remove the whole statement
if
(
part
.
def
.
type
===
'field'
)
{
if
(
this
.
selectModels
.
length
>
1
)
{
...
...
@@ -120,13 +122,13 @@ export default class InfluxQueryModel {
this
.
updatePersistedParts
();
}
addSelectPart
(
selectParts
,
type
)
{
addSelectPart
(
selectParts
:
any
[],
type
:
string
)
{
const
partModel
=
queryPart
.
create
({
type
:
type
});
partModel
.
def
.
addStrategy
(
selectParts
,
partModel
,
this
);
this
.
updatePersistedParts
();
}
private
renderTagCondition
(
tag
,
index
,
interpolate
)
{
private
renderTagCondition
(
tag
:
InfluxQueryTag
,
index
:
number
,
interpolate
:
boolean
)
{
let
str
=
''
;
let
operator
=
tag
.
operator
;
let
value
=
tag
.
value
;
...
...
@@ -157,7 +159,7 @@ export default class InfluxQueryModel {
return str + '"
' + tag.key + '
" ' + operator + ' ' + value;
}
getMeasurementAndPolicy(interpolate) {
getMeasurementAndPolicy(interpolate
: any
) {
let policy = this.target.policy;
let measurement = this.target.measurement || 'measurement';
...
...
@@ -176,7 +178,7 @@ export default class InfluxQueryModel {
return policy + measurement;
}
interpolateQueryStr(value
, variable, defaultFormatFn
) {
interpolateQueryStr(value
: any[], variable: { multi: any; includeAll: any }, defaultFormatFn: any
) {
// if no multi or include all do not regexEscape
if (!variable.multi && !variable.includeAll) {
return value;
...
...
@@ -190,7 +192,7 @@ export default class InfluxQueryModel {
return '(' + escapedValues.join('|') + ')';
}
render(interpolate?) {
render(interpolate?
: boolean
) {
const target = this.target;
if (target.rawQuery) {
...
...
@@ -265,7 +267,7 @@ export default class InfluxQueryModel {
return query;
}
renderAdhocFilters(filters) {
renderAdhocFilters(filters
: any[]
) {
const conditions = _.map(filters, (tag, index) => {
return this.renderTagCondition(tag, index, false);
});
...
...
public/app/plugins/datasource/influxdb/influx_series.ts
View file @
418dba4b
...
...
@@ -7,14 +7,14 @@ export default class InfluxSeries {
alias
:
any
;
annotation
:
any
;
constructor
(
options
)
{
constructor
(
options
:
{
series
:
any
;
alias
?:
any
;
annotation
?:
any
}
)
{
this
.
series
=
options
.
series
;
this
.
alias
=
options
.
alias
;
this
.
annotation
=
options
.
annotation
;
}
getTimeSeries
()
{
const
output
=
[];
const
output
:
any
[]
=
[];
let
i
,
j
;
if
(
this
.
series
.
length
===
0
)
{
...
...
@@ -54,11 +54,11 @@ export default class InfluxSeries {
return
output
;
}
_getSeriesName
(
series
,
index
)
{
_getSeriesName
(
series
:
any
,
index
:
number
)
{
const
regex
=
/
\$(\w
+
)
|
\[\[([\s\S]
+
?)\]\]
/g
;
const
segments
=
series
.
name
.
split
(
'.'
);
return
this
.
alias
.
replace
(
regex
,
(
match
,
g1
,
g2
)
=>
{
return
this
.
alias
.
replace
(
regex
,
(
match
:
any
,
g1
:
any
,
g2
:
any
)
=>
{
const
group
=
g1
||
g2
;
const
segIndex
=
parseInt
(
group
,
10
);
...
...
@@ -84,13 +84,13 @@ export default class InfluxSeries {
}
getAnnotations
()
{
const
list
=
[];
const
list
:
any
[]
=
[];
_
.
each
(
this
.
series
,
series
=>
{
let
titleCol
=
null
;
let
timeCol
=
null
;
const
tagsCol
=
[];
let
textCol
=
null
;
let
titleCol
:
any
=
null
;
let
timeCol
:
any
=
null
;
const
tagsCol
:
any
=
[];
let
textCol
:
any
=
null
;
_
.
each
(
series
.
columns
,
(
column
,
index
)
=>
{
if
(
column
===
'time'
)
{
...
...
@@ -126,10 +126,10 @@ export default class InfluxSeries {
// Remove empty values, then split in different tags for comma separated values
tags
:
_
.
flatten
(
tagsCol
.
filter
(
t
=>
{
.
filter
(
(
t
:
any
)
=>
{
return
value
[
t
];
})
.
map
(
t
=>
{
.
map
(
(
t
:
any
)
=>
{
return
value
[
t
].
split
(
','
);
})
),
...
...
public/app/plugins/datasource/influxdb/query_builder.ts
View file @
418dba4b
import
_
from
'lodash'
;
import
kbn
from
'app/core/utils/kbn'
;
function
renderTagCondition
(
tag
,
index
)
{
function
renderTagCondition
(
tag
:
{
operator
:
any
;
value
:
string
;
condition
:
any
;
key
:
string
},
index
:
number
)
{
let
str
=
''
;
let
operator
=
tag
.
operator
;
let
value
=
tag
.
value
;
...
...
@@ -26,7 +26,7 @@ function renderTagCondition(tag, index) {
}
export
class
InfluxQueryBuilder
{
constructor
(
private
target
,
private
database
?
)
{}
constructor
(
private
target
:
{
measurement
:
any
;
tags
:
any
;
policy
?:
any
},
private
database
?:
string
)
{}
buildExploreQuery
(
type
:
string
,
withKey
?:
string
,
withMeasurementFilter
?:
string
)
{
let
query
;
...
...
public/app/plugins/datasource/influxdb/query_ctrl.ts
View file @
418dba4b
import
angular
from
'angular'
;
import
angular
,
{
auto
,
IQService
}
from
'angular'
;
import
_
from
'lodash'
;
import
{
InfluxQueryBuilder
}
from
'./query_builder'
;
import
InfluxQueryModel
from
'./influx_query_model'
;
import
queryPart
from
'./query_part'
;
import
{
QueryCtrl
}
from
'app/plugins/sdk'
;
import
{
TemplateSrv
}
from
'app/features/templating/template_srv'
;
export
class
InfluxQueryCtrl
extends
QueryCtrl
{
static
templateUrl
=
'partials/query.editor.html'
;
...
...
@@ -20,7 +21,13 @@ export class InfluxQueryCtrl extends QueryCtrl {
removeTagFilterSegment
:
any
;
/** @ngInject */
constructor
(
$scope
,
$injector
,
private
templateSrv
,
private
$q
,
private
uiSegmentSrv
)
{
constructor
(
$scope
:
any
,
$injector
:
auto
.
IInjectorService
,
private
templateSrv
:
TemplateSrv
,
private
$q
:
IQService
,
private
uiSegmentSrv
:
any
)
{
super
(
$scope
,
$injector
);
this
.
target
=
this
.
target
;
this
.
queryModel
=
new
InfluxQueryModel
(
this
.
target
,
templateSrv
,
this
.
panel
.
scopedVars
);
...
...
@@ -73,7 +80,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
(
memo
,
cat
,
key
)
=>
{
const
menu
=
{
text
:
key
,
submenu
:
cat
.
map
(
item
=>
{
submenu
:
cat
.
map
(
(
item
:
any
)
=>
{
return
{
text
:
item
.
type
,
value
:
item
.
type
};
}),
};
...
...
@@ -89,7 +96,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
return
this
.
datasource
.
metricFindQuery
(
query
)
.
then
(
tags
=>
{
.
then
(
(
tags
:
any
)
=>
{
const
options
=
[];
if
(
!
this
.
queryModel
.
hasFill
())
{
options
.
push
(
this
.
uiSegmentSrv
.
newSegment
({
value
:
'fill(null)'
}));
...
...
@@ -146,12 +153,12 @@ export class InfluxQueryCtrl extends QueryCtrl {
this
.
panelCtrl
.
refresh
();
}
addSelectPart
(
selectParts
,
cat
,
subitem
)
{
addSelectPart
(
selectParts
:
any
,
cat
:
any
,
subitem
:
{
value
:
any
}
)
{
this
.
queryModel
.
addSelectPart
(
selectParts
,
subitem
.
value
);
this
.
panelCtrl
.
refresh
();
}
handleSelectPartEvent
(
selectParts
,
part
,
evt
)
{
handleSelectPartEvent
(
selectParts
:
any
,
part
:
any
,
evt
:
{
name
:
any
}
)
{
switch
(
evt
.
name
)
{
case
'get-param-options'
:
{
const
fieldsQuery
=
this
.
queryBuilder
.
buildExploreQuery
(
'FIELDS'
);
...
...
@@ -175,7 +182,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
}
}
handleGroupByPartEvent
(
part
,
index
,
evt
)
{
handleGroupByPartEvent
(
part
:
any
,
index
:
any
,
evt
:
{
name
:
any
}
)
{
switch
(
evt
.
name
)
{
case
'get-param-options'
:
{
const
tagsQuery
=
this
.
queryBuilder
.
buildExploreQuery
(
'TAG_KEYS'
);
...
...
@@ -235,7 +242,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
this
.
target
.
rawQuery
=
!
this
.
target
.
rawQuery
;
}
getMeasurements
(
measurementFilter
)
{
getMeasurements
(
measurementFilter
:
any
)
{
const
query
=
this
.
queryBuilder
.
buildExploreQuery
(
'MEASUREMENTS'
,
undefined
,
measurementFilter
);
return
this
.
datasource
.
metricFindQuery
(
query
)
...
...
@@ -243,13 +250,13 @@ export class InfluxQueryCtrl extends QueryCtrl {
.
catch
(
this
.
handleQueryError
.
bind
(
this
));
}
handleQueryError
(
err
)
{
handleQueryError
(
err
:
any
):
any
[]
{
this
.
error
=
err
.
message
||
'Failed to issue metric query'
;
return
[];
}
transformToSegments
(
addTemplateVars
)
{
return
results
=>
{
transformToSegments
(
addTemplateVars
:
any
)
{
return
(
results
:
any
)
=>
{
const
segments
=
_
.
map
(
results
,
segment
=>
{
return
this
.
uiSegmentSrv
.
newSegment
({
value
:
segment
.
text
,
...
...
@@ -273,7 +280,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
};
}
getTagsOrValues
(
segment
,
index
)
{
getTagsOrValues
(
segment
:
{
type
:
string
},
index
:
number
)
{
if
(
segment
.
type
===
'condition'
)
{
return
this
.
$q
.
when
([
this
.
uiSegmentSrv
.
newSegment
(
'AND'
),
this
.
uiSegmentSrv
.
newSegment
(
'OR'
)]);
}
...
...
@@ -298,7 +305,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
return
this
.
datasource
.
metricFindQuery
(
query
)
.
then
(
this
.
transformToSegments
(
addTemplateVars
))
.
then
(
results
=>
{
.
then
(
(
results
:
any
)
=>
{
if
(
segment
.
type
===
'key'
)
{
results
.
splice
(
0
,
0
,
angular
.
copy
(
this
.
removeTagFilterSegment
));
}
...
...
@@ -315,7 +322,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
.
catch
(
this
.
handleQueryError
);
}
tagSegmentUpdated
(
segment
,
index
)
{
tagSegmentUpdated
(
segment
:
{
value
:
any
;
type
:
string
;
cssClass
:
string
},
index
:
number
)
{
this
.
tagSegments
[
index
]
=
segment
;
// handle remove tag condition
...
...
@@ -349,7 +356,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
}
rebuildTargetTagConditions
()
{
const
tags
=
[];
const
tags
:
any
[]
=
[];
let
tagIndex
=
0
;
let
tagOperator
=
''
;
...
...
@@ -378,7 +385,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
this
.
panelCtrl
.
refresh
();
}
getTagValueOperator
(
tagValue
,
tagOperator
):
string
{
getTagValueOperator
(
tagValue
:
string
,
tagOperator
:
string
):
string
{
if
(
tagOperator
!==
'=~'
&&
tagOperator
!==
'!~'
&&
/^
\/
.*
\/
$/
.
test
(
tagValue
))
{
return
'=~'
;
}
else
if
((
tagOperator
===
'=~'
||
tagOperator
===
'!~'
)
&&
/^
(?!\/
.*
\/
$
)
/
.
test
(
tagValue
))
{
...
...
public/app/plugins/datasource/influxdb/query_part.ts
View file @
418dba4b
import
_
from
'lodash'
;
import
{
QueryPartDef
,
QueryPart
,
functionRenderer
,
suffixRenderer
}
from
'app/core/components/query_part/query_part'
;
const
index
=
[];
const
categories
=
{
const
index
:
any
[]
=
[];
const
categories
:
any
=
{
Aggregations
:
[],
Selectors
:
[],
Transformations
:
[],
...
...
@@ -12,7 +12,7 @@ const categories = {
Fields
:
[],
};
function
createPart
(
part
):
any
{
function
createPart
(
part
:
any
):
any
{
const
def
=
index
[
part
.
type
];
if
(
!
def
)
{
throw
{
message
:
'Could not find query part '
+
part
.
type
};
...
...
@@ -26,20 +26,20 @@ function register(options: any) {
options
.
category
.
push
(
index
[
options
.
type
]);
}
const
groupByTimeFunctions
=
[];
const
groupByTimeFunctions
:
any
[]
=
[];
function
aliasRenderer
(
part
,
innerExpr
)
{
function
aliasRenderer
(
part
:
{
params
:
string
[]
},
innerExpr
:
string
)
{
return
innerExpr
+
' AS '
+
'"'
+
part
.
params
[
0
]
+
'"'
;
}
function
fieldRenderer
(
part
,
innerExpr
)
{
function
fieldRenderer
(
part
:
{
params
:
string
[]
},
innerExpr
:
any
)
{
if
(
part
.
params
[
0
]
===
'*'
)
{
return
'*'
;
}
return
'"'
+
part
.
params
[
0
]
+
'"'
;
}
function
replaceAggregationAddStrategy
(
selectParts
,
partModel
)
{
function
replaceAggregationAddStrategy
(
selectParts
:
any
[],
partModel
:
{
def
:
{
type
:
string
}
}
)
{
// look for existing aggregation
for
(
let
i
=
0
;
i
<
selectParts
.
length
;
i
++
)
{
const
part
=
selectParts
[
i
];
...
...
@@ -78,7 +78,7 @@ function replaceAggregationAddStrategy(selectParts, partModel) {
selectParts
.
splice
(
1
,
0
,
partModel
);
}
function
addTransformationStrategy
(
selectParts
,
partModel
)
{
function
addTransformationStrategy
(
selectParts
:
any
[],
partModel
:
any
)
{
let
i
;
// look for index to add transformation
for
(
i
=
0
;
i
<
selectParts
.
length
;
i
++
)
{
...
...
@@ -91,7 +91,7 @@ function addTransformationStrategy(selectParts, partModel) {
selectParts
.
splice
(
i
,
0
,
partModel
);
}
function
addMathStrategy
(
selectParts
,
partModel
)
{
function
addMathStrategy
(
selectParts
:
any
[],
partModel
:
any
)
{
const
partCount
=
selectParts
.
length
;
if
(
partCount
>
0
)
{
// if last is math, replace it
...
...
@@ -112,7 +112,7 @@ function addMathStrategy(selectParts, partModel) {
selectParts
.
push
(
partModel
);
}
function
addAliasStrategy
(
selectParts
,
partModel
)
{
function
addAliasStrategy
(
selectParts
:
any
[],
partModel
:
any
)
{
const
partCount
=
selectParts
.
length
;
if
(
partCount
>
0
)
{
// if last is alias, replace it
...
...
@@ -124,7 +124,7 @@ function addAliasStrategy(selectParts, partModel) {
selectParts
.
push
(
partModel
);
}
function
addFieldStrategy
(
selectParts
,
partModel
,
query
)
{
function
addFieldStrategy
(
selectParts
:
any
,
partModel
:
any
,
query
:
{
selectModels
:
any
[][]
}
)
{
// copy all parts
const
parts
=
_
.
map
(
selectParts
,
(
part
:
any
)
=>
{
return
createPart
({
type
:
part
.
def
.
type
,
params
:
_
.
clone
(
part
.
params
)
});
...
...
public/app/plugins/datasource/influxdb/response_parser.ts
View file @
418dba4b
import
_
from
'lodash'
;
export
default
class
ResponseParser
{
parse
(
query
,
results
)
{
parse
(
query
:
string
,
results
:
{
results
:
any
}
)
{
if
(
!
results
||
results
.
results
.
length
===
0
)
{
return
[];
}
...
...
@@ -52,6 +52,6 @@ export default class ResponseParser {
}
}
function
addUnique
(
arr
,
value
)
{
function
addUnique
(
arr
:
{
[
x
:
string
]:
any
},
value
:
string
|
number
)
{
arr
[
value
]
=
value
;
}
public/app/plugins/datasource/influxdb/specs/datasource.test.ts
View file @
418dba4b
import
InfluxDatasource
from
'../datasource'
;
//@ts-ignore
import
$q
from
'q'
;
import
{
TemplateSrvStub
}
from
'test/specs/helpers'
;
...
...
@@ -6,6 +7,7 @@ describe('InfluxDataSource', () => {
const
ctx
:
any
=
{
backendSrv
:
{},
$q
:
$q
,
//@ts-ignore
templateSrv
:
new
TemplateSrvStub
(),
instanceSettings
:
{
url
:
'url'
,
name
:
'influxDb'
,
jsonData
:
{
httpMode
:
'GET'
}
},
};
...
...
@@ -23,10 +25,10 @@ describe('InfluxDataSource', () => {
to
:
'2018-01-02T00:00:00Z'
,
},
};
let
requestQuery
,
requestMethod
,
requestData
;
let
requestQuery
:
any
,
requestMethod
:
any
,
requestData
:
any
;
beforeEach
(
async
()
=>
{
ctx
.
backendSrv
.
datasourceRequest
=
req
=>
{
ctx
.
backendSrv
.
datasourceRequest
=
(
req
:
any
)
=>
{
requestMethod
=
req
.
method
;
requestQuery
=
req
.
params
.
q
;
requestData
=
req
.
data
;
...
...
@@ -45,7 +47,7 @@ describe('InfluxDataSource', () => {
});
};
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
).
then
(
_
=>
{});
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
).
then
(
()
=>
{});
});
it
(
'should replace $timefilter'
,
()
=>
{
...
...
@@ -65,7 +67,8 @@ describe('InfluxDataSource', () => {
describe
(
'InfluxDataSource in POST query mode'
,
()
=>
{
const
ctx
:
any
=
{
backendSrv
:
{},
$q
:
$q
,
$q
,
//@ts-ignore
templateSrv
:
new
TemplateSrvStub
(),
instanceSettings
:
{
url
:
'url'
,
name
:
'influxDb'
,
jsonData
:
{
httpMode
:
'POST'
}
},
};
...
...
@@ -78,10 +81,10 @@ describe('InfluxDataSource in POST query mode', () => {
describe
(
'When issuing metricFindQuery'
,
()
=>
{
const
query
=
'SELECT max(value) FROM measurement'
;
const
queryOptions
:
any
=
{};
let
requestMethod
,
requestQueryParameter
,
queryEncoded
,
requestQuer
y
;
let
requestMethod
:
any
,
requestQueryParameter
:
any
,
queryEncoded
:
any
,
requestQuery
:
an
y
;
beforeEach
(
async
()
=>
{
ctx
.
backendSrv
.
datasourceRequest
=
req
=>
{
ctx
.
backendSrv
.
datasourceRequest
=
(
req
:
any
)
=>
{
requestMethod
=
req
.
method
;
requestQueryParameter
=
req
.
params
;
requestQuery
=
req
.
data
;
...
...
@@ -101,7 +104,7 @@ describe('InfluxDataSource in POST query mode', () => {
};
queryEncoded
=
await
ctx
.
ds
.
serializeParams
({
q
:
query
});
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
).
then
(
_
=>
{});
await
ctx
.
ds
.
metricFindQuery
(
query
,
queryOptions
).
then
(
()
=>
{});
});
it
(
'should have the query form urlencoded'
,
()
=>
{
...
...
public/app/plugins/datasource/influxdb/specs/influx_query_model.test.ts
View file @
418dba4b
import
InfluxQueryModel
from
'../influx_query_model'
;
describe
(
'InfluxQuery'
,
()
=>
{
const
templateSrv
=
{
replace
:
val
=>
val
};
const
templateSrv
:
any
=
{
replace
:
(
val
:
any
)
=>
val
};
describe
(
'render series with mesurement only'
,
()
=>
{
it
(
'should generate correct query'
,
()
=>
{
...
...
public/app/plugins/datasource/influxdb/specs/query_ctrl.test.ts
View file @
418dba4b
...
...
@@ -19,10 +19,11 @@ describe('InfluxDBQueryCtrl', () => {
ctx
.
ctrl
=
new
InfluxQueryCtrl
(
{},
{},
{},
{},
new
uiSegmentSrv
({
trustAsHtml
:
html
=>
html
},
{
highlightVariablesAsHtml
:
()
=>
{}
})
{}
as
any
,
{}
as
any
,
{}
as
any
,
//@ts-ignore
new
uiSegmentSrv
({
trustAsHtml
:
(
html
:
any
)
=>
html
},
{
highlightVariablesAsHtml
:
()
=>
{}
})
);
});
...
...
public/app/plugins/datasource/mssql/config_ctrl.ts
View file @
418dba4b
...
...
@@ -12,7 +12,7 @@ export class MssqlConfigCtrl {
onPasswordChange
:
ReturnType
<
typeof
createChangeHandler
>
;
/** @ngInject */
constructor
(
$scope
)
{
constructor
(
$scope
:
any
)
{
this
.
current
.
jsonData
.
encrypt
=
this
.
current
.
jsonData
.
encrypt
||
'false'
;
this
.
onPasswordReset
=
createResetHandler
(
this
,
PasswordFieldEnum
.
Password
);
this
.
onPasswordChange
=
createChangeHandler
(
this
,
PasswordFieldEnum
.
Password
);
...
...
public/app/plugins/datasource/mssql/datasource.ts
View file @
418dba4b
import
_
from
'lodash'
;
import
ResponseParser
from
'./response_parser'
;
import
{
BackendSrv
}
from
'app/core/services/backend_srv'
;
import
{
IQService
}
from
'angular'
;
import
{
TemplateSrv
}
from
'app/features/templating/template_srv'
;
import
{
TimeSrv
}
from
'app/features/dashboard/services/TimeSrv'
;
export
class
MssqlDatasource
{
id
:
any
;
...
...
@@ -8,14 +12,20 @@ export class MssqlDatasource {
interval
:
string
;
/** @ngInject */
constructor
(
instanceSettings
,
private
backendSrv
,
private
$q
,
private
templateSrv
,
private
timeSrv
)
{
constructor
(
instanceSettings
:
any
,
private
backendSrv
:
BackendSrv
,
private
$q
:
IQService
,
private
templateSrv
:
TemplateSrv
,
private
timeSrv
:
TimeSrv
)
{
this
.
name
=
instanceSettings
.
name
;
this
.
id
=
instanceSettings
.
id
;
this
.
responseParser
=
new
ResponseParser
(
this
.
$q
);
this
.
interval
=
(
instanceSettings
.
jsonData
||
{}).
timeInterval
||
'1m'
;
}
interpolateVariable
(
value
,
variable
)
{
interpolateVariable
(
value
:
any
,
variable
:
any
)
{
if
(
typeof
value
===
'string'
)
{
if
(
variable
.
multi
||
variable
.
includeAll
)
{
return
"'"
+
value
.
replace
(
/'/g
,
`''`
)
+
"'"
;
...
...
@@ -38,7 +48,7 @@ export class MssqlDatasource {
return
quotedValues
.
join
(
','
);
}
query
(
options
)
{
query
(
options
:
any
)
{
const
queries
=
_
.
filter
(
options
.
targets
,
item
=>
{
return
item
.
hide
!==
true
;
}).
map
(
item
=>
{
...
...
@@ -69,7 +79,7 @@ export class MssqlDatasource {
.
then
(
this
.
responseParser
.
processQueryResult
);
}
annotationQuery
(
options
)
{
annotationQuery
(
options
:
any
)
{
if
(
!
options
.
annotation
.
rawQuery
)
{
return
this
.
$q
.
reject
({
message
:
'Query missing in annotation definition'
});
}
...
...
@@ -91,10 +101,10 @@ export class MssqlDatasource {
queries
:
[
query
],
},
})
.
then
(
data
=>
this
.
responseParser
.
transformAnnotationResponse
(
options
,
data
));
.
then
(
(
data
:
any
)
=>
this
.
responseParser
.
transformAnnotationResponse
(
options
,
data
));
}
metricFindQuery
(
query
,
optionalOptions
)
{
metricFindQuery
(
query
:
string
,
optionalOptions
:
{
variable
:
{
name
:
string
}
}
)
{
let
refId
=
'tempvar'
;
if
(
optionalOptions
&&
optionalOptions
.
variable
&&
optionalOptions
.
variable
.
name
)
{
refId
=
optionalOptions
.
variable
.
name
;
...
...
@@ -120,7 +130,7 @@ export class MssqlDatasource {
method
:
'POST'
,
data
:
data
,
})
.
then
(
data
=>
this
.
responseParser
.
parseMetricFindQueryResult
(
refId
,
data
));
.
then
(
(
data
:
any
)
=>
this
.
responseParser
.
parseMetricFindQueryResult
(
refId
,
data
));
}
testDatasource
()
{
...
...
@@ -143,10 +153,10 @@ export class MssqlDatasource {
],
},
})
.
then
(
res
=>
{
.
then
(
(
res
:
any
)
=>
{
return
{
status
:
'success'
,
message
:
'Database Connection OK'
};
})
.
catch
(
err
=>
{
.
catch
(
(
err
:
any
)
=>
{
console
.
log
(
err
);
if
(
err
.
data
&&
err
.
data
.
message
)
{
return
{
status
:
'error'
,
message
:
err
.
data
.
message
};
...
...
public/app/plugins/datasource/mssql/query_ctrl.ts
View file @
418dba4b
import
_
from
'lodash'
;
import
{
QueryCtrl
}
from
'app/plugins/sdk'
;
import
{
auto
}
from
'angular'
;
export
interface
MssqlQuery
{
refId
:
string
;
...
...
@@ -34,7 +35,7 @@ export class MssqlQueryCtrl extends QueryCtrl {
showHelp
:
boolean
;
/** @ngInject */
constructor
(
$scope
,
$injector
)
{
constructor
(
$scope
:
any
,
$injector
:
auto
.
IInjectorService
)
{
super
(
$scope
,
$injector
);
this
.
target
.
format
=
this
.
target
.
format
||
'time_series'
;
...
...
@@ -55,7 +56,7 @@ export class MssqlQueryCtrl extends QueryCtrl {
this
.
panelCtrl
.
events
.
on
(
'data-error'
,
this
.
onDataError
.
bind
(
this
),
$scope
);
}
onDataReceived
(
dataList
)
{
onDataReceived
(
dataList
:
any
)
{
this
.
lastQueryMeta
=
null
;
this
.
lastQueryError
=
null
;
...
...
@@ -65,7 +66,7 @@ export class MssqlQueryCtrl extends QueryCtrl {
}
}
onDataError
(
err
)
{
onDataError
(
err
:
any
)
{
if
(
err
.
data
&&
err
.
data
.
results
)
{
const
queryRes
=
err
.
data
.
results
[
this
.
target
.
refId
];
if
(
queryRes
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment