diff --git a/packages/backend-split/src/experimental/features.http b/packages/backend-split/src/experimental/features.http index 41c07e99d4..34c8703bcd 100644 --- a/packages/backend-split/src/experimental/features.http +++ b/packages/backend-split/src/experimental/features.http @@ -1,4 +1,5 @@ -GET http://localhost:7007/.backstage/systemInfo/features/installed +// Not working yet, the metadata plugin HTTP APIs need to be moved to rootHttpRouter. +# GET http://localhost:7007/.backstage/systemInfo/features/installed ### diff --git a/packages/backend-split/src/experimental/instanceMetadata.ts b/packages/backend-split/src/experimental/instanceMetadata.ts index 370ec02325..abdb53dfeb 100644 --- a/packages/backend-split/src/experimental/instanceMetadata.ts +++ b/packages/backend-split/src/experimental/instanceMetadata.ts @@ -20,7 +20,7 @@ import { // Example usage of the instance metadata service to log the installed plugins. export default createBackendPlugin({ - pluginId: 'instance-metadata-logging', + pluginId: 'instance-metadata', register(env) { env.registerInit({ deps: { diff --git a/packages/backend-split/src/experimental/systemMetadata.ts b/packages/backend-split/src/experimental/systemMetadata.ts index 3b70059711..e567903356 100644 --- a/packages/backend-split/src/experimental/systemMetadata.ts +++ b/packages/backend-split/src/experimental/systemMetadata.ts @@ -23,9 +23,9 @@ import { } from '@backstage/backend-plugin-api/alpha'; import Router from 'express-promise-router'; -// Example usage of the instance metadata service to log the installed features. +// Example usage of the instance metadata service to log the list of instances and a small HTTP API. export default createBackendPlugin({ - pluginId: 'system-metadata-logging', + pluginId: 'system-metadata', register(env) { env.registerInit({ deps: { diff --git a/packages/backend/package.json b/packages/backend/package.json index 12eba46769..8fd42507dd 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -26,8 +26,8 @@ "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", "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": { @@ -70,8 +70,7 @@ "@opentelemetry/auto-instrumentations-node": "^0.61.0", "@opentelemetry/exporter-prometheus": "^0.54.0", "@opentelemetry/sdk-node": "^0.54.0", - "example-app": "link:../app", - "express-promise-router": "^4.1.0" + "example-app": "link:../app" }, "devDependencies": { "@backstage/cli": "workspace:^" diff --git a/packages/backend/src/experimental/instanceMetadata.ts b/packages/backend/src/experimental/instanceMetadata.ts deleted file mode 100644 index 09e2b0cae8..0000000000 --- a/packages/backend/src/experimental/instanceMetadata.ts +++ /dev/null @@ -1,50 +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. - */ -import { - coreServices, - createBackendPlugin, -} from '@backstage/backend-plugin-api'; -import { instanceMetadataServiceRef } from '@backstage/backend-plugin-api/alpha'; -import Router from 'express-promise-router'; - -// Example usage of the instance metadata service to log the installed features. -export default createBackendPlugin({ - pluginId: 'instance-metadata-logging', - register(env) { - env.registerInit({ - deps: { - instanceMetadata: instanceMetadataServiceRef, - logger: coreServices.logger, - httpRouter: coreServices.rootHttpRouter, - }, - async init({ instanceMetadata, logger, httpRouter }) { - logger.info( - `Installed features on this instance: ${JSON.stringify( - instanceMetadata.getInstalledFeatures(), - )}`, - ); - - const router = Router(); - - router.get('/features/installed', (_, res) => { - res.json({ items: instanceMetadata.getInstalledFeatures() }); - }); - - httpRouter.use('/.backstage/instanceInfo', router); - }, - }); - }, -}); diff --git a/packages/backend/src/experimental/systemMetadata.ts b/packages/backend/src/experimental/systemMetadata.ts deleted file mode 100644 index 3b70059711..0000000000 --- a/packages/backend/src/experimental/systemMetadata.ts +++ /dev/null @@ -1,93 +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. - */ -import { - coreServices, - createBackendPlugin, -} from '@backstage/backend-plugin-api'; -import { - BackendFeatureMeta, - systemMetadataServiceRef, -} from '@backstage/backend-plugin-api/alpha'; -import Router from 'express-promise-router'; - -// Example usage of the instance metadata service to log the installed features. -export default createBackendPlugin({ - pluginId: 'system-metadata-logging', - register(env) { - env.registerInit({ - deps: { - systemMetadata: systemMetadataServiceRef, - logger: coreServices.logger, - httpRouter: coreServices.rootHttpRouter, - }, - async init({ systemMetadata, logger, httpRouter }) { - logger.info( - `Instances in this system: ${JSON.stringify( - await systemMetadata.listInstances(), - )}`, - ); - - const router = Router(); - - router.get('/instances', async (_, res) => { - res.json(await systemMetadata.listInstances()); - }); - - router.get('/features/installed', async (_, res) => { - const instances = await systemMetadata.listInstances(); - const featurePromises = await Promise.allSettled( - instances.map(async instance => { - const response = await fetch( - `${instance.url}/.backstage/instanceInfo/features/installed`, - ); - if (response.ok) { - return { instance, response: await response.json() }; - } - throw new Error( - `Failed to fetch installed features from ${instance.url}`, - ); - }), - ); - const pluginByInstance: Record = {}; - for (const result of featurePromises) { - if (result.status !== 'fulfilled') { - logger.error( - `Failed to fetch installed features: ${result.reason}`, - ); - continue; - } - const instance = result.value.instance; - const installedFeatures = result.value.response - .items as BackendFeatureMeta[]; - for (const feature of installedFeatures) { - if (feature.type === 'plugin') { - if (!pluginByInstance[feature.pluginId]) { - pluginByInstance[feature.pluginId] = []; - } - pluginByInstance[feature.pluginId].push( - `${instance.url}/api/${feature.pluginId}`, - ); - } - } - } - res.json(pluginByInstance); - }); - - httpRouter.use('/.backstage/systemInfo', router); - }, - }); - }, -}); diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index 2728068ab5..87abbdcc93 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -70,8 +70,6 @@ backend.add(searchLoader); backend.add(import('@backstage/plugin-techdocs-backend')); backend.add(import('@backstage/plugin-signals-backend')); backend.add(import('@backstage/plugin-notifications-backend')); -backend.add(import('./experimental/instanceMetadata')); -backend.add(import('./experimental/systemMetadata')); backend.add(systemMetadataServiceFactory); backend.add(import('@backstage/plugin-events-backend-module-google-pubsub'));