Skip to content

Commit

Permalink
Add stats for bytes metered and scanned (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmgot committed Nov 8, 2021
1 parent cef0bf1 commit 8da8ded
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ScopedVars,
QueryResultMetaStat,
TimeRange,
getValueFormat,
} from '@grafana/data';
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
import { Observable, of, merge } from 'rxjs';
Expand Down Expand Up @@ -133,6 +134,7 @@ export class DataSource extends DataSourceWithBackend<TimestreamQuery, Timestrea
if (!meta) {
return allData.length ? allData : data; // NOOP
}
const valueFormat = getValueFormat('decbytes');

// Single request
meta.fetchStartTime = t.fetchStartTime;
Expand Down Expand Up @@ -226,6 +228,24 @@ export class DataSource extends DataSourceWithBackend<TimestreamQuery, Timestrea
});
}
}
if (tracker.status.CumulativeBytesMetered) {
const v = valueFormat(tracker.status.CumulativeBytesMetered, 2, 1024);
stats.push({
displayName: 'Cumulative bytes metered',
value: Number(v.text),
unit: v.suffix?.trimLeft(),
decimals: 2,
});
}
if (tracker.status.CumulativeBytesScanned) {
const v = valueFormat(tracker.status.CumulativeBytesScanned, 2, 1024);
stats.push({
displayName: 'Cumulative bytes scanned',
value: Number(v.text),
unit: v.suffix?.trimLeft(),
decimals: 2,
});
}
allData[0].meta!.stats = stats;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export interface TimestreamCustomMeta {
fetchEndTime?: number; // The frontend clock
fetchTime?: number; // The frontend clock

status: {
CumulativeBytesMetered?: number;
CumulativeBytesScanned?: number;
};

// when multiple queries exist we keep track of each request
subs?: TimestreamCustomMeta[];
}
Expand Down

0 comments on commit 8da8ded

Please sign in to comment.