Skip to content

Commit c6e3428

Browse files
[8.x] 🌊 Enable streams in the UI for serverless observability (elastic#215533) (elastic#218009)
# Backport This will backport the following commits from `main` to `8.x`: - [🌊 Enable streams in the UI for serverless observability (elastic#215533)](elastic#215533) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Joe Reuter","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-11T16:53:10Z","message":"🌊 Enable streams in the UI for serverless observability (elastic#215533)\n\n# Only merge this if you want streams to go public\n\nThis PR changes the logic for the client side \"status$\" observable for\nstreams to look for whether it's on serverless in an observability\nproject (because this is where we want to launch first).\n\nLater on, this logic can be adjusted as necessary for on-prem launches\netc.\n\nTo make this work locally, you need to add\n`xpack.cloud.serverless.project_id: \"project_id\"` to your\n`config/kibana.dev.yml`\n\nIt still shows the streams app if wired streams are enabled (basically\nit keeps the old behavior plus always defaulting to `enabled` if it's an\nobservability serverless project.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"77ff3c2f62b37b5590d06084f42d566907a70522","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","Feature:Streams","v9.1.0","v8.19.0"],"title":"🌊 Enable streams in the UI for serverless observability","number":215533,"url":"https://github.com/elastic/kibana/pull/215533","mergeCommit":{"message":"🌊 Enable streams in the UI for serverless observability (elastic#215533)\n\n# Only merge this if you want streams to go public\n\nThis PR changes the logic for the client side \"status$\" observable for\nstreams to look for whether it's on serverless in an observability\nproject (because this is where we want to launch first).\n\nLater on, this logic can be adjusted as necessary for on-prem launches\netc.\n\nTo make this work locally, you need to add\n`xpack.cloud.serverless.project_id: \"project_id\"` to your\n`config/kibana.dev.yml`\n\nIt still shows the streams app if wired streams are enabled (basically\nit keeps the old behavior plus always defaulting to `enabled` if it's an\nobservability serverless project.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"77ff3c2f62b37b5590d06084f42d566907a70522"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215533","number":215533,"mergeCommit":{"message":"🌊 Enable streams in the UI for serverless observability (elastic#215533)\n\n# Only merge this if you want streams to go public\n\nThis PR changes the logic for the client side \"status$\" observable for\nstreams to look for whether it's on serverless in an observability\nproject (because this is where we want to launch first).\n\nLater on, this logic can be adjusted as necessary for on-prem launches\netc.\n\nTo make this work locally, you need to add\n`xpack.cloud.serverless.project_id: \"project_id\"` to your\n`config/kibana.dev.yml`\n\nIt still shows the streams app if wired streams are enabled (basically\nit keeps the old behavior plus always defaulting to `enabled` if it's an\nobservability serverless project.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"77ff3c2f62b37b5590d06084f42d566907a70522"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Joe Reuter <[email protected]>
1 parent df83efc commit c6e3428

File tree

3 files changed

+68
-27
lines changed

3 files changed

+68
-27
lines changed

β€Žx-pack/platform/plugins/shared/streams/public/plugin.tsβ€Ž

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ import { CoreSetup, CoreStart, PluginInitializerContext } from '@kbn/core/public
99
import { Logger } from '@kbn/logging';
1010

1111
import { createRepositoryClient } from '@kbn/server-route-repository-client';
12-
import { from, shareReplay, startWith } from 'rxjs';
12+
import { Observable, from, shareReplay, startWith } from 'rxjs';
1313
import { once } from 'lodash';
1414
import type { StreamsPublicConfig } from '../common/config';
15-
import { StreamsPluginClass, StreamsPluginSetup, StreamsPluginStart } from './types';
15+
import {
16+
StreamsPluginClass,
17+
StreamsPluginSetup,
18+
StreamsPluginSetupDependencies,
19+
StreamsPluginStart,
20+
StreamsPluginStartDependencies,
21+
StreamsStatus,
22+
} from './types';
1623
import { StreamsRepositoryClient } from './api';
1724

1825
export class Plugin implements StreamsPluginClass {
@@ -26,37 +33,52 @@ export class Plugin implements StreamsPluginClass {
2633
this.logger = context.logger.get();
2734
}
2835

29-
setup(core: CoreSetup<{}>, pluginSetup: {}): StreamsPluginSetup {
36+
setup(core: CoreSetup, pluginSetup: StreamsPluginSetupDependencies): StreamsPluginSetup {
3037
this.repositoryClient = createRepositoryClient(core);
3138
return {
32-
status$: createStatusObservable(this.logger, this.repositoryClient),
39+
status$: createStreamsStatusObservable(pluginSetup, this.repositoryClient, this.logger),
3340
};
3441
}
3542

36-
start(core: CoreStart, pluginsStart: {}): StreamsPluginStart {
43+
start(core: CoreStart, pluginsStart: StreamsPluginStartDependencies): StreamsPluginStart {
3744
return {
3845
streamsRepositoryClient: this.repositoryClient,
39-
status$: createStatusObservable(this.logger, this.repositoryClient),
46+
status$: createStreamsStatusObservable(pluginsStart, this.repositoryClient, this.logger),
4047
};
4148
}
4249

4350
stop() {}
4451
}
4552

46-
const createStatusObservable = once((logger: Logger, repositoryClient: StreamsRepositoryClient) => {
47-
return from(
48-
repositoryClient
49-
.fetch('GET /api/streams/_status', {
50-
signal: new AbortController().signal,
51-
})
52-
.then(
53-
(response) => ({
54-
status: response.enabled ? ('enabled' as const) : ('disabled' as const),
55-
}),
56-
(error) => {
57-
logger.error(error);
58-
return { status: 'unknown' as const };
59-
}
60-
)
61-
).pipe(startWith({ status: 'unknown' as const }), shareReplay(1));
62-
});
53+
const ENABLED_STATUS: StreamsStatus = { status: 'enabled' };
54+
const DISABLED_STATUS: StreamsStatus = { status: 'disabled' };
55+
const UNKNOWN_STATUS: StreamsStatus = { status: 'unknown' };
56+
57+
const createStreamsStatusObservable = once(
58+
(
59+
deps: StreamsPluginSetupDependencies | StreamsPluginStartDependencies,
60+
repositoryClient: StreamsRepositoryClient,
61+
logger: Logger
62+
): Observable<StreamsStatus> => {
63+
const isObservabilityServerless =
64+
deps.cloud?.isServerlessEnabled && deps.cloud?.serverless.projectType === 'observability';
65+
66+
if (isObservabilityServerless) {
67+
return from([ENABLED_STATUS]);
68+
}
69+
70+
return from(
71+
repositoryClient
72+
.fetch('GET /api/streams/_status', {
73+
signal: new AbortController().signal,
74+
})
75+
.then(
76+
(response) => (response.enabled ? ENABLED_STATUS : DISABLED_STATUS),
77+
(error) => {
78+
logger.error(error);
79+
return UNKNOWN_STATUS;
80+
}
81+
)
82+
).pipe(startWith(UNKNOWN_STATUS), shareReplay(1));
83+
}
84+
);

β€Žx-pack/platform/plugins/shared/streams/public/types.tsβ€Ž

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,33 @@
77

88
import type { Plugin as PluginClass } from '@kbn/core/public';
99
import { Observable } from 'rxjs';
10+
import { CloudSetup, CloudStart } from '@kbn/cloud-plugin/public';
1011
import type { StreamsRepositoryClient } from './api';
1112

13+
export interface StreamsStatus {
14+
status: 'unknown' | 'enabled' | 'disabled';
15+
}
16+
1217
export interface StreamsPluginSetup {
13-
status$: Observable<{ status: 'unknown' | 'enabled' | 'disabled' }>;
18+
status$: Observable<StreamsStatus>;
1419
}
1520

1621
export interface StreamsPluginStart {
1722
streamsRepositoryClient: StreamsRepositoryClient;
18-
status$: Observable<{ status: 'unknown' | 'enabled' | 'disabled' }>;
23+
status$: Observable<StreamsStatus>;
24+
}
25+
26+
export interface StreamsPluginSetupDependencies {
27+
cloud?: CloudSetup;
28+
}
29+
30+
export interface StreamsPluginStartDependencies {
31+
cloud?: CloudStart;
1932
}
2033

21-
export type StreamsPluginClass = PluginClass<StreamsPluginSetup, StreamsPluginStart, {}, {}>;
34+
export type StreamsPluginClass = PluginClass<
35+
StreamsPluginSetup,
36+
StreamsPluginStart,
37+
StreamsPluginSetupDependencies,
38+
StreamsPluginStartDependencies
39+
>;

β€Žx-pack/platform/plugins/shared/streams/tsconfig.jsonβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@kbn/utils",
4444
"@kbn/core-saved-objects-server-internal",
4545
"@kbn/core-analytics-server",
46-
"@kbn/es-types",
46+
"@kbn/cloud-plugin",
47+
"@kbn/es-types"
4748
]
4849
}

0 commit comments

Comments
Β (0)