Skip to content

Commit

Permalink
DBAAS-4651 : Support for intervals in past for streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyotsna Ramineni authored and Jyotsna Ramineni committed Oct 26, 2020
1 parent 37ed16b commit d66f301
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
24 changes: 16 additions & 8 deletions grafana-plugins/splice-plugin/dist/module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion grafana-plugins/splice-plugin/dist/module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion grafana-plugins/splice-plugin/dist/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
"screenshots": [],
"version": "1.0.0",
"updated": "2020-09-21"
"updated": "2020-10-26"
},
"dependencies": {
"grafanaVersion": "7.x.x",
Expand Down
21 changes: 13 additions & 8 deletions grafana-plugins/splice-plugin/src/runStreams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function runStream(
): Observable<DataQueryResponse> {
return new Observable<DataQueryResponse>(subscriber => {
const streamId = `signal-${req.panelId}-${target.refId}`;
const { intervalMs, requestId } = req;
const { intervalMs, requestId, range } = req;
const speed = intervalMs || 5000;
const maxDataPoints = req.maxDataPoints || 750;

Expand All @@ -35,7 +35,7 @@ export function runStream(
//fetch data for time

const queries: any[] = [];
const range = {
const curRange = {
from: toUtc(fromtime),
to: toUtc(totime),
};
Expand All @@ -50,9 +50,9 @@ export function runStream(
const body: any = {
queries,
};
body.range = range;
body.from = range.from.valueOf().toString();
body.to = range.to.valueOf().toString();
body.range = curRange;
body.from = curRange.from.valueOf().toString();
body.to = curRange.to.valueOf().toString();

getBackendSrv()
.datasourceRequest({
Expand All @@ -79,15 +79,20 @@ export function runStream(

// Fill the buffer on init
if (true) {
let time = Date.now() - maxDataPoints * speed;
let initFromTime = Date.now() - maxDataPoints * speed;
let initToTime = Date.now();
if (range) {
initFromTime = range.from.valueOf();
initToTime = range.to.valueOf();
}
prevAddRowDone = false;
addNextRow(time, Date.now());
addNextRow(initFromTime, initToTime);
}

const pushNextEvent = () => {
if (prevAddRowDone) {
prevAddRowDone = false;
addNextRow(prevTime, Date.now());
addNextRow(prevTime, prevTime + speed);
subscriber.next({
data: [data],
key: streamId,
Expand Down

0 comments on commit d66f301

Please sign in to comment.