Skip to content

Commit 8e6ff32

Browse files
[8.x] 🌊 Streams: Make deleting orphaned streams work (#218054) (#218117)
# Backport This will backport the following commits from `main` to `8.x`: - [🌊 Streams: Make deleting orphaned streams work (#218054)](#218054) <!--- 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-14T13:49:00Z","message":"🌊 Streams: Make deleting orphaned streams work (#218054)\n\nCurrently streams doesn't allow you to delete an orphaned stream because\n`getPipelineTargets` required the data stream to exist.\n\nThis PR fixes the problem by handling the case gracefully.","sha":"e2f0fddfd12d5f0fad09821f6559054190305ac7","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-logs","backport:version","Feature:Streams","v9.1.0","v8.19.0"],"title":"🌊 Streams: Make deleting orphaned streams work","number":218054,"url":"https://github.com/elastic/kibana/pull/218054","mergeCommit":{"message":"🌊 Streams: Make deleting orphaned streams work (#218054)\n\nCurrently streams doesn't allow you to delete an orphaned stream because\n`getPipelineTargets` required the data stream to exist.\n\nThis PR fixes the problem by handling the case gracefully.","sha":"e2f0fddfd12d5f0fad09821f6559054190305ac7"}},"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/218054","number":218054,"mergeCommit":{"message":"🌊 Streams: Make deleting orphaned streams work (#218054)\n\nCurrently streams doesn't allow you to delete an orphaned stream because\n`getPipelineTargets` required the data stream to exist.\n\nThis PR fixes the problem by handling the case gracefully.","sha":"e2f0fddfd12d5f0fad09821f6559054190305ac7"}},{"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 2d50a33 commit 8e6ff32

File tree

2 files changed

+37
-14
lines changed
  • x-pack
    • platform/plugins/shared/streams/server/lib/streams/state_management/streams
    • test/api_integration/deployment_agnostic/apis/observability/streams

2 files changed

+37
-14
lines changed

β€Žx-pack/platform/plugins/shared/streams/server/lib/streams/state_management/streams/unwired_stream.tsβ€Ž

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
* 2.0.
66
*/
77

8-
import type { IngestProcessorContainer } from '@elastic/elasticsearch/lib/api/types';
8+
import type {
9+
IndicesDataStream,
10+
IngestProcessorContainer,
11+
} from '@elastic/elasticsearch/lib/api/types';
912
import type {
1013
IngestStreamLifecycle,
1114
StreamDefinition,
@@ -202,7 +205,11 @@ export class UnwiredStream extends StreamActiveRecord<UnwiredStreamDefinition> {
202205
},
203206
});
204207

205-
const { pipeline, template } = await this.getPipelineTargets();
208+
const pipelineTargets = await this.getPipelineTargets();
209+
if (!pipelineTargets) {
210+
throw new StatusError('Could not find pipeline targets', 500);
211+
}
212+
const { pipeline, template } = pipelineTargets;
206213
actions.push({
207214
type: 'delete_processor_from_ingest_pipeline',
208215
pipeline,
@@ -253,7 +260,11 @@ export class UnwiredStream extends StreamActiveRecord<UnwiredStreamDefinition> {
253260
},
254261
};
255262

256-
const { pipeline, template } = await this.getPipelineTargets();
263+
const pipelineTargets = await this.getPipelineTargets();
264+
if (!pipelineTargets) {
265+
throw new StatusError('Could not find pipeline targets', 500);
266+
}
267+
const { pipeline, template } = pipelineTargets;
257268
actions.push({
258269
type: 'append_processor_to_ingest_pipeline',
259270
pipeline,
@@ -290,21 +301,32 @@ export class UnwiredStream extends StreamActiveRecord<UnwiredStreamDefinition> {
290301
name: streamManagedPipelineName,
291302
},
292303
});
293-
const { pipeline, template } = await this.getPipelineTargets();
294-
actions.push({
295-
type: 'delete_processor_from_ingest_pipeline',
296-
pipeline,
297-
template,
298-
dataStream: this._definition.name,
299-
referencePipeline: streamManagedPipelineName,
300-
});
304+
const pipelineTargets = await this.getPipelineTargets();
305+
if (pipelineTargets) {
306+
const { pipeline, template } = pipelineTargets;
307+
actions.push({
308+
type: 'delete_processor_from_ingest_pipeline',
309+
pipeline,
310+
template,
311+
dataStream: this._definition.name,
312+
referencePipeline: streamManagedPipelineName,
313+
});
314+
}
301315
}
302316

303317
return actions;
304318
}
305319

306320
private async getPipelineTargets() {
307-
const dataStream = await this.dependencies.streamsClient.getDataStream(this._definition.name);
321+
let dataStream: IndicesDataStream;
322+
try {
323+
dataStream = await this.dependencies.streamsClient.getDataStream(this._definition.name);
324+
} catch (error) {
325+
if (isNotFoundError(error)) {
326+
return undefined;
327+
}
328+
throw error;
329+
}
308330
const unmanagedAssets = await getUnmanagedElasticsearchAssets({
309331
dataStream,
310332
scopedClusterClient: this.dependencies.scopedClusterClient,

β€Žx-pack/test/api_integration/deployment_agnostic/apis/observability/streams/classic.tsβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,15 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
585585
expect(isUnwiredStreamDefinition(classicStream!.stream)).to.be(true);
586586
});
587587

588-
after(async () => {
589-
await apiClient.fetch('DELETE /api/streams/{name} 2023-10-31', {
588+
it('should allow deleting', async () => {
589+
const response = await apiClient.fetch('DELETE /api/streams/{name} 2023-10-31', {
590590
params: {
591591
path: {
592592
name: ORPHANED_STREAM_NAME,
593593
},
594594
},
595595
});
596+
expect(response.status).to.eql(200);
596597
});
597598
});
598599
});

0 commit comments

Comments
Β (0)