Skip to content

fix(streams): Delete stream's queries and children's queries upon stream deletion#230126

Merged
kdelemme merged 5 commits intoelastic:mainfrom
kdelemme:streams/fix/sig-events-deletion-from-parent
Aug 4, 2025
Merged

fix(streams): Delete stream's queries and children's queries upon stream deletion#230126
kdelemme merged 5 commits intoelastic:mainfrom
kdelemme:streams/fix/sig-events-deletion-from-parent

Conversation

@kdelemme
Copy link
Contributor

@kdelemme kdelemme commented Jul 31, 2025

Summary

Resolves #229715

When deleting a stream we used to delete the queries attached to it but did not delete the children's stream queries.

This PR handles the deletion of the queries when deleting a stream directly from the state management service for both classic and wired streams, thus deleting all children's stream queries.

I'm not changing how we manage queries in this PR to keep the surface area small.

Manual tests

PUT kbn:/api/streams/logs.child
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": [
          {
            "destination": "logs.child.child",
            "if": {
              "field": "foo",
              "operator": "eq",
              "value": "bar"
            }
          },
          {
            "destination": "logs.child.child2",
            "if": {
              "always": {}
            }
          }
        ]
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "f744f2d0-0b17-477e-b80a-c11b98ddfc2d",
      "title": "logs.child.first",
      "kql": {
        "query": "message:\"test\""
      }
    },
    {
      "id": "2ce604e7-4156-44eb-bf3f-97ef2b333818",
      "title": "logs.child.second",
      "kql": {
        "query": ""
      }
    }
  ]
}


PUT kbn:/api/streams/logs.child.child
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": []
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "009a886b-9abe-4c1c-91e3-34f17691418e",
      "title": "logs.child.child",
      "kql": {
        "query": ""
      }
    }
  ]
}


PUT kbn:/api/streams/logs.child.child2
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": []
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "a966e062-303d-42f5-84b0-017414ab7ef1",
      "title": "logs.child.child2.first",
      "kql": {
        "query": ""
      }
    },
    {
      "id": "3a8538c0-06eb-45ec-8ee3-3b4b5363dd17",
      "title": "logs.child.child2.second",
      "kql": {
        "query": ""
      }
    }
  ]
}


DELETE kbn:/api/streams/logs.child

Assert all rules in the stack management are gone.

@kdelemme kdelemme self-assigned this Jul 31, 2025
@github-actions github-actions bot added the author:obs-ux-management PRs authored by the obs ux management team label Jul 31, 2025
@kdelemme kdelemme added release_note:skip Skip the PR/issue when compiling release notes Team:actionable-obs Formerly "obs-ux-management", responsible for SLO, o11y alerting, significant events, & synthetics. v9.2.0 backport:skip This PR does not require backporting and removed author:obs-ux-management PRs authored by the obs ux management team labels Jul 31, 2025
@kdelemme
Copy link
Contributor Author

/ci

@kdelemme kdelemme changed the title fix(streams): Delete stream's queries and childrens upon stream deletion fix(streams): Delete stream's queries and children's queries upon stream deletion Jul 31, 2025
@kdelemme
Copy link
Contributor Author

/ci

@kdelemme
Copy link
Contributor Author

/ci

@kdelemme kdelemme marked this pull request as ready for review July 31, 2025 20:48
@kdelemme kdelemme requested review from a team as code owners July 31, 2025 20:48
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-management-team (Team:obs-ux-management)

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start moving query handling into the execution plan! Left some comments

...delete_dot_streams_document,
]);

await this.deleteQueries(delete_queries);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add this to an existing parallel batch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sure, just don't want to do it too early in case another step fails, might do it with the previous call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this won't be super cheap (requires at least one request to Elasticsearch to check whether queries exist), we shouldn't make it its own step if we don't have to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, I'll move it above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed here 032ff65

@kdelemme kdelemme requested a review from flash1293 August 1, 2025 20:59
@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #36 / Agents fleet_agents_status should return incoming data status for specified agents

Metrics [docs]

✅ unchanged

History

cc @kdelemme

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, works as expected

@kdelemme kdelemme merged commit cda208d into elastic:main Aug 4, 2025
12 checks passed
@kdelemme kdelemme deleted the streams/fix/sig-events-deletion-from-parent branch August 4, 2025 16:31
szaffarano pushed a commit to szaffarano/kibana that referenced this pull request Aug 5, 2025
…eam deletion (elastic#230126)

## Summary

Resolves elastic#229715

When deleting a stream we used to delete the queries attached to it but
did not delete the children's stream queries.

This PR handles the deletion of the queries when deleting a stream
directly from the state management service for both classic and wired
streams, thus deleting all children's stream queries.

I'm not changing how we manage queries in this PR to keep the surface
area small.

### Manual tests

```
PUT kbn:/api/streams/logs.child
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": [
          {
            "destination": "logs.child.child",
            "if": {
              "field": "foo",
              "operator": "eq",
              "value": "bar"
            }
          },
          {
            "destination": "logs.child.child2",
            "if": {
              "always": {}
            }
          }
        ]
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "f744f2d0-0b17-477e-b80a-c11b98ddfc2d",
      "title": "logs.child.first",
      "kql": {
        "query": "message:\"test\""
      }
    },
    {
      "id": "2ce604e7-4156-44eb-bf3f-97ef2b333818",
      "title": "logs.child.second",
      "kql": {
        "query": ""
      }
    }
  ]
}


PUT kbn:/api/streams/logs.child.child
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": []
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "009a886b-9abe-4c1c-91e3-34f17691418e",
      "title": "logs.child.child",
      "kql": {
        "query": ""
      }
    }
  ]
}


PUT kbn:/api/streams/logs.child.child2
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": []
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "a966e062-303d-42f5-84b0-017414ab7ef1",
      "title": "logs.child.child2.first",
      "kql": {
        "query": ""
      }
    },
    {
      "id": "3a8538c0-06eb-45ec-8ee3-3b4b5363dd17",
      "title": "logs.child.child2.second",
      "kql": {
        "query": ""
      }
    }
  ]
}


DELETE kbn:/api/streams/logs.child
```

Assert all rules in the stack management are gone.
delanni pushed a commit to delanni/kibana that referenced this pull request Aug 5, 2025
…eam deletion (elastic#230126)

## Summary

Resolves elastic#229715

When deleting a stream we used to delete the queries attached to it but
did not delete the children's stream queries.

This PR handles the deletion of the queries when deleting a stream
directly from the state management service for both classic and wired
streams, thus deleting all children's stream queries.

I'm not changing how we manage queries in this PR to keep the surface
area small.

### Manual tests

```
PUT kbn:/api/streams/logs.child
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": [
          {
            "destination": "logs.child.child",
            "if": {
              "field": "foo",
              "operator": "eq",
              "value": "bar"
            }
          },
          {
            "destination": "logs.child.child2",
            "if": {
              "always": {}
            }
          }
        ]
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "f744f2d0-0b17-477e-b80a-c11b98ddfc2d",
      "title": "logs.child.first",
      "kql": {
        "query": "message:\"test\""
      }
    },
    {
      "id": "2ce604e7-4156-44eb-bf3f-97ef2b333818",
      "title": "logs.child.second",
      "kql": {
        "query": ""
      }
    }
  ]
}


PUT kbn:/api/streams/logs.child.child
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": []
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "009a886b-9abe-4c1c-91e3-34f17691418e",
      "title": "logs.child.child",
      "kql": {
        "query": ""
      }
    }
  ]
}


PUT kbn:/api/streams/logs.child.child2
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": []
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "a966e062-303d-42f5-84b0-017414ab7ef1",
      "title": "logs.child.child2.first",
      "kql": {
        "query": ""
      }
    },
    {
      "id": "3a8538c0-06eb-45ec-8ee3-3b4b5363dd17",
      "title": "logs.child.child2.second",
      "kql": {
        "query": ""
      }
    }
  ]
}


DELETE kbn:/api/streams/logs.child
```

Assert all rules in the stack management are gone.
@wildemat wildemat mentioned this pull request Aug 7, 2025
10 tasks
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Aug 18, 2025
…eam deletion (elastic#230126)

## Summary

Resolves elastic#229715

When deleting a stream we used to delete the queries attached to it but
did not delete the children's stream queries.

This PR handles the deletion of the queries when deleting a stream
directly from the state management service for both classic and wired
streams, thus deleting all children's stream queries.

I'm not changing how we manage queries in this PR to keep the surface
area small.

### Manual tests

```
PUT kbn:/api/streams/logs.child
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": [
          {
            "destination": "logs.child.child",
            "if": {
              "field": "foo",
              "operator": "eq",
              "value": "bar"
            }
          },
          {
            "destination": "logs.child.child2",
            "if": {
              "always": {}
            }
          }
        ]
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "f744f2d0-0b17-477e-b80a-c11b98ddfc2d",
      "title": "logs.child.first",
      "kql": {
        "query": "message:\"test\""
      }
    },
    {
      "id": "2ce604e7-4156-44eb-bf3f-97ef2b333818",
      "title": "logs.child.second",
      "kql": {
        "query": ""
      }
    }
  ]
}


PUT kbn:/api/streams/logs.child.child
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": []
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "009a886b-9abe-4c1c-91e3-34f17691418e",
      "title": "logs.child.child",
      "kql": {
        "query": ""
      }
    }
  ]
}


PUT kbn:/api/streams/logs.child.child2
{
  "stream": {
    "description": "",
    "ingest": {
      "processing": [],
      "lifecycle": {
        "inherit": {}
      },
      "wired": {
        "fields": {},
        "routing": []
      }
    }
  },
  "dashboards": [],
  "queries": [
    {
      "id": "a966e062-303d-42f5-84b0-017414ab7ef1",
      "title": "logs.child.child2.first",
      "kql": {
        "query": ""
      }
    },
    {
      "id": "3a8538c0-06eb-45ec-8ee3-3b4b5363dd17",
      "title": "logs.child.child2.second",
      "kql": {
        "query": ""
      }
    }
  ]
}


DELETE kbn:/api/streams/logs.child
```

Assert all rules in the stack management are gone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:actionable-obs Formerly "obs-ux-management", responsible for SLO, o11y alerting, significant events, & synthetics. v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[streams] child rules are still running when deleting a parent

4 participants