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

[Fleet] Agent tags not loading with default status filters, bulk update tags not working #148233

Closed
juliaElastic opened this issue Dec 30, 2022 · 4 comments · Fixed by #148618
Closed
Assignees
Labels
bug Fixes for quality problems that affect the customer experience Team:Fleet Team label for Observability Data Collection Fleet team

Comments

@juliaElastic
Copy link
Contributor

juliaElastic commented Dec 30, 2022

Kibana version: 8.7.0

Describe the bug: With the default filters (Healthy, Unhealthy, Updating, Offline) Agent Tags are not loading, and bulk update tags doesn't update any agents. Something might be wrong with the default filters.

Steps to reproduce:

  1. Start kibana on prem or in cloud
  2. Enroll agents with horde
  3. See agents with tags in agent list
  4. Tags filters are not loading with default filters, they load when removing all status filters
  5. Select all agents, add/remove tags with default status filters, the action does not do anything, and Agent activity shows "0 agents updated"

Expected behavior:
Tags filters should be loaded with default status filters, bulk update tags should work.

Screenshots (if relevant):
image
image

Any additional context:

Caused by #147552 where the status field has changed.

Tags request:

http://localhost:5601/julia/api/fleet/agents/tags?kuery=status%3Aonline%20or%20(status%3Aerror%20or%20status%3Adegraded)%20or%20(status%3Aupdating%20or%20status%3Aunenrolling%20or%20status%3Aenrolling)%20or%20status%3Aoffline&showInactive=false

Bulk update tags request:

POST http://localhost:5601/julia/api/fleet/agents/bulk_update_agent_tags"
"{\"agents\":\"status:online or (status:error or status:degraded) or (status:updating or status:unenrolling or status:enrolling) or status:offline\",\"tagsToAdd\":[\"new\"],\"tagsToRemove\":[]}"
@juliaElastic juliaElastic added bug Fixes for quality problems that affect the customer experience Team:Fleet Team label for Observability Data Collection Fleet team labels Dec 30, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@juliaElastic
Copy link
Contributor Author

juliaElastic commented Dec 30, 2022

I think the root cause is that we have several places where the status filters can be used in the code, and those places have to be updated to use the runtime fields: https://github.com/elastic/kibana/pull/147552/files#diff-f7377ed9ad56eaa8ea188b64e957e771ccc7a7652fd1eaf44251c25b930f8448

It is easy to fix the /tags by passing the runtime fields, but the update agent tags uses an updateByQuery call, which doesn't support runtime fields. The fix here is trickier, we might have to bring back the previous logic of status filters without the runtime field.

As a quick fix we could remove the status filters from update tags (at least when the filters are set to the default values) to unblock the feature.

I reviewed the code where the agents index is queried with filters, and none of the other places have missing runtime fields.

cc @hop-dev @kpollich

@joshdover
Copy link
Contributor

It is easy to fix the /tags by passing the runtime fields, but the update agent tags uses an updateByQuery call, which doesn't support runtime fields.

This is a pretty big caveat to runtime fields usage. Wouldn't this also apply to bulk upgrades where we update all the agent documents' update_started_at fields?

I wonder if we could find a way to re-use the runtime script from the mappings in the query itself. Not sure if it's supported in the ways we would need, but we could explore using a stored script that is called from the runtime field and the update_by_query calls.

juliaElastic added a commit that referenced this issue Jan 5, 2023
## Summary

Partial fix for #148233

Added missing runtime fields to tags query.
This fixes Tags filter on Agent List UI when status filters are present.

<img width="1060" alt="image"
src="https://user-images.githubusercontent.com/90178898/210068647-347ed2a9-9339-47f3-b84a-b916afbf17d1.png">

Added a quick fix to remove default status filter from bulk update tags.
This will not work correctly if there are inactive/unenrolled agents.
Update tags with non-default status filters doesn't work either.

EDIT: added back status filters on real fields from history, and using
them in update tags. The missing piece is to tweak the
unenrolled/inactive filters to their latest logic. This should fix
update tags on all status filters, though we have the status logic in
two places. Ideally the status field should become a real field.

<img width="1039" alt="image"
src="https://user-images.githubusercontent.com/90178898/210070213-f466b381-59a8-454c-81be-699989becf02.png">

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@juliaElastic
Copy link
Contributor Author

This is a pretty big caveat to runtime fields usage. Wouldn't this also apply to bulk upgrades where we update all the agent documents' update_started_at fields?

No, upgrade is not using updateByQuery.

I wonder if we could find a way to re-use the runtime script from the mappings in the query itself. Not sure if it's supported in the ways we would need, but we could explore using a stored script that is called from the runtime field and the update_by_query calls.

I thought about this, though update tags already uses a script with updateByQuery, so I don't think we could combine that with a stored script.

@hop-dev suggested another solution here to do a search first with runtime fields, and then do the updateByQuery, I've started exploring that, though it is a bigger refactor, as we have to bring back batch processing, as we can't pass all agent ids at once from the search.

juliaElastic added a commit that referenced this issue Jan 24, 2023
## Summary

Closes #148233

Fixing issue of bulk update tags not working with the new agent status
runtime field.
Refactored update tags to use batching again, resolving 10k agent ids at
a time and `updateByQuery` on batches.
Works locally with dummy agents, has to be tested on cloud with horde to
simulate conflicts.


### Checklist

- [x] [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

Co-authored-by: Kibana Machine <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
bug Fixes for quality problems that affect the customer experience Team:Fleet Team label for Observability Data Collection Fleet team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants