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

[Integration][GitLab] - Improve on GitOps push events #1028

Merged
merged 11 commits into from
Sep 18, 2024

Conversation

PeyGis
Copy link
Contributor

@PeyGis PeyGis commented Sep 17, 2024

Description

What - Improved on the way the integration handles GitOps push events by using only files that have been changed in the push even rather than fetching the entire repository tree

Why - Some customers were not receiving the push events in their GitLab GitOps

How -

Type of change

Please leave one option from the following and delete the rest:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • New Integration (non-breaking change which adds a new integration)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Non-breaking change (fix of existing functionality that will not change current behavior)
  • Documentation (added/updated documentation)

All tests should be run against the port production environment(using a testing org).

Core testing checklist

  • Integration able to create all default resources from scratch
  • Resync finishes successfully
  • Resync able to create entities
  • Resync able to update entities
  • Resync able to detect and delete entities
  • Scheduled resync able to abort existing resync and start a new one
  • Tested with at least 2 integrations from scratch
  • Tested with Kafka and Polling event listeners
  • Tested deletion of entities that don't pass the selector

Integration testing checklist

  • Integration able to create all default resources from scratch
  • Resync able to create entities
  • Resync able to update entities
  • Resync able to detect and delete entities
  • Resync finishes successfully
  • If new resource kind is added or updated in the integration, add example raw data, mapping and expected result to the examples folder in the integration directory.
  • If resource kind is updated, run the integration with the example data and check if the expected result is achieved
  • If new resource kind is added or updated, validate that live-events for that resource are working as expected
  • Docs PR link here

Preflight checklist

  • Handled rate limiting
  • Handled pagination
  • Implemented the code in async
  • Support Multi account

Screenshots

showing successful ingestion
Screenshot 2024-09-17 at 8 03 09 PM

entity diffs operations
Screenshot 2024-09-17 at 8 03 26 PM

API Documentation

Provide links to the API documentation used for this integration.

@PeyGis PeyGis requested a review from a team as a code owner September 17, 2024 20:03
Copy link
Member

@matan84 matan84 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@matan84 matan84 left a comment

Choose a reason for hiding this comment

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

Left one small recommendation

f"Found file {file} in spec_path {spec_path} pattern, processing its entity diff"
)

if file_action == FileAction.DELETED:
Copy link
Member

Choose a reason for hiding this comment

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

match, case here will be prettier imo

Comment on lines 18 to 56
class FileAction(StrEnum):
DELETED = "deleted"
ADDED = "added"
MODIFIED = "modified"


class PushHook(ProjectHandler):
events = ["Push Hook"]
system_events = ["push"]

async def _on_hook(self, body: dict[str, Any], gitlab_project: Project) -> None:
before, after, ref = body.get("before"), body.get("after"), body.get("ref")
commit_before, commit_after, ref = (
body.get("before"),
body.get("after"),
body.get("ref"),
)

if before is None or after is None or ref is None:
if commit_before is None or commit_after is None or ref is None:
raise ValueError(
"Invalid push hook. Missing one or more of the required fields (before, after, ref)"
)

added_files = [
added_file
for commit in body.get("commits", [])
for added_file in commit.get("added", [])
]
modified_files = [
modified_file
for commit in body.get("commits", [])
for modified_file in commit.get("modified", [])
]

removed_files = [
removed_file
for commit in body.get("commits", [])
for removed_file in commit.get("removed", [])
]

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe worth using the same verb names as in the push hook.
instead of diverging between removed and deleted to use the same removed key that way in the commit.get( you could use the consts that you've created

Comment on lines 123 to 132
logger.info(
f"Processing {file_action} files {files} for project {gitlab_project.path_with_namespace}"
)

for file in files:
try:
if does_pattern_apply(spec_path, file):
logger.info(
f"Found file {file} in spec_path {spec_path} pattern, processing its entity diff"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why would we want to pass all the files that have been added / removed / modified to this function and to this log.

it can be very spammy and irrelevant.
I would rather move this outside of this method, to where we filter the each type of changed files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed it from the loop. i see we are already logging the file info in the method where we get the entities from the commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-09-18 at 12 16 37 PM So far I don't think it's spammy, we only log the relevant info that needs to be displayed. And this will be crucial for debugging

Comment on lines 171 to 174
else:
logger.info(
f"Skipping file {file} as it does not match the spec_path pattern {spec_path}"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

should be debug I think 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

and should be moved outside of the method

Copy link
Contributor

@Tankilevitch Tankilevitch left a comment

Choose a reason for hiding this comment

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

Looks very good 🚀 🌊

for file in files:
try:
if does_pattern_apply(spec_path, file):

Copy link
Contributor

Choose a reason for hiding this comment

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

redundant

@github-actions github-actions bot added size/L and removed size/M labels Sep 18, 2024
@PeyGis PeyGis merged commit 7142248 into main Sep 18, 2024
15 checks passed
@PeyGis PeyGis deleted the PORT-10524-git-lab-gitops-push-event-improvement branch September 18, 2024 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants