Skip to content

Commit b3b1055

Browse files
committed
change: Utilize datasource defined timestamp column automatically in data frame parser
1 parent 0df4c9f commit b3b1055

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/datasource.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ export class DataSource
7272

7373
// As we don't show histogram for sql mode in explore
7474
if (options.app === 'explore' && target?.refId?.includes(REF_ID_STARTER_LOG_VOLUME) && target.sqlMode) {
75-
return getGraphDataFrame([], target, options.app);
75+
return getGraphDataFrame([], target, options.app, this.timestampColumn);
7676
}
7777

7878
this.cachedQuery.requestQuery = JSON.stringify(reqData);
7979
this.cachedQuery.isFetching = true;
8080
return this.doRequest(target, reqData)
8181
.then((response) => {
8282
if (options.app === 'panel-editor' || options.app === 'dashboard') {
83-
return getGraphDataFrame(response.hits, target, options.app);
83+
return getGraphDataFrame(response.hits, target, options.app, this.timestampColumn);
8484
}
8585

8686
const logsDataFrame = getLogsDataFrame(response.hits, target, this.streamFields, this.timestampColumn);
8787

88-
const graphDataFrame = getGraphDataFrame(response?.aggs?.histogram || [], target, options.app);
88+
const graphDataFrame = getGraphDataFrame(response?.aggs?.histogram || [], target, options.app, this.timestampColumn);
8989

9090
this.cachedQuery.promise?.resolve({ graph: graphDataFrame, logs: logsDataFrame });
9191

src/features/log/queryResponseBuilder.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ export const getLogsDataFrame = (
3636
return logsData;
3737
};
3838

39-
export const getGraphDataFrame = (data: any, target: MyQuery, app: string) => {
39+
export const getGraphDataFrame = (
40+
data: any,
41+
target: MyQuery,
42+
app: string,
43+
timestampColumn = '_timestamp'
44+
) => {
4045
const graphData = getDefaultDataFrame(target.refId, 'graph');
4146

4247
let fields = ['zo_sql_key', 'zo_sql_num'];
@@ -50,7 +55,7 @@ export const getGraphDataFrame = (data: any, target: MyQuery, app: string) => {
5055
}
5156

5257
for (let i = 0; i < fields.length; i++) {
53-
if (fields[i] === '_timestamp') {
58+
if (fields[i] === timestampColumn) {
5459
graphData.addField({
5560
config: {
5661
filterable: true,
@@ -70,7 +75,7 @@ export const getGraphDataFrame = (data: any, target: MyQuery, app: string) => {
7075
}
7176

7277
data.forEach((log: any) => {
73-
graphData.add(getField(log, fields, '_timestamp'));
78+
graphData.add(getField(log, fields, timestampColumn));
7479
});
7580

7681
return graphData;

0 commit comments

Comments
 (0)