catalog-backend-module-incremental-ingestion: move providers to extension point instead of options
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend-module-incremental-ingestion': patch
|
||||
---
|
||||
|
||||
Export new alpha `incrementalIngestionProvidersExtensionPoint` for registering incremental providers, rather than the providers being passed as options to the backend module.
|
||||
@@ -4,16 +4,23 @@
|
||||
|
||||
```ts
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { IncrementalEntityProvider } from '@backstage/plugin-catalog-backend-module-incremental-ingestion';
|
||||
import { IncrementalEntityProviderOptions } from '@backstage/plugin-catalog-backend-module-incremental-ingestion';
|
||||
|
||||
// @alpha
|
||||
export const catalogModuleIncrementalIngestionEntityProvider: (options: {
|
||||
providers: {
|
||||
provider: IncrementalEntityProvider<unknown, unknown>;
|
||||
export const catalogModuleIncrementalIngestionEntityProvider: () => BackendFeature;
|
||||
|
||||
// @alpha
|
||||
export interface IncrementalIngestionProviderExtensionPoint {
|
||||
addProvider<TCursor, TContext>(config: {
|
||||
options: IncrementalEntityProviderOptions;
|
||||
}[];
|
||||
}) => BackendFeature;
|
||||
provider: IncrementalEntityProvider<TCursor, TContext>;
|
||||
}): void;
|
||||
}
|
||||
|
||||
// @alpha
|
||||
export const incrementalIngestionProvidersExtensionPoint: ExtensionPoint<IncrementalIngestionProviderExtensionPoint>;
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
```
|
||||
|
||||
+27
-13
@@ -15,12 +15,18 @@
|
||||
*/
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { coreServices } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { startTestBackend } from '@backstage/backend-test-utils';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';
|
||||
import { IncrementalEntityProvider } from '../types';
|
||||
import { catalogModuleIncrementalIngestionEntityProvider } from './catalogModuleIncrementalIngestionEntityProvider';
|
||||
import {
|
||||
catalogModuleIncrementalIngestionEntityProvider,
|
||||
incrementalIngestionProvidersExtensionPoint,
|
||||
} from './catalogModuleIncrementalIngestionEntityProvider';
|
||||
|
||||
describe('catalogModuleIncrementalIngestionEntityProvider', () => {
|
||||
it('should register provider at the catalog extension point', async () => {
|
||||
@@ -57,18 +63,26 @@ describe('catalogModuleIncrementalIngestionEntityProvider', () => {
|
||||
[coreServices.scheduler, scheduler],
|
||||
],
|
||||
features: [
|
||||
catalogModuleIncrementalIngestionEntityProvider({
|
||||
providers: [
|
||||
{
|
||||
provider: provider1,
|
||||
options: {
|
||||
burstInterval: { seconds: 1 },
|
||||
burstLength: { seconds: 1 },
|
||||
restLength: { seconds: 1 },
|
||||
catalogModuleIncrementalIngestionEntityProvider(),
|
||||
createBackendModule({
|
||||
pluginId: 'catalog',
|
||||
moduleId: 'incrementalTest',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: { extension: incrementalIngestionProvidersExtensionPoint },
|
||||
async init({ extension }) {
|
||||
extension.addProvider({
|
||||
provider: provider1,
|
||||
options: {
|
||||
burstInterval: { seconds: 1 },
|
||||
burstLength: { seconds: 1 },
|
||||
restLength: { seconds: 1 },
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
},
|
||||
})(),
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
+95
-40
@@ -17,6 +17,7 @@
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
createExtensionPoint,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';
|
||||
import {
|
||||
@@ -25,56 +26,110 @@ import {
|
||||
} from '@backstage/plugin-catalog-backend-module-incremental-ingestion';
|
||||
import { WrapperProviders } from './WrapperProviders';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
* Interface for {@link incrementalIngestionProvidersExtensionPoint}.
|
||||
*/
|
||||
export interface IncrementalIngestionProviderExtensionPoint {
|
||||
/** Adds a new incremental entity provider */
|
||||
addProvider<TCursor, TContext>(config: {
|
||||
options: IncrementalEntityProviderOptions;
|
||||
provider: IncrementalEntityProvider<TCursor, TContext>;
|
||||
}): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*
|
||||
* Extension point for registering incremental ingestion providers.
|
||||
* The `catalogModuleIncrementalIngestionEntityProvider` must be installed for these providers to work.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* backend.add(createBackendModule({
|
||||
* pluginId: 'catalog',
|
||||
* register(env) {
|
||||
* env.registerInit({
|
||||
* deps: {
|
||||
* extension: incrementalIngestionProvidersExtensionPoint,
|
||||
* },
|
||||
* async init({ extension }) {
|
||||
* extension.addProvider({
|
||||
* burstInterval: ...,
|
||||
* burstLength: ...,
|
||||
* restLength: ...,
|
||||
* }, {
|
||||
* next(context, cursor) {
|
||||
* ...
|
||||
* },
|
||||
* ...
|
||||
* })
|
||||
* })
|
||||
* })
|
||||
* }
|
||||
* }))
|
||||
* ```
|
||||
*/
|
||||
export const incrementalIngestionProvidersExtensionPoint =
|
||||
createExtensionPoint<IncrementalIngestionProviderExtensionPoint>({
|
||||
id: 'catalog.incrementalIngestionProvider.providers',
|
||||
});
|
||||
|
||||
/**
|
||||
* Registers the incremental entity provider with the catalog processing extension point.
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export const catalogModuleIncrementalIngestionEntityProvider =
|
||||
createBackendModule(
|
||||
(options: {
|
||||
providers: Array<{
|
||||
createBackendModule({
|
||||
pluginId: 'catalog',
|
||||
moduleId: 'incrementalIngestionEntityProvider',
|
||||
register(env) {
|
||||
const addedProviders = new Array<{
|
||||
provider: IncrementalEntityProvider<unknown, unknown>;
|
||||
options: IncrementalEntityProviderOptions;
|
||||
}>;
|
||||
}) => ({
|
||||
pluginId: 'catalog',
|
||||
moduleId: 'incrementalIngestionEntityProvider',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
catalog: catalogProcessingExtensionPoint,
|
||||
config: coreServices.rootConfig,
|
||||
database: coreServices.database,
|
||||
httpRouter: coreServices.httpRouter,
|
||||
logger: coreServices.logger,
|
||||
scheduler: coreServices.scheduler,
|
||||
},
|
||||
async init({
|
||||
catalog,
|
||||
}>();
|
||||
|
||||
env.registerExtensionPoint(incrementalIngestionProvidersExtensionPoint, {
|
||||
addProvider({ options, provider }) {
|
||||
addedProviders.push({ options, provider });
|
||||
},
|
||||
});
|
||||
|
||||
env.registerInit({
|
||||
deps: {
|
||||
catalog: catalogProcessingExtensionPoint,
|
||||
config: coreServices.rootConfig,
|
||||
database: coreServices.database,
|
||||
httpRouter: coreServices.httpRouter,
|
||||
logger: coreServices.logger,
|
||||
scheduler: coreServices.scheduler,
|
||||
},
|
||||
async init({
|
||||
catalog,
|
||||
config,
|
||||
database,
|
||||
httpRouter,
|
||||
logger,
|
||||
scheduler,
|
||||
}) {
|
||||
const client = await database.getClient();
|
||||
|
||||
const providers = new WrapperProviders({
|
||||
config,
|
||||
database,
|
||||
httpRouter,
|
||||
logger,
|
||||
client,
|
||||
scheduler,
|
||||
}) {
|
||||
const client = await database.getClient();
|
||||
});
|
||||
|
||||
const providers = new WrapperProviders({
|
||||
config,
|
||||
logger,
|
||||
client,
|
||||
scheduler,
|
||||
});
|
||||
for (const entry of addedProviders) {
|
||||
const wrapped = providers.wrap(entry.provider, entry.options);
|
||||
catalog.addEntityProvider(wrapped);
|
||||
}
|
||||
|
||||
for (const entry of options.providers) {
|
||||
const wrapped = providers.wrap(entry.provider, entry.options);
|
||||
catalog.addEntityProvider(wrapped);
|
||||
}
|
||||
|
||||
httpRouter.use(await providers.adminRouter());
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
httpRouter.use(await providers.adminRouter());
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -14,4 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { catalogModuleIncrementalIngestionEntityProvider } from './catalogModuleIncrementalIngestionEntityProvider';
|
||||
export {
|
||||
catalogModuleIncrementalIngestionEntityProvider,
|
||||
incrementalIngestionProvidersExtensionPoint,
|
||||
type IncrementalIngestionProviderExtensionPoint,
|
||||
} from './catalogModuleIncrementalIngestionEntityProvider';
|
||||
|
||||
@@ -20,12 +20,16 @@
|
||||
import { createBackend } from '@backstage/backend-defaults';
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
createServiceFactory,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { catalogPlugin } from '@backstage/plugin-catalog-backend/alpha';
|
||||
import { IncrementalEntityProvider } from '.';
|
||||
import { catalogModuleIncrementalIngestionEntityProvider } from './alpha';
|
||||
import {
|
||||
catalogModuleIncrementalIngestionEntityProvider,
|
||||
incrementalIngestionProvidersExtensionPoint,
|
||||
} from './alpha';
|
||||
|
||||
const provider: IncrementalEntityProvider<number, {}> = {
|
||||
getProviderName: () => 'test-provider',
|
||||
@@ -62,19 +66,27 @@ async function main() {
|
||||
});
|
||||
|
||||
backend.add(catalogPlugin());
|
||||
backend.add(catalogModuleIncrementalIngestionEntityProvider());
|
||||
backend.add(
|
||||
catalogModuleIncrementalIngestionEntityProvider({
|
||||
providers: [
|
||||
{
|
||||
provider: provider,
|
||||
options: {
|
||||
burstInterval: { seconds: 1 },
|
||||
burstLength: { seconds: 10 },
|
||||
restLength: { seconds: 10 },
|
||||
createBackendModule({
|
||||
pluginId: 'catalog',
|
||||
moduleId: 'incrementalTestProvider',
|
||||
register(reg) {
|
||||
reg.registerInit({
|
||||
deps: { extension: incrementalIngestionProvidersExtensionPoint },
|
||||
async init({ extension }) {
|
||||
extension.addProvider({
|
||||
provider: provider,
|
||||
options: {
|
||||
burstInterval: { seconds: 1 },
|
||||
burstLength: { seconds: 10 },
|
||||
restLength: { seconds: 10 },
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
},
|
||||
})(),
|
||||
);
|
||||
|
||||
await backend.start();
|
||||
|
||||
Reference in New Issue
Block a user