backstage / community-plugins

Community plugins for Backstage
Apache License 2.0
111 stars 80 forks source link

πŸ› ADR: new backend system support #515

Open moreiramarti opened 1 month ago

moreiramarti commented 1 month ago

Plugin Name

ADR

πŸ“œ Description

I'm using the new backend system and I'm struggling to set up ADR search. It looks like adr type is not recognized. Backstage version : 1.27.5 ADR version : 0.4.17

πŸ‘ Expected behavior

Search for ADRs in catalog

πŸ‘Ž Actual Behavior with Screenshots

image

πŸ‘Ÿ Reproduction steps

Install ADR plugin with new backend system : Add menu on packages/app/src/components/search/SearchPage.tsx

  return (
    <Page themeId="home">
      <Header title="Search" />
      <Content>
        <Grid container direction="row">
          <Grid item xs={12}>
            <Paper className={classes.bar}>
              <SearchBar />
            </Paper>
          </Grid>
          <Grid item xs={3}>
            <SearchType.Accordion
              name="Result Type"
              defaultValue="software-catalog"
              types={[
                {
                  value: 'software-catalog',
                  name: 'Software Catalog',
                  icon: <CatalogIcon />,
                },
                {
                  value: 'techdocs',
                  name: 'Documentation',
                  icon: <DocsIcon />,
                },
                {
                  value: 'adr',
                  name: 'Architecture Decision Records',
                  icon: <DocsIcon />,
                },
              ]}
            />
...
            <SearchResult>
              <CatalogSearchResultListItem icon={<CatalogIcon />} />
              <TechDocsSearchResultListItem icon={<DocsIcon />} />
              <AdrSearchResultListItem icon={<DocsIcon />} />
            </SearchResult>

πŸ“ƒ Provide the context for the Bug.

No response

πŸ‘€ Have you spent some time to check if this bug has been raised before?

🏒 Have you read the Code of Conduct?

Are you willing to submit PR?

None

kuangp commented 4 weeks ago

Could you also share what your backend search setup looks like to confirm if the ADR search collator is correctly hooked up there?

moreiramarti commented 4 weeks ago

If you meant packages/backend/src/index.ts, here it is :

import { createBackend } from '@backstage/backend-defaults';
import { dbtPlugin } from '@iiben_orgii/backstage-plugin-dbt-backend';

const backend = createBackend();

backend.add(import('@backstage/plugin-app-backend/alpha'));
backend.add(import('@backstage/plugin-proxy-backend/alpha'));
backend.add(import('@backstage/plugin-scaffolder-backend/alpha'));
backend.add(import('@backstage/plugin-techdocs-backend/alpha'));
backend.add(import('@roadiehq/scaffolder-backend-module-utils/new-backend'));

// auth plugin
backend.add(import('@backstage/plugin-auth-backend'));
backend.add(import('@backstage/plugin-auth-backend-module-github-provider'));
// See https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin
backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
// See https://github.com/backstage/backstage/blob/master/docs/auth/guest/provider.md

// catalog plugin
backend.add(import('@backstage/plugin-catalog-backend/alpha'));
backend.add(
  import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'),
);
backend.add(import('@backstage/plugin-scaffolder-backend-module-github'));
backend.add(import('@backstage/plugin-catalog-backend-module-github/alpha'));
backend.add(import('@backstage/plugin-catalog-backend-module-github-org'));

// adr plugin
backend.add(import('@backstage-community/plugin-adr-backend'));

// permission plugin
backend.add(import('@backstage/plugin-permission-backend/alpha'));
backend.add(
  import('@backstage/plugin-permission-backend-module-allow-all-policy'),
);

// search plugin
backend.add(import('@backstage/plugin-search-backend/alpha'));
backend.add(import('@backstage/plugin-search-backend-module-pg/alpha'));
backend.add(import('@backstage/plugin-search-backend-module-catalog/alpha'));
backend.add(import('@backstage/plugin-search-backend-module-techdocs/alpha'));

backend.start();
kuangp commented 4 weeks ago

It looks like you don't have the ADR search collator hooked up to your search backend - unfortunately there currently isn't a search backend module for ADR that you can dynamically install like there is for the catalog/techdocs collators eg. backend.add(import('@backstage/plugin-search-backend-module-adr'));. Open for contributions though if you would like to implement one πŸ˜„

Right now you can manually add your own search module like so to hook up the ADR collator:

// backend/src/searchBackendModuleAdr.ts
import { cacheToPluginCacheManager } from '@backstage/backend-common';
import {
  coreServices,
  createBackendModule,
} from '@backstage/backend-plugin-api';
import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha';
import { DefaultAdrCollatorFactory } from '@backstage-community/plugin-adr-backend';

export default createBackendModule({
  pluginId: 'search',
  moduleId: 'adrCollator',
  register(env) {
    env.registerInit({
      deps: {
        auth: coreServices.auth,
        cache: coreServices.cache,
        config: coreServices.rootConfig,
        discovery: coreServices.discovery,
        logger: coreServices.logger,
        reader: coreServices.urlReader,
        scheduler: coreServices.scheduler,
        search: searchIndexRegistryExtensionPoint,
      },
      async init({
        auth,
        cache,
        config,
        discovery,
        logger,
        reader,
        scheduler,
        search,
      }) {
        search.addCollator({
          schedule: scheduler.createScheduledTaskRunner({
            // Customize this schedule as you see fit
            frequency: { hours: 12 },
            timeout: { minutes: 30 },
            initialDelay: { minutes: 1 },
          }),
          factory: DefaultAdrCollatorFactory.fromConfig({
            auth,
            cache: cacheToPluginCacheManager(cache),
            config,
            discovery,
            logger,
            reader,
          }),
        });
      },
    });
  },
});

and add it to your backend:

// backend/src/index.ts
...
backend.add(import('./searchBackendModuleAdr'));
...
moreiramarti commented 4 weeks ago

Thanks, that's what I though. I'll try to implement it if I manage to find some time ;)

vinzscam commented 4 weeks ago

Help wanted for creating the new module!

cftad commented 2 weeks ago

Related PR: #549