@backstage/plugin-events-backend 0.3.16-next.3 → 0.3.17-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/config.d.ts +6 -0
- package/dist/service/EventsPlugin.cjs.js +5 -1
- package/dist/service/EventsPlugin.cjs.js.map +1 -1
- package/dist/service/hub/createEventBusRouter.cjs.js +5 -0
- package/dist/service/hub/createEventBusRouter.cjs.js.map +1 -1
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @backstage/plugin-events-backend
|
|
2
2
|
|
|
3
|
+
## 0.3.17-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1577511: Allow configuring a timeout for event bus polling requests. This can be set like so in your app-config:
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
events:
|
|
11
|
+
notifyTimeoutMs: 30000
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @backstage/backend-plugin-api@1.0.3-next.0
|
|
16
|
+
- @backstage/plugin-events-node@0.4.6-next.0
|
|
17
|
+
- @backstage/backend-openapi-utils@0.3.1-next.0
|
|
18
|
+
- @backstage/config@1.3.0
|
|
19
|
+
- @backstage/errors@1.2.5
|
|
20
|
+
- @backstage/types@1.2.0
|
|
21
|
+
|
|
22
|
+
## 0.3.16
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- e02a02b: Fix `events.useEventBus` by propagating config to `DefaultEventsService`
|
|
27
|
+
- 9816f51: Add raw body information to `RequestDetails`
|
|
28
|
+
and use the raw body when validating incoming event requests.
|
|
29
|
+
- b7d0334: Cleaning up event subscriptions after the max age window
|
|
30
|
+
- Updated dependencies
|
|
31
|
+
- @backstage/config@1.3.0
|
|
32
|
+
- @backstage/plugin-events-node@0.4.5
|
|
33
|
+
- @backstage/types@1.2.0
|
|
34
|
+
- @backstage/backend-plugin-api@1.0.2
|
|
35
|
+
- @backstage/backend-openapi-utils@0.3.0
|
|
36
|
+
- @backstage/errors@1.2.5
|
|
37
|
+
|
|
3
38
|
## 0.3.16-next.3
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
package/config.d.ts
CHANGED
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
|
|
17
17
|
export interface Config {
|
|
18
18
|
events?: {
|
|
19
|
+
/**
|
|
20
|
+
* Timeout in milliseconds for how long to wait before closing subscription events
|
|
21
|
+
* requests to ensure they don't stall or that events get stuck. Defaults to 55 seconds.
|
|
22
|
+
*/
|
|
23
|
+
notifyTimeoutMs?: number;
|
|
24
|
+
|
|
19
25
|
http?: {
|
|
20
26
|
/**
|
|
21
27
|
* Topics for which a route has to be registered
|
|
@@ -76,13 +76,17 @@ const eventsPlugin = backendPluginApi.createBackendPlugin({
|
|
|
76
76
|
const eventsRouter = Router__default.default();
|
|
77
77
|
http.bind(eventsRouter);
|
|
78
78
|
httpRouter.use(eventsRouter);
|
|
79
|
+
const notifyTimeoutMs = config.getOptionalNumber(
|
|
80
|
+
"events.notifyTimeoutMs"
|
|
81
|
+
);
|
|
79
82
|
httpRouter.use(
|
|
80
83
|
await createEventBusRouter.createEventBusRouter({
|
|
81
84
|
database,
|
|
82
85
|
lifecycle,
|
|
83
86
|
logger,
|
|
84
87
|
httpAuth,
|
|
85
|
-
scheduler
|
|
88
|
+
scheduler,
|
|
89
|
+
notifyTimeoutMs
|
|
86
90
|
})
|
|
87
91
|
);
|
|
88
92
|
httpRouter.addAuthPolicy({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventsPlugin.cjs.js","sources":["../../src/service/EventsPlugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createBackendPlugin,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport {\n eventsExtensionPoint,\n EventsExtensionPoint,\n} from '@backstage/plugin-events-node/alpha';\nimport {\n eventsServiceRef,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\nimport Router from 'express-promise-router';\nimport { HttpPostIngressEventPublisher } from './http';\nimport { createEventBusRouter } from './hub';\n\nclass EventsExtensionPointImpl implements EventsExtensionPoint {\n #httpPostIngresses: HttpPostIngressOptions[] = [];\n\n setEventBroker(_: any): void {\n throw new Error(\n 'setEventBroker is not supported anymore; use eventsServiceRef instead',\n );\n }\n\n addPublishers(_: any): void {\n throw new Error(\n 'addPublishers is not supported anymore; use EventsService instead',\n );\n }\n\n addSubscribers(_: any): void {\n throw new Error(\n 'addSubscribers is not supported anymore; use EventsService instead',\n );\n }\n\n addHttpPostIngress(options: HttpPostIngressOptions) {\n this.#httpPostIngresses.push(options);\n }\n\n get httpPostIngresses() {\n return this.#httpPostIngresses;\n }\n}\n\n/**\n * Events plugin\n *\n * @public\n */\nexport const eventsPlugin = createBackendPlugin({\n pluginId: 'events',\n register(env) {\n const extensionPoint = new EventsExtensionPointImpl();\n env.registerExtensionPoint(eventsExtensionPoint, extensionPoint);\n\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n events: eventsServiceRef,\n database: coreServices.database,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n lifecycle: coreServices.lifecycle,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({\n config,\n events,\n database,\n httpAuth,\n httpRouter,\n lifecycle,\n logger,\n scheduler,\n }) {\n const ingresses = Object.fromEntries(\n extensionPoint.httpPostIngresses.map(ingress => [\n ingress.topic,\n ingress as Omit<HttpPostIngressOptions, 'topic'>,\n ]),\n );\n\n const http = HttpPostIngressEventPublisher.fromConfig({\n config,\n events,\n ingresses,\n logger,\n });\n const eventsRouter = Router();\n http.bind(eventsRouter);\n\n // MUST be registered *before* the event bus router.\n // Otherwise, it would already make use of `express.json()`\n // that is used there as part of the middleware stack.\n httpRouter.use(eventsRouter);\n\n httpRouter.use(\n await createEventBusRouter({\n database,\n lifecycle,\n logger,\n httpAuth,\n scheduler,\n }),\n );\n\n httpRouter.addAuthPolicy({\n allow: 'unauthenticated',\n path: '/http',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","eventsExtensionPoint","coreServices","eventsServiceRef","HttpPostIngressEventPublisher","Router","createEventBusRouter"],"mappings":";;;;;;;;;;;;;AAgCA,MAAM,wBAAyD,CAAA;AAAA,EAC7D,qBAA+C,EAAC;AAAA,EAEhD,eAAe,CAAc,EAAA;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,cAAc,CAAc,EAAA;AAC1B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,eAAe,CAAc,EAAA;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,mBAAmB,OAAiC,EAAA;AAClD,IAAK,IAAA,CAAA,kBAAA,CAAmB,KAAK,OAAO,CAAA;AAAA;AACtC,EAEA,IAAI,iBAAoB,GAAA;AACtB,IAAA,OAAO,IAAK,CAAA,kBAAA;AAAA;AAEhB;AAOO,MAAM,eAAeA,oCAAoB,CAAA;AAAA,EAC9C,QAAU,EAAA,QAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAM,MAAA,cAAA,GAAiB,IAAI,wBAAyB,EAAA;AACpD,IAAI,GAAA,CAAA,sBAAA,CAAuBC,4BAAsB,cAAc,CAAA;AAE/D,IAAA,GAAA,CAAI,YAAa,CAAA;AAA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AAEL,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"EventsPlugin.cjs.js","sources":["../../src/service/EventsPlugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createBackendPlugin,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport {\n eventsExtensionPoint,\n EventsExtensionPoint,\n} from '@backstage/plugin-events-node/alpha';\nimport {\n eventsServiceRef,\n HttpPostIngressOptions,\n} from '@backstage/plugin-events-node';\nimport Router from 'express-promise-router';\nimport { HttpPostIngressEventPublisher } from './http';\nimport { createEventBusRouter } from './hub';\n\nclass EventsExtensionPointImpl implements EventsExtensionPoint {\n #httpPostIngresses: HttpPostIngressOptions[] = [];\n\n setEventBroker(_: any): void {\n throw new Error(\n 'setEventBroker is not supported anymore; use eventsServiceRef instead',\n );\n }\n\n addPublishers(_: any): void {\n throw new Error(\n 'addPublishers is not supported anymore; use EventsService instead',\n );\n }\n\n addSubscribers(_: any): void {\n throw new Error(\n 'addSubscribers is not supported anymore; use EventsService instead',\n );\n }\n\n addHttpPostIngress(options: HttpPostIngressOptions) {\n this.#httpPostIngresses.push(options);\n }\n\n get httpPostIngresses() {\n return this.#httpPostIngresses;\n }\n}\n\n/**\n * Events plugin\n *\n * @public\n */\nexport const eventsPlugin = createBackendPlugin({\n pluginId: 'events',\n register(env) {\n const extensionPoint = new EventsExtensionPointImpl();\n env.registerExtensionPoint(eventsExtensionPoint, extensionPoint);\n\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n events: eventsServiceRef,\n database: coreServices.database,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n lifecycle: coreServices.lifecycle,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({\n config,\n events,\n database,\n httpAuth,\n httpRouter,\n lifecycle,\n logger,\n scheduler,\n }) {\n const ingresses = Object.fromEntries(\n extensionPoint.httpPostIngresses.map(ingress => [\n ingress.topic,\n ingress as Omit<HttpPostIngressOptions, 'topic'>,\n ]),\n );\n\n const http = HttpPostIngressEventPublisher.fromConfig({\n config,\n events,\n ingresses,\n logger,\n });\n const eventsRouter = Router();\n http.bind(eventsRouter);\n\n // MUST be registered *before* the event bus router.\n // Otherwise, it would already make use of `express.json()`\n // that is used there as part of the middleware stack.\n httpRouter.use(eventsRouter);\n\n const notifyTimeoutMs = config.getOptionalNumber(\n 'events.notifyTimeoutMs',\n );\n\n httpRouter.use(\n await createEventBusRouter({\n database,\n lifecycle,\n logger,\n httpAuth,\n scheduler,\n notifyTimeoutMs,\n }),\n );\n\n httpRouter.addAuthPolicy({\n allow: 'unauthenticated',\n path: '/http',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","eventsExtensionPoint","coreServices","eventsServiceRef","HttpPostIngressEventPublisher","Router","createEventBusRouter"],"mappings":";;;;;;;;;;;;;AAgCA,MAAM,wBAAyD,CAAA;AAAA,EAC7D,qBAA+C,EAAC;AAAA,EAEhD,eAAe,CAAc,EAAA;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,cAAc,CAAc,EAAA;AAC1B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,eAAe,CAAc,EAAA;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AACF,EAEA,mBAAmB,OAAiC,EAAA;AAClD,IAAK,IAAA,CAAA,kBAAA,CAAmB,KAAK,OAAO,CAAA;AAAA;AACtC,EAEA,IAAI,iBAAoB,GAAA;AACt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,QAAA,MAAM,kBAAkB,MAAO,CAAA,iBAAA;AAAA,UAC7B;AAAA,SACF;AAEA,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAMC,yCAAqB,CAAA;AAAA,YACzB,QAAA;AAAA,YACA,SAAA;AAAA,YACA,MAAA;AAAA,YACA,QAAA;AAAA,YACA,SAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAEA,QAAA,UAAA,CAAW,aAAc,CAAA;AAAA,UACvB,KAAO,EAAA,iBAAA;AAAA,UACP,IAAM,EAAA;AAAA,SACP,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var openapi_generated = require('../../schema/openapi.generated.cjs.js');
|
|
4
4
|
var MemoryEventBusStore = require('./MemoryEventBusStore.cjs.js');
|
|
5
5
|
var DatabaseEventBusStore = require('./DatabaseEventBusStore.cjs.js');
|
|
6
|
+
var pluginEventsNode = require('@backstage/plugin-events-node');
|
|
6
7
|
|
|
7
8
|
const DEFAULT_NOTIFY_TIMEOUT_MS = 55e3;
|
|
8
9
|
async function createEventBusStore(deps) {
|
|
@@ -86,6 +87,10 @@ async function createEventBusRouter(options) {
|
|
|
86
87
|
}))
|
|
87
88
|
});
|
|
88
89
|
} else {
|
|
90
|
+
res.setHeader(
|
|
91
|
+
pluginEventsNode.EVENTS_NOTIFY_TIMEOUT_HEADER,
|
|
92
|
+
notifyTimeoutMs.toString()
|
|
93
|
+
);
|
|
89
94
|
res.status(202);
|
|
90
95
|
res.flushHeaders();
|
|
91
96
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEventBusRouter.cjs.js","sources":["../../../src/service/hub/createEventBusRouter.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DatabaseService,\n HttpAuthService,\n LifecycleService,\n LoggerService,\n SchedulerService,\n} from '@backstage/backend-plugin-api';\nimport { Handler } from 'express';\nimport { createOpenApiRouter } from '../../schema/openapi.generated';\nimport { MemoryEventBusStore } from './MemoryEventBusStore';\nimport { DatabaseEventBusStore } from './DatabaseEventBusStore';\nimport { EventBusStore } from './types';\nimport { EventParams } from '@backstage/plugin-events-node';\n\nconst DEFAULT_NOTIFY_TIMEOUT_MS = 55_000; // Just below 60s, which is a common HTTP timeout\n\n/*\n\n# Event Bus\n\nThis comment describes the event bus that is implemented here in the events\nbackend, and by default used by the events service.\n\n## Overview\n\nThe events bus implements a subscription mechanism where subscribers must exist\nupfront for events to be stored. It uses a single inbox for all events, with\neach subscriber having its own pointer for how far into the inbox it has read.\n\nIn order to avoid busy polling, the API uses a long-polling mechanism where a\nrequest is left hanging until the client should try to read again.\n\nThe event bus is not implemented with any guarantees of events being consumed,\nbut it does aim to make it unlikely that events are dropped\n\n## API\n\n### POST /bus/v1/events\n\nThis endpoint is used to publish new events to the event bus on a specific\ntopic. It can optionally include a set of subscription IDs for subscribers that\nhave already been notified of the event. This is to enable an optimization where\nwe notify subscribers locally if possible, and avoid the need for events to be\nrelayed through the events bus at all of possible.\n\nFor an event to be published and stored there must already exist a subscriber\nthat is subscribed to the event's topic, and that hasn't already been notified\nof the event. If no such subscriber is found, the event will be discarded.\n\n### PUT /bus/v1/subscriptions/:subscriptionId\n\nThis endpoint is used to create or update a subscriptions. Subscriptions are\nshared across the entire bus and divided by subscription ID. Multiple clients\ncan be reading events from the same subscription at the same time, but only one\nof those clients will receive each event. This enables division of work by using\nthe same subscriber ID across multiple instances, as well as broadcasting by\nensuring separate subscribers IDs.\n\n### GET /bus/v1/subscriptions/:subscriptionId/events\n\nThis endpoint is used to read events from a subscription. It will return a batch\nof events for the subscribed topics that have not yet been read by the\nsubscription. If no such events are available, the endpoint will return a 202\nresponse and then hang end response until an event is available or a timeout is\nreached. This allows clients to call this endpoint in a loop but will keep\ntraffic overhead fairly low.\n\n## Delivery guarantees\n\nWhen reading events from the event bus, clients should always implement a\ngraceful shutdown where they process any events that are received from the\nevents endpoint before shutting down. This is also the reason that the events\nendpoint does not return any events when responding with a 202 blocking the\nresponse, because there would otherwise be a race condition where the events\nmight be lost in transit if the client shuts down. By always sending an empty\nresponse and requiring the client to send another request, we ensure that the\nclient is prepared to halt shutdown until the request had been fully processed.\n\n## Local processing optimization\n\nWhen possible, events will be processed locally before sent to the event bus.\nThe client will also inform the bus of which subscriptions have already been\nnotified of the event, so that the bus can completely avoid storing an event if\nit has already been fully consumed by all subscribers.\n\n## Automated cleanup & event window\n\nEvents are deleted once they are outside the guaranteed storage window. By\ndefault the window 10 minutes for all events, and 24 hours for the last 10000\nevents. This ensures that the event log doesn't grow indefinitely, while still\nallowing subscribers with restarts or outages to catch up to past events,\nensuring that events are likely not lost.\n\nSubscriptions are also cleaned up if their read pointer falls outside of the\ncurrent event window. This ensures that stale subscribers don't accumulate and\ncause unnecessary storage of events.\n\n*/\n\nasync function createEventBusStore(deps: {\n logger: LoggerService;\n database: DatabaseService;\n scheduler: SchedulerService;\n lifecycle: LifecycleService;\n httpAuth: HttpAuthService;\n}): Promise<EventBusStore> {\n const db = await deps.database.getClient();\n if (db.client.config.client === 'pg') {\n deps.logger.info('Database is PostgreSQL, using database store');\n return await DatabaseEventBusStore.create(deps);\n }\n\n deps.logger.info('Database is not PostgreSQL, using memory store');\n return new MemoryEventBusStore();\n}\n\n/**\n * Creates a new event bus router\n * @internal\n */\nexport async function createEventBusRouter(options: {\n logger: LoggerService;\n database: DatabaseService;\n scheduler: SchedulerService;\n lifecycle: LifecycleService;\n httpAuth: HttpAuthService;\n notifyTimeoutMs?: number; // for testing\n}): Promise<Handler> {\n const { httpAuth, notifyTimeoutMs = DEFAULT_NOTIFY_TIMEOUT_MS } = options;\n const logger = options.logger.child({ type: 'EventBus' });\n\n const store = await createEventBusStore(options);\n\n const apiRouter = await createOpenApiRouter();\n\n apiRouter.post('/bus/v1/events', async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const topic = req.body.event.topic;\n const notifiedSubscribers = req.body.notifiedSubscribers;\n const result = await store.publish({\n event: {\n topic,\n eventPayload: req.body.event.payload,\n } as EventParams,\n notifiedSubscribers,\n credentials,\n });\n if (result) {\n logger.debug(\n `Published event to '${topic}' with ID '${result.eventId}'`,\n {\n subject: credentials.principal.subject,\n },\n );\n res.status(201).end();\n } else {\n if (notifiedSubscribers) {\n const notified = `'${notifiedSubscribers.join(\"', '\")}'`;\n logger.debug(\n `Skipped publishing of event to '${topic}', subscribers have already been notified: ${notified}`,\n { subject: credentials.principal.subject },\n );\n } else {\n logger.debug(\n `Skipped publishing of event to '${topic}', no subscribers present`,\n { subject: credentials.principal.subject },\n );\n }\n res.status(204).end();\n }\n });\n\n apiRouter.get(\n '/bus/v1/subscriptions/:subscriptionId/events',\n async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const id = req.params.subscriptionId;\n\n const controller = new AbortController();\n req.on('end', () => controller.abort());\n\n // By setting up the listener first we make sure we don't miss any events\n // that are published while reading. If an event is published we'll receive\n // a notification, which we may ignore depending on the outcome of the read\n const listener = await store.setupListener(id, {\n signal: controller.signal,\n });\n\n // By timing out requests we make sure they don't stall or that events get stuck.\n // For the caller there's no difference between a timeout and a\n // notification, either way they should try reading again.\n const timeout = setTimeout(() => {\n controller.abort();\n }, notifyTimeoutMs);\n\n try {\n const { events } = await store.readSubscription(id);\n\n logger.debug(\n `Reading subscription '${id}' resulted in ${events.length} events`,\n { subject: credentials.principal.subject },\n );\n\n if (events.length > 0) {\n res.json({\n events: events.map(event => ({\n topic: event.topic,\n payload: event.eventPayload,\n })),\n });\n } else {\n res.status(202);\n res.flushHeaders();\n\n try {\n const { topic } = await listener.waitForUpdate();\n logger.debug(\n `Received notification for subscription '${id}' for topic '${topic}'`,\n { subject: credentials.principal.subject },\n );\n } catch (error) {\n if (error !== controller.signal.reason) {\n logger.error(`Error listening for subscription '${id}'`, error);\n }\n } finally {\n // A small extra delay ensures a more even spread of events across\n // consumers in case some consumers are faster than others\n await new Promise(resolve =>\n setTimeout(resolve, 1 + Math.random() * 9),\n );\n res.end();\n }\n }\n } finally {\n controller.abort();\n clearTimeout(timeout);\n }\n },\n );\n\n apiRouter.put('/bus/v1/subscriptions/:subscriptionId', async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const id = req.params.subscriptionId;\n\n await store.upsertSubscription(id, req.body.topics, credentials);\n\n logger.debug(\n `New subscription '${id}' for topics '${req.body.topics.join(\"', '\")}'`,\n { subject: credentials.principal.subject },\n );\n\n res.status(201).end();\n });\n\n return apiRouter;\n}\n"],"names":["DatabaseEventBusStore","MemoryEventBusStore","createOpenApiRouter"],"mappings":";;;;;;AA8BA,MAAM,yBAA4B,GAAA,IAAA;AAqFlC,eAAe,oBAAoB,IAMR,EAAA;AACzB,EAAA,MAAM,EAAK,GAAA,MAAM,IAAK,CAAA,QAAA,CAAS,SAAU,EAAA;AACzC,EAAA,IAAI,EAAG,CAAA,MAAA,CAAO,MAAO,CAAA,MAAA,KAAW,IAAM,EAAA;AACpC,IAAK,IAAA,CAAA,MAAA,CAAO,KAAK,8CAA8C,CAAA;AAC/D,IAAO,OAAA,MAAMA,2CAAsB,CAAA,MAAA,CAAO,IAAI,CAAA;AAAA;AAGhD,EAAK,IAAA,CAAA,MAAA,CAAO,KAAK,gDAAgD,CAAA;AACjE,EAAA,OAAO,IAAIC,uCAAoB,EAAA;AACjC;AAMA,eAAsB,qBAAqB,OAOtB,EAAA;AACnB,EAAA,MAAM,EAAE,QAAA,EAAU,eAAkB,GAAA,yBAAA,EAA8B,GAA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,CAAA,uCAAA,EAAyC,OAAO,GAAA,EAAK,GAAQ,KAAA;AACzE,IAAA,MAAM,WAAc,GAAA,MAAM,QAAS,CAAA,WAAA,CAAY,GAAK,EAAA;AAAA,MAClD,KAAA,EAAO,CAAC,SAAS;AAAA,KAClB,CAAA;AACD,IAAM,MAAA,EAAA,GAAK,IAAI,MAAO,CAAA,cAAA;AAEtB,IAAA,MAAM,MAAM,kBAAmB,CAAA,EAAA,EAAI,GAAI,CAAA,IAAA,CAAK,QAAQ,WAAW,CAAA;AAE/D,IAAO,MAAA,CAAA,KAAA;AAAA,MACL,CAAA,kBAAA,EAAqB,EAAE,CAAiB,cAAA,EAAA,GAAA,CAAI,KAAK,MAAO,CAAA,IAAA,CAAK,MAAM,CAAC,CAAA,CAAA,CAAA;AAAA,MACpE,EAAE,OAAA,EAAS,WAAY,CAAA,SAAA,CAAU,OAAQ;AAAA,KAC3C;AAEA,IAAI,GAAA,CAAA,MAAA,CAAO,GAAG,CAAA,CAAE,GAAI,EAAA;AAAA,GACrB,CAAA;AAED,EAAO,OAAA,SAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"createEventBusRouter.cjs.js","sources":["../../../src/service/hub/createEventBusRouter.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DatabaseService,\n HttpAuthService,\n LifecycleService,\n LoggerService,\n SchedulerService,\n} from '@backstage/backend-plugin-api';\nimport { Handler } from 'express';\nimport { createOpenApiRouter } from '../../schema/openapi.generated';\nimport { MemoryEventBusStore } from './MemoryEventBusStore';\nimport { DatabaseEventBusStore } from './DatabaseEventBusStore';\nimport { EventBusStore } from './types';\nimport {\n EVENTS_NOTIFY_TIMEOUT_HEADER,\n EventParams,\n} from '@backstage/plugin-events-node';\n\nconst DEFAULT_NOTIFY_TIMEOUT_MS = 55_000; // Just below 60s, which is a common HTTP timeout\n\n/*\n\n# Event Bus\n\nThis comment describes the event bus that is implemented here in the events\nbackend, and by default used by the events service.\n\n## Overview\n\nThe events bus implements a subscription mechanism where subscribers must exist\nupfront for events to be stored. It uses a single inbox for all events, with\neach subscriber having its own pointer for how far into the inbox it has read.\n\nIn order to avoid busy polling, the API uses a long-polling mechanism where a\nrequest is left hanging until the client should try to read again.\n\nThe event bus is not implemented with any guarantees of events being consumed,\nbut it does aim to make it unlikely that events are dropped\n\n## API\n\n### POST /bus/v1/events\n\nThis endpoint is used to publish new events to the event bus on a specific\ntopic. It can optionally include a set of subscription IDs for subscribers that\nhave already been notified of the event. This is to enable an optimization where\nwe notify subscribers locally if possible, and avoid the need for events to be\nrelayed through the events bus at all of possible.\n\nFor an event to be published and stored there must already exist a subscriber\nthat is subscribed to the event's topic, and that hasn't already been notified\nof the event. If no such subscriber is found, the event will be discarded.\n\n### PUT /bus/v1/subscriptions/:subscriptionId\n\nThis endpoint is used to create or update a subscriptions. Subscriptions are\nshared across the entire bus and divided by subscription ID. Multiple clients\ncan be reading events from the same subscription at the same time, but only one\nof those clients will receive each event. This enables division of work by using\nthe same subscriber ID across multiple instances, as well as broadcasting by\nensuring separate subscribers IDs.\n\n### GET /bus/v1/subscriptions/:subscriptionId/events\n\nThis endpoint is used to read events from a subscription. It will return a batch\nof events for the subscribed topics that have not yet been read by the\nsubscription. If no such events are available, the endpoint will return a 202\nresponse and then hang end response until an event is available or a timeout is\nreached. This allows clients to call this endpoint in a loop but will keep\ntraffic overhead fairly low.\n\n## Delivery guarantees\n\nWhen reading events from the event bus, clients should always implement a\ngraceful shutdown where they process any events that are received from the\nevents endpoint before shutting down. This is also the reason that the events\nendpoint does not return any events when responding with a 202 blocking the\nresponse, because there would otherwise be a race condition where the events\nmight be lost in transit if the client shuts down. By always sending an empty\nresponse and requiring the client to send another request, we ensure that the\nclient is prepared to halt shutdown until the request had been fully processed.\n\n## Local processing optimization\n\nWhen possible, events will be processed locally before sent to the event bus.\nThe client will also inform the bus of which subscriptions have already been\nnotified of the event, so that the bus can completely avoid storing an event if\nit has already been fully consumed by all subscribers.\n\n## Automated cleanup & event window\n\nEvents are deleted once they are outside the guaranteed storage window. By\ndefault the window 10 minutes for all events, and 24 hours for the last 10000\nevents. This ensures that the event log doesn't grow indefinitely, while still\nallowing subscribers with restarts or outages to catch up to past events,\nensuring that events are likely not lost.\n\nSubscriptions are also cleaned up if their read pointer falls outside of the\ncurrent event window. This ensures that stale subscribers don't accumulate and\ncause unnecessary storage of events.\n\n*/\n\nasync function createEventBusStore(deps: {\n logger: LoggerService;\n database: DatabaseService;\n scheduler: SchedulerService;\n lifecycle: LifecycleService;\n httpAuth: HttpAuthService;\n}): Promise<EventBusStore> {\n const db = await deps.database.getClient();\n if (db.client.config.client === 'pg') {\n deps.logger.info('Database is PostgreSQL, using database store');\n return await DatabaseEventBusStore.create(deps);\n }\n\n deps.logger.info('Database is not PostgreSQL, using memory store');\n return new MemoryEventBusStore();\n}\n\n/**\n * Creates a new event bus router\n * @internal\n */\nexport async function createEventBusRouter(options: {\n logger: LoggerService;\n database: DatabaseService;\n scheduler: SchedulerService;\n lifecycle: LifecycleService;\n httpAuth: HttpAuthService;\n notifyTimeoutMs?: number; // for testing\n}): Promise<Handler> {\n const { httpAuth, notifyTimeoutMs = DEFAULT_NOTIFY_TIMEOUT_MS } = options;\n const logger = options.logger.child({ type: 'EventBus' });\n\n const store = await createEventBusStore(options);\n\n const apiRouter = await createOpenApiRouter();\n\n apiRouter.post('/bus/v1/events', async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const topic = req.body.event.topic;\n const notifiedSubscribers = req.body.notifiedSubscribers;\n const result = await store.publish({\n event: {\n topic,\n eventPayload: req.body.event.payload,\n } as EventParams,\n notifiedSubscribers,\n credentials,\n });\n if (result) {\n logger.debug(\n `Published event to '${topic}' with ID '${result.eventId}'`,\n {\n subject: credentials.principal.subject,\n },\n );\n res.status(201).end();\n } else {\n if (notifiedSubscribers) {\n const notified = `'${notifiedSubscribers.join(\"', '\")}'`;\n logger.debug(\n `Skipped publishing of event to '${topic}', subscribers have already been notified: ${notified}`,\n { subject: credentials.principal.subject },\n );\n } else {\n logger.debug(\n `Skipped publishing of event to '${topic}', no subscribers present`,\n { subject: credentials.principal.subject },\n );\n }\n res.status(204).end();\n }\n });\n\n apiRouter.get(\n '/bus/v1/subscriptions/:subscriptionId/events',\n async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const id = req.params.subscriptionId;\n\n const controller = new AbortController();\n req.on('end', () => controller.abort());\n\n // By setting up the listener first we make sure we don't miss any events\n // that are published while reading. If an event is published we'll receive\n // a notification, which we may ignore depending on the outcome of the read\n const listener = await store.setupListener(id, {\n signal: controller.signal,\n });\n\n // By timing out requests we make sure they don't stall or that events get stuck.\n // For the caller there's no difference between a timeout and a\n // notification, either way they should try reading again.\n const timeout = setTimeout(() => {\n controller.abort();\n }, notifyTimeoutMs);\n\n try {\n const { events } = await store.readSubscription(id);\n\n logger.debug(\n `Reading subscription '${id}' resulted in ${events.length} events`,\n { subject: credentials.principal.subject },\n );\n\n if (events.length > 0) {\n res.json({\n events: events.map(event => ({\n topic: event.topic,\n payload: event.eventPayload,\n })),\n });\n } else {\n res.setHeader(\n EVENTS_NOTIFY_TIMEOUT_HEADER,\n notifyTimeoutMs.toString(),\n );\n res.status(202);\n res.flushHeaders();\n\n try {\n const { topic } = await listener.waitForUpdate();\n logger.debug(\n `Received notification for subscription '${id}' for topic '${topic}'`,\n { subject: credentials.principal.subject },\n );\n } catch (error) {\n if (error !== controller.signal.reason) {\n logger.error(`Error listening for subscription '${id}'`, error);\n }\n } finally {\n // A small extra delay ensures a more even spread of events across\n // consumers in case some consumers are faster than others\n await new Promise(resolve =>\n setTimeout(resolve, 1 + Math.random() * 9),\n );\n res.end();\n }\n }\n } finally {\n controller.abort();\n clearTimeout(timeout);\n }\n },\n );\n\n apiRouter.put('/bus/v1/subscriptions/:subscriptionId', async (req, res) => {\n const credentials = await httpAuth.credentials(req, {\n allow: ['service'],\n });\n const id = req.params.subscriptionId;\n\n await store.upsertSubscription(id, req.body.topics, credentials);\n\n logger.debug(\n `New subscription '${id}' for topics '${req.body.topics.join(\"', '\")}'`,\n { subject: credentials.principal.subject },\n );\n\n res.status(201).end();\n });\n\n return apiRouter;\n}\n"],"names":["DatabaseEventBusStore","MemoryEventBusStore","createOpenApiRouter","EVENTS_NOTIFY_TIMEOUT_HEADER"],"mappings":";;;;;;;AAiCA,MAAM,yBAA4B,GAAA,IAAA;AAqFlC,eAAe,oBAAoB,IAMR,EAAA;AACzB,EAAA,MAAM,EAAK,GAAA,MAAM,IAAK,CAAA,QAAA,CAAS,SAAU,EAAA;AACzC,EAAA,IAAI,EAAG,CAAA,MAAA,CAAO,MAAO,CAAA,MAAA,KAAW,IAAM,EAAA;AACpC,IAAK,IAAA,CAAA,MAAA,CAAO,KAAK,8CAA8C,CAAA;AAC/D,IAAO,OAAA,MAAMA,2CAAsB,CAAA,MAAA,CAAO,IAAI,CAAA;AAAA;AAGhD,EAAK,IAAA,CAAA,MAAA,CAAO,KAAK,gDAAgD,CAAA;AACjE,EAAA,OAAO,IAAIC,uCAAoB,EAAA;AACjC;AAMA,eAAsB,qBAAqB,OAOtB,EAAA;AACnB,EAAA,MAAM,EAAE,QAAA,EAAU,eAAkB,GAAA,yBAAA,EAA8B,GAAA,OAAA;AAClE,EAAA,MAAM,SAAS,OAAQ,CAAA,MAAA,CAAO,MAAM,EAAE,IAAA,EAAM,YAAY,CAAA;AAExD,EAAM,MAAA,KAAA,GAAQ,MAAM,mBAAA,CAAoB,OAAO,CAAA;AAE/C,EAAM,MAAA,SAAA,GAAY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WAAA,CAAY,GAAK,EAAA;AAAA,MAClD,KAAA,EAAO,CAAC,SAAS;AAAA,KAClB,CAAA;AACD,IAAM,MAAA,EAAA,GAAK,IAAI,MAAO,CAAA,cAAA;AAEtB,IAAA,MAAM,MAAM,kBAAmB,CAAA,EAAA,EAAI,GAAI,CAAA,IAAA,CAAK,QAAQ,WAAW,CAAA;AAE/D,IAAO,MAAA,CAAA,KAAA;AAAA,MACL,CAAA,kBAAA,EAAqB,EAAE,CAAiB,cAAA,EAAA,GAAA,CAAI,KAAK,MAAO,CAAA,IAAA,CAAK,MAAM,CAAC,CAAA,CAAA,CAAA;AAAA,MACpE,EAAE,OAAA,EAAS,WAAY,CAAA,SAAA,CAAU,OAAQ;AAAA,KAC3C;AAEA,IAAI,GAAA,CAAA,MAAA,CAAO,GAAG,CAAA,CAAE,GAAI,EAAA;AAAA,GACrB,CAAA;AAED,EAAO,OAAA,SAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-events-backend",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17-next.0",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "backend-plugin",
|
|
6
6
|
"pluginId": "events",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@backstage/backend-common": "^0.25.0",
|
|
67
|
-
"@backstage/backend-openapi-utils": "0.3.
|
|
68
|
-
"@backstage/backend-plugin-api": "1.0.
|
|
69
|
-
"@backstage/config": "1.
|
|
70
|
-
"@backstage/errors": "1.2.
|
|
71
|
-
"@backstage/plugin-events-node": "0.4.
|
|
72
|
-
"@backstage/types": "1.
|
|
67
|
+
"@backstage/backend-openapi-utils": "0.3.1-next.0",
|
|
68
|
+
"@backstage/backend-plugin-api": "1.0.3-next.0",
|
|
69
|
+
"@backstage/config": "1.3.0",
|
|
70
|
+
"@backstage/errors": "1.2.5",
|
|
71
|
+
"@backstage/plugin-events-node": "0.4.6-next.0",
|
|
72
|
+
"@backstage/types": "1.2.0",
|
|
73
73
|
"@types/express": "^4.17.6",
|
|
74
74
|
"content-type": "^1.0.5",
|
|
75
75
|
"express": "^4.17.1",
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
"winston": "^3.2.1"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@backstage/backend-app-api": "1.0.
|
|
82
|
-
"@backstage/backend-defaults": "0.
|
|
83
|
-
"@backstage/backend-test-utils": "1.
|
|
84
|
-
"@backstage/cli": "0.29.
|
|
85
|
-
"@backstage/plugin-events-backend-test-utils": "0.1.
|
|
86
|
-
"@backstage/repo-tools": "0.
|
|
81
|
+
"@backstage/backend-app-api": "1.0.3-next.0",
|
|
82
|
+
"@backstage/backend-defaults": "0.6.0-next.0",
|
|
83
|
+
"@backstage/backend-test-utils": "1.2.0-next.0",
|
|
84
|
+
"@backstage/cli": "0.29.3-next.0",
|
|
85
|
+
"@backstage/plugin-events-backend-test-utils": "0.1.39-next.0",
|
|
86
|
+
"@backstage/repo-tools": "0.12.0-next.0",
|
|
87
87
|
"@types/content-type": "^1.1.8",
|
|
88
88
|
"supertest": "^7.0.0"
|
|
89
89
|
},
|