(panel: Panel, dashboardId: string)
| 184 | |
| 185 | |
| 186 | const queryData = async (panel: Panel, dashboardId: string) => { |
| 187 | console.time("time used - query data for panel:") |
| 188 | const ds = panel.datasource |
| 189 | const datasource = getDatasource(ds.id) |
| 190 | if (!datasource) { |
| 191 | return |
| 192 | } |
| 193 | |
| 194 | |
| 195 | let data = [] |
| 196 | let needUpdate = false |
| 197 | const intervalObj = calculateInterval(timeRange, ds.queryOptions.maxDataPoints ?? DatasourceMaxDataPoints, isEmpty(ds.queryOptions.minInterval) ? DatasourceMinInterval : ds.queryOptions.minInterval) |
| 198 | const interval = intervalObj.intervalMs / 1000 |
| 199 | |
| 200 | setLoading(true) |
| 201 | if (panel.type == PanelType.Alert) { |
| 202 | const res = await queryAlerts(panel, timeRange, panel.plugins.alert.filter.datasources, panel.plugins.alert.filter.httpQuery, datasources) |
| 203 | setQueryError(res.error) |
| 204 | data = res.data |
| 205 | } else { |
| 206 | const promises = [] |
| 207 | for (const q0 of ds.queries) { |
| 208 | if (!q0.visible) { |
| 209 | continue |
| 210 | } |
| 211 | const q: PanelQuery = { ...cloneDeep(q0), interval } |
| 212 | replaceQueryWithVariables(q, datasource.type, intervalObj.interval) |
| 213 | if (datasource.type != DatasourceType.TestData && hasVariableFormat(q.metrics)) { |
| 214 | // there are variables still not replaced, maybe because variable's loadValues has not completed |
| 215 | continue |
| 216 | } |
| 217 | |
| 218 | const id = formatQueryId(ds.id, dashboardId, panel.id, q.id, panel.type) |
| 219 | const prevQuery = prevQueries.get(id) |
| 220 | const currentQuery = [q, timeRange, datasource.type] |
| 221 | if (isEqual(prevQuery, currentQuery)) { |
| 222 | const d = prevQueryData[id] |
| 223 | if (d) { |
| 224 | data.push(d) |
| 225 | } |
| 226 | setQueryError(null) |
| 227 | console.log("query data from cache!", panel.id) |
| 228 | continue |
| 229 | } |
| 230 | |
| 231 | needUpdate = true |
| 232 | // console.log("re-query data! metrics id:", q.id, " query id:", queryId) |
| 233 | |
| 234 | |
| 235 | let res |
| 236 | //@needs-update-when-add-new-datasource |
| 237 | switch (datasource.type) { |
| 238 | case DatasourceType.Prometheus: |
| 239 | res = run_prometheus_query(panel, q, timeRange, datasource) |
| 240 | break; |
| 241 | case DatasourceType.TestData: |
| 242 | res = run_testdata_query(panel, q, timeRange, datasource) |
| 243 | break; |
no test coverage detected