Skip to content

Commit

Permalink
Add Tech Insights plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
timosalm committed Dec 7, 2023
1 parent 421a585 commit 2ab19d6
Show file tree
Hide file tree
Showing 6 changed files with 710 additions and 2 deletions.
1 change: 1 addition & 0 deletions oss-backstage/packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@backstage/plugin-scaffolder": "^1.15.1",
"@backstage/plugin-search": "^1.4.1",
"@backstage/plugin-search-react": "^1.7.1",
"@backstage/plugin-tech-insights": "^0.3.19",
"@backstage/plugin-tech-radar": "^0.6.9",
"@backstage/plugin-techdocs": "^1.8.0",
"@backstage/plugin-techdocs-module-addons-contrib": "^1.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
RELATION_PART_OF,
RELATION_PROVIDES_API,
} from '@backstage/catalog-model';
import { EntityTechInsightsScorecardContent } from '@backstage/plugin-tech-insights';

import { TechDocsAddons } from '@backstage/plugin-techdocs-react';
import { ReportIssue } from '@backstage/plugin-techdocs-module-addons-contrib';
Expand Down Expand Up @@ -180,6 +181,13 @@ const serviceEntityPage = (
<EntityLayout.Route path="/kubernetes" title="Kubernetes">
<EntityKubernetesContent refreshIntervalMs={30000} />
</EntityLayout.Route>

<EntityLayout.Route path="/tech-insights" title="TechInsights">
<EntityTechInsightsScorecardContent
title="TechInsights Scorecard"
description="TechInsight's default fact-checkers"
/>
</EntityLayout.Route>
</EntityLayout>
);

Expand Down
2 changes: 2 additions & 0 deletions oss-backstage/packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@backstage/plugin-search-backend": "^1.4.6",
"@backstage/plugin-search-backend-module-pg": "^0.5.15",
"@backstage/plugin-search-backend-node": "^1.2.10",
"@backstage/plugin-tech-insights-backend": "^0.5.21",
"@backstage/plugin-tech-insights-backend-module-jsonfc": "^0.1.39",
"@backstage/plugin-techdocs-backend": "^1.8.0",
"app": "link:../app",
"better-sqlite3": "^8.0.0",
Expand Down
3 changes: 3 additions & 0 deletions oss-backstage/packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { PluginEnvironment } from './types';
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
import kubernetes from './plugins/kubernetes';
import techInsights from './plugins/techInsights';

function makeCreateEnv(config: Config) {
const root = getRootLogger();
Expand Down Expand Up @@ -87,6 +88,7 @@ async function main() {
const searchEnv = useHotMemoize(module, () => createEnv('search'));
const appEnv = useHotMemoize(module, () => createEnv('app'));
const kubernetesEnv = useHotMemoize(module, () => createEnv('kubernetes'));
const techInsightsEnv = useHotMemoize(module, () => createEnv('tech_insights'));


const apiRouter = Router();
Expand All @@ -97,6 +99,7 @@ async function main() {
apiRouter.use('/proxy', await proxy(proxyEnv));
apiRouter.use('/search', await search(searchEnv));
apiRouter.use('/kubernetes', await kubernetes(kubernetesEnv));
apiRouter.use('/tech-insights', await techInsights(techInsightsEnv));
// Add backends ABOVE this line; this 404 handler is the catch-all fallback
apiRouter.use(notFoundHandler());

Expand Down
114 changes: 114 additions & 0 deletions oss-backstage/packages/backend/src/plugins/techInsights.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import {
createRouter,
buildTechInsightsContext,
createFactRetrieverRegistration,
entityOwnershipFactRetriever,
entityMetadataFactRetriever,
techdocsFactRetriever,
} from '@backstage/plugin-tech-insights-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import {
JsonRulesEngineFactCheckerFactory,
JSON_RULE_ENGINE_CHECK_TYPE,
} from '@backstage/plugin-tech-insights-backend-module-jsonfc';

const ttlTwoWeeks = { timeToLive: { weeks: 2 } };

export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const techInsightsContext = await buildTechInsightsContext({
logger: env.logger,
config: env.config,
database: env.database,
discovery: env.discovery,
tokenManager: env.tokenManager,
scheduler: env.scheduler,
factRetrievers: [
createFactRetrieverRegistration({
cadence: '0 */6 * * *', // Run every 6 hours - https://crontab.guru/#0_*/6_*_*_*
factRetriever: entityOwnershipFactRetriever,
lifecycle: ttlTwoWeeks,
}),
createFactRetrieverRegistration({
cadence: '0 */6 * * *',
factRetriever: entityMetadataFactRetriever,
lifecycle: ttlTwoWeeks,
}),
createFactRetrieverRegistration({
cadence: '0 */6 * * *',
factRetriever: techdocsFactRetriever,
lifecycle: ttlTwoWeeks,
}),
],
factCheckerFactory: new JsonRulesEngineFactCheckerFactory({
logger: env.logger,
checks: [
{
id: 'groupOwnerCheck',
type: JSON_RULE_ENGINE_CHECK_TYPE,
name: 'Group Owner Check',
description:
'Verifies that a Group has been set as the owner for this entity',
factIds: ['entityOwnershipFactRetriever'],
rule: {
conditions: {
all: [
{
fact: 'hasGroupOwner',
operator: 'equal',
value: true,
},
],
},
},
},
{
id: 'titleCheck',
type: JSON_RULE_ENGINE_CHECK_TYPE,
name: 'Title Check',
description:
'Verifies that a Title, used to improve readability, has been set for this entity',
factIds: ['entityMetadataFactRetriever'],
rule: {
conditions: {
all: [
{
fact: 'hasTitle',
operator: 'equal',
value: true,
},
],
},
},
},
{
id: 'techDocsCheck',
type: JSON_RULE_ENGINE_CHECK_TYPE,
name: 'TechDocs Check',
description:
'Verifies that TechDocs has been enabled for this entity',
factIds: ['techdocsFactRetriever'],
rule: {
conditions: {
all: [
{
fact: 'hasAnnotationBackstageIoTechdocsRef',
operator: 'equal',
value: true,
},
],
},
},
},
],
}),
});

return await createRouter({
...techInsightsContext,
logger: env.logger,
config: env.config,
});
}

0 comments on commit 2ab19d6

Please sign in to comment.