|
|
@ -28,39 +28,39 @@ export class Exporter { |
|
|
|
private _task: ExportTask; |
|
|
|
private _task: ExportTask; |
|
|
|
|
|
|
|
|
|
|
|
public async export(task: ExportTask, datasourceUrl: string) { |
|
|
|
public async export(task: ExportTask, datasourceUrl: string) { |
|
|
|
this._task = _.cloneDeep(task); |
|
|
|
|
|
|
|
this._task.id = uuidv4(); |
|
|
|
|
|
|
|
this._task.progress = _.cloneDeep(DEFAULT_PROGRESS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const targets = task.queries.map((query: DashboardQuery) => new Target( |
|
|
|
|
|
|
|
query.panel, |
|
|
|
|
|
|
|
query.datasource, |
|
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._validateTargets(datasourceUrl, targets); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this._updateProgress(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const queryConfigs = targets.map( |
|
|
|
|
|
|
|
target => |
|
|
|
|
|
|
|
new QueryConfig( |
|
|
|
|
|
|
|
QueryType.GRAFANA, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
...target.datasource, |
|
|
|
|
|
|
|
url: datasourceUrl |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
target.panel.targets |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let from = +this._task.timeRange.from; |
|
|
|
|
|
|
|
let to = +this._task.timeRange.to; |
|
|
|
|
|
|
|
const days = Math.ceil((to - from) / MS_IN_DAY); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Total days: ${days}`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const stream = this._initCsvStream(); |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
this._task = _.cloneDeep(task); |
|
|
|
|
|
|
|
this._task.id = uuidv4(); |
|
|
|
|
|
|
|
this._task.progress = _.cloneDeep(DEFAULT_PROGRESS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const targets = task.queries.map((query: DashboardQuery) => new Target( |
|
|
|
|
|
|
|
query.panel, |
|
|
|
|
|
|
|
query.datasource, |
|
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._validateTargets(datasourceUrl, targets); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this._updateProgress(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const queryConfigs = targets.map( |
|
|
|
|
|
|
|
target => |
|
|
|
|
|
|
|
new QueryConfig( |
|
|
|
|
|
|
|
QueryType.GRAFANA, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
...target.datasource, |
|
|
|
|
|
|
|
url: datasourceUrl |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
target.panel.targets |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let from = +this._task.timeRange.from; |
|
|
|
|
|
|
|
let to = +this._task.timeRange.to; |
|
|
|
|
|
|
|
const days = Math.ceil((to - from) / MS_IN_DAY); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Total days: ${days}`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const stream = this._initCsvStream(); |
|
|
|
for(let day = 0; day < days; day++) { |
|
|
|
for(let day = 0; day < days; day++) { |
|
|
|
to = from + MS_IN_DAY; |
|
|
|
to = from + MS_IN_DAY; |
|
|
|
|
|
|
|
|
|
|
@ -86,10 +86,10 @@ export class Exporter { |
|
|
|
|
|
|
|
|
|
|
|
from += MS_IN_DAY; |
|
|
|
from += MS_IN_DAY; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
stream.end(); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
await this._updateProgress({ status: ExportStatus.ERROR, errorMessage: e.message }); |
|
|
|
await this._updateProgress({ status: ExportStatus.ERROR, errorMessage: e.message }); |
|
|
|
} |
|
|
|
} |
|
|
|
stream.end(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _initCsvStream() { |
|
|
|
private _initCsvStream() { |
|
|
|