Skip to content

[Entity Store][API] Fix snake case on CRUD API List response#246003

Merged
kubasobon merged 29 commits intomainfrom
fix-entity-store-api-list
Dec 17, 2025
Merged

[Entity Store][API] Fix snake case on CRUD API List response#246003
kubasobon merged 29 commits intomainfrom
fix-entity-store-api-list

Conversation

@kubasobon
Copy link
Member

@kubasobon kubasobon commented Dec 11, 2025

Summary

Closes #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.

image

@kubasobon kubasobon requested a review from a team as a code owner December 11, 2025 13:24
@kubasobon kubasobon self-assigned this Dec 11, 2025
@kubasobon kubasobon added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting labels Dec 11, 2025
Copy link
Member

@romulets romulets left a comment

Choose a reason for hiding this comment

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

looks fine. This setup (that I implemented) still doesn't sit right me........ argh.

Anyway, looks good!

@kubasobon kubasobon enabled auto-merge (squash) December 16, 2025 08:43
@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod bot requested a review from a team as a code owner December 16, 2025 09:07
@markov00 markov00 removed the request for review from a team December 16, 2025 17:11
@kubasobon kubasobon disabled auto-merge December 17, 2025 10:13
Copy link
Contributor

@tiansivive tiansivive left a comment

Choose a reason for hiding this comment

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

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)

@kubasobon
Copy link
Member Author

@tiansivive All very good remarks! Thank you for going over it and teaching me something about TS in the process.
As for the collisions - we're not worried about them because the keys themselves, while not being ECS, are very precisely defined and managed by our own code, not the user.

@kubasobon kubasobon requested a review from tiansivive December 17, 2025 11:28
Copy link
Contributor

@tiansivive tiansivive left a comment

Choose a reason for hiding this comment

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

Alright!
If key collisions aren't expected to be an issue then I think we're all good!

Awesome stuff ✅

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @kubasobon

@kubasobon kubasobon merged commit 4313f44 into main Dec 17, 2025
14 checks passed
@kubasobon kubasobon deleted the fix-entity-store-api-list branch December 17, 2025 13:23
mbondyra added a commit to mbondyra/kibana that referenced this pull request Dec 17, 2025
…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)
  ...
KodeRad pushed a commit to KodeRad/kibana that referenced this pull request Dec 17, 2025
…#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>
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 v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Entity Store] List doesn't return properly attributes, behaviors and lifecycle custom fields

5 participants