Expose catalogFactRetriever & configure in backend
Signed-off-by: Iain Billett <iain@roadie.io>
This commit is contained in:
@@ -17,10 +17,10 @@ import {
|
||||
createRouter,
|
||||
buildTechInsightsContext,
|
||||
createFactRetrieverRegistration,
|
||||
createCatalogFactRetriever,
|
||||
} from '@backstage/plugin-tech-insights-backend';
|
||||
import { Router } from 'express';
|
||||
import { PluginEnvironment } from '../types';
|
||||
import { CatalogClient } from '@backstage/catalog-client';
|
||||
import {
|
||||
JsonRulesEngineFactCheckerFactory,
|
||||
JSON_RULE_ENGINE_CHECK_TYPE,
|
||||
@@ -38,41 +38,10 @@ export default async function createPlugin({
|
||||
database,
|
||||
discovery,
|
||||
factRetrievers: [
|
||||
createFactRetrieverRegistration('5 4 * * 6', {
|
||||
// Example cron, At 04:05 on Saturday.
|
||||
id: 'testRetriever',
|
||||
version: '1.1.2',
|
||||
entityFilter: [{ kind: 'component' }], // EntityFilter to be used in the future (creating checks, graphs etc.) to figure out which entities this fact retrieves data for.
|
||||
schema: {
|
||||
examplenumberfact: {
|
||||
type: 'integer',
|
||||
description: 'Example fact returning a number',
|
||||
},
|
||||
},
|
||||
handler: async _ctx => {
|
||||
const catalogClient = new CatalogClient({
|
||||
discoveryApi: discovery,
|
||||
});
|
||||
const entities = await catalogClient.getEntities({
|
||||
filter: [{ kind: 'component' }],
|
||||
});
|
||||
|
||||
return Promise.resolve(
|
||||
entities.items.map(it => {
|
||||
return {
|
||||
entity: {
|
||||
namespace: it.metadata.namespace!!,
|
||||
kind: it.kind,
|
||||
name: it.metadata.name,
|
||||
},
|
||||
facts: {
|
||||
examplenumberfact: 2,
|
||||
},
|
||||
};
|
||||
}),
|
||||
);
|
||||
},
|
||||
}),
|
||||
createFactRetrieverRegistration(
|
||||
'* * * * *', // Example cron, every minute
|
||||
createCatalogFactRetriever(),
|
||||
),
|
||||
],
|
||||
factCheckerFactory: new JsonRulesEngineFactCheckerFactory({
|
||||
checks: [
|
||||
|
||||
Reference in New Issue
Block a user