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

[POR-1616] [POR-1469] [POR-1881] [POR-2026] [POR-1451] [POR-1766] Backend changes to support notifications #3921

Merged
merged 30 commits into from
Nov 10, 2023

Conversation

ferozemohideen
Copy link

@ferozemohideen ferozemohideen commented Nov 2, 2023

POR-1616 POR-1469 POR-1881 POR-2026

What does this PR do?

These changes are introduced to reduce user confusion when it comes to APP_EVENT type events. Instead of changing the agent code to send better app events, we now convert app events to the new Notification struct on the Porter server side.

I would recommend looking at the changes in create_and_update_events.go first, which then brings the logic to the internal/notifications package. From there, you can follow the steps of HandleNotification in notification.go

@ferozemohideen ferozemohideen changed the title Backend changes to support notifications [POR-1616] [POR-1469] [POR-1881] [POR-2026] Backend changes to support notifications Nov 2, 2023
Comment on lines +185 to +186
if err := repo.db.Where("porter_app_id = ? AND type = 'NOTIFICATION' AND metadata->>'app_revision_id' = ?", strAppID, appRevisionId).Find(&notifications).Error; err != nil {
return notifications, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not needed now but could end up being nice just to have app_revision_id as its own column on events

internal/porter_app/notifications/app_event.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@stefanmcshane stefanmcshane left a comment

Choose a reason for hiding this comment

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

Few comments, but overall a great step forward

return nil // nothing to update here
}

serviceStatus, ok := matchEvent.Metadata["service_deployment_metadata"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make the serviceDeploymentGenericMap a type? If not because of dynamic keys, is there a better way we can represent that data?

If the goal here is just to sort the data, can we move that to an auxiliary function to make this more clear

Copy link
Author

Choose a reason for hiding this comment

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

the service deployment metadata would be handled much easier if it was a list type, but changing that would require changing the way we publish it in ccp

Filing a ticket for making that refactor, after which we can simplify this code: https://linear.app/porter/issue/POR-2101/turn-servicedeploymentmetadata-from-a-map-into-a-list-in-ccp

return serviceDeploymentMetadata, telemetry.Error(ctx, span, nil, "event is not a deploy event")
}

serviceStatus, ok := deployEvent.Metadata["service_deployment_metadata"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to the above - can we change the structure, or pull this code out?

return telemetry.Error(ctx, span, err, "deployment target id cannot be nil")
}

notificationMap := make(map[string]any)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can drop this marshalling with the JSONB part also. Test it out to be sure so gorm has no issues

internal/porter_app/notifications/deployment.go Outdated Show resolved Hide resolved
internal/porter_app/notifications/notification.go Outdated Show resolved Hide resolved
@@ -0,0 +1,281 @@
package porter_error
Copy link
Collaborator

Choose a reason for hiding this comment

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

None of this is a requested change, just a suggestion for when dealing with this type of code again.

This is a good implementation but relies on never changing error messages from the agent side. This is where having a distributed contract for the errors which can be returned, which can be read into the agent, or Porter is massively helpful (like an api contract, not just in the porter-dev/api-contracts proto sense)

Since a lot of this code is copy-pasta with minor changes, that usually is a good case for code generation based on a yaml, toml, etc.

Protobuf handles this with messages, grapqhl has error extensions, open api has error definitions which would allow you to consolidate this if needed.

@ferozemohideen ferozemohideen merged commit 10cbb20 into master Nov 10, 2023
9 checks passed
@ferozemohideen ferozemohideen deleted the stacks-v2-notifications-backend branch November 10, 2023 20:35
@ferozemohideen ferozemohideen changed the title [POR-1616] [POR-1469] [POR-1881] [POR-2026] Backend changes to support notifications [POR-1616] [POR-1469] [POR-1881] [POR-2026] [POR-1823] Backend changes to support notifications Nov 17, 2023
@ferozemohideen ferozemohideen changed the title [POR-1616] [POR-1469] [POR-1881] [POR-2026] [POR-1823] Backend changes to support notifications [POR-1616] [POR-1469] [POR-1881] [POR-2026] [POR-1451] [POR-1766] Backend changes to support notifications Nov 17, 2023
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