-
Notifications
You must be signed in to change notification settings - Fork 125
ACM-44888: fix non-admin SSE OOM on release-2.16 #6839
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
Open
Ginxo
wants to merge
8
commits into
stolostron:release-2.16
Choose a base branch
from
Ginxo:ACM-44888
base: release-2.16
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a1f48ba
ACM-44888: fix non-admin SSE OOM under large inventory on release-2.16
Ginxo 457f510
ACM-44888: add SSE RBAC unit tests for release-2.16
Ginxo 72266b5
ACM-44888: drop forwardEventsToClients on release-2.16
Ginxo bd09347
ACM-44888: remove resetIsObservabilityInstalled test helper
Ginxo cb1698d
eventsDefinitions reverted back to release-2.16
Ginxo 8525646
PR #5863 removed from events.ts
Ginxo 286bb03
lint error fixed
Ginxo 0193a19
references to #6609 reverted back from events.ts
Ginxo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ import { constants } from 'node:http2' | |
| import type { Transform } from 'node:stream' | ||
| import { clearInterval } from 'node:timers' | ||
| import type { Zlib } from 'node:zlib' | ||
| import { batchPromiseAll } from './batch-promise-all' | ||
| import { getEncodeStream, inflateEvent } from './compression' | ||
| import { setCookie } from './cookies' | ||
| import { logger } from './logger' | ||
|
|
@@ -17,7 +16,7 @@ import { sizeOf } from '../routes/aggregators/utils' | |
|
|
||
| // If a client hasn't finished receiving a broadcast in PURGE_CLIENT_TIMEOUT | ||
| // assume the browser has been refreshed or closed | ||
| const PURGE_CLIENT_TIMEOUT = 4 * 60 * 60 * 1000 | ||
| const PURGE_CLIENT_TIMEOUT = 30 * 60 * 1000 | ||
|
|
||
| const instanceID = randomString(8) | ||
|
|
||
|
|
@@ -35,6 +34,15 @@ export interface ServerSideEvent<DataT = unknown> { | |
| namespace?: string | ||
| data?: DataT | ||
| } | ||
|
|
||
| /** Lightweight resource identity for RBAC filtering without inflating compressed objects. */ | ||
| export interface EventResourceMeta { | ||
| kind: string | ||
| apiVersion: string | ||
| name?: string | ||
| namespace?: string | ||
| } | ||
|
|
||
| export interface WatchEvent { | ||
| type: 'ADDED' | 'DELETED' | 'MODIFIED' | 'EOP' | ||
| object: { | ||
|
|
@@ -46,6 +54,24 @@ export interface WatchEvent { | |
| resourceVersion: string | ||
| } | ||
| } | ||
| meta?: EventResourceMeta | ||
| } | ||
|
|
||
| /** Resolve kind/apiVersion/name/namespace from meta or an already-inflated object. */ | ||
| export function getEventResourceMeta(event: ServerSideEvent): EventResourceMeta | undefined { | ||
| const data = event.data as (WatchEvent & { type?: string }) | undefined | ||
| if (!data || typeof data !== 'object') return undefined | ||
| if (data.meta?.kind) return data.meta | ||
| const object = data.object as WatchEvent['object'] | Buffer | undefined | ||
| if (object && !Buffer.isBuffer(object) && typeof object === 'object' && object.kind) { | ||
| return { | ||
| kind: object.kind, | ||
| apiVersion: object.apiVersion, | ||
| name: object.metadata?.name, | ||
| namespace: object.metadata?.namespace, | ||
| } | ||
| } | ||
| return undefined | ||
| } | ||
|
|
||
| export interface ServerSideEventClient { | ||
|
|
@@ -125,22 +151,26 @@ export class ServerSideEvents { | |
| } | ||
| } | ||
|
|
||
| private static async sendEvent(clientID: string, event: ServerSideEvent): Promise<void> { | ||
| private static sendEvent(clientID: string, event: ServerSideEvent): Promise<void> { | ||
| const client = this.clients[clientID] | ||
| if (!client) return | ||
| if (client.events && !client.events[event.name]) return | ||
| if (client.namespaces && !client.namespaces[event.namespace]) return | ||
| event = await inflateEvent(event) | ||
| if (!client) return Promise.resolve() | ||
| if (client.events && !client.events[event.name]) return Promise.resolve() | ||
| if (client.namespaces && !client.namespaces[event.namespace]) return Promise.resolve() | ||
| // Filter before inflate so denied events never materialize full resource JSON in memory. | ||
| if (this.eventFilter) { | ||
| client.eventQueue.push( | ||
| this.eventFilter(client.token, event) | ||
| .then((shouldSendEvent) => (shouldSendEvent ? event : undefined)) | ||
| .then((shouldSendEvent) => { | ||
| if (!shouldSendEvent) return undefined | ||
| return inflateEvent(event) | ||
| }) | ||
| .catch((): undefined => undefined) | ||
| ) | ||
| } else { | ||
| client.eventQueue.push(Promise.resolve(event)) | ||
| client.eventQueue.push(inflateEvent(event)) | ||
| } | ||
| void this.processClient(clientID) | ||
| return Promise.resolve() | ||
| } | ||
|
|
||
| private static async processClient(clientID: string): Promise<void> { | ||
|
|
@@ -243,8 +273,8 @@ export class ServerSideEvents { | |
| res: Http2ServerResponse | ||
| ): Promise<ServerSideEventClient> { | ||
| const [writableStream, compressionStream, encoding] = getEncodeStream( | ||
| res as unknown as NodeJS.WritableStream, | ||
| req.headers[HTTP2_HEADER_ACCEPT_ENCODING] as string, | ||
| res, | ||
| req.headers[HTTP2_HEADER_ACCEPT_ENCODING], | ||
|
Comment on lines
+276
to
+277
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 just typing |
||
| process.env.DISABLE_STREAM_COMPRESSION === 'true' | ||
| ) | ||
|
|
||
|
|
@@ -311,10 +341,10 @@ export class ServerSideEvents { | |
|
|
||
| // SORT EVENTS INTO SMALLER PACKETS | ||
| // SO THAT BROWSER PAGE LOADS QUICKER | ||
| // uncompress and split events into packets | ||
| // Classify using meta / inflated object identity — do not inflate the whole cache up front. | ||
| const values = Object.values(this.events) | ||
| const compressed = sizeOf(values) | ||
| let parts = await batchPromiseAll(values, (event) => inflateEvent(event)) | ||
| let parts: ServerSideEvent[] = [...values] | ||
|
|
||
| // mock a large environment | ||
| if (process.env.MOCK_CLUSTERS) { | ||
|
|
@@ -343,9 +373,9 @@ export class ServerSideEvents { | |
| const other: ServerSideEvent<unknown>[] = [] | ||
| const remainder: ServerSideEvent<unknown>[] = [] | ||
| parts.forEach((event) => { | ||
| const data = event.data as WatchEvent | ||
| const meta = getEventResourceMeta(event) | ||
| // see frontend/src/components/LoadPluginData.tsx for what pages are fast loaded | ||
| switch (data.object.kind) { | ||
| switch (meta?.kind) { | ||
| case 'ManagedCluster': | ||
| case 'HostedCluster': | ||
| case 'ClusterDeployment': | ||
|
|
@@ -384,9 +414,9 @@ export class ServerSideEvents { | |
| // sort events alphabetically so that browser list fills from top to bottom | ||
| const compareFn = | ||
| (propName: 'name' | 'namespace') => (a: ServerSideEvent<unknown>, b: ServerSideEvent<unknown>) => { | ||
| const adata = a.data as WatchEvent | ||
| const bdata = b.data as WatchEvent | ||
| return adata.object.metadata[propName].localeCompare(bdata.object.metadata[propName]) | ||
| const aVal = getEventResourceMeta(a)?.[propName] ?? '' | ||
| const bVal = getEventResourceMeta(b)?.[propName] ?? '' | ||
| return aVal.localeCompare(bVal) | ||
| } | ||
| clusters.sort(compareFn('name')) | ||
| infos.sort(compareFn('namespace')) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 aligned with version from 5.1