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
0d6e5298
Unverified
Commit
0d6e5298
authored
Feb 19, 2021
by
Dominik Prokop
Committed by
GitHub
Feb 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DatasourceSrv: Fix instance retrieval when datasource variable value set to "default" (#31347)
* Failing tests * Fixed
parent
ce63df42
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
public/app/features/plugins/datasource_srv.ts
+9
-1
public/app/features/plugins/specs/datasource_srv.test.ts
+18
-2
No files found.
public/app/features/plugins/datasource_srv.ts
View file @
0d6e5298
...
...
@@ -54,7 +54,15 @@ export class DatasourceSrv implements DataSourceService {
// For this we just pick the current or first data source in the variable
if
(
nameOrUid
[
0
]
===
'$'
)
{
const
interpolatedName
=
this
.
templateSrv
.
replace
(
nameOrUid
,
{},
variableInterpolation
);
const
dsSettings
=
this
.
settingsMapByUid
[
interpolatedName
]
??
this
.
settingsMapByName
[
interpolatedName
];
let
dsSettings
;
if
(
interpolatedName
===
'default'
)
{
dsSettings
=
this
.
settingsMapByName
[
this
.
defaultName
];
}
else
{
dsSettings
=
this
.
settingsMapByUid
[
interpolatedName
]
??
this
.
settingsMapByName
[
interpolatedName
];
}
if
(
!
dsSettings
)
{
return
undefined
;
}
...
...
public/app/features/plugins/specs/datasource_srv.test.ts
View file @
0d6e5298
...
...
@@ -11,9 +11,18 @@ const templateSrv: any = {
value
:
'BBB'
,
},
},
{
type
:
'datasource'
,
name
:
'datasourceDefault'
,
current
:
{
value
:
'default'
,
},
},
],
replace
:
(
v
:
string
)
=>
{
return
v
.
replace
(
'${datasource}'
,
'BBB'
);
let
result
=
v
.
replace
(
'${datasource}'
,
'BBB'
);
result
=
result
.
replace
(
'${datasourceDefault}'
,
'default'
);
return
result
;
},
};
...
...
@@ -117,6 +126,12 @@ describe('datasource_srv', () => {
expect
(
ds
?.
name
).
toBe
(
'${datasource}'
);
expect
(
ds
?.
uid
).
toBe
(
'uid-code-BBB'
);
});
it
(
'should work with variable'
,
()
=>
{
const
ds
=
dataSourceSrv
.
getInstanceSettings
(
'${datasourceDefault}'
);
expect
(
ds
?.
name
).
toBe
(
'${datasourceDefault}'
);
expect
(
ds
?.
uid
).
toBe
(
'uid-code-BBB'
);
});
});
describe
(
'when getting external metric sources'
,
()
=>
{
...
...
@@ -135,7 +150,8 @@ describe('datasource_srv', () => {
it
(
'Can get list of data sources with variables: true'
,
()
=>
{
const
list
=
dataSourceSrv
.
getList
({
metrics
:
true
,
variables
:
true
});
expect
(
list
[
0
].
name
).
toBe
(
'${datasource}'
);
expect
(
list
[
0
].
name
).
toBe
(
'${datasourceDefault}'
);
expect
(
list
[
1
].
name
).
toBe
(
'${datasource}'
);
});
it
(
'Can get list of data sources with tracing: true'
,
()
=>
{
...
...
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