[Entity Store][API] Fix snake case on CRUD API List response#246003
[Entity Store][API] Fix snake case on CRUD API List response#246003
Conversation
...y/plugins/security_solution/server/lib/entity_analytics/entity_store/routes/entities/list.ts
Outdated
Show resolved
Hide resolved
romulets
left a comment
There was a problem hiding this comment.
looks fine. This setup (that I implemented) still doesn't sit right me........ argh.
Anyway, looks good!
… into fix-entity-store-api-list
There was a problem hiding this comment.
Hey! Thanks for all the work here!
I see one potential issue regarding key collisions.
I don't expect it to happen, bur since we're converting stuff now, I can imagine a scenario where we encounter something like:
{
entity: {
attributes: { Field: "blah", field: "something else" }
}
}
And we might lose data?
Do you think this could be a problem? should we have some collision detection safety guard?
Secondly, I'm always a bit uneasy about allowing code with disabled eslint and ts rules. I think we can slightly change the code to a more declarative approach that removes the need for the continue statements, as well as simplifies all the checks:
// just override the entity field with the normalized fields
records.foreach(record => {
const result = buildNormalizedFields(record.entity, ['behaviors', 'lifecycle', 'attributes'])
record.entity = { ...record.entity, ...result }
})
function normalizeEntityFields(
obj: Record<string, unknown>,
properties: string[]
) {
// only use properties whose val is an object, skip them if undefined or some other type
const hasObjVal = (p: string) => obj[p] !== null && typeof obj[p] === "object" && !Array.isArray(obj[p])
const entries = properties
.filter(hasObjVal)
.map(p => [p, toLowercaseKeys(obj[p] as Record<string, unknown>)])
return Object.fromEntries(entries)
}
function toLowercaseKeys(
obj: Record<string, unknown>
): Record<string, unknown> {
// iterate to rebuild the sub object with the lowercase keys.
// No need for checking if it appears in the old sub or to `delete`
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k.toLowerCase(), v]))
}(this doesn't cover the key collision issue tho)
...y/plugins/security_solution/server/lib/entity_analytics/entity_store/routes/entities/list.ts
Outdated
Show resolved
Hide resolved
...y/plugins/security_solution/server/lib/entity_analytics/entity_store/routes/entities/list.ts
Outdated
Show resolved
Hide resolved
...y/plugins/security_solution/server/lib/entity_analytics/entity_store/routes/entities/list.ts
Outdated
Show resolved
Hide resolved
|
@tiansivive All very good remarks! Thank you for going over it and teaching me something about TS in the process. |
tiansivive
left a comment
There was a problem hiding this comment.
Alright!
If key collisions aren't expected to be an issue then I think we're all good!
Awesome stuff ✅
💚 Build Succeeded
Metrics [docs]
History
cc @kubasobon |
…donly * commit 'bb1f55fa520b30ceb923af069ef403b24dcb1606': (52 commits) [CPS][Maps] Support CPS Picker in Maps (elastic#246382) [APM] Migrate the Transaction Overview tests to Scout/Playwright/Component/API tests (elastic#245972) [Cases] Change nested field search to be case insensitive (elastic#246643) [ES|QL] PromQL parser initial implementation (elastic#246552) [Agent Builder] Adds keyboard shortcut and toggle behavior to AI Agent button (elastic#246659) Retry on "all shards failed" from ES (elastic#246533) [Streams] Test enable wired streams flow (elastic#246113) [Agent Builder] Fast-follow bugfixes for MCP Tool type (elastic#246665) [Entity Store][API] Fix snake case on CRUD API List response (elastic#246003) [ResponseOps][Slack] Simplify channel configuration (elastic#245423) Add Canonical Name Badge to Documentation (elastic#246647) [Streams] Add simulation filtering by conditions (elastic#245400) [o11y AI] Add `get_hosts` tool (elastic#246541) [agent builder] create_visualization: support heatmap and regionmap (elastic#246671) [AI Infra] Chat experience: Selection modal title change (elastic#246683) [Background search] Change polling behavior (elastic#244760) [ES|QL ] Common Lookup Join Fields Are Not Listed First (elastic#246582) Add missing `dynamic: false` (elastic#246685) [Metrics in Discover] Unskip metrics api test (elastic#246593) [ES|QL] Show next actions after simple field assignment in RERANK ON Clause (elastic#246676) ...
…#246003) ## Summary Closes elastic#241120 A quick fix for `entity.attibutes`, `entity.behaviors`, and `entity.lifecycle` entries being returned with ECS formatting. Now they are lower snake case, as expected. <img width="1998" height="928" alt="image" src="https://github.com/user-attachments/assets/fa781005-740e-4b68-9171-19cf34aae5f2" /> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Summary
Closes #241120
A quick fix for
entity.attibutes,entity.behaviors, andentity.lifecycleentries being returned with ECS formatting. Now they are lower snake case, as expected.