catalog-backend: inline synthetic load test module

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-08-10 11:25:53 +02:00
parent 999376ee01
commit b8d6b22acd
3 changed files with 38 additions and 35 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Internal refactor for load test
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { createBackendModule } from '@backstage/backend-plugin-api';
import { Entity } from '@backstage/catalog-model';
import { LocationSpec } from '@backstage/plugin-catalog-common';
import {
@@ -26,7 +25,6 @@ import {
EntityProviderConnection,
processingResult,
} from '@backstage/plugin-catalog-node';
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';
/**
* Options for a fixed initial load of entities.
@@ -143,12 +141,15 @@ export const common = {
/**
* The entity provider that drives the initial base entity injection
* @internal
*/
class SyntheticLoadEntitiesProvider implements EntityProvider {
export class SyntheticLoadEntitiesProvider implements EntityProvider {
constructor(
private readonly load: SyntheticLoadOptions,
private readonly events: SyntheticLoadEvents,
) {}
) {
validateSyntheticLoadOptions(load);
}
getProviderName(): string {
return 'SyntheticLoadEntitiesProvider';
@@ -180,9 +181,12 @@ class SyntheticLoadEntitiesProvider implements EntityProvider {
/**
* Supporting processor for emitting children and relations
* @internal
*/
class SyntheticLoadEntitiesProcessor implements CatalogProcessor {
constructor(private readonly load: SyntheticLoadOptions) {}
export class SyntheticLoadEntitiesProcessor implements CatalogProcessor {
constructor(private readonly load: SyntheticLoadOptions) {
validateSyntheticLoadOptions(load);
}
getProcessorName(): string {
return 'SyntheticLoadEntitiesProcessor';
@@ -231,27 +235,3 @@ class SyntheticLoadEntitiesProcessor implements CatalogProcessor {
return entity;
}
}
export const catalogModuleSyntheticLoadEntities = createBackendModule(
(options: { load: SyntheticLoadOptions; events?: SyntheticLoadEvents }) => ({
moduleId: 'syntheticLoadEntities',
pluginId: 'catalog',
register(reg) {
reg.registerInit({
deps: {
catalog: catalogProcessingExtensionPoint,
},
async init({ catalog }) {
const { load, events = {} } = options;
validateSyntheticLoadOptions(load);
const provider = new SyntheticLoadEntitiesProvider(load, events);
const processor = new SyntheticLoadEntitiesProcessor(load);
catalog.addEntityProvider(provider);
catalog.addProcessor(processor);
},
});
},
}),
);
@@ -16,16 +16,19 @@
import {
coreServices,
createBackendModule,
createServiceFactory,
} from '@backstage/backend-plugin-api';
import { TestDatabases, startTestBackend } from '@backstage/backend-test-utils';
import { catalogPlugin } from '@backstage/plugin-catalog-backend/alpha';
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';
import { Knex } from 'knex';
import { applyDatabaseMigrations } from '../../database/migrations';
import {
SyntheticLoadEvents,
SyntheticLoadOptions,
catalogModuleSyntheticLoadEntities,
SyntheticLoadEntitiesProvider,
SyntheticLoadEntitiesProcessor,
} from './lib/catalogModuleSyntheticLoadEntities';
import { describePerformanceTest, performanceTraceEnabled } from './lib/env';
@@ -180,10 +183,25 @@ describePerformanceTest('stitchingPerformance', () => {
services: [staticDatabase(knex)],
features: [
catalogPlugin(),
catalogModuleSyntheticLoadEntities({
load,
events: tracker.events(),
}),
createBackendModule({
moduleId: 'syntheticLoadEntities',
pluginId: 'catalog',
register(reg) {
reg.registerInit({
deps: {
catalog: catalogProcessingExtensionPoint,
},
async init({ catalog }) {
catalog.addEntityProvider(
new SyntheticLoadEntitiesProvider(load, tracker.events()),
);
catalog.addProcessor(
new SyntheticLoadEntitiesProcessor(load),
);
},
});
},
})(),
],
});