Skip to content

Commit 5d10512

Browse files
authored
Support time series panels with PQs (#81)
* Support time series panels with PQs * Lint issues * Lint issues * Test update
1 parent 23c9f4b commit 5d10512

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

dist/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ can find documentation on API Keys [here](https://www.scalyr.com/help/api#scalyr
3535

3636
```bash
3737
grafana-cli --pluginUrl \
38-
https://github.com/scalyr/scalyr-grafana-datasource-plugin/releases/download/2.3.5/scalyr_grafana_plugin_2a30795.zip \
38+
https://github.com/scalyr/scalyr-grafana-datasource-plugin/releases/download/2.3.6/scalyr_grafana_plugin_3243979.zip \
3939
plugins install scalyr-datasource
4040
```
4141

dist/module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datasource.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ export class GenericDatasource {
364364
const cloneData = _.clone(data);
365365
cloneData.columns.map((col) => {col.text = col.name; return col;});
366366

367+
cloneData.columns.forEach((col, index) => {
368+
if (col.text === "timestamp") {
369+
col.text = "time";
370+
col.name = "time";
371+
cloneData.values.forEach((value) => {
372+
value[index] = Number(value[index]) / 1000000;
373+
});
374+
}
375+
});
376+
367377
return {
368378
data : [{
369379
type: this.visualizationType.TABLE,

src/specs/datasource.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,29 @@ describe('Scalyr datasource tests', () => {
140140
});
141141
});
142142

143+
describe('Power queries timeseries', () => {
144+
let results;
145+
beforeEach(() => {
146+
results = {
147+
columns: [{name: 'col1'}, {name: 'col2'}, {name: 'timestamp'}],
148+
warnings: [],
149+
values: [['r1', 1, 1640732355000000000]]
150+
};
151+
});
152+
153+
it('Should transform power query results to table', () => {
154+
const transformedResults = datasource.transformPowerQueryDataToTable(results).data;
155+
expect(transformedResults.length).toBe(1);
156+
const resultEntry = transformedResults[0];
157+
expect(resultEntry.columns.length).toBe(3);
158+
expect(resultEntry.columns.some(x => x.text === 'col1')).toBeTruthy();
159+
expect(resultEntry.columns.some(x => x.text === 'time')).toBeTruthy();
160+
expect(resultEntry.rows.length).toBe(results.values.length);
161+
expect(resultEntry.rows.every(x => x.length === 3)).toBeTruthy();
162+
expect(resultEntry.rows.some(x => x[2] === 1640732355000)).toBeTruthy();
163+
});
164+
});
165+
143166
describe('Annotation queries', () => {
144167
let results;
145168
beforeEach(() => {

0 commit comments

Comments
 (0)