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
b90a078b
Commit
b90a078b
authored
Jan 15, 2016
by
Mitsuhiro Tanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(cloudwatch) change implementation to testable
parent
73ec4864
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
13 deletions
+9
-13
pkg/api/cloudwatch/metrics.go
+9
-13
No files found.
pkg/api/cloudwatch/metrics.go
View file @
b90a078b
...
...
@@ -154,7 +154,7 @@ func handleGetMetrics(req *cwRequest, c *middleware.Context) {
}
}
else
{
var
err
error
if
namespaceMetrics
,
err
=
getMetricsForCustomMetrics
(
req
,
reqParam
.
Parameters
.
Namespace
);
err
!=
nil
{
if
namespaceMetrics
,
err
=
getMetricsForCustomMetrics
(
req
.
Region
,
reqParam
.
Parameters
.
Namespace
,
req
.
DataSource
.
Database
,
getAllMetrics
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to call AWS API"
,
err
)
return
}
...
...
@@ -187,7 +187,7 @@ func handleGetDimensions(req *cwRequest, c *middleware.Context) {
}
}
else
{
var
err
error
if
dimensionValues
,
err
=
getDimensionsForCustomMetrics
(
req
,
reqParam
.
Parameters
.
Namespace
);
err
!=
nil
{
if
dimensionValues
,
err
=
getDimensionsForCustomMetrics
(
req
.
Region
,
reqParam
.
Parameters
.
Namespace
,
req
.
DataSource
.
Database
,
getAllMetrics
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to call AWS API"
,
err
)
return
}
...
...
@@ -202,10 +202,10 @@ func handleGetDimensions(req *cwRequest, c *middleware.Context) {
c
.
JSON
(
200
,
result
)
}
func
getAllMetrics
(
re
q
*
cwRequest
,
namespac
e
string
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
{
func
getAllMetrics
(
re
gion
string
,
namespace
string
,
databas
e
string
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
{
cfg
:=
&
aws
.
Config
{
Region
:
aws
.
String
(
re
q
.
Re
gion
),
Credentials
:
getCredentials
(
req
.
DataSource
.
D
atabase
),
Region
:
aws
.
String
(
region
),
Credentials
:
getCredentials
(
d
atabase
),
}
svc
:=
cloudwatch
.
New
(
session
.
New
(
cfg
),
cfg
)
...
...
@@ -232,8 +232,8 @@ func getAllMetrics(req *cwRequest, namespace string) (cloudwatch.ListMetricsOutp
var
metricsCacheLock
sync
.
Mutex
func
getMetricsForCustomMetrics
(
re
q
*
cwRequest
,
namespace
string
)
([]
string
,
error
)
{
result
,
err
:=
getAllMetrics
(
re
q
,
namespac
e
)
func
getMetricsForCustomMetrics
(
re
gion
string
,
namespace
string
,
database
string
,
getAllMetrics
func
(
string
,
string
,
string
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
)
([]
string
,
error
)
{
result
,
err
:=
getAllMetrics
(
re
gion
,
namespace
,
databas
e
)
if
err
!=
nil
{
return
[]
string
{},
err
}
...
...
@@ -241,8 +241,6 @@ func getMetricsForCustomMetrics(req *cwRequest, namespace string) ([]string, err
metricsCacheLock
.
Lock
()
defer
metricsCacheLock
.
Unlock
()
database
:=
req
.
DataSource
.
Database
region
:=
req
.
Region
if
_
,
ok
:=
customMetricsMetricsMap
[
database
];
!
ok
{
customMetricsMetricsMap
[
database
]
=
make
(
map
[
string
]
map
[
string
]
*
CustomMetricsCache
)
}
...
...
@@ -272,8 +270,8 @@ func getMetricsForCustomMetrics(req *cwRequest, namespace string) ([]string, err
var
dimensionsCacheLock
sync
.
Mutex
func
getDimensionsForCustomMetrics
(
re
q
*
cwRequest
,
namespace
string
)
([]
string
,
error
)
{
result
,
err
:=
getAllMetrics
(
re
q
,
namespac
e
)
func
getDimensionsForCustomMetrics
(
re
gion
string
,
namespace
string
,
database
string
,
getAllMetrics
func
(
string
,
string
,
string
)
(
cloudwatch
.
ListMetricsOutput
,
error
)
)
([]
string
,
error
)
{
result
,
err
:=
getAllMetrics
(
re
gion
,
namespace
,
databas
e
)
if
err
!=
nil
{
return
[]
string
{},
err
}
...
...
@@ -281,8 +279,6 @@ func getDimensionsForCustomMetrics(req *cwRequest, namespace string) ([]string,
dimensionsCacheLock
.
Lock
()
defer
dimensionsCacheLock
.
Unlock
()
database
:=
req
.
DataSource
.
Database
region
:=
req
.
Region
if
_
,
ok
:=
customMetricsDimensionsMap
[
database
];
!
ok
{
customMetricsDimensionsMap
[
database
]
=
make
(
map
[
string
]
map
[
string
]
*
CustomMetricsCache
)
}
...
...
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