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
ae8a7651
Commit
ae8a7651
authored
Oct 11, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: improve error handling
parent
5b04a8b6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
27 deletions
+41
-27
public/app/plugins/datasource/stackdriver/datasource.ts
+35
-26
public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts
+6
-1
No files found.
public/app/plugins/datasource/stackdriver/datasource.ts
View file @
ae8a7651
import
{
stackdriverUnitMappings
}
from
'./constants'
;
import
appEvents
from
'app/core/app_events'
;
import
_
from
'lodash'
;
export
default
class
StackdriverDatasource
{
id
:
number
;
url
:
string
;
baseUrl
:
string
;
projectName
:
string
;
authenticationType
:
string
;
queryPromise
:
Promise
<
any
>
;
/** @ngInject */
...
...
@@ -15,6 +17,7 @@ export default class StackdriverDatasource {
this
.
doRequest
=
this
.
doRequest
;
this
.
id
=
instanceSettings
.
id
;
this
.
projectName
=
instanceSettings
.
jsonData
.
defaultProject
||
''
;
this
.
authenticationType
=
instanceSettings
.
jsonData
.
authenticationType
||
'jwt'
;
}
async
getTimeSeries
(
options
)
{
...
...
@@ -178,29 +181,36 @@ export default class StackdriverDatasource {
}
async
testDatasource
()
{
let
status
,
message
;
const
defaultErrorMessage
=
'Cannot connect to Stackdriver API'
;
try
{
await
this
.
backendSrv
.
datasourceRequest
({
url
:
'/api/tsdb/query'
,
method
:
'POST'
,
data
:
{
queries
:
[
{
refId
:
'testDatasource'
,
datasourceId
:
this
.
id
,
type
:
'testDatasource'
,
},
],
},
});
return
{
status
:
'success'
,
message
:
'Successfully queried the Stackdriver API.'
,
title
:
'Success'
,
};
const
projectName
=
await
this
.
getDefaultProject
();
const
path
=
`v3/projects/
${
projectName
}
/metricDescriptors`
;
const
response
=
await
this
.
doRequest
(
`
${
this
.
baseUrl
}${
path
}
`
);
if
(
response
.
status
===
200
)
{
status
=
'success'
;
message
=
'Successfully queried the Stackdriver API.'
;
}
else
{
status
=
'error'
;
message
=
response
.
statusText
?
response
.
statusText
:
defaultErrorMessage
;
}
}
catch
(
error
)
{
status
=
'error'
;
if
(
_
.
isString
(
error
))
{
message
=
error
;
}
else
{
message
=
'Stackdriver: '
;
message
+=
error
.
statusText
?
error
.
statusText
+
': '
:
''
;
if
(
error
.
data
&&
error
.
data
.
error
&&
error
.
data
.
error
.
code
)
{
message
+=
error
.
data
.
error
.
code
+
'. '
+
error
.
data
.
error
.
message
;
}
else
{
message
=
defaultErrorMessage
;
}
}
}
finally
{
return
{
status
:
'error'
,
message
:
this
.
formatStackdriverError
(
error
)
,
status
,
message
,
};
}
}
...
...
@@ -223,28 +233,27 @@ export default class StackdriverDatasource {
async
getDefaultProject
()
{
try
{
if
(
!
this
.
projectName
)
{
if
(
this
.
authenticationType
===
'gce'
||
!
this
.
projectName
)
{
const
{
data
}
=
await
this
.
backendSrv
.
datasourceRequest
({
url
:
'/api/tsdb/query'
,
method
:
'POST'
,
data
:
{
queries
:
[
{
refId
:
'
defaultProject
'
,
type
:
'
defaultProject
'
,
refId
:
'
ensureDefaultProjectQuery
'
,
type
:
'
ensureDefaultProjectQuery
'
,
datasourceId
:
this
.
id
,
},
],
},
});
this
.
projectName
=
data
.
results
.
defaultProject
.
meta
.
defaultProject
;
this
.
projectName
=
data
.
results
.
ensureDefaultProjectQuery
.
meta
.
defaultProject
;
return
this
.
projectName
;
}
else
{
return
this
.
projectName
;
}
}
catch
(
error
)
{
appEvents
.
emit
(
'ds-request-error'
,
this
.
formatStackdriverError
(
error
));
return
''
;
throw
this
.
formatStackdriverError
(
error
);
}
}
...
...
public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts
View file @
ae8a7651
...
...
@@ -79,11 +79,16 @@ export class StackdriverFilterCtrl {
}
async
getCurrentProject
()
{
return
new
Promise
(
async
resolve
=>
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
try
{
if
(
!
this
.
target
.
defaultProject
||
this
.
target
.
defaultProject
===
'loading project...'
)
{
this
.
target
.
defaultProject
=
await
this
.
datasource
.
getDefaultProject
();
}
resolve
(
this
.
target
.
defaultProject
);
}
catch
(
error
)
{
appEvents
.
emit
(
'ds-request-error'
,
error
);
reject
();
}
});
}
...
...
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