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

Skip replicating empty relations when deleting role #1429

Merged
merged 7 commits into from
Jan 22, 2025

Conversation

astrozzc
Copy link
Contributor

Link(s) to Jira

Description of Intent of Change(s)

The what, why and how.

Local Testing

How can the feature be exercised?
How can the bug be exploited and fix confirmed?
Is any special local setup required?

Checklist

  • if API spec changes are required, is the spec updated?
  • are there any pre/post merge actions required? if so, document here.
  • are theses changes covered by unit tests?
  • if warranted, are documentation changes accounted for?
  • does this require migration changes?
    • if yes, are they backwards compatible?
  • is there known, direct impact to dependent teams/components?
    • if yes, how will this be handled?

Secure Coding Practices Checklist Link

Secure Coding Practices Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

@lpichler
Copy link
Contributor

@astrozzc can you describe what is reason that relations are empty ? is because that role doesn't have any assignments ?

@astrozzc astrozzc force-pushed the empty branch 2 times, most recently from 0d486b8 to 2421e0b Compare January 10, 2025 15:07
@astrozzc
Copy link
Contributor Author

@astrozzc can you describe what is reason that relations are empty ? is because that role doesn't have any assignments ?

Yea, the created role has empty access, so there is no relations created for it, and no bindingmapping. When deleting it, there is no relationships to delete too, which explains why the delete/create has almost the same number.
image

@alechenninger
Copy link
Collaborator

Didn't take too close a look but if possible please add logging any time we are not replicating (info level is probably appropriate, I think that's what we do in some other places. Possibly warning if it's unexpected.)

@astrozzc
Copy link
Contributor Author

Didn't take too close a look but if possible please add logging any time we are not replicating (info level is probably appropriate, I think that's what we do in some other places. Possibly warning if it's unexpected.)

Updated with logging. Using info to distinguish with the unexpected skipping replication events

@@ -274,17 +283,31 @@ def replicate_new_or_updated_role(self, role):
return
self.role = role
self._generate_relations_and_mappings_for_role()
# No need to replicate if creating role with empty access, which won't have any relationships
if not role.access.all() and self.event_type == ReplicationEventType.CREATE_CUSTOM_ROLE:
Copy link
Contributor

Choose a reason for hiding this comment

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

Overall idea looks to me.

My concern is whether we should put this logic in to dual write handler or in view/perform_ methods, build _expected_empty_relation_reason here pass it in dual write handler and into replicator.
Replicator will output log info message about the reason.

Reason is that it will not complicate dual write handler methods.

example:

        # check emptiness
        if not role.access.all():
           expected_empty_relation_reason = <build reason>
        dual_write_handler = RelationApiDualWriteHandler(instance, ReplicationEventType.DELETE_CUSTOM_ROLE)
         if not role.access.all():
            dual_write_handler.set_expected_empty_relation_reason_to_replicator(expected_empty_relation_reason)
            or
            dual_write_handler.replicator.set_expected_empty_relation_reason(expected_empty_relation_reason)
       else:
             dual_write_handler.prepare_for_update()

        self.delete_policies_if_no_role_attached(instance)
        instance.delete()

        dual_write_handler.replicate_deleted_role() # this will output only log message as replicator will react on set expected_empty_relation_reason
        role_obj_change_notification_handler(instance, "deleted", self.request.user)

it is just suggestion please let me know what do you think about it.

@astrozzc astrozzc force-pushed the empty branch 4 times, most recently from 4334755 to 4b16ecd Compare January 21, 2025 16:32
@lpichler
Copy link
Contributor

/retest

@lpichler lpichler merged commit 8ab4491 into RedHatInsights:master Jan 22, 2025
11 checks passed
@astrozzc astrozzc deleted the empty branch January 22, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants