Skip to content

Commit 38430fd

Browse files
committed
Add support for Mirabelle
In Mirabelle https://github.com/mcorbin/Mirabelle websocket events have timestamp in fractional seconds.
1 parent c84ed0b commit 38430fd

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 2021-04-30 Release v0.1.5
4+
5+
* Add support for events with numeric time (in seconds)
6+
This makes this plugin also compatible with Mirabelle
7+
https://github.com/mcorbin/mirabelle
8+
39
## 2021-01-28 Release v0.1.4
410

511
* Fix time scrolling in Grafana 7.4.x

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ccin2p3-riemann-datasource",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "Subscribe to riemann.io websocket streams!",
55
"scripts": {
66
"build": "grafana-toolkit plugin:build",

src/DataSource.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
6161
return new Observable<DataQueryResponse>(subscriber => {
6262
ws.onmessage = function(event) {
6363
var parsedEvent = JSON.parse(event.data);
64-
parsedEvent['time'] = new Date(parsedEvent['time']).getTime();
64+
var typeOfTime = typeof parsedEvent['time'];
65+
if (typeOfTime === 'number') {
66+
// Mirabelle sends time as (fractional) seconds
67+
parsedEvent['time'] *= 1000;
68+
// Riemann sends time as Isodate string
69+
} else if (typeOfTime === 'string') {
70+
parsedEvent['time'] = new Date(parsedEvent['time']).getTime();
71+
// In any other case, use current time
72+
} else {
73+
parsedEvent['time'] = new Date().getTime();
74+
}
6575
const seriesId = getSeriesId(event, ...query.groupBy);
6676
let frame: CircularDataFrame;
6777
if (seriesId in seriesList) {

0 commit comments

Comments
 (0)