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