From 8154b1d111f2d5b8bb67651f655b917e98634137 Mon Sep 17 00:00:00 2001 From: aramissennyeydd Date: Tue, 13 May 2025 17:42:44 -0400 Subject: [PATCH] clean up PR following review Signed-off-by: aramissennyeydd --- .../lib/DefaultSystemMetadataService.ts | 6 ++- .../lib/createSystemMetadataRouter.ts | 14 +++-- .../systemMetadataServiceFactory.ts | 3 +- .../backend-plugin-api/src/alpha/index.ts | 11 ---- .../definitions/SystemMetadataService.ts | 2 +- .../src/services/definitions/coreServices.ts | 11 ++++ packages/backend-split/.eslintrc.js | 1 - packages/backend-split/README.md | 8 --- packages/backend-split/app-config.split.yaml | 14 ----- packages/backend-split/catalog-info.yaml | 9 ---- packages/backend-split/package.json | 53 ------------------- .../src/experimental/features.http | 7 --- packages/backend-split/src/index.ts | 35 ------------ packages/backend-split/src/instrumentation.js | 34 ------------ packages/backend/app-config.split.yaml | 11 ---- packages/backend/package.json | 1 - yarn.lock | 31 ----------- 17 files changed, 26 insertions(+), 225 deletions(-) delete mode 100644 packages/backend-split/.eslintrc.js delete mode 100644 packages/backend-split/README.md delete mode 100644 packages/backend-split/app-config.split.yaml delete mode 100644 packages/backend-split/catalog-info.yaml delete mode 100644 packages/backend-split/package.json delete mode 100644 packages/backend-split/src/experimental/features.http delete mode 100644 packages/backend-split/src/index.ts delete mode 100644 packages/backend-split/src/instrumentation.js delete mode 100644 packages/backend/app-config.split.yaml diff --git a/packages/backend-defaults/src/entrypoints/systemMetadata/lib/DefaultSystemMetadataService.ts b/packages/backend-defaults/src/entrypoints/systemMetadata/lib/DefaultSystemMetadataService.ts index 0d1583a113..41fd4aa0a2 100644 --- a/packages/backend-defaults/src/entrypoints/systemMetadata/lib/DefaultSystemMetadataService.ts +++ b/packages/backend-defaults/src/entrypoints/systemMetadata/lib/DefaultSystemMetadataService.ts @@ -73,7 +73,9 @@ export class DefaultSystemMetadataService implements SystemMetadataService { return new DefaultSystemMetadataService(pluginEnv); } - async listInstances() { - return this.instances; + async introspect() { + return { + instances: this.instances, + }; } } diff --git a/packages/backend-defaults/src/entrypoints/systemMetadata/lib/createSystemMetadataRouter.ts b/packages/backend-defaults/src/entrypoints/systemMetadata/lib/createSystemMetadataRouter.ts index 66e1759213..6da27958c0 100644 --- a/packages/backend-defaults/src/entrypoints/systemMetadata/lib/createSystemMetadataRouter.ts +++ b/packages/backend-defaults/src/entrypoints/systemMetadata/lib/createSystemMetadataRouter.ts @@ -26,20 +26,24 @@ export async function createSystemMetadataRouter(options: { systemMetadata: SystemMetadataService; }) { const { logger, systemMetadata } = options; + + async function getInstances() { + const instances = await systemMetadata.introspect(); + return instances.instances; + } + logger.info( - `Instances in this system: ${JSON.stringify( - await systemMetadata.listInstances(), - )}`, + `Instances in this system: ${JSON.stringify(await getInstances())}`, ); const router = Router(); router.get('/instances', async (_, res) => { - res.json(await systemMetadata.listInstances()); + res.json(await getInstances()); }); router.get('/features/installed', async (_, res) => { - const instances = await systemMetadata.listInstances(); + const instances = await getInstances(); const featurePromises = await Promise.allSettled( instances.map(async instance => { const response = await fetch( diff --git a/packages/backend-defaults/src/entrypoints/systemMetadata/systemMetadataServiceFactory.ts b/packages/backend-defaults/src/entrypoints/systemMetadata/systemMetadataServiceFactory.ts index 2eaec11caa..929ea569d1 100644 --- a/packages/backend-defaults/src/entrypoints/systemMetadata/systemMetadataServiceFactory.ts +++ b/packages/backend-defaults/src/entrypoints/systemMetadata/systemMetadataServiceFactory.ts @@ -19,7 +19,6 @@ import { createServiceFactory, } from '@backstage/backend-plugin-api'; import { DefaultSystemMetadataService } from './lib/DefaultSystemMetadataService'; -import { systemMetadataServiceRef } from '@backstage/backend-plugin-api/alpha'; import { createSystemMetadataRouter } from './lib/createSystemMetadataRouter'; /** @@ -28,7 +27,7 @@ import { createSystemMetadataRouter } from './lib/createSystemMetadataRouter'; * @alpha */ export const systemMetadataServiceFactory = createServiceFactory({ - service: systemMetadataServiceRef, + service: coreServices.systemMetadataServiceRef, deps: { logger: coreServices.rootLogger, config: coreServices.rootConfig, diff --git a/packages/backend-plugin-api/src/alpha/index.ts b/packages/backend-plugin-api/src/alpha/index.ts index be5cb882fc..815b0ac8f9 100644 --- a/packages/backend-plugin-api/src/alpha/index.ts +++ b/packages/backend-plugin-api/src/alpha/index.ts @@ -26,17 +26,6 @@ export { actionsRegistryServiceRef, actionsServiceRef } from './refs'; import { createServiceRef } from '@backstage/backend-plugin-api'; -/** - * EXPERIMENTAL: System metadata service. - * @alpha - */ -export const systemMetadataServiceRef = createServiceRef< - import('./services/definitions/SystemMetadataService').SystemMetadataService ->({ - id: 'core.systemMetadata', - scope: 'root', -}); - export type { BackstageInstance, SystemMetadataService, diff --git a/packages/backend-plugin-api/src/services/definitions/SystemMetadataService.ts b/packages/backend-plugin-api/src/services/definitions/SystemMetadataService.ts index 20ce759679..ebbb07b25a 100644 --- a/packages/backend-plugin-api/src/services/definitions/SystemMetadataService.ts +++ b/packages/backend-plugin-api/src/services/definitions/SystemMetadataService.ts @@ -26,5 +26,5 @@ export interface BackstageInstance { * @alpha */ export interface SystemMetadataService { - listInstances(): Promise; + introspect(): Promise<{ instances: BackstageInstance[] }>; } diff --git a/packages/backend-plugin-api/src/services/definitions/coreServices.ts b/packages/backend-plugin-api/src/services/definitions/coreServices.ts index 887b05ee4e..ab3c4406d4 100644 --- a/packages/backend-plugin-api/src/services/definitions/coreServices.ts +++ b/packages/backend-plugin-api/src/services/definitions/coreServices.ts @@ -289,4 +289,15 @@ export namespace coreServices { id: 'core.rootInstanceMetadata', scope: 'root', }); + + /** + * Read information about your current Backstage deployment. + * @alpha + */ + export const systemMetadataServiceRef = createServiceRef< + import('./SystemMetadataService').SystemMetadataService + >({ + id: 'core.systemMetadata', + scope: 'root', + }); } diff --git a/packages/backend-split/.eslintrc.js b/packages/backend-split/.eslintrc.js deleted file mode 100644 index e2a53a6ad2..0000000000 --- a/packages/backend-split/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/packages/backend-split/README.md b/packages/backend-split/README.md deleted file mode 100644 index d5d2abe027..0000000000 --- a/packages/backend-split/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# example-backend - -This package is an EXAMPLE of a Backstage backend using the [new backend system](https://backstage.io/docs/backend-system/). - -The main purpose of this package is to provide a test bed for Backstage split deployment work. You can deploy both this package and the main `packages/backend` together by running the `start:split` command in both packages. This will run the following backends: - -1. `packages/backend` running on `:7007` with the default plugins installed. -2. `packages/backend-split` running on `:7008` with a subset of plugins installed for testing. diff --git a/packages/backend-split/app-config.split.yaml b/packages/backend-split/app-config.split.yaml deleted file mode 100644 index 80d77aaa3d..0000000000 --- a/packages/backend-split/app-config.split.yaml +++ /dev/null @@ -1,14 +0,0 @@ -backend: - baseUrl: http://localhost:7008 - listen: - port: 7008 - -discovery: - endpoints: - - target: http://localhost:7007/api/{{pluginId}} - plugins: [proxy] - - target: http://localhost:7008/api/{{pluginId}} - plugins: [catalog] - instances: - - baseUrl: http://localhost:7007 - - baseUrl: http://localhost:7008 diff --git a/packages/backend-split/catalog-info.yaml b/packages/backend-split/catalog-info.yaml deleted file mode 100644 index 8c81e9d5e9..0000000000 --- a/packages/backend-split/catalog-info.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: backstage.io/v1alpha1 -kind: Component -metadata: - name: example-backend-split - title: example-backend-split -spec: - lifecycle: experimental - type: backstage-backend - owner: maintainers diff --git a/packages/backend-split/package.json b/packages/backend-split/package.json deleted file mode 100644 index a517a8b49e..0000000000 --- a/packages/backend-split/package.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "example-backend-split", - "version": "0.0.1", - "backstage": { - "role": "backend" - }, - "private": true, - "keywords": [ - "backstage" - ], - "homepage": "https://backstage.io", - "repository": { - "type": "git", - "url": "https://github.com/backstage/backstage", - "directory": "packages/backend-split" - }, - "license": "Apache-2.0", - "main": "dist/index.cjs.js", - "types": "src/index.ts", - "files": [ - "dist" - ], - "scripts": { - "build": "backstage-cli package build", - "clean": "backstage-cli package clean", - "lint": "backstage-cli package lint", - "start": "backstage-cli package start --require ./src/instrumentation.js", - "start:split": "backstage-cli package start --require ./src/instrumentation.js --config ../../app-config.yaml --config app-config.split.yaml", - "test": "backstage-cli package test" - }, - "dependencies": { - "@backstage/backend-defaults": "workspace:^", - "@backstage/backend-plugin-api": "workspace:^", - "@backstage/catalog-model": "workspace:^", - "@backstage/plugin-catalog-backend": "workspace:^", - "@backstage/plugin-catalog-backend-module-backstage-openapi": "workspace:^", - "@backstage/plugin-catalog-backend-module-openapi": "workspace:^", - "@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "workspace:^", - "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^", - "@backstage/plugin-permission-backend": "workspace:^", - "@backstage/plugin-permission-backend-module-allow-all-policy": "workspace:^", - "@backstage/plugin-permission-common": "workspace:^", - "@backstage/plugin-permission-node": "workspace:^", - "@opentelemetry/auto-instrumentations-node": "^0.54.0", - "@opentelemetry/exporter-prometheus": "^0.54.0", - "@opentelemetry/sdk-node": "^0.54.0", - "example-app": "link:../app", - "express-promise-router": "^4.1.0" - }, - "devDependencies": { - "@backstage/cli": "workspace:^" - } -} diff --git a/packages/backend-split/src/experimental/features.http b/packages/backend-split/src/experimental/features.http deleted file mode 100644 index bb9287f61c..0000000000 --- a/packages/backend-split/src/experimental/features.http +++ /dev/null @@ -1,7 +0,0 @@ -// Test requests for the split backend to test the system metadata service :) -// The 2 below requests should return the same data. -GET http://localhost:7007/.backstage/systemMetadata/v1/features/installed - -### - -GET http://localhost:7008/.backstage/systemMetadata/v1/features/installed \ No newline at end of file diff --git a/packages/backend-split/src/index.ts b/packages/backend-split/src/index.ts deleted file mode 100644 index 2238713ffe..0000000000 --- a/packages/backend-split/src/index.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2022 The Backstage Authors - * - * 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 { createBackend } from '@backstage/backend-defaults'; -import { systemMetadataServiceFactory } from '@backstage/backend-defaults/alpha'; - -const backend = createBackend(); - -backend.add(import('@backstage/plugin-catalog-backend-module-unprocessed')); -backend.add( - import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'), -); -backend.add(import('@backstage/plugin-catalog-backend')); - -backend.add( - import('@backstage/plugin-permission-backend-module-allow-all-policy'), -); -backend.add(import('@backstage/plugin-permission-backend')); - -backend.add(systemMetadataServiceFactory); - -backend.start(); diff --git a/packages/backend-split/src/instrumentation.js b/packages/backend-split/src/instrumentation.js deleted file mode 100644 index e3725632c1..0000000000 --- a/packages/backend-split/src/instrumentation.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2024 The Backstage Authors - * - * 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. - */ - -const { NodeSDK } = require('@opentelemetry/sdk-node'); -const { - getNodeAutoInstrumentations, -} = require('@opentelemetry/auto-instrumentations-node'); -const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); - -// Expose opentelemetry metrics using a Prometheus exporter on -// http://localhost:9464/metrics. See packages/backend/prometheus.yml for -// more information on how to scrape it. -const prometheus = new PrometheusExporter(); - -const sdk = new NodeSDK({ - // traceExporter: ..., - metricReader: prometheus, - instrumentations: [getNodeAutoInstrumentations()], -}); - -sdk.start(); diff --git a/packages/backend/app-config.split.yaml b/packages/backend/app-config.split.yaml deleted file mode 100644 index 0eadc9f091..0000000000 --- a/packages/backend/app-config.split.yaml +++ /dev/null @@ -1,11 +0,0 @@ -discovery: - endpoints: - - target: http://localhost:7007/api/{{pluginId}} - plugins: [proxy] - - target: http://localhost:7008/api/{{pluginId}} - plugins: [catalog] - instances: - - baseUrl: http://localhost:7007 - - baseUrl: - internal: http://localhost:7008 - external: http://127.0.0.1:7008 diff --git a/packages/backend/package.json b/packages/backend/package.json index 8fd42507dd..2af36b8077 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -27,7 +27,6 @@ "lint": "backstage-cli package lint", "start": "backstage-cli package start --require ./src/instrumentation.js", "start:prometheus": "docker run --mount type=bind,source=./prometheus.yml,destination=/etc/prometheus/prometheus.yml --publish published=9090,target=9090,protocol=tcp prom/prometheus", - "start:split": "backstage-cli package start --require ./src/instrumentation.js --config ../../app-config.yaml --config app-config.split.yaml", "test": "backstage-cli package test" }, "dependencies": { diff --git a/yarn.lock b/yarn.lock index eec211526d..98c89bb0ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -30233,12 +30233,6 @@ __metadata: languageName: node linkType: soft -"example-app@link:../app::locator=example-backend-split%40workspace%3Apackages%2Fbackend-split": - version: 0.0.0-use.local - resolution: "example-app@link:../app::locator=example-backend-split%40workspace%3Apackages%2Fbackend-split" - languageName: node - linkType: soft - "example-app@workspace:packages/app": version: 0.0.0-use.local resolution: "example-app@workspace:packages/app" @@ -30307,31 +30301,6 @@ __metadata: languageName: unknown linkType: soft -"example-backend-split@workspace:packages/backend-split": - version: 0.0.0-use.local - resolution: "example-backend-split@workspace:packages/backend-split" - dependencies: - "@backstage/backend-defaults": "workspace:^" - "@backstage/backend-plugin-api": "workspace:^" - "@backstage/catalog-model": "workspace:^" - "@backstage/cli": "workspace:^" - "@backstage/plugin-catalog-backend": "workspace:^" - "@backstage/plugin-catalog-backend-module-backstage-openapi": "workspace:^" - "@backstage/plugin-catalog-backend-module-openapi": "workspace:^" - "@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "workspace:^" - "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^" - "@backstage/plugin-permission-backend": "workspace:^" - "@backstage/plugin-permission-backend-module-allow-all-policy": "workspace:^" - "@backstage/plugin-permission-common": "workspace:^" - "@backstage/plugin-permission-node": "workspace:^" - "@opentelemetry/auto-instrumentations-node": "npm:^0.54.0" - "@opentelemetry/exporter-prometheus": "npm:^0.54.0" - "@opentelemetry/sdk-node": "npm:^0.54.0" - example-app: "link:../app" - express-promise-router: "npm:^4.1.0" - languageName: unknown - linkType: soft - "example-backend@workspace:packages/backend": version: 0.0.0-use.local resolution: "example-backend@workspace:packages/backend"