Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new backend support #15

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

Ryangr0
Copy link

@Ryangr0 Ryangr0 commented Dec 10, 2024

📝 Description

As discussed in #12, following the documentation does not lead to a working instance of this plugin, when you use the latest version of Backstage. I've created this PR as a draft to hopefully start collaboration on working on a solution for this. I will document below a small list of steps I've done to get Backstage to load the plugin.

  1. Place the plugins/library-check-backend directory into your Backstage's plugins/library-check-backend
  2. Place the following in your Backstage's packages/backend/src/index.ts
import {catalogProcessingExtensionPoint} from "@backstage/plugin-catalog-node/alpha";
import {loggerToWinstonLogger} from '@backstage/backend-common';
import {LibraryCheckProcessor, LibraryCheckUpdaterProcessor} from "../../../plugins/library-check-backend";
const libraryCheckModule = createBackendModule({
    pluginId: 'catalog',
    moduleId: 'library-check',
    register(env) {
        env.registerInit({
            deps: {
                catalog: catalogProcessingExtensionPoint,
                logger: coreServices.logger,
                scheduler: coreServices.scheduler,
                reader: coreServices.urlReader,
                discovery: coreServices.discovery,
                config: coreServices.rootConfig,
            },
            async init({ catalog, logger, scheduler, reader, discovery, config}) {

                const defaultSchedule = {
                    initialDelay: { seconds: 15 },
                    frequency: { minutes: 10 },
                    timeout: { minutes: 15 },
                };
                scheduler.createScheduledTaskRunner(defaultSchedule);

                const winstonLogger = loggerToWinstonLogger(logger);
                
                catalog.addProcessor(
                  LibraryCheckProcessor.fromConfig(
                    config,
                    {
                        reader: reader,
                        discoveryService: discovery,
                        logger: winstonLogger
                    }
                  )
                );
                catalog.addProcessor(
                  LibraryCheckUpdaterProcessor.fromConfig(
                    config,
                    {
                        reader: reader,
                        discoveryService: discovery,
                        logger: winstonLogger
                    }
                  )
                );
            },
        });
    },
});
backend.add(libraryCheckModule);

** THIS IS NOT A FULLY WORKING IMPLEMENTATION AT THIS POINT **
When I run backstage, and the "import" of all the library files starts, everything seems to fail.
A small excerpt of the logs that indicate failure:

backstage-application  | {"level":"info","message":"LibraryCheckProcessor: Saved entity metadata libraries on database","plugin":"catalog","service":"***"}
backstage-application  | {"level":"info","message":"[10/Dec/2024:06:38:56 +0000] \"POST /api/library-check/libraries HTTP/1.1\" 404 - \"-\" \"axios/1.7.8\"","service":"rootHttpRouter","type":"incomingRequest"}                                                                                                                               
backstage-application  | {"level":"info","message":"LibraryCheckProcessor: Descriptor files found at https://github.com/webgrip/github-webhook-observer/tree/main/**/requirements.txt","plugin":"catalog","service":"***"}                                                                                                                      
backstage-application  | {"level":"info","message":"LibraryCheckProcessor: Descriptor files found at https://github.com/webgrip/github-webhook-observer/tree/main/**/package.json","plugin":"catalog","service":"***"}                                                                                                                          
backstage-application  | {"level":"info","message":"LibraryCheckProcessor: Saved entity metadata libraries on database","plugin":"catalog","service":"***"}
backstage-application  | LibraryCheckService: Error trying to save libraries on database                                                                                
backstage-application  | {"level":"info","message":"[10/Dec/2024:06:38:56 +0000] \"POST /api/library-check/libraries/search HTTP/1.1\" 404 - \"-\" \"axios/1.7.8\"","service":"rootHttpRouter","type":"incomingRequest"}
backstage-application  | {"level":"info","message":"LibraryCheckProcessor: Saved entity metadata libraries on database","plugin":"catalog","service":"***"}
backstage-application  | {"level":"info","message":"LibraryCheckProcessor: Saved entity metadata libraries on database","plugin":"catalog","service":"***"}             
backstage-application  | {"level":"info","message":"LibraryCheckProcessor: Descriptor files found at https://github.com/webgrip/***-application/tree/main/**/package.json","plugin":"catalog","service":"***"}                                                                                                                                  
backstage-application  | LibraryCheckService: Error trying to search for libraries on database
backstage-application  | {"level":"info","message":"[10/Dec/2024:06:38:56 +0000] \"POST /api/library-check/libraries HTTP/1.1\" 404 - \"-\" \"axios/1.7.8\"","service":"rootHttpRouter","type":"incomingRequest"}                                                                                                                               
backstage-application  | {"level":"info","message":"[10/Dec/2024:06:38:56 +0000] \"POST /api/library-check/libraries-updates HTTP/1.1\" 404 - \"-\" \"axios/1.7.8\"","service":"rootHttpRouter","type":"incomingRequest"}                                                                                                                       
backstage-application  | {"level":"info","message":"[10/Dec/2024:06:38:56 +0000] \"POST /api/library-check/libraries HTTP/1.1\" 404 - \"-\" \"axios/1.7.8\"","service":"rootHttpRouter","type":"incomingRequest"}
backstage-application  | LibraryCheckService: Error trying to save libraries on database
backstage-application  | LibraryCheckService: Error trying to update libraries occurrences records on entities_libraries table AxiosError: Request failed with status code 404 

⛳️ Current behavior

Supports old backend

🚀 New behavior

Supports new backend

💣 Is this a breaking change (Yes/No):

Not sure yet, probably yes.

📝 Additional Information

I would like some help on this. I'm unfamiliar with the changes that one needs to make to migrate a backstage plugin to the new backend. It's been a slow process of trial and error so far. I'd like to leverage other people's expertise on the matter and hopefully start of a discussion on how this should be done.

Checklist

  • Have you written tests for your changes?
  • Have you successfully ran tests with your changes locally?
  • Have you lint your code locally prior to submission?
  • Have you updated the plugin documentation with the changes?

Copy link

changeset-bot bot commented Dec 10, 2024

⚠️ No Changeset found

Latest commit: 4c9449a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant