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
fe9fca38
Commit
fe9fca38
authored
Sep 26, 2017
by
Mitsuhiro Tanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move cloudwatch crendential related code
parent
4f5f38f4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
31 deletions
+15
-31
pkg/tsdb/cloudwatch/cloudwatch.go
+2
-3
pkg/tsdb/cloudwatch/credentials.go
+3
-3
pkg/tsdb/cloudwatch/credentials_test.go
+0
-0
pkg/tsdb/cloudwatch/metric_find_query.go
+6
-20
pkg/tsdb/cloudwatch/metric_find_query_test.go
+4
-5
No files found.
pkg/tsdb/cloudwatch/cloudwatch.go
View file @
fe9fca38
...
@@ -17,7 +17,6 @@ import (
...
@@ -17,7 +17,6 @@ import (
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatch"
cwapi
"github.com/grafana/grafana/pkg/api/cloudwatch"
"github.com/grafana/grafana/pkg/components/null"
"github.com/grafana/grafana/pkg/components/null"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/metrics"
...
@@ -128,7 +127,7 @@ func (e *CloudWatchExecutor) getClient(region string) (*cloudwatch.CloudWatch, e
...
@@ -128,7 +127,7 @@ func (e *CloudWatchExecutor) getClient(region string) (*cloudwatch.CloudWatch, e
}
}
}
}
datasourceInfo
:=
&
cwapi
.
DatasourceInfo
{
datasourceInfo
:=
&
DatasourceInfo
{
Region
:
region
,
Region
:
region
,
Profile
:
e
.
DataSource
.
Database
,
Profile
:
e
.
DataSource
.
Database
,
AssumeRoleArn
:
assumeRoleArn
,
AssumeRoleArn
:
assumeRoleArn
,
...
@@ -136,7 +135,7 @@ func (e *CloudWatchExecutor) getClient(region string) (*cloudwatch.CloudWatch, e
...
@@ -136,7 +135,7 @@ func (e *CloudWatchExecutor) getClient(region string) (*cloudwatch.CloudWatch, e
SecretKey
:
secretKey
,
SecretKey
:
secretKey
,
}
}
credentials
,
err
:=
cwapi
.
GetCredentials
(
datasourceInfo
)
credentials
,
err
:=
GetCredentials
(
datasourceInfo
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/
api/cloudwatch/cloudwatch
.go
→
pkg/
tsdb/cloudwatch/credentials
.go
View file @
fe9fca38
...
@@ -183,14 +183,14 @@ func ec2RoleProvider(sess *session.Session) credentials.Provider {
...
@@ -183,14 +183,14 @@ func ec2RoleProvider(sess *session.Session) credentials.Provider {
return
&
ec2rolecreds
.
EC2RoleProvider
{
Client
:
ec2metadata
.
New
(
sess
),
ExpiryWindow
:
5
*
time
.
Minute
}
return
&
ec2rolecreds
.
EC2RoleProvider
{
Client
:
ec2metadata
.
New
(
sess
),
ExpiryWindow
:
5
*
time
.
Minute
}
}
}
func
getAwsConfig
(
req
*
cwRequest
)
(
*
aws
.
Config
,
error
)
{
func
getAwsConfig
(
dsInfo
*
DatasourceInfo
)
(
*
aws
.
Config
,
error
)
{
creds
,
err
:=
GetCredentials
(
req
.
GetDatasourceInfo
()
)
creds
,
err
:=
GetCredentials
(
dsInfo
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
cfg
:=
&
aws
.
Config
{
cfg
:=
&
aws
.
Config
{
Region
:
aws
.
String
(
req
.
Region
),
Region
:
aws
.
String
(
dsInfo
.
Region
),
Credentials
:
creds
,
Credentials
:
creds
,
}
}
return
cfg
,
nil
return
cfg
,
nil
...
...
pkg/
api/cloudwatch/cloudwatch
_test.go
→
pkg/
tsdb/cloudwatch/credentials
_test.go
View file @
fe9fca38
File moved
pkg/tsdb/cloudwatch/metric_find_query.go
View file @
fe9fca38
...
@@ -14,7 +14,6 @@ import (
...
@@ -14,7 +14,6 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2"
cwapi
"github.com/grafana/grafana/pkg/api/cloudwatch"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/tsdb"
"github.com/grafana/grafana/pkg/tsdb"
...
@@ -211,7 +210,7 @@ func transformToTable(data []suggestData, result *tsdb.QueryResult) {
...
@@ -211,7 +210,7 @@ func transformToTable(data []suggestData, result *tsdb.QueryResult) {
result
.
Meta
.
Set
(
"rowCount"
,
len
(
data
))
result
.
Meta
.
Set
(
"rowCount"
,
len
(
data
))
}
}
func
(
e
*
CloudWatchExecutor
)
getDsInfo
(
region
string
)
*
cwapi
.
DatasourceInfo
{
func
(
e
*
CloudWatchExecutor
)
getDsInfo
(
region
string
)
*
DatasourceInfo
{
assumeRoleArn
:=
e
.
DataSource
.
JsonData
.
Get
(
"assumeRoleArn"
)
.
MustString
()
assumeRoleArn
:=
e
.
DataSource
.
JsonData
.
Get
(
"assumeRoleArn"
)
.
MustString
()
accessKey
:=
""
accessKey
:=
""
secretKey
:=
""
secretKey
:=
""
...
@@ -224,7 +223,7 @@ func (e *CloudWatchExecutor) getDsInfo(region string) *cwapi.DatasourceInfo {
...
@@ -224,7 +223,7 @@ func (e *CloudWatchExecutor) getDsInfo(region string) *cwapi.DatasourceInfo {
}
}
}
}
datasourceInfo
:=
&
cwapi
.
DatasourceInfo
{
datasourceInfo
:=
&
DatasourceInfo
{
Region
:
region
,
Region
:
region
,
Profile
:
e
.
DataSource
.
Database
,
Profile
:
e
.
DataSource
.
Database
,
AssumeRoleArn
:
assumeRoleArn
,
AssumeRoleArn
:
assumeRoleArn
,
...
@@ -460,19 +459,6 @@ func (e *CloudWatchExecutor) handleGetEc2InstanceAttribute(ctx context.Context,
...
@@ -460,19 +459,6 @@ func (e *CloudWatchExecutor) handleGetEc2InstanceAttribute(ctx context.Context,
return
result
,
nil
return
result
,
nil
}
}
func
getAwsConfig
(
dsInfo
*
cwapi
.
DatasourceInfo
)
(
*
aws
.
Config
,
error
)
{
creds
,
err
:=
cwapi
.
GetCredentials
(
dsInfo
)
if
err
!=
nil
{
return
nil
,
err
}
cfg
:=
&
aws
.
Config
{
Region
:
aws
.
String
(
dsInfo
.
Region
),
Credentials
:
creds
,
}
return
cfg
,
nil
}
func
(
e
*
CloudWatchExecutor
)
cloudwatchListMetrics
(
region
string
,
namespace
string
,
metricName
string
,
dimensions
[]
*
cloudwatch
.
DimensionFilter
)
(
*
cloudwatch
.
ListMetricsOutput
,
error
)
{
func
(
e
*
CloudWatchExecutor
)
cloudwatchListMetrics
(
region
string
,
namespace
string
,
metricName
string
,
dimensions
[]
*
cloudwatch
.
DimensionFilter
)
(
*
cloudwatch
.
ListMetricsOutput
,
error
)
{
dsInfo
:=
e
.
getDsInfo
(
region
)
dsInfo
:=
e
.
getDsInfo
(
region
)
cfg
,
err
:=
getAwsConfig
(
dsInfo
)
cfg
,
err
:=
getAwsConfig
(
dsInfo
)
...
@@ -541,8 +527,8 @@ func (e *CloudWatchExecutor) ec2DescribeInstances(region string, filters []*ec2.
...
@@ -541,8 +527,8 @@ func (e *CloudWatchExecutor) ec2DescribeInstances(region string, filters []*ec2.
return
&
resp
,
nil
return
&
resp
,
nil
}
}
func
getAllMetrics
(
cwData
*
cwapi
.
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
{
func
getAllMetrics
(
cwData
*
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
{
creds
,
err
:=
cwapi
.
GetCredentials
(
cwData
)
creds
,
err
:=
GetCredentials
(
cwData
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cloudwatch
.
ListMetricsOutput
{},
err
return
cloudwatch
.
ListMetricsOutput
{},
err
}
}
...
@@ -579,7 +565,7 @@ func getAllMetrics(cwData *cwapi.DatasourceInfo) (cloudwatch.ListMetricsOutput,
...
@@ -579,7 +565,7 @@ func getAllMetrics(cwData *cwapi.DatasourceInfo) (cloudwatch.ListMetricsOutput,
var
metricsCacheLock
sync
.
Mutex
var
metricsCacheLock
sync
.
Mutex
func
getMetricsForCustomMetrics
(
dsInfo
*
cwapi
.
DatasourceInfo
,
getAllMetrics
func
(
*
cwapi
.
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
))
([]
string
,
error
)
{
func
getMetricsForCustomMetrics
(
dsInfo
*
DatasourceInfo
,
getAllMetrics
func
(
*
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
))
([]
string
,
error
)
{
metricsCacheLock
.
Lock
()
metricsCacheLock
.
Lock
()
defer
metricsCacheLock
.
Unlock
()
defer
metricsCacheLock
.
Unlock
()
...
@@ -616,7 +602,7 @@ func getMetricsForCustomMetrics(dsInfo *cwapi.DatasourceInfo, getAllMetrics func
...
@@ -616,7 +602,7 @@ func getMetricsForCustomMetrics(dsInfo *cwapi.DatasourceInfo, getAllMetrics func
var
dimensionsCacheLock
sync
.
Mutex
var
dimensionsCacheLock
sync
.
Mutex
func
getDimensionsForCustomMetrics
(
dsInfo
*
cwapi
.
DatasourceInfo
,
getAllMetrics
func
(
*
cwapi
.
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
))
([]
string
,
error
)
{
func
getDimensionsForCustomMetrics
(
dsInfo
*
DatasourceInfo
,
getAllMetrics
func
(
*
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
))
([]
string
,
error
)
{
dimensionsCacheLock
.
Lock
()
dimensionsCacheLock
.
Lock
()
defer
dimensionsCacheLock
.
Unlock
()
defer
dimensionsCacheLock
.
Unlock
()
...
...
pkg/tsdb/cloudwatch/metric_find_query_test.go
View file @
fe9fca38
...
@@ -5,20 +5,19 @@ import (
...
@@ -5,20 +5,19 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatch"
cwapi
"github.com/grafana/grafana/pkg/api/cloudwatch"
.
"github.com/smartystreets/goconvey/convey"
.
"github.com/smartystreets/goconvey/convey"
)
)
func
TestCloudWatchMetrics
(
t
*
testing
.
T
)
{
func
TestCloudWatchMetrics
(
t
*
testing
.
T
)
{
Convey
(
"When calling getMetricsForCustomMetrics"
,
t
,
func
()
{
Convey
(
"When calling getMetricsForCustomMetrics"
,
t
,
func
()
{
dsInfo
:=
&
cwapi
.
DatasourceInfo
{
dsInfo
:=
&
DatasourceInfo
{
Region
:
"us-east-1"
,
Region
:
"us-east-1"
,
Namespace
:
"Foo"
,
Namespace
:
"Foo"
,
Profile
:
"default"
,
Profile
:
"default"
,
AssumeRoleArn
:
""
,
AssumeRoleArn
:
""
,
}
}
f
:=
func
(
dsInfo
*
cwapi
.
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
{
f
:=
func
(
dsInfo
*
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
{
return
cloudwatch
.
ListMetricsOutput
{
return
cloudwatch
.
ListMetricsOutput
{
Metrics
:
[]
*
cloudwatch
.
Metric
{
Metrics
:
[]
*
cloudwatch
.
Metric
{
{
{
...
@@ -40,13 +39,13 @@ func TestCloudWatchMetrics(t *testing.T) {
...
@@ -40,13 +39,13 @@ func TestCloudWatchMetrics(t *testing.T) {
})
})
Convey
(
"When calling getDimensionsForCustomMetrics"
,
t
,
func
()
{
Convey
(
"When calling getDimensionsForCustomMetrics"
,
t
,
func
()
{
dsInfo
:=
&
cwapi
.
DatasourceInfo
{
dsInfo
:=
&
DatasourceInfo
{
Region
:
"us-east-1"
,
Region
:
"us-east-1"
,
Namespace
:
"Foo"
,
Namespace
:
"Foo"
,
Profile
:
"default"
,
Profile
:
"default"
,
AssumeRoleArn
:
""
,
AssumeRoleArn
:
""
,
}
}
f
:=
func
(
dsInfo
*
cwapi
.
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
{
f
:=
func
(
dsInfo
*
DatasourceInfo
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
{
return
cloudwatch
.
ListMetricsOutput
{
return
cloudwatch
.
ListMetricsOutput
{
Metrics
:
[]
*
cloudwatch
.
Metric
{
Metrics
:
[]
*
cloudwatch
.
Metric
{
{
{
...
...
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