[Nightshift] Add impact entities endpoint - #290331
mykolaharmash wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Reviewed the new _impact_entities endpoint. The route wiring, validation, security scoping, and type refactor look sound. Left one inline comment about the 1000-document cap and missing sort in findImpactEntities, which affects completeness and determinism at scale.
Generated by Claude Reviewer for #290331 · claude · opus · 102 AIC · ⌖ 25.7 AIC · ⊞ 5.5K
There was a problem hiding this comment.
One concern on findImpactEntities: it derives the distinct impact-entity filter list from only the 1,000 most recent matching investigations with no pagination, so entities from older in-range investigations are silently dropped. Flagged inline with a suggested alternative. Otherwise the change looks sound and well tested.
Generated by Claude Reviewer for #290331 · claude · opus · 120.2 AIC · ⌖ 23 AIC · ⊞ 5.5K
cesco-f
left a comment
There was a problem hiding this comment.
Question: did you link the wrong issue in the PR description? This work doesn't seem to address the issue you linked.
| filter: buildBaseInvestigationFilter(query), | ||
| sortField: 'created_at', | ||
| sortOrder: 'desc', | ||
| perPage: 1000, |
There was a problem hiding this comment.
I see the same comment was resolved twice, but I still see the issue?
There was a problem hiding this comment.
I've added sortField: 'created_at', sortOrder: 'desc' and resolved it leaving a fixed perPage: 1000. This seems like a reasonable limit for this endpoint and it avoids the additional logic for pagination, WDYT?
For now, added a comment in the code to make it explicit.
There was a problem hiding this comment.
Before we settle on the fixed perPage: 1000, two things I'd like to resolve first.
The cap doesn't hold at scale. Past 1,000 matching investigations, entities that only appear in older ones silently drop out, so a user can't filter by an entity that demonstrably exists. How are we planning to handle that?
Can the same name carry different types? So will the filter accept name, or name + type? #1217 says name only, in which case {checkout, service} and {checkout, host} are two options returning identical results. But if it's the pair, I don't think it can be implemented correctly — impact is flattened, which loses field association inside object arrays, so name: checkout AND type: host would match an investigation where checkout is a service and something else is a host.
There was a problem hiding this comment.
Fair points, my thinking here: this endpoint is meant to serve a specific part of the UI:
The date range of the investigation list marches the date filter for impact entities list. Realistically, 1000 limit should be more then enough, we only want to see entities that are part of the current investigation list. But you're probably right, to have it technically complete and be on the safe side, I'll add pagination 👍
Can the same name carry different types? So will the filter accept name, or
name+type?
It will be name + type because we need to filter by services specifically. name: checkout AND type: host concern is valid and we need to think how to do it, but it's not part of this change, this one is only about returning the list of entities that the UI can render and use as a filter.
There was a problem hiding this comment.
Added pagination to get all investigations 393f7b4
There was a problem hiding this comment.
Pagination solves the completeness problem, thanks. One thing it introduces though: perPage: 1000 was also the only bound on cost, and there's nothing replacing it. Since all six date params are optional, a bare GET /_impact_entities builds no filter and the finder now walks every investigation in the space.
Could we require a date range?
Good point, the issue is correct but this PR addresses only part of it. I've change the description. |
| filter: buildBaseInvestigationFilter(query), | ||
| sortField: 'created_at', | ||
| sortOrder: 'desc', | ||
| perPage: 1000, |
There was a problem hiding this comment.
Before we settle on the fixed perPage: 1000, two things I'd like to resolve first.
The cap doesn't hold at scale. Past 1,000 matching investigations, entities that only appear in older ones silently drop out, so a user can't filter by an entity that demonstrably exists. How are we planning to handle that?
Can the same name carry different types? So will the filter accept name, or name + type? #1217 says name only, in which case {checkout, service} and {checkout, host} are two options returning identical results. But if it's the pair, I don't think it can be implemented correctly — impact is flattened, which loses field association inside object arrays, so name: checkout AND type: host would match an investigation where checkout is a service and something else is a host.
|
@mykolaharmash I didn't test this, but do we have to load the whole SO to do the aggregation in node? I thought there was a way to push this down to Elasticsearch by using aggregations (I might be wrong) If that would be possible, it would also remove the 1000 cap concerns |
I believe in order to do it on the ES side, we'd need to change the mapping of the |
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]
Test Failures
History
|
Should we add an indexed field (a |
what's the problem with that? Seems like it's for this kind of stuff. I might miss context here though |
|
I think as well we're free to change the mapping, at this stage we we don't need to worry about backward compatibility. |
|
It seems like pushing down the entity discovery to Elasticsearch by nested plus server side agg is the "right way" of doing things here, it also would align well with how I imagine to consolidate this with the shared agentic_investigations plugin in a follow-up: #290802 |
I wasn't sure if we can change the mapping of a saved object, but if we can let's do it. |
no, you're right, we have these saved objects with current mappings on serverless already, we need a backward-compatible solution. |
|
As discussed, let's postpone the filtering tasks until after the migration to |
Part of https://github.com/elastic/nightshift-program/issues/1217
Adds the
GET /internal/nightshift/investigations/_impact_entitiesendpoint to list all entities identified by investigations as impacted by the investigated events in the specified date range.This endpoint is designed to be used by the Investigations UI as part of the list filtering.
Notable changes
{ name, type? }impact-entity pairs matching investigations.How to test
This is an endpoint-only change, running unit tests should be enough: