Expose catalogFactRetriever & configure in backend

Signed-off-by: Iain Billett <iain@roadie.io>
This commit is contained in:
Iain Billett
2021-11-15 18:27:48 +00:00
parent 5b31874a76
commit d4a3dbb75b
5 changed files with 40 additions and 49 deletions
+5 -36
View File
@@ -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: [