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

[Rule Registry] Switch to _source for updating documents instead of Fields API #118245

Merged
merged 10 commits into from
Dec 9, 2021

Conversation

simianhacker
Copy link
Member

@simianhacker simianhacker commented Nov 10, 2021

Summary

This PR closes #113003 by removing the Fields API query and including _source in the results, then it used hit._source inplace of hit.fields for parsing the technical fields. I choose this options because it solved the main issue, Fields API returns derived fields which shouldn't be indexed, with the smallest surface area of change.

It appears that the alerts are only being created and updated via the ruleDataClient.getWriter().bulk(...) operation here:

await ruleDataClient.getWriter().bulk({
body: allEventsToIndex.flatMap(({ event, indexName }) => [
indexName
? { index: { _id: event[ALERT_UUID]!, _index: indexName, require_alias: false } }
: { index: { _id: event[ALERT_UUID]! } },
event,
]),
});

Checklist

@simianhacker simianhacker marked this pull request as ready for review November 15, 2021 16:53
@simianhacker simianhacker added release_note:fix v8.0.0 v8.1.0 Project: Actionable Observability - DEPRECATED Deprecated - Do not use Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" labels Nov 15, 2021
@elastic elastic deleted a comment from kibanamachine Nov 15, 2021
@simianhacker simianhacker marked this pull request as draft November 16, 2021 22:20
@ersin-erdal
Copy link
Contributor

TBH i didn't fully understand what an executor does, but it looks like switching form fields to _source when reading from ruleDataClient is enough. Then the result of that request is sent back with await ruleDataClient.getWriter().bulk action...
LGTM :)

Note: i know not related to this issue but, functions with side-effects like:

const lifecycleAlertServices: LifecycleAlertServices<
      InstanceState,
      InstanceContext,
      ActionGroupIds
    > = {
      alertWithLifecycle: ({ id, fields }) => {
        currentAlerts[id] = fields;
        return alertInstanceFactory(id);
      },
    };

🥺

@simianhacker simianhacker marked this pull request as ready for review November 29, 2021 18:53
@mgiota
Copy link
Contributor

mgiota commented Dec 7, 2021

@simianhacker I started looking into this and assuming we agree to use _source instead of fields, shouldn't we change other parts in the code as well to make it more clear we read from _source? I am not saying we should do following changes, I am just thinking of the scenario we might want to use both fields and _source later on as separate fields, then naming would be confusing. Unless we merged fields and _source in one key called fields, then it should be fine. What do you think? Shall we keep just your current changes or do we want to consider below changes? This would require even more changes to each observability rule type executor (apm, uptime and metric)

Screenshot 2021-12-07 at 14 11 12

To be completely honest I don't feel comfortable with this change, since we are changing to something we don't even use (we don't make use of any object type at the moment, so why do we change it now).

However I tested your changes with existing rule types (created a log threshold rule type, an alert was triggered, I relaxed rule conditions, status was updated from active to recovered) and everything worked as expected. I didn't create an object type though so that I could test that the retrieved ES alert document would not change and be saved back to its original form). We could create a few tests.

I'll meet with @dgieselaar to further discuss on this topic, so I'll summarize the conclusions here.

cc @jasonrhodes

@mgiota
Copy link
Contributor

mgiota commented Dec 7, 2021

@simianhacker We talked with @dgieselaar regarding parseTechnicalFields() and he confirmed that it was written with fields and not _source in mind.

runtimeTypeFromFieldMap assumes that:

  • field names are flattened
  • every value is an array

At the moment everything works because we don't use any nested field type, once we do so, the mismatch might cause surprises.

So if we want to use _source instead of fields, we would want to look into this function. I suggest we create separate functions parseTechnicalSource (or something like this) and runtimeTypeFromSourceMap

I suggest we focus on writing some tests with fields of an object type and see how things work.

@mgiota mgiota self-requested a review December 7, 2021 14:05
@mgiota
Copy link
Contributor

mgiota commented Dec 7, 2021

@afgomez What's your thoughts on this?

Copy link
Contributor

@afgomez afgomez left a comment

Choose a reason for hiding this comment

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

I did some testing and everything seems to work. I introduced a { foo: { bar: 'baz' }} field in the event to see what happened with nested fields and it kept working right.

LGTM!

@simianhacker
Copy link
Member Author

@afgomez Thanks for testing it. I'm in the process of creating a functional/integration test that does exactly this.

@simianhacker
Copy link
Member Author

@elasticmachine merge upstream

Copy link
Contributor

@mgiota mgiota left a comment

Choose a reason for hiding this comment

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

LGTM! Let's wait for CI and we can merge!

@mgiota mgiota added the auto-backport Deprecated - use backport:version if exact versions are needed label Dec 9, 2021
@mgiota mgiota added the Theme: rac label obsolete label Dec 9, 2021
@simianhacker simianhacker enabled auto-merge (squash) December 9, 2021 20:45
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Test Failures

  • [job] [logs] Docker CI Group / Fleet Endpoints EPM Endpoints setup api setup performs upgrades upgrades the endpoint package from 0.13.0 to the latest version available

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@simianhacker simianhacker merged commit 21af670 into elastic:main Dec 9, 2021
@kibanamachine
Copy link
Contributor

💔 Backport failed

Status Branch Result
8.0 Commit could not be cherrypicked due to conflicts

To backport manually run:
node scripts/backport --pr 118245

simianhacker added a commit to simianhacker/kibana that referenced this pull request Dec 9, 2021
…ields API (elastic#118245)

* [Rule Registry] Switch to _source for updating documents instead of Fields API

* updating test with _source instead of fields

* removing mapValues dep

* Refactor types and clean up names

Co-authored-by: Kibana Machine <[email protected]>
simianhacker added a commit that referenced this pull request Dec 13, 2021
…ields API (#118245) (#121026)

* [Rule Registry] Switch to _source for updating documents instead of Fields API

* updating test with _source instead of fields

* removing mapValues dep

* Refactor types and clean up names

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
TinLe pushed a commit to TinLe/kibana that referenced this pull request Dec 22, 2021
…ields API (elastic#118245)

* [Rule Registry] Switch to _source for updating documents instead of Fields API

* updating test with _source instead of fields

* removing mapValues dep

* Refactor types and clean up names

Co-authored-by: Kibana Machine <[email protected]>
@KOTungseth KOTungseth added Team:APM All issues that need APM UI Team support Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability labels Jan 5, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/uptime (Team:uptime)

@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:apm)

gbamparop pushed a commit to gbamparop/kibana that referenced this pull request Jan 12, 2022
…ields API (elastic#118245)

* [Rule Registry] Switch to _source for updating documents instead of Fields API

* updating test with _source instead of fields

* removing mapValues dep

* Refactor types and clean up names

Co-authored-by: Kibana Machine <[email protected]>
simianhacker added a commit to simianhacker/kibana that referenced this pull request Mar 30, 2022
…ields API (elastic#118245)

* [Rule Registry] Switch to _source for updating documents instead of Fields API

* updating test with _source instead of fields

* removing mapValues dep

* Refactor types and clean up names

Co-authored-by: Kibana Machine <[email protected]>
(cherry picked from commit 21af670)

# Conflicts:
#	x-pack/plugins/rule_registry/server/utils/create_lifecycle_rule_type.test.ts
simianhacker added a commit that referenced this pull request Mar 30, 2022
…ields API (#118245) (#128941)

* [Rule Registry] Switch to _source for updating documents instead of Fields API

* updating test with _source instead of fields

* removing mapValues dep

* Refactor types and clean up names

Co-authored-by: Kibana Machine <[email protected]>
(cherry picked from commit 21af670)

# Conflicts:
#	x-pack/plugins/rule_registry/server/utils/create_lifecycle_rule_type.test.ts
@simianhacker simianhacker deleted the issue-113003-switch-to-source branch April 17, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Project: Actionable Observability - DEPRECATED Deprecated - Do not use release_note:fix Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" Team:APM All issues that need APM UI Team support Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability Theme: rac label obsolete v8.0.0 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RAC] Alert document updates should not spread results of a fields API query
8 participants