Skip to content

Commit b866496

Browse files
committed
fix: getField
* Fix bug which skips the first column regardless of if it is a timestamp * date(timestamp + "Z") was breaking timestamps. Use whatever O2 gives us, unless it's microseconds which needs converting to MS. * Only add Time column if it's part of the request [breaking for queries relying on this implicit field, but deduplicating for the queries that manually request it including example requests]
1 parent b8983b2 commit b866496

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/features/log/queryResponseBuilder.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,31 @@ export const getGraphDataFrame = (data: any, target: MyQuery, app: string) => {
6969
}
7070

7171
data.forEach((log: any) => {
72-
graphData.add(getField(log, fields));
72+
graphData.add(getField(log, fields, '_timestamp'));
7373
});
7474

7575
return graphData;
7676
};
7777

78-
const getField = (log: any, columns: any) => {
79-
let field: any = {
80-
Time: new Date(log[columns[0]] + 'Z').getTime(),
81-
};
82-
83-
for (let i = 1; i < columns.length; i++) {
84-
field[columns[i]] = log[columns[i]];
78+
const getField = (log: any, columns: any, timestampColumn: string) => {
79+
let field: any = {};
80+
81+
for (let i = 0; i < columns.length; i++) {
82+
let col_name = columns[i];
83+
let col_value = log[col_name]
84+
if (col_name === timestampColumn) {
85+
// We have to convert microseconds if we receive them
86+
// 500 billion / year 17814 is probably a good threshold for milliseconds
87+
if (col_value > 500_000_000_000) {
88+
col_value = convertTimeToMs(col_value);
89+
field["Time"] = col_value;
90+
} else {
91+
// Convert any other date fmt
92+
field["Time"] = new Date(col_value).getTime();
93+
}
94+
} else {
95+
field[col_name] = log[col_name];
96+
}
8597
}
8698

8799
return field;

0 commit comments

Comments
 (0)