Skip to content

Commit

Permalink
fix: request use old responce
Browse files Browse the repository at this point in the history
  • Loading branch information
justahole committed May 9, 2020
1 parent 127c489 commit e232502
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/stores/monitoring/custom/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default class PanelMonitor {
* grafana template panel config
*/
this.config = config
this.requestID = 0
}

/**
Expand Down Expand Up @@ -118,6 +119,12 @@ export default class PanelMonitor {
fetchMetrics = async ({ start, end }) => {
const { targets = [], namespace } = this.config

const req = {
ID: ++this.requestID,
errorMessage: '',
metrics: [],
}

try {
const result = await Promise.all(
targets.map(async target => {
Expand All @@ -132,7 +139,7 @@ export default class PanelMonitor {
return { data, target }
})
)
this.metrics = result.reduce((metrics, metricsGroup) => {
req.metrics = result.reduce((metrics, metricsGroup) => {
const { data = [], target = {} } = metricsGroup
const { expr, refId: targetID } = target

Expand All @@ -152,10 +159,13 @@ export default class PanelMonitor {

return metrics.concat(parsedMetrics)
}, [])
this.errorMessage = ''
} catch (err) {
this.errorMessage = err.message
this.metrics = []
req.errorMessage = err.message
} finally {
if (req.ID === this.requestID) {
this.metrics = req.metrics
this.errorMessage = req.errorMessage
}
}
}

Expand Down

0 comments on commit e232502

Please sign in to comment.