Skip to content

Commit

Permalink
Merge 6a5ce46 into a36a2e4
Browse files Browse the repository at this point in the history
  • Loading branch information
chribsen committed Jan 17, 2019
2 parents a36a2e4 + 6a5ce46 commit fafcbf4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
8 changes: 5 additions & 3 deletions src/metric.js
Expand Up @@ -18,9 +18,11 @@ class MetricRegistry {
return metric
}
async logMetrics() {
for (let metric of await this.getMetrics()) {
statistic(`Metric dump`, this.convertTimestampToIsoString(metric))
}
const metrics = await this.getMetrics()

statistic(`Metric dump`, {
metrics: metrics.map(this.convertTimestampToIsoString)
})
}
async getMetrics() {
let result = []
Expand Down
42 changes: 18 additions & 24 deletions src/metric.test.js
Expand Up @@ -161,37 +161,31 @@ describe('src/metric.js', () => {
await this.metricRegistry.cumulative('cumulative', 20, { brand: 'vw' })
await this.metricRegistry.logMetrics()

expect(this.statistic.callCount, 'to be', 2)
expect(this.statistic.callCount, 'to be', 1)
expect(this.statistic.args[0].length, 'to be', 1)
expect(
this.statistic.args[0][0],
'to equal',
JSON.stringify({
message: 'Metric dump',
context: {
name: 'gauge',
type: 'GAUGE',
value: 4,
labels: { brand: 'vw' },
endTime: '2017-09-01T13:37:42.000Z'
},
level: 'STATISTIC',
timestamp: '2017-09-01T13:37:42.000Z'
})
)

expect(
this.statistic.args[1][0],
'to equal',
JSON.stringify({
message: 'Metric dump',
context: {
name: 'cumulative',
type: 'CUMULATIVE',
value: 20,
labels: { brand: 'vw' },
startTime: '2017-09-01T13:37:42.000Z',
endTime: '2017-09-01T13:37:42.000Z'
metrics: [
{
name: 'gauge',
type: 'GAUGE',
value: 4,
labels: { brand: 'vw' },
endTime: '2017-09-01T13:37:42.000Z'
},
{
name: 'cumulative',
type: 'CUMULATIVE',
value: 20,
labels: { brand: 'vw' },
startTime: '2017-09-01T13:37:42.000Z',
endTime: '2017-09-01T13:37:42.000Z'
}
]
},
level: 'STATISTIC',
timestamp: '2017-09-01T13:37:42.000Z'
Expand Down

0 comments on commit fafcbf4

Please sign in to comment.