Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance access query logic to handle user ID and name conditions #202833

Conversation

arturoliduena
Copy link
Contributor

@arturoliduena arturoliduena commented Dec 3, 2024

[Obs AI Assistant] Fetch user instructions and conversation using user id instead of user name - #192701

To avoid potential collisions when fetching data, we should query for the user id instead of the user name when getting instructions or conversations.

If user.id is provided:

  • Matches documents with user.id equal to the provided value.
  • Falls back to user.name when user.id does not exist in the document.

If user.id is not provided:

  • Matches only documents with user.name.

Summary

Summarize your PR. If it involves visual changes include a screenshot or gif.

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

@arturoliduena arturoliduena added release_note:fix backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Team:Obs AI Assistant Observability AI Assistant labels Dec 3, 2024
@arturoliduena arturoliduena requested a review from a team as a code owner December 3, 2024 22:44
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ai-assistant (Team:Obs AI Assistant)

@botelastic botelastic bot added the ci:project-deploy-observability Create an Observability project label Dec 3, 2024
Copy link
Contributor

github-actions bot commented Dec 3, 2024

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

Comment on lines 23 to 33
? user.id
? [
{ term: { 'user.id': user.id } },
{
bool: {
must_not: { exists: { field: 'user.id' } },
must: { term: { 'user.name': user.name } },
},
},
]
: [{ term: { 'user.name': user.name } }]
Copy link
Member

@sorenlouv sorenlouv Dec 3, 2024

Choose a reason for hiding this comment

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

Perhaps the flattened ternaries are easier to read?

Suggested change
? user.id
? [
{ term: { 'user.id': user.id } },
{
bool: {
must_not: { exists: { field: 'user.id' } },
must: { term: { 'user.name': user.name } },
},
},
]
: [{ term: { 'user.name': user.name } }]
...(user?.id ? [
{ term: { "user.id": user.id } },
{
bool: {
must_not: { exists: { field: "user.id" } },
must: { term: { "user.name": user.name } },
},
},
]
: []),
...(user?.name && !user.id ? [{ term: { "user.name": user.name } }] : []),

Copy link
Member

Choose a reason for hiding this comment

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

Or alternatively a separate function

function getUserAccessFilters(user?: User) {
  if (!user) {
    return [];
  }

  if (user.id) {
    return [
      { term: { 'user.id': user.id } },
      {
        bool: {
          must_not: { exists: { field: 'user.id' } },
          must: { term: { 'user.name': user.name } },
        },
      },
    ];
  }

  return [{ term: { 'user.name': user.name } }];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a separate function is even easier to read. I prefer this alternative.

@sorenlouv
Copy link
Member

sorenlouv commented Dec 3, 2024

Would it make sense to have a get_access_query.test.ts?

Actually, scratch that. Instead a simple API test would be better to actually test the 3 cases.

@elasticmachine
Copy link
Contributor

elasticmachine commented Dec 4, 2024

💚 Build Succeeded

  • Buildkite Build
  • Commit: 90df2f7
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-202833-90df2f779a7b

Metrics [docs]

✅ unchanged

History

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

lgtm! As mentioned, an API test would be nice but not blocking. I'd rather get this in ASAP and backported to 8.17 and 8.x

@arturoliduena arturoliduena added the backport:prev-major Backport to (8.x, 8.17, 8.16) the previous major branch and other branches in development label Dec 4, 2024
@arturoliduena arturoliduena merged commit 720ddd7 into elastic:main Dec 4, 2024
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.15, 8.16, 8.17, 8.x

https://github.com/elastic/kibana/actions/runs/12161234533

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 4, 2024
…stic#202833)

[Obs AI Assistant] Fetch user instructions and conversation using user
id instead of user name -
elastic#192701

To avoid potential collisions when fetching data, we should query for
the user id instead of the user name when getting instructions or
conversations.

**If user.id is provided:**
  - Matches documents with user.id equal to the provided value.
  - Falls back to user.name when user.id does not exist in the document.

**If user.id is not provided:**
  - Matches only documents with user.name.

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 720ddd7)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 4, 2024
…stic#202833)

[Obs AI Assistant] Fetch user instructions and conversation using user
id instead of user name -
elastic#192701

To avoid potential collisions when fetching data, we should query for
the user id instead of the user name when getting instructions or
conversations.

**If user.id is provided:**
  - Matches documents with user.id equal to the provided value.
  - Falls back to user.name when user.id does not exist in the document.

**If user.id is not provided:**
  - Matches only documents with user.name.

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 720ddd7)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.15 Backport failed because of merge conflicts
8.16 Backport failed because of merge conflicts
8.17
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 202833

Questions ?

Please refer to the Backport tool documentation

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 5, 2024
@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.

@sorenlouv sorenlouv added v8.17.0 and removed backport:prev-major Backport to (8.x, 8.17, 8.16) the previous major branch and other branches in development labels Dec 6, 2024
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
…stic#202833)

[Obs AI Assistant] Fetch user instructions and conversation using user
id instead of user name -
elastic#192701

To avoid potential collisions when fetching data, we should query for
the user id instead of the user name when getting instructions or
conversations.

**If user.id is provided:**
  - Matches documents with user.id equal to the provided value.
  - Falls back to user.name when user.id does not exist in the document.
 
**If user.id is not provided:**
  - Matches only documents with user.name.

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
…stic#202833)

[Obs AI Assistant] Fetch user instructions and conversation using user
id instead of user name -
elastic#192701

To avoid potential collisions when fetching data, we should query for
the user id instead of the user name when getting instructions or
conversations.

**If user.id is provided:**
  - Matches documents with user.id equal to the provided value.
  - Falls back to user.name when user.id does not exist in the document.
 
**If user.id is not provided:**
  - Matches only documents with user.name.

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.

kibanamachine added a commit that referenced this pull request Dec 9, 2024
#202833) (#202930)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Enhance access query logic to handle user ID and name conditions
(#202833)](#202833)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Arturo
Lidueña","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-04T13:56:28Z","message":"Enhance
access query logic to handle user ID and name conditions
(#202833)\n\n[Obs AI Assistant] Fetch user instructions and conversation
using user\r\nid instead of user name
-\r\nhttps://github.com//issues/192701\r\n\r\nTo avoid
potential collisions when fetching data, we should query for\r\nthe user
id instead of the user name when getting instructions
or\r\nconversations.\r\n\r\n**If user.id is provided:**\r\n - Matches
documents with user.id equal to the provided value.\r\n - Falls back to
user.name when user.id does not exist in the document.\r\n \r\n**If
user.id is not provided:**\r\n - Matches only documents with
user.name.\r\n\r\n## Summary\r\n\r\nSummarize your PR. If it involves
visual changes include a screenshot or\r\ngif.\r\n\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"720ddd716bda9210ca92d21b0ed7065554118859","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","backport:prev-minor","backport:prev-major","Team:Obs
AI Assistant","ci:project-deploy-observability"],"title":"Enhance access
query logic to handle user ID and name
conditions","number":202833,"url":"https://github.com/elastic/kibana/pull/202833","mergeCommit":{"message":"Enhance
access query logic to handle user ID and name conditions
(#202833)\n\n[Obs AI Assistant] Fetch user instructions and conversation
using user\r\nid instead of user name
-\r\nhttps://github.com//issues/192701\r\n\r\nTo avoid
potential collisions when fetching data, we should query for\r\nthe user
id instead of the user name when getting instructions
or\r\nconversations.\r\n\r\n**If user.id is provided:**\r\n - Matches
documents with user.id equal to the provided value.\r\n - Falls back to
user.name when user.id does not exist in the document.\r\n \r\n**If
user.id is not provided:**\r\n - Matches only documents with
user.name.\r\n\r\n## Summary\r\n\r\nSummarize your PR. If it involves
visual changes include a screenshot or\r\ngif.\r\n\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"720ddd716bda9210ca92d21b0ed7065554118859"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202833","number":202833,"mergeCommit":{"message":"Enhance
access query logic to handle user ID and name conditions
(#202833)\n\n[Obs AI Assistant] Fetch user instructions and conversation
using user\r\nid instead of user name
-\r\nhttps://github.com//issues/192701\r\n\r\nTo avoid
potential collisions when fetching data, we should query for\r\nthe user
id instead of the user name when getting instructions
or\r\nconversations.\r\n\r\n**If user.id is provided:**\r\n - Matches
documents with user.id equal to the provided value.\r\n - Falls back to
user.name when user.id does not exist in the document.\r\n \r\n**If
user.id is not provided:**\r\n - Matches only documents with
user.name.\r\n\r\n## Summary\r\n\r\nSummarize your PR. If it involves
visual changes include a screenshot or\r\ngif.\r\n\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"720ddd716bda9210ca92d21b0ed7065554118859"}}]}]
BACKPORT-->

Co-authored-by: Arturo Lidueña <[email protected]>
Co-authored-by: Søren Louv-Jansen <[email protected]>
kibanamachine added a commit that referenced this pull request Dec 9, 2024
…ns (#202833) (#202929)

# Backport

This will backport the following commits from `main` to `8.17`:
- [Enhance access query logic to handle user ID and name conditions
(#202833)](#202833)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Arturo
Lidueña","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-04T13:56:28Z","message":"Enhance
access query logic to handle user ID and name conditions
(#202833)\n\n[Obs AI Assistant] Fetch user instructions and conversation
using user\r\nid instead of user name
-\r\nhttps://github.com//issues/192701\r\n\r\nTo avoid
potential collisions when fetching data, we should query for\r\nthe user
id instead of the user name when getting instructions
or\r\nconversations.\r\n\r\n**If user.id is provided:**\r\n - Matches
documents with user.id equal to the provided value.\r\n - Falls back to
user.name when user.id does not exist in the document.\r\n \r\n**If
user.id is not provided:**\r\n - Matches only documents with
user.name.\r\n\r\n## Summary\r\n\r\nSummarize your PR. If it involves
visual changes include a screenshot or\r\ngif.\r\n\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"720ddd716bda9210ca92d21b0ed7065554118859","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","backport:prev-minor","backport:prev-major","Team:Obs
AI Assistant","ci:project-deploy-observability"],"title":"Enhance access
query logic to handle user ID and name
conditions","number":202833,"url":"https://github.com/elastic/kibana/pull/202833","mergeCommit":{"message":"Enhance
access query logic to handle user ID and name conditions
(#202833)\n\n[Obs AI Assistant] Fetch user instructions and conversation
using user\r\nid instead of user name
-\r\nhttps://github.com//issues/192701\r\n\r\nTo avoid
potential collisions when fetching data, we should query for\r\nthe user
id instead of the user name when getting instructions
or\r\nconversations.\r\n\r\n**If user.id is provided:**\r\n - Matches
documents with user.id equal to the provided value.\r\n - Falls back to
user.name when user.id does not exist in the document.\r\n \r\n**If
user.id is not provided:**\r\n - Matches only documents with
user.name.\r\n\r\n## Summary\r\n\r\nSummarize your PR. If it involves
visual changes include a screenshot or\r\ngif.\r\n\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"720ddd716bda9210ca92d21b0ed7065554118859"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202833","number":202833,"mergeCommit":{"message":"Enhance
access query logic to handle user ID and name conditions
(#202833)\n\n[Obs AI Assistant] Fetch user instructions and conversation
using user\r\nid instead of user name
-\r\nhttps://github.com//issues/192701\r\n\r\nTo avoid
potential collisions when fetching data, we should query for\r\nthe user
id instead of the user name when getting instructions
or\r\nconversations.\r\n\r\n**If user.id is provided:**\r\n - Matches
documents with user.id equal to the provided value.\r\n - Falls back to
user.name when user.id does not exist in the document.\r\n \r\n**If
user.id is not provided:**\r\n - Matches only documents with
user.name.\r\n\r\n## Summary\r\n\r\nSummarize your PR. If it involves
visual changes include a screenshot or\r\ngif.\r\n\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"720ddd716bda9210ca92d21b0ed7065554118859"}}]}]
BACKPORT-->

Co-authored-by: Arturo Lidueña <[email protected]>
Co-authored-by: Søren Louv-Jansen <[email protected]>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 9, 2024
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 9, 2024
…stic#202833)

[Obs AI Assistant] Fetch user instructions and conversation using user
id instead of user name -
elastic#192701

To avoid potential collisions when fetching data, we should query for
the user id instead of the user name when getting instructions or
conversations.

**If user.id is provided:**
  - Matches documents with user.id equal to the provided value.
  - Falls back to user.name when user.id does not exist in the document.
 
**If user.id is not provided:**
  - Matches only documents with user.name.

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
…stic#202833)

[Obs AI Assistant] Fetch user instructions and conversation using user
id instead of user name -
elastic#192701

To avoid potential collisions when fetching data, we should query for
the user id instead of the user name when getting instructions or
conversations.

**If user.id is provided:**
  - Matches documents with user.id equal to the provided value.
  - Falls back to user.name when user.id does not exist in the document.
 
**If user.id is not provided:**
  - Matches only documents with user.name.

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) ci:project-deploy-observability Create an Observability project release_note:fix Team:Obs AI Assistant Observability AI Assistant v8.17.0 v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants