-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for real-time reporting (#281)
* feat: detect in-progress report * feat: add real-time support in dashboard * refactor(test): move `ReportsController` to the correct directory * refactor: rename test files to be in the correct format * test: add `RealTimeUpdatesController.spec.ts` And various validations have been added. * test: add various sse related tests these were copied from the stryker-js implementation with some minor changes. We should probably make a seperate packages for this soon. * feat: add `constructApiUri` method Helper method that helps with constructing the uri we need. * feat(frontend): use correct api url * feat: upload real-time reports to a different URL This does not disturb the report that already exists. * refactor: move controllers to the right package This time it's correct... * feat: reject in-progress reports on default URL * refactor: use `realTime` in slug instead of a seperate if statement * test: add `realtime=true` query parameter * feat: saving intermediate results in azure blobs * test: all the things * refactor: move in-progress uploading to the correct controller * feat: delete both blobs after finished event has been sent * feat: use better identifier in orchestrator * feat: validate incoming mutants * feat: return stable report if real-time report is not available * chore: fix naming of `MutationEventOrchestrator` * chore: naming fixes * feat: add ability to set CORS in `SseServer` * fix: configuration tests * Fix naming issues * Fix cors setting * Remove unnecessary validation checks * Fix module not used * refactor: greatly simplify working of real-time reporting Instead of creating a new server every time, simply keep track of all the responses and remove them when we are done with real-time reporting * refactor: use `URL` class instead of `URLSearchParams` * fix: `toId` now works correctly * test: simplify `RealTimeReportsController.spec.ts` * fix: `constructApiUri` tests * test: remove `realTime` query string in e2e test * feat: emit event when connection closes * test: add e2e tests * fix: add `js` extension to import * test: add faulty mutants test * fix: linting issues * refactor: use `filter` instead of `splice` Makes it more clear what we are actually doing. * docs: clarify usage of `split(...)[1]` * chore: linting issues
- Loading branch information
1 parent
ba3b533
commit 5ef3f98
Showing
48 changed files
with
1,843 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export function constructApiUri( | ||
location: string, | ||
slug: string, | ||
queryParams: { module: string | undefined; realTime: string | undefined } | ||
) { | ||
const url = new URL(`${location}/api/reports/${slug}`); | ||
for (const [key, value] of Object.entries(queryParams)) { | ||
if (value !== undefined && value !== null) { | ||
url.searchParams.append(key, value); | ||
} | ||
} | ||
|
||
return url.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './slug.js'; | ||
export * from './Report.js'; | ||
export * from './Logger.js'; | ||
export * from './Uri.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { expect } from 'chai'; | ||
import { constructApiUri } from '../../src/Uri.js'; | ||
|
||
describe(constructApiUri.name, () => { | ||
const baseUrl = 'http://stryker-website'; | ||
it('should return the default API uri when params are empty', () => { | ||
const uri = constructApiUri(baseUrl, 'github.com/user/project', { | ||
module: undefined, | ||
realTime: undefined, | ||
}); | ||
|
||
expect(uri).to.eq( | ||
'http://stryker-website/api/reports/github.com/user/project' | ||
); | ||
}); | ||
|
||
it('should also ignore null values', () => { | ||
const uri = constructApiUri(baseUrl, 'github.com/user/project', { | ||
module: null as unknown as undefined, | ||
realTime: null as unknown as undefined, | ||
}); | ||
|
||
expect(uri).to.eq( | ||
'http://stryker-website/api/reports/github.com/user/project' | ||
); | ||
}); | ||
|
||
it('should return the API uri with the module as query param', () => { | ||
const uri = constructApiUri(baseUrl, 'github.com/user/project', { | ||
module: 'project-submodule', | ||
realTime: undefined, | ||
}); | ||
|
||
expect(uri).to.eq( | ||
'http://stryker-website/api/reports/github.com/user/project?module=project-submodule' | ||
); | ||
}); | ||
|
||
it('should return the API uri with realTime as query param', () => { | ||
const uri = constructApiUri(baseUrl, 'github.com/user/project', { | ||
module: undefined, | ||
realTime: 'true', | ||
}); | ||
|
||
expect(uri).to.eq( | ||
'http://stryker-website/api/reports/github.com/user/project?realTime=true' | ||
); | ||
}); | ||
|
||
it('should return the API uri with both the module and realTime query param', () => { | ||
const uri = constructApiUri(baseUrl, 'github.com/user/project', { | ||
module: 'project-submodule', | ||
realTime: 'true', | ||
}); | ||
|
||
expect(uri).to.eq( | ||
'http://stryker-website/api/reports/github.com/user/project?module=project-submodule&realTime=true' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './models/index.js'; | ||
export * from './mappers/index.js'; | ||
export { MutationTestingReportService } from './services/MutationTestingReportService.js'; | ||
export { RealTimeMutantsBlobService } from './services/RealTimeMutantsBlobService.js'; | ||
export * from './errors/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/data-access/src/services/RealTimeMutantsBlobService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { ReportIdentifier } from '@stryker-mutator/dashboard-common'; | ||
import { BlobServiceAsPromised } from './BlobServiceAsPromised.js'; | ||
import { toBlobName } from '../utils.js'; | ||
import { MutantResult } from 'mutation-testing-report-schema'; | ||
|
||
// To make resource delete themselves automatically, this should be managed from within Azure: | ||
// https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-overview?tabs=azure-portal | ||
export class RealTimeMutantsBlobService { | ||
private static readonly CONTAINER_NAME = 'real-time-mutant-results'; | ||
|
||
#blobService: BlobServiceAsPromised; | ||
|
||
constructor(blobService = new BlobServiceAsPromised()) { | ||
this.#blobService = blobService; | ||
} | ||
|
||
public async createStorageIfNotExists() { | ||
await this.#blobService.createContainerIfNotExists( | ||
RealTimeMutantsBlobService.CONTAINER_NAME, | ||
{} | ||
); | ||
} | ||
|
||
public async createReport(id: ReportIdentifier) { | ||
await this.#blobService.createAppendBlobFromText( | ||
RealTimeMutantsBlobService.CONTAINER_NAME, | ||
toBlobName(id), | ||
'' | ||
); | ||
} | ||
|
||
public async appendToReport( | ||
id: ReportIdentifier, | ||
mutants: Array<Partial<MutantResult>> | ||
) { | ||
const blobName = toBlobName(id); | ||
const data = mutants | ||
.map((mutant) => `${JSON.stringify(mutant)}\n`) | ||
.join(''); | ||
|
||
await this.#blobService.appendBlockFromText( | ||
RealTimeMutantsBlobService.CONTAINER_NAME, | ||
blobName, | ||
data | ||
); | ||
} | ||
|
||
public async getReport( | ||
id: ReportIdentifier | ||
): Promise<Array<Partial<MutantResult>>> { | ||
const data = await this.#blobService.blobToText( | ||
RealTimeMutantsBlobService.CONTAINER_NAME, | ||
toBlobName(id) | ||
); | ||
|
||
if (data === '') { | ||
return []; | ||
} | ||
|
||
return ( | ||
data | ||
.split('\n') | ||
// Since every line has a newline it will produce an empty string in the list. | ||
// Remove it, so nothing breaks. | ||
.filter((row) => row !== '') | ||
.map((mutant) => JSON.parse(mutant)) | ||
); | ||
} | ||
|
||
public async delete(id: ReportIdentifier): Promise<void> { | ||
const blobName = toBlobName(id); | ||
this.#blobService.deleteBlobIfExists( | ||
RealTimeMutantsBlobService.CONTAINER_NAME, | ||
blobName | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.