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

MGMT-18863: Fix bug in host event list endpoint #6846

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

paul-maidment
Copy link
Contributor

There is a scenario in which a user will use the same host for multiple installation attempts, in this scenario the cluster, infra env and original host will be deleted each time an installation is attempted.

When a new cluster is created and the host is added, it will have the same ID as the previously installed host. The events will contain entries for all previous incarnations of that host.

The problem occurs when the user attempts to fetch "host bound" events for that host, providing the host ID exclusively.The existing implementation of the events endpoint will return all events for a given host ID.

This creates an excessively large number of results, many of which are invalid.

The solution implemented in this PR
is to ensure that when fetching host exclusive events we condsider only events for which there is an infra env and a host, this will ensure that the events are for the "current" version of that host.

Additionally, some changes have been made to the way in which we fetch events from the ORM (gorm), the previous implementation focussed on binding to models of Hosts, Clusters or InfraEnvs, when in fact the core fields we use are event related.The queries have been rephrased to emphasize this "event centric" nature and to hopefully make the queries clearer to understand.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Sep 30, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented Sep 30, 2024

@paul-maidment: This pull request references MGMT-18863 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "4.18.0" version, but no target version was set.

In response to this:

There is a scenario in which a user will use the same host for multiple installation attempts, in this scenario the cluster, infra env and original host will be deleted each time an installation is attempted.

When a new cluster is created and the host is added, it will have the same ID as the previously installed host. The events will contain entries for all previous incarnations of that host.

The problem occurs when the user attempts to fetch "host bound" events for that host, providing the host ID exclusively.The existing implementation of the events endpoint will return all events for a given host ID.

This creates an excessively large number of results, many of which are invalid.

The solution implemented in this PR
is to ensure that when fetching host exclusive events we condsider only events for which there is an infra env and a host, this will ensure that the events are for the "current" version of that host.

Additionally, some changes have been made to the way in which we fetch events from the ORM (gorm), the previous implementation focussed on binding to models of Hosts, Clusters or InfraEnvs, when in fact the core fields we use are event related.The queries have been rephrased to emphasize this "event centric" nature and to hopefully make the queries clearer to understand.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 30, 2024
Copy link

openshift-ci bot commented Sep 30, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: paul-maidment

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 30, 2024
internal/events/event.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.70%. Comparing base (0fde766) to head (1553507).
Report is 35 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6846      +/-   ##
==========================================
- Coverage   68.73%   68.70%   -0.03%     
==========================================
  Files         249      249              
  Lines       37278    37302      +24     
==========================================
+ Hits        25624    25630       +6     
- Misses       9373     9382       +9     
- Partials     2281     2290       +9     
Flag Coverage Δ
68.70% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/events/event.go 84.50% <100.00%> (ø)

... and 8 files with indirect coverage changes

@rccrdpccl
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 30, 2024
@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD f29f2d8 and 2 for PR HEAD 4882798 in total

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD 4b7dba1 and 1 for PR HEAD 4882798 in total

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD cbbdf27 and 0 for PR HEAD 4882798 in total

@openshift-ci-robot
Copy link

/hold

Revision 4882798 was retested 3 times: holding

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 30, 2024
Copy link

openshift-ci bot commented Oct 1, 2024

New changes are detected. LGTM label has been removed.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Oct 1, 2024
There is a scenario in which a user will use the same host for multiple installation attempts,
in this scenario the cluster, infra env and original host will be deleted each time an installation is attempted.

When a new cluster is created and the host is added, it will have the same ID as the previously installed host. The events will contain entries for all previous incarnations of that host.

The problem occurs when the user attempts to fetch "host bound" events for that host, providing the host ID exclusively.The existing implementation of the events endpoint
will return all events for a given host ID.

This creates an excessively large number of results, many of which are invalid.

The solution implemented in this PR
is to ensure that when fetching host exclusive events we condsider only events for which there is an infra env and a host,
this will ensure that the events are for the "current" version of that host.

Additionally, some changes have been made to the way in which we fetch events from the ORM (gorm),
the previous implementation focussed on binding to models of Hosts, Clusters or InfraEnvs,
when in fact the core fields we use are event related.The queries have been rephrased to emphasize this "event centric" nature and to hopefully make the queries clearer to understand.
@paul-maidment
Copy link
Contributor Author

/test edge-subsystem-kubeapi-aws

@paul-maidment
Copy link
Contributor Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 1, 2024
return tx.Model(&common.Event{}).Select("events.*, infra_envs.user_name, infra_envs.org_id").
Joins("INNER JOIN infra_envs ON infra_envs.id = events.infra_env_id").
Joins("INNER JOIN hosts ON hosts.id = events.host_id"). // This join is here to ensure that only events for a host that exists are fetched
Where("hosts.deleted_at IS NULL") // Only interested in active hosts
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a new behaviour? Would we be able to see deleted host right now?

Copy link
Contributor Author

@paul-maidment paul-maidment Oct 27, 2024

Choose a reason for hiding this comment

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

@rccrdpccl
tx.Model.Select(...) usually considers fields such as "deleted at" because we are dealing with entities (GORM models the entities with fields such as deleted_at and uses this field to understand which entities should be considered "soft deleted") .

The only entity that we use in this query is Event, the remaining tables are not represented as GORM entities in this query (and I think it would be overkill/bad for performance)

It is my understanding that the various pieces of SQL, joins and so on, will not be aware of the deleted/non deleted status of the Host.

So it's not new behaviour but it is something we need to take care of when changing the model from Host to Event.

Copy link

openshift-ci bot commented Oct 28, 2024

@paul-maidment: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/edge-e2e-metal-assisted-mtv-4-17 1553507 link true /test edge-e2e-metal-assisted-mtv-4-17

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants