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
b3c7a41e
Unverified
Commit
b3c7a41e
authored
Oct 26, 2018
by
Torkel Ödegaard
Committed by
GitHub
Oct 26, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13819 from mtanda/cw_desc_region
use default region to call DescribeRegions
parents
e7f6cdc6
220c4f4a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
pkg/tsdb/cloudwatch/metric_find_query.go
+11
-2
pkg/tsdb/cloudwatch/metric_find_query_test.go
+31
-0
No files found.
pkg/tsdb/cloudwatch/metric_find_query.go
View file @
b3c7a41e
...
...
@@ -35,6 +35,7 @@ type CustomMetricsCache struct {
var
customMetricsMetricsMap
map
[
string
]
map
[
string
]
map
[
string
]
*
CustomMetricsCache
var
customMetricsDimensionsMap
map
[
string
]
map
[
string
]
map
[
string
]
*
CustomMetricsCache
var
regionCache
sync
.
Map
func
init
()
{
metricsMap
=
map
[
string
][]
string
{
...
...
@@ -233,13 +234,20 @@ func parseMultiSelectValue(input string) []string {
// Whenever this list is updated, frontend list should also be updated.
// Please update the region list in public/app/plugins/datasource/cloudwatch/partials/config.html
func
(
e
*
CloudWatchExecutor
)
handleGetRegions
(
ctx
context
.
Context
,
parameters
*
simplejson
.
Json
,
queryContext
*
tsdb
.
TsdbQuery
)
([]
suggestData
,
error
)
{
dsInfo
:=
e
.
getDsInfo
(
"default"
)
profile
:=
dsInfo
.
Profile
if
cache
,
ok
:=
regionCache
.
Load
(
profile
);
ok
{
if
cache2
,
ok2
:=
cache
.
([]
suggestData
);
ok2
{
return
cache2
,
nil
}
}
regions
:=
[]
string
{
"ap-northeast-1"
,
"ap-northeast-2"
,
"ap-northeast-3"
,
"ap-south-1"
,
"ap-southeast-1"
,
"ap-southeast-2"
,
"ca-central-1"
,
"eu-central-1"
,
"eu-north-1"
,
"eu-west-1"
,
"eu-west-2"
,
"eu-west-3"
,
"me-south-1"
,
"sa-east-1"
,
"us-east-1"
,
"us-east-2"
,
"us-west-1"
,
"us-west-2"
,
"cn-north-1"
,
"cn-northwest-1"
,
"us-gov-east-1"
,
"us-gov-west-1"
,
"us-isob-east-1"
,
"us-iso-east-1"
,
}
err
:=
e
.
ensureClientSession
(
"us-east-1"
)
err
:=
e
.
ensureClientSession
(
"default"
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -269,6 +277,7 @@ func (e *CloudWatchExecutor) handleGetRegions(ctx context.Context, parameters *s
for
_
,
region
:=
range
regions
{
result
=
append
(
result
,
suggestData
{
Text
:
region
,
Value
:
region
})
}
regionCache
.
Store
(
profile
,
result
)
return
result
,
nil
}
...
...
pkg/tsdb/cloudwatch/metric_find_query_test.go
View file @
b3c7a41e
...
...
@@ -9,7 +9,9 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/bmizerany/assert"
"github.com/grafana/grafana/pkg/components/securejsondata"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/tsdb"
.
"github.com/smartystreets/goconvey/convey"
)
...
...
@@ -17,12 +19,16 @@ import (
type
mockedEc2
struct
{
ec2iface
.
EC2API
Resp
ec2
.
DescribeInstancesOutput
RespRegions
ec2
.
DescribeRegionsOutput
}
func
(
m
mockedEc2
)
DescribeInstancesPages
(
in
*
ec2
.
DescribeInstancesInput
,
fn
func
(
*
ec2
.
DescribeInstancesOutput
,
bool
)
bool
)
error
{
fn
(
&
m
.
Resp
,
true
)
return
nil
}
func
(
m
mockedEc2
)
DescribeRegions
(
in
*
ec2
.
DescribeRegionsInput
)
(
*
ec2
.
DescribeRegionsOutput
,
error
)
{
return
&
m
.
RespRegions
,
nil
}
func
TestCloudWatchMetrics
(
t
*
testing
.
T
)
{
...
...
@@ -82,6 +88,31 @@ func TestCloudWatchMetrics(t *testing.T) {
})
})
Convey
(
"When calling handleGetRegions"
,
t
,
func
()
{
executor
:=
&
CloudWatchExecutor
{
ec2Svc
:
mockedEc2
{
RespRegions
:
ec2
.
DescribeRegionsOutput
{
Regions
:
[]
*
ec2
.
Region
{
{
RegionName
:
aws
.
String
(
"ap-northeast-2"
),
},
},
}},
}
jsonData
:=
simplejson
.
New
()
jsonData
.
Set
(
"defaultRegion"
,
"default"
)
executor
.
DataSource
=
&
models
.
DataSource
{
JsonData
:
jsonData
,
SecureJsonData
:
securejsondata
.
SecureJsonData
{},
}
result
,
_
:=
executor
.
handleGetRegions
(
context
.
Background
(),
simplejson
.
New
(),
&
tsdb
.
TsdbQuery
{})
Convey
(
"Should return regions"
,
func
()
{
So
(
result
[
0
]
.
Text
,
ShouldEqual
,
"ap-northeast-1"
)
So
(
result
[
1
]
.
Text
,
ShouldEqual
,
"ap-northeast-2"
)
})
})
Convey
(
"When calling handleGetEc2InstanceAttribute"
,
t
,
func
()
{
executor
:=
&
CloudWatchExecutor
{
ec2Svc
:
mockedEc2
{
Resp
:
ec2
.
DescribeInstancesOutput
{
...
...
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