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
68409687
Commit
68409687
authored
Sep 05, 2018
by
Erik Sundell
Committed by
Daniel Lee
Sep 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds unit tests to test datasource
parent
f9b75244
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
14 deletions
+107
-14
public/app/plugins/datasource/stackdriver/datasource.ts
+5
-14
public/app/plugins/datasource/stackdriver/specs/datasource.test.ts
+60
-0
public/app/plugins/datasource/stackdriver/specs/testData.ts
+42
-0
No files found.
public/app/plugins/datasource/stackdriver/datasource.ts
View file @
68409687
...
...
@@ -2,18 +2,14 @@
export
default
class
StackdriverDatasource
{
url
:
string
;
baseUrl
:
string
;
cloudName
:
string
;
constructor
(
instanceSettings
,
private
backendSrv
)
{
this
.
cloudName
=
'stackdriver'
;
this
.
baseUrl
=
`/
${
this
.
cloudName
}
/`
;
this
.
baseUrl
=
`/stackdriver/`
;
this
.
url
=
instanceSettings
.
url
;
}
testDatasource
()
{
const
path
=
`v3/projects/raintank-production/timeSeries?aggregation.crossSeriesReducer=
REDUCE_NONE&filter=metric.type%20%3D%20%22compute.googleapis.com%2Finstance%2Fcpu%2Fusage_time%
22&aggregation.perSeriesAligner=ALIGN_NONE&interval.startTime=2018-09-04T05%3A16%3A02.383Z&interval.endTime=2018-09-04T11%3A16%3A02.383Z`
;
const
path
=
`v3/projects/raintank-production/metricDescriptors`
;
return
this
.
doRequest
(
`
${
this
.
baseUrl
}${
path
}
`
)
.
then
(
response
=>
{
if
(
response
.
status
===
200
)
{
...
...
@@ -22,22 +18,17 @@ export default class StackdriverDatasource {
message
:
'Successfully queried the Azure Monitor service.'
,
title
:
'Success'
,
};
}
else
{
throw
new
Error
();
}
})
.
catch
(
error
=>
{
let
message
=
'
Azure Monito
r: '
;
let
message
=
'
Stackdrive
r: '
;
message
+=
error
.
statusText
?
error
.
statusText
+
': '
:
''
;
if
(
error
.
data
&&
error
.
data
.
error
&&
error
.
data
.
error
.
code
)
{
// 400, 401
message
+=
error
.
data
.
error
.
code
+
'. '
+
error
.
data
.
error
.
message
;
}
else
if
(
error
.
data
&&
error
.
data
.
error
)
{
message
+=
error
.
data
.
error
;
}
else
if
(
error
.
data
)
{
message
+=
error
.
data
;
}
else
{
message
+=
'Cannot connect to
Azure Monitor REST API.
'
;
message
+=
'Cannot connect to
Stackdriver API
'
;
}
return
{
status
:
'error'
,
...
...
public/app/plugins/datasource/stackdriver/specs/datasource.test.ts
0 → 100644
View file @
68409687
import
StackdriverDataSource
from
'../datasource'
;
import
{
metricDescriptors
}
from
'./testData'
;
describe
(
'StackdriverDataSource'
,
()
=>
{
describe
(
'when performing testDataSource'
,
()
=>
{
describe
(
'and call to stackdriver api succeeds'
,
()
=>
{
let
ds
;
let
result
;
beforeEach
(
async
()
=>
{
const
backendSrv
=
{
async
datasourceRequest
()
{
return
Promise
.
resolve
({
status
:
200
});
},
};
ds
=
new
StackdriverDataSource
({},
backendSrv
);
result
=
await
ds
.
testDatasource
();
});
it
(
'should return successfully'
,
()
=>
{
expect
(
result
.
status
).
toBe
(
'success'
);
});
});
describe
(
'and a list of metricDescriptors are returned'
,
()
=>
{
let
ds
;
let
result
;
beforeEach
(
async
()
=>
{
console
.
log
(
'erik'
,
metricDescriptors
);
const
backendSrv
=
{
datasourceRequest
:
async
()
=>
Promise
.
resolve
({
status
:
200
,
data
:
metricDescriptors
}),
};
ds
=
new
StackdriverDataSource
({},
backendSrv
);
result
=
await
ds
.
testDatasource
();
});
it
(
'should return status success'
,
()
=>
{
expect
(
result
.
status
).
toBe
(
'success'
);
});
});
describe
(
'and call to stackdriver api fails with 400 error'
,
()
=>
{
let
ds
;
let
result
;
beforeEach
(
async
()
=>
{
const
backendSrv
=
{
datasourceRequest
:
async
()
=>
Promise
.
reject
({
statusText
:
'Bad Request'
,
data
:
{
error
:
{
code
:
400
,
message
:
'Field interval.endTime had an invalid value'
}
},
}),
};
ds
=
new
StackdriverDataSource
({},
backendSrv
);
result
=
await
ds
.
testDatasource
();
});
it
(
'should return error status and a detailed error message'
,
()
=>
{
expect
(
result
.
status
).
toEqual
(
'error'
);
expect
(
result
.
message
).
toBe
(
'Stackdriver: Bad Request: 400. Field interval.endTime had an invalid value'
);
});
});
});
});
public/app/plugins/datasource/stackdriver/specs/testData.ts
0 → 100644
View file @
68409687
export
const
metricDescriptors
=
[
{
name
:
'projects/raintank-production/metricDescriptors/agent.googleapis.com/agent/api_request_count'
,
labels
:
[
{
key
:
'state'
,
description
:
'Request state'
,
},
],
metricKind
:
'CUMULATIVE'
,
valueType
:
'INT64'
,
unit
:
'1'
,
description
:
'API request count'
,
displayName
:
'API Request Count'
,
type
:
'agent.googleapis.com/agent/api_request_count'
,
metadata
:
{
launchStage
:
'GA'
,
samplePeriod
:
'60s'
,
ingestDelay
:
'0s'
,
},
},
{
name
:
'projects/raintank-production/metricDescriptors/agent.googleapis.com/agent/log_entry_count'
,
labels
:
[
{
key
:
'response_code'
,
description
:
'HTTP response code'
,
},
],
metricKind
:
'CUMULATIVE'
,
valueType
:
'INT64'
,
unit
:
'1'
,
description
:
'Count of log entry writes'
,
displayName
:
'Log Entry Count'
,
type
:
'agent.googleapis.com/agent/log_entry_count'
,
metadata
:
{
launchStage
:
'GA'
,
samplePeriod
:
'60s'
,
ingestDelay
:
'0s'
,
},
},
];
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