Skip to content

Commit c19b984

Browse files
committed
fix: fixed logs volume and dashboard chart
1 parent fa11c75 commit c19b984

File tree

2 files changed

+97
-86
lines changed

2 files changed

+97
-86
lines changed

src/datasource.ts

Lines changed: 91 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -132,94 +132,105 @@ export class DataSource
132132

133133
currentCache.requestQuery = cacheKey;
134134
currentCache.isFetching = true;
135-
return this.doRequest(target, reqData)
136-
.then((response) => {
137-
if (options.app === 'panel-editor' || options.app === 'dashboard') {
135+
136+
// For volume, panel-editor, or dashboard contexts, use partition + histogram flow
137+
if (target?.refId?.includes(REF_ID_STARTER_LOG_VOLUME) || options.app === 'panel-editor' || options.app === 'dashboard') {
138+
if(reqData.query && reqData.query.hasOwnProperty('size')) {
139+
delete reqData.query.size;
140+
}
141+
return this.doPartitionRequest(target, reqData.query)
142+
.then((partitionResponse) => {
143+
// Check if partitions are available
144+
if (partitionResponse?.partitions?.length > 0) {
145+
// Use partitions to make histogram requests
146+
const partitions = partitionResponse.partitions;
147+
148+
if (!partitionResponse.is_histogram_eligible) {
149+
const mode = target.displayMode || 'auto';
150+
if(mode === 'graph' || target?.refId?.includes(REF_ID_STARTER_LOG_VOLUME)){
151+
let dataFrame = getGraphDataFrame([], target, options.app, "zo_sql_key");
152+
currentCache.promise?.resolve(dataFrame);
153+
return dataFrame;
154+
} else {
155+
let dataFrame = getLogsDataFrame([], target, this.streamFields, this.timestampColumn);
156+
currentCache.promise?.resolve(dataFrame);
157+
return dataFrame;
158+
}
159+
}
160+
161+
const histogramPromises = partitions.map((partition: any) => {
162+
// Create histogram query for each partition
163+
const partitionHistogramQuery = {
164+
...reqData,
165+
query: {
166+
...reqData.query,
167+
start_time: partition[0],
168+
end_time: partition[1],
169+
histogram_interval: partitionResponse.histogram_interval,
170+
},
171+
};
172+
173+
return this.doHistogramRequest(target, partitionHistogramQuery);
174+
});
175+
176+
// Combine results from all partitions
177+
return Promise.all(histogramPromises).then((histogramResponses) => {
178+
// Merge histogram data from all partitions
179+
const combinedHits = histogramResponses.reduce((acc, response) => {
180+
return acc.concat(response.hits || []);
181+
}, []);
182+
183+
const mode = target.displayMode || 'auto';
184+
console.log('combinedHits', combinedHits, target);
185+
if((mode === 'graph' || mode === 'auto') || target?.refId?.includes(REF_ID_STARTER_LOG_VOLUME)){
186+
const graphDf = getGraphDataFrame(combinedHits, target, options.app, "zo_sql_key");
187+
currentCache.promise?.resolve(graphDf);
188+
console.log('graphDf', graphDf);
189+
return graphDf;
190+
} else {
191+
const logsDf = getLogsDataFrame(combinedHits, target, this.streamFields, this.timestampColumn);
192+
currentCache.promise?.resolve(logsDf);
193+
return logsDf;
194+
}
195+
});
196+
} else {
197+
// Fallback to direct histogram request if no partitions
198+
return this.doHistogramRequest(target, reqData).then((histogramResponse) => {
199+
const mode = target.displayMode || 'auto';
200+
if(mode === 'graph' || target?.refId?.includes(REF_ID_STARTER_LOG_VOLUME)){
201+
const graphDf = getGraphDataFrame(histogramResponse.hits, target, options.app, this.timestampColumn);
202+
currentCache.promise?.resolve(graphDf);
203+
return graphDf;
204+
} else {
205+
const logsDf = getLogsDataFrame(histogramResponse.hits, target, this.streamFields, this.timestampColumn);
206+
currentCache.promise?.resolve(logsDf);
207+
return logsDf;
208+
}
209+
});
210+
}
211+
})
212+
.catch((error) => {
213+
console.error('Partition or histogram request failed:', error);
214+
// Fallback to empty data
138215
const mode = target.displayMode || 'auto';
139-
if(mode === 'graph'){
140-
const graphDf = getGraphDataFrame(response.hits, target, options.app, this.timestampColumn);
216+
if(mode === 'graph' || target?.refId?.includes(REF_ID_STARTER_LOG_VOLUME)){
217+
const graphDf = getGraphDataFrame([], target, options.app, this.timestampColumn);
141218
currentCache.promise?.resolve(graphDf);
142219
return graphDf;
143220
} else {
144-
const logsDf = getLogsDataFrame(response.hits, target, this.streamFields, this.timestampColumn);
221+
const logsDf = getLogsDataFrame([], target, this.streamFields, this.timestampColumn);
145222
currentCache.promise?.resolve(logsDf);
146223
return logsDf;
147224
}
148-
}
225+
});
226+
}
149227

150-
// Handle histogram queries for log volume using partitions
151-
if (target?.refId?.includes(REF_ID_STARTER_LOG_VOLUME) && this.histogramQuery) {
152-
// First, get partition information for histogram queries
153-
return this.doPartitionRequest(target, this.histogramQuery.query)
154-
.then((partitionResponse) => {
155-
// Check if partitions are available
156-
if (partitionResponse?.partitions?.length > 0) {
157-
// Use partitions to make histogram requests
158-
const partitions = partitionResponse.partitions;
159-
160-
if (!partitionResponse.is_histogram_eligible) {
161-
let dataFrame = getGraphDataFrame([], target, options.app, this.timestampColumn);
162-
currentCache.promise?.resolve(dataFrame);
163-
return dataFrame;
164-
}
165-
166-
const histogramPromises = partitions.map((partition: any) => {
167-
// Create histogram query for each partition
168-
const partitionHistogramQuery = {
169-
...this.histogramQuery,
170-
query: {
171-
...this.histogramQuery.query,
172-
start_time: partition[0],
173-
end_time: partition[1],
174-
histogram_interval: partitionResponse.histogram_interval,
175-
},
176-
};
177-
178-
return this.doHistogramRequest(target, partitionHistogramQuery);
179-
});
180-
181-
// Combine results from all partitions
182-
return Promise.all(histogramPromises).then((histogramResponses) => {
183-
// Merge histogram data from all partitions
184-
const combinedHits = histogramResponses.reduce((acc, response) => {
185-
return acc.concat(response.hits || []);
186-
}, []);
187-
188-
const graphDataFrame = getGraphDataFrame(combinedHits, target, options.app, 'zo_sql_key');
189-
currentCache.promise?.resolve(graphDataFrame);
190-
191-
return graphDataFrame;
192-
});
193-
} else {
194-
// Fallback to direct histogram request if no partitions
195-
return this.doHistogramRequest(target, this.histogramQuery).then((histogramResponse) => {
196-
const graphDataFrame = getGraphDataFrame(
197-
histogramResponse.hits,
198-
target,
199-
options.app,
200-
this.timestampColumn
201-
);
202-
currentCache.promise?.resolve(graphDataFrame);
203-
return graphDataFrame;
204-
});
205-
}
206-
})
207-
.catch((error) => {
208-
console.error('Partition or histogram request failed:', error);
209-
// Fallback to empty graph
210-
const graphDataFrame = getGraphDataFrame([], target, options.app, this.timestampColumn);
211-
currentCache.promise?.resolve(graphDataFrame);
212-
return graphDataFrame;
213-
});
214-
} else if (target?.refId?.includes(REF_ID_STARTER_LOG_VOLUME)) {
215-
const graphDataFrame = getGraphDataFrame([], target, options.app, this.timestampColumn);
216-
currentCache.promise?.resolve(graphDataFrame);
217-
return graphDataFrame;
218-
} else {
219-
const logsDataFrame = getLogsDataFrame(response.hits, target, this.streamFields, this.timestampColumn);
220-
currentCache.promise?.resolve(logsDataFrame);
221-
return logsDataFrame;
222-
}
228+
// For logs, continue using doRequest
229+
return this.doRequest(target, reqData)
230+
.then((response) => {
231+
const logsDataFrame = getLogsDataFrame(response.hits, target, this.streamFields, this.timestampColumn);
232+
currentCache.promise?.resolve(logsDataFrame);
233+
return logsDataFrame;
223234
})
224235
.catch((err) => {
225236
currentCache.promise?.reject(err);

src/features/log/queryResponseBuilder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ export const getGraphDataFrame = (data: any, target: MyQuery, app: string, times
4141

4242
let fields = ['zo_sql_key', 'zo_sql_num'];
4343

44-
if (app !== 'explore') {
45-
const columns = getColumnsFromQuery(target.query);
44+
// if (app !== 'explore') {
45+
// const columns = getColumnsFromQuery(target.query);
4646

47-
if (columns.length) {
48-
fields = columns;
49-
}
50-
}
47+
// if (columns.length) {
48+
// fields = columns;
49+
// }
50+
// }
5151

5252
for (let i = 0; i < fields.length; i++) {
5353
if (isTimeField(fields[i], timestampColumn)) {

0 commit comments

Comments
 (0)