-
Notifications
You must be signed in to change notification settings - Fork 5
fix: notification event payload #2299
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
Open
adityathebe
wants to merge
17
commits into
main
Choose a base branch
from
fix/notification-event-payload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ddb25f7
fix: notification event payload
adityathebe 2c92150
fix: config.changed properties handling
adityathebe 4a7d0dc
test: events -> playbook run
adityathebe c4c3f3f
fix: config.updated event handling for notification
adityathebe 8e37ed6
fix: handle new event_id column in event_queue
adityathebe b3ddeaf
fix: cel env for notification events
adityathebe 2823d37
fix: notification event resource handling
adityathebe 6b3850c
fix: usage of Resource ID
adityathebe 46f890d
fix(events): align event IDs across queue and playbook runs
adityathebe 916a225
fix(notification): use EventQueueOnConflictClause for incremental scrape
adityathebe 1cf3619
fix(playbook): use unique event_id per child playbook in AI actions
adityathebe abba5f7
fix(notification): use ON CONFLICT for playbook.run event creation
adityathebe 53aeacd
fix(events): tighten dedupe keys and AI playbook enqueue
adityathebe 665f6c8
refactor(events): use Find with Limit instead of First in BuildEventR…
adityathebe 881c2a1
fix: proper error message
adityathebe dc6a3fc
fix: err message
adityathebe 90bc618
refactor(events): read into local var before assigning to eventResource
adityathebe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| package events | ||
|
|
||
| import ( | ||
| "github.com/flanksource/duty" | ||
| dutyAPI "github.com/flanksource/duty/api" | ||
| "github.com/flanksource/duty/context" | ||
| "github.com/flanksource/duty/models" | ||
| "github.com/google/uuid" | ||
|
|
||
| "github.com/flanksource/incident-commander/api" | ||
| ) | ||
|
|
||
| type EventResource struct { | ||
| Component *models.Component `json:"component,omitempty"` | ||
| Config *models.ConfigItem `json:"config,omitempty"` | ||
| Check *models.Check `json:"check,omitempty"` | ||
| CheckSummary *models.CheckSummary `json:"check_summary,omitempty"` | ||
| Canary *models.Canary `json:"canary,omitempty"` | ||
| } | ||
|
|
||
| func (t *EventResource) AsMap() map[string]any { | ||
| output := map[string]any{} | ||
|
|
||
| if t.Component != nil { | ||
| output["component"] = t.Component.AsMap() | ||
| } | ||
| if t.Config != nil { | ||
| output["config"] = t.Config.AsMap() | ||
| } | ||
| if t.Check != nil { | ||
| output["check"] = t.Check.AsMap() | ||
| } | ||
| if t.Canary != nil { | ||
| output["canary"] = t.Canary.AsMap() | ||
| } | ||
| if t.CheckSummary != nil { | ||
| output["check_summary"] = t.CheckSummary.AsMap() | ||
| } | ||
|
|
||
| return output | ||
| } | ||
|
|
||
| // BuildEventResource creates an EventResource from an event by fetching the appropriate models from the database | ||
| func BuildEventResource(ctx context.Context, event models.Event) (EventResource, error) { | ||
| var eventResource EventResource | ||
| switch event.Name { | ||
| case api.EventCheckFailed, api.EventCheckPassed: | ||
| checkID := event.EventID | ||
| var check models.Check | ||
| if err := ctx.DB().Where("id = ?", checkID).Limit(1).Find(&check).Error; err != nil { | ||
| return eventResource, err | ||
| } | ||
| if check.ID == uuid.Nil { | ||
| return eventResource, dutyAPI.Errorf(dutyAPI.ENOTFOUND, "check(id=%s) not found", checkID) | ||
| } | ||
| eventResource.Check = &check | ||
|
|
||
| if summary, err := duty.CheckSummary(ctx, checkID.String()); err != nil { | ||
| return eventResource, err | ||
| } else if summary != nil { | ||
| eventResource.CheckSummary = summary | ||
| } | ||
|
|
||
| var canary models.Canary | ||
| if err := ctx.DB().Where("id = ?", eventResource.Check.CanaryID).Limit(1).Find(&canary).Error; err != nil { | ||
| return eventResource, err | ||
| } | ||
| if canary.ID == uuid.Nil { | ||
| return eventResource, dutyAPI.Errorf(dutyAPI.ENOTFOUND, "canary(id=%s) not found", eventResource.Check.CanaryID) | ||
| } | ||
| eventResource.Canary = &canary | ||
|
|
||
| case api.EventComponentHealthy, api.EventComponentUnhealthy, api.EventComponentWarning, api.EventComponentUnknown: | ||
| var component models.Component | ||
| if err := ctx.DB().Model(&models.Component{}).Where("id = ?", event.EventID).Limit(1).Find(&component).Error; err != nil { | ||
| return eventResource, err | ||
| } | ||
| if component.ID == uuid.Nil { | ||
| return eventResource, dutyAPI.Errorf(dutyAPI.ENOTFOUND, "component(id=%s) not found", event.EventID) | ||
| } | ||
| eventResource.Component = &component | ||
|
|
||
| case api.EventConfigHealthy, api.EventConfigUnhealthy, api.EventConfigWarning, api.EventConfigUnknown, api.EventConfigDegraded: | ||
| var config models.ConfigItem | ||
| if err := ctx.DB().Model(&models.ConfigItem{}).Where("id = ?", event.EventID).Limit(1).Find(&config).Error; err != nil { | ||
| return eventResource, err | ||
| } | ||
| if config.ID == uuid.Nil { | ||
| return eventResource, dutyAPI.Errorf(dutyAPI.ENOTFOUND, "config(id=%s) not found", event.EventID) | ||
| } | ||
| eventResource.Config = &config | ||
|
|
||
| case api.EventConfigCreated, api.EventConfigDeleted: | ||
| var config models.ConfigItem | ||
| if err := ctx.DB().Model(&models.ConfigItem{}).Where("id = ?", event.EventID).Limit(1).Find(&config).Error; err != nil { | ||
| return eventResource, err | ||
| } | ||
| if config.ID == uuid.Nil { | ||
| return eventResource, dutyAPI.Errorf(dutyAPI.ENOTFOUND, "config(id=%s) not found", event.EventID) | ||
| } | ||
| eventResource.Config = &config | ||
|
|
||
| case api.EventConfigChanged, api.EventConfigUpdated: | ||
| var config models.ConfigItem | ||
| if err := ctx.DB().Model(&models.ConfigItem{}).Where("id = ?", event.Properties["config_id"]).Limit(1).Find(&config).Error; err != nil { | ||
| return eventResource, err | ||
| } | ||
| if config.ID == uuid.Nil { | ||
| return eventResource, dutyAPI.Errorf(dutyAPI.ENOTFOUND, "config(id=%s) not found", event.Properties["config_id"]) | ||
| } | ||
| eventResource.Config = &config | ||
| } | ||
| return eventResource, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.