Skip to content

Commit

Permalink
feat(recording): API v3 downloads (#1206)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores authored Jan 11, 2024
1 parent 067c8d2 commit 361483a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 44 deletions.
48 changes: 6 additions & 42 deletions src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import {
XMLHttpRequestConfig,
XMLHttpResponse,
} from './api.types';
import { isHttpError, isActiveRecording, includesTarget, isHttpOk, isXMLHttpError } from './api.utils';
import { isHttpError, includesTarget, isHttpOk, isXMLHttpError } from './api.utils';
import { LoginService } from './Login.service';
import { NotificationService } from './Notifications.service';
import { SessionState } from './service.types';
Expand Down Expand Up @@ -775,48 +775,12 @@ export class ApiService {
);
}

downloadReport(recording: Recording): void {
const body = new window.FormData();
if (isActiveRecording(recording)) {
body.append('resource', recording.reportUrl.replace('/api/v1', '/api/v2.1'));
} else {
body.append('resource', recording.reportUrl.concat('/jwt'));
}
this.sendRequest('v2.1', 'auth/token', {
method: 'POST',
body,
})
.pipe(
concatMap((resp) => resp.json()),
map((response: AssetJwtResponse) => response.data.result.resourceUrl),
)
.subscribe((resourceUrl) => {
this.downloadFile(resourceUrl, `${recording.name}.report.json`, false);
});
}

downloadRecording(recording: Recording): void {
const body = new window.FormData();
if (isActiveRecording(recording)) {
body.append('resource', recording.downloadUrl.replace('/api/v1', '/api/v2.1'));
} else {
body.append('resource', recording.downloadUrl.concat('/jwt'));
}
this.sendRequest('v2.1', 'auth/token', {
method: 'POST',
body,
})
.pipe(
concatMap((resp) => resp.json()),
map((response: AssetJwtResponse) => response.data.result.resourceUrl),
)
.subscribe((resourceUrl) => {
this.downloadFile(resourceUrl, recording.name + (recording.name.endsWith('.jfr') ? '' : '.jfr'));
this.downloadFile(
createBlobURL(JSON.stringify(recording.metadata), 'application/json'), // Blob for metadata
recording.name.replace(/\.jfr$/, '') + '.metadata.json',
);
});
this.downloadFile(recording.downloadUrl, recording.name + (recording.name.endsWith('.jfr') ? '' : '.jfr'));
this.downloadFile(
createBlobURL(JSON.stringify(recording.metadata), 'application/json'),
recording.name.replace(/\.jfr$/, '') + '.metadata.json',
);
}

downloadTemplate(template: EventTemplate): void {
Expand Down
1 change: 0 additions & 1 deletion src/test/Recordings/ActiveRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ jest.spyOn(defaultServices.api, 'archiveRecording').mockReturnValue(of(true));
jest.spyOn(defaultServices.api, 'deleteRecording').mockReturnValue(of(true));
jest.spyOn(defaultServices.api, 'doGet').mockReturnValue(of([mockRecording]));
jest.spyOn(defaultServices.api, 'downloadRecording').mockReturnValue(void 0);
jest.spyOn(defaultServices.api, 'downloadReport').mockReturnValue(void 0);
jest.spyOn(defaultServices.api, 'grafanaDashboardUrl').mockReturnValue(of('/grafanaUrl'));
jest.spyOn(defaultServices.api, 'grafanaDatasourceUrl').mockReturnValue(of('/datasource'));
jest.spyOn(defaultServices.api, 'stopRecording').mockReturnValue(of(true));
Expand Down
1 change: 0 additions & 1 deletion src/test/Recordings/ArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ jest.mock('@app/Recordings/RecordingFilters', () => {

jest.spyOn(defaultServices.api, 'deleteArchivedRecording').mockReturnValue(of(true));
jest.spyOn(defaultServices.api, 'downloadRecording').mockReturnValue();
jest.spyOn(defaultServices.api, 'downloadReport').mockReturnValue();
jest.spyOn(defaultServices.api, 'grafanaDatasourceUrl').mockReturnValue(of('/datasource'));
jest.spyOn(defaultServices.api, 'grafanaDashboardUrl').mockReturnValue(of('/grafanaUrl'));
jest.spyOn(defaultServices.api, 'graphql').mockReturnValue(of(mockArchivedRecordingsResponse));
Expand Down

0 comments on commit 361483a

Please sign in to comment.