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
e65cf5cb
Commit
e65cf5cb
authored
May 18, 2018
by
Mitsuhiro Tanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix directly specified variable rendering
parent
238139fa
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
6 deletions
+67
-6
public/app/plugins/datasource/cloudwatch/datasource.ts
+16
-6
public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts
+51
-0
No files found.
public/app/plugins/datasource/cloudwatch/datasource.ts
View file @
e65cf5cb
...
...
@@ -374,23 +374,33 @@ export default class CloudWatchDatasource {
getExpandedVariables
(
target
,
dimensionKey
,
variable
,
templateSrv
)
{
/* if the all checkbox is marked we should add all values to the targets */
var
allSelected
=
_
.
find
(
variable
.
options
,
{
selected
:
true
,
text
:
'All'
});
return
_
.
chain
(
variable
.
options
)
.
filter
(
v
=>
{
var
selectedVariables
=
_
.
filter
(
variable
.
options
,
v
=>
{
if
(
allSelected
)
{
return
v
.
text
!==
'All'
;
}
else
{
return
v
.
selected
;
}
})
.
map
(
v
=>
{
});
var
currentVariables
=
!
_
.
isArray
(
variable
.
current
.
value
)
?
[
variable
.
current
]
:
variable
.
current
.
value
.
map
(
v
=>
{
return
{
text
:
v
,
value
:
v
,
};
});
let
useSelectedVariables
=
selectedVariables
.
some
(
s
=>
{
return
s
.
value
===
currentVariables
[
0
].
value
;
})
||
currentVariables
[
0
].
value
===
'$__all'
;
return
(
useSelectedVariables
?
selectedVariables
:
currentVariables
).
map
(
v
=>
{
var
t
=
angular
.
copy
(
target
);
var
scopedVar
=
{};
scopedVar
[
variable
.
name
]
=
v
;
t
.
refId
=
target
.
refId
+
'_'
+
v
.
value
;
t
.
dimensions
[
dimensionKey
]
=
templateSrv
.
replace
(
t
.
dimensions
[
dimensionKey
],
scopedVar
);
return
t
;
})
.
value
();
});
}
expandTemplateVariable
(
targets
,
scopedVars
,
templateSrv
)
{
...
...
public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts
View file @
e65cf5cb
...
...
@@ -133,6 +133,10 @@ describe('CloudWatchDatasource', function() {
{
text
:
'i-23456789'
,
value
:
'i-23456789'
,
selected
:
false
},
{
text
:
'i-34567890'
,
value
:
'i-34567890'
,
selected
:
true
},
],
current
:
{
text
:
'i-34567890'
,
value
:
'i-34567890'
,
},
},
],
replace
:
function
(
target
,
scopedVars
)
{
...
...
@@ -169,6 +173,53 @@ describe('CloudWatchDatasource', function() {
var
result
=
ctx
.
ds
.
expandTemplateVariable
(
targets
,
{},
templateSrv
);
expect
(
result
[
0
].
dimensions
.
InstanceId
).
to
.
be
(
'i-34567890'
);
});
it
(
'should generate the correct targets by expanding template variables from url'
,
function
()
{
var
templateSrv
=
{
variables
:
[
{
name
:
'instance_id'
,
options
:
[
{
text
:
'i-23456789'
,
value
:
'i-23456789'
,
selected
:
false
},
{
text
:
'i-34567890'
,
value
:
'i-34567890'
,
selected
:
false
},
],
current
:
'i-45678901'
,
},
],
replace
:
function
(
target
,
scopedVars
)
{
if
(
target
===
'$instance_id'
)
{
return
'i-45678901'
;
}
else
{
return
''
;
}
},
getVariableName
:
function
(
e
)
{
return
'instance_id'
;
},
variableExists
:
function
(
e
)
{
return
true
;
},
containsVariable
:
function
(
str
,
variableName
)
{
return
str
.
indexOf
(
'$'
+
variableName
)
!==
-
1
;
},
};
var
targets
=
[
{
region
:
'us-east-1'
,
namespace
:
'AWS/EC2'
,
metricName
:
'CPUUtilization'
,
dimensions
:
{
InstanceId
:
'$instance_id'
,
},
statistics
:
[
'Average'
],
period
:
300
,
},
];
var
result
=
ctx
.
ds
.
expandTemplateVariable
(
targets
,
{},
templateSrv
);
expect
(
result
[
0
].
dimensions
.
InstanceId
).
to
.
be
(
'i-45678901'
);
});
});
describe
(
'When query region is "default"'
,
function
()
{
...
...
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