Illustrate potential software catalog indexing.

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2021-02-15 17:36:45 +01:00
parent 3e2e3ffe4f
commit 3e9d8427b6
8 changed files with 96 additions and 3 deletions
+1
View File
@@ -41,6 +41,7 @@
"@backstage/plugin-rollbar-backend": "^0.1.8",
"@backstage/plugin-scaffolder-backend": "^0.9.2",
"@backstage/plugin-search-backend": "^0.1.1",
"@backstage/plugin-search-indexer-backend": "^0.1.1",
"@backstage/plugin-techdocs-backend": "^0.6.5",
"@backstage/plugin-todo-backend": "^0.1.1",
"@gitbeaker/node": "^28.0.2",
+2
View File
@@ -110,6 +110,8 @@ async function main() {
console.log(err);
process.exit(1);
});
// @todo Start Search Refresh Loop Here?
}
module.hot?.accept();
+8
View File
@@ -19,8 +19,10 @@ import {
CatalogBuilder,
createRouter,
runPeriodically,
SearchCollatorFactory,
} from '@backstage/plugin-catalog-backend';
import { Router } from 'express';
import { registerCollator } from '@backstage/plugin-search-indexer-backend';
import { PluginEnvironment } from '../types';
export default async function createPlugin(
@@ -39,6 +41,12 @@ export default async function createPlugin(
runPeriodically(() => higherOrderOperation.refreshAllLocations(), 100000),
);
registerCollator({
type: 'software-catalog',
defaultRefreshIntervalSeconds: 600,
collator: SearchCollatorFactory(entitiesCatalog),
});
return await createRouter({
entitiesCatalog,
locationsCatalog,
+1
View File
@@ -35,6 +35,7 @@
"@backstage/config": "^0.1.4",
"@backstage/errors": "^0.1.1",
"@backstage/integration": "^0.5.1",
"@backstage/plugin-search-indexer-backend": "^0.1.1",
"@octokit/graphql": "^4.5.8",
"@types/express": "^4.17.6",
"@types/ldapjs": "^1.0.9",
+1
View File
@@ -17,5 +17,6 @@
export * from './catalog';
export * from './database';
export * from './ingestion';
export * from './search';
export * from './service';
export * from './util';
@@ -0,0 +1,51 @@
/*
* Copyright 2021 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
IndexableDocument,
IndexableDocumentCollator,
} from '@backstage/plugin-search-indexer-backend';
import { EntitiesCatalog } from '../catalog';
import { EntityFilters } from '../service/EntityFilters';
export interface CatalogEntityDocument extends IndexableDocument {
componentType: string;
}
export const SearchCollatorFactory = (
entitiesCatalog: EntitiesCatalog,
): IndexableDocumentCollator => {
return async (): Promise<IndexableDocument[]> => {
const filter = EntityFilters.ofQuery({ kind: 'Component' });
const entities = await entitiesCatalog.entities(filter);
return entities.map(
(entity): CatalogEntityDocument => {
return {
title: entity.metadata.name,
location: `/catalog/${
entity.metadata.namespace || 'default'
}/component/${entity.metadata.name}`,
text: entity.metadata.description || '',
componentType: entity.spec?.type?.toString() || 'other',
...(entity.spec?.owner && { owner: entity.spec.owner.toString() }),
...(entity.metadata.lifecycle && {
lifecycle: entity.metadata.lifecycle.toString(),
}),
};
},
);
};
};
@@ -0,0 +1,17 @@
/*
* Copyright 2021 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './Collator';
+15 -3
View File
@@ -15,9 +15,21 @@
*/
import { Registry } from './registry';
import {
RegisterCollatorParameters,
RegisterDecoratorParameters,
} from './types';
const registry = Registry.getInstance();
export const registerCollator = registry.addCollator;
export const registerDecorator = registry.addDecorator;
export const registerCollator = (params: RegisterCollatorParameters) => {
registry.addCollator(params);
};
export const registerDecorator = (params: RegisterDecoratorParameters) => {
registry.addDecorator(params);
};
export type { IndexableDocument } from './types';
export type {
IndexableDocument,
IndexableDocumentCollator,
IndexableDocumentDecorator,
} from './types';