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
105879ab
Commit
105879ab
authored
Feb 09, 2019
by
thatsparesh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use timeSrv in metricFindQuery as timeRange
parent
716db35f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
12 deletions
+50
-12
public/app/plugins/datasource/mssql/datasource.ts
+4
-10
public/app/plugins/datasource/mssql/specs/datasource.test.ts
+46
-2
No files found.
public/app/plugins/datasource/mssql/datasource.ts
View file @
105879ab
...
...
@@ -8,7 +8,7 @@ export class MssqlDatasource {
interval
:
string
;
/** @ngInject */
constructor
(
instanceSettings
,
private
backendSrv
,
private
$q
,
private
templateSrv
)
{
constructor
(
instanceSettings
,
private
backendSrv
,
private
$q
,
private
templateSrv
,
private
timeSrv
)
{
this
.
name
=
instanceSettings
.
name
;
this
.
id
=
instanceSettings
.
id
;
this
.
responseParser
=
new
ResponseParser
(
this
.
$q
);
...
...
@@ -107,19 +107,13 @@ export class MssqlDatasource {
format
:
'table'
,
};
const
range
=
this
.
timeSrv
.
timeRange
();
const
data
=
{
queries
:
[
interpolatedQuery
],
from
:
range
.
from
.
valueOf
().
toString
(),
to
:
range
.
to
.
valueOf
().
toString
(),
};
if
(
optionalOptions
&&
optionalOptions
.
range
)
{
if
(
optionalOptions
.
range
.
from
)
{
data
[
'from'
]
=
optionalOptions
.
range
.
from
.
valueOf
().
toString
();
}
if
(
optionalOptions
.
range
.
to
)
{
data
[
'to'
]
=
optionalOptions
.
range
.
to
.
valueOf
().
toString
();
}
}
return
this
.
backendSrv
.
datasourceRequest
({
url
:
'/api/tsdb/query'
,
...
...
public/app/plugins/datasource/mssql/specs/datasource.test.ts
View file @
105879ab
import
moment
from
'moment'
;
import
{
MssqlDatasource
}
from
'../datasource'
;
import
{
TemplateSrvStub
}
from
'test/specs/helpers'
;
import
{
TemplateSrvStub
,
TimeSrvStub
}
from
'test/specs/helpers'
;
import
{
CustomVariable
}
from
'app/features/templating/custom_variable'
;
import
q
from
'q'
;
...
...
@@ -8,13 +8,14 @@ describe('MSSQLDatasource', () => {
const
ctx
:
any
=
{
backendSrv
:
{},
templateSrv
:
new
TemplateSrvStub
(),
timeSrv
:
new
TimeSrvStub
(),
};
beforeEach
(()
=>
{
ctx
.
$q
=
q
;
ctx
.
instanceSettings
=
{
name
:
'mssql'
};
ctx
.
ds
=
new
MssqlDatasource
(
ctx
.
instanceSettings
,
ctx
.
backendSrv
,
ctx
.
$q
,
ctx
.
templateSrv
);
ctx
.
ds
=
new
MssqlDatasource
(
ctx
.
instanceSettings
,
ctx
.
backendSrv
,
ctx
.
$q
,
ctx
.
templateSrv
,
ctx
.
timeSrv
);
});
describe
(
'When performing annotationQuery'
,
()
=>
{
...
...
@@ -188,6 +189,49 @@ describe('MSSQLDatasource', () => {
});
});
describe
(
'When performing metricFindQuery'
,
()
=>
{
let
results
;
const
query
=
'select * from atable'
;
const
response
=
{
results
:
{
tempvar
:
{
meta
:
{
rowCount
:
1
,
},
refId
:
'tempvar'
,
tables
:
[
{
columns
:
[{
text
:
'title'
}],
rows
:
[[
'aTitle'
]],
},
],
},
},
};
const
time
=
{
from
:
moment
(
1521545610656
),
to
:
moment
(
1521546251185
)
};
beforeEach
(()
=>
{
ctx
.
timeSrv
.
setTime
(
time
);
ctx
.
backendSrv
.
datasourceRequest
=
options
=>
{
results
=
options
.
data
;
return
ctx
.
$q
.
when
({
data
:
response
,
status
:
200
});
};
return
ctx
.
ds
.
metricFindQuery
(
query
);
});
it
(
'should pass timerange to datasourceRequest'
,
()
=>
{
expect
(
results
.
from
).
toBe
(
time
.
from
.
valueOf
().
toString
());
expect
(
results
.
to
).
toBe
(
time
.
to
.
valueOf
().
toString
());
expect
(
results
.
queries
.
length
).
toBe
(
1
);
expect
(
results
.
queries
[
0
].
rawSql
).
toBe
(
query
);
});
});
describe
(
'When interpolating variables'
,
()
=>
{
beforeEach
(()
=>
{
ctx
.
variable
=
new
CustomVariable
({},
{});
...
...
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