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
8b067a5f
Unverified
Commit
8b067a5f
authored
Mar 13, 2020
by
Ryan McKinley
Committed by
GitHub
Mar 13, 2020
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DataSourceWithBackend: use /health endpoint for test (#22789)
parent
dfb3272b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
4 deletions
+44
-4
packages/grafana-runtime/src/utils/DataSourceWithBackend.ts
+44
-4
No files found.
packages/grafana-runtime/src/utils/DataSourceWithBackend.ts
View file @
8b067a5f
...
...
@@ -13,6 +13,18 @@ import { getBackendSrv } from '../services';
// Ideally internal (exported for consistency)
const
ExpressionDatasourceID
=
'__expr__'
;
export
enum
HealthStatus
{
Unknown
=
'UNKNOWN'
,
OK
=
'OK'
,
Error
=
'ERROR'
,
}
export
interface
HealthCheckResult
{
status
:
HealthStatus
;
message
:
string
;
details
?:
Record
<
string
,
any
>
;
}
export
class
DataSourceWithBackend
<
TQuery
extends
DataQuery
=
DataQuery
,
TOptions
extends
DataSourceJsonData
=
DataSourceJsonData
...
...
@@ -22,7 +34,7 @@ export class DataSourceWithBackend<
}
/**
* Ideally final -- any other implementation
would be wrong!
* Ideally final -- any other implementation
may not work as expected
*/
query
(
request
:
DataQueryRequest
):
Observable
<
DataQueryResponse
>
{
const
{
targets
,
intervalMs
,
maxDataPoints
,
range
}
=
request
;
...
...
@@ -101,8 +113,36 @@ export class DataSourceWithBackend<
return
getBackendSrv
().
post
(
`/api/datasources/
${
this
.
id
}
/resources/
${
path
}
`
,
{
...
body
});
}
testDatasource
()
{
// TODO, this will call the backend healthcheck endpoint
return
Promise
.
resolve
({});
/**
* Run the datasource healthcheck
*/
async
callHealthCheck
():
Promise
<
HealthCheckResult
>
{
return
getBackendSrv
()
.
get
(
`/api/datasources/
${
this
.
id
}
/health`
)
.
then
(
v
=>
{
return
v
as
HealthCheckResult
;
})
.
catch
(
err
=>
{
err
.
isHandled
=
true
;
// Avoid extra popup warning
return
err
.
data
as
HealthCheckResult
;
});
}
/**
* Checks the plugin health
*/
async
testDatasource
():
Promise
<
any
>
{
return
this
.
callHealthCheck
().
then
(
res
=>
{
if
(
res
.
status
===
HealthStatus
.
OK
)
{
return
{
status
:
'success'
,
message
:
res
.
message
,
};
}
return
{
status
:
'fail'
,
message
:
res
.
message
,
};
});
}
}
Kornkitt Poolsup
@Doratong24
mentioned in commit
3d0bc141
Mar 05, 2021
mentioned in commit
3d0bc141
mentioned in commit 3d0bc141c7a347d0dac3ec081ca823a26a4b75bf
Toggle commit list
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