This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 435
Adding log as destination for alerting #87
Closed
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7784e5d
typo fix.
anupsv-cb d97f295
Adding "log" alert destination
anupsv-cb 1e3eaa6
Fixing client init call to specify slack type.
anupsv-cb c63a40e
Adding log type to constants.
anupsv-cb 1369e3f
Update internal/core/constants.go
anupsv-cb 7b82409
Update internal/alert/manager.go
anupsv-cb 20b4517
Merge branch 'master' into issue-62
anupsv-cb 207b2b8
Fixing the name.
anupsv-cb 67405fa
Merge branch 'master' into issue-62
anupsv-cb 58364a0
Fixing test.
anupsv-cb 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
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -33,7 +33,7 @@ type alertManager struct { | |
} | ||
|
||
// NewManager ... Instantiates a new alert manager | ||
func NewManager(ctx context.Context, sc client.SlackClient) Manager { | ||
func NewSlackManager(ctx context.Context, sc client.SlackClient) Manager { | ||
// NOTE - Consider constructing dependencies in higher level | ||
// abstraction and passing them in | ||
|
||
|
@@ -52,6 +52,21 @@ func NewManager(ctx context.Context, sc client.SlackClient) Manager { | |
return am | ||
} | ||
|
||
func NewLogManager(ctx context.Context) Manager { | ||
ctx, cancel := context.WithCancel(ctx) | ||
|
||
am := &alertManager{ | ||
ctx: ctx, | ||
cancel: cancel, | ||
|
||
sc: client.NewSlackClient(""), // will change when deps are constructed at higher level | ||
interpolator: NewInterpolator(), | ||
store: NewStore(), | ||
alertTransit: make(chan core.Alert), | ||
} | ||
return am | ||
} | ||
|
||
// AddInvariantSession ... Adds an invariant session to the alert manager store | ||
func (am *alertManager) AddInvariantSession(sUUID core.SUUID, alertDestination core.AlertDestination) error { | ||
return am.store.AddAlertDestination(sUUID, alertDestination) | ||
|
@@ -62,7 +77,7 @@ func (am *alertManager) Transit() chan core.Alert { | |
return am.alertTransit | ||
} | ||
|
||
// handleSlackPost ... Handles posting an alert to slack channel | ||
// handleSlackPost ... Handles posting an alert to Slack channel | ||
func (am *alertManager) handleSlackPost(alert core.Alert) error { | ||
slackMsg := am.interpolator.InterpolateSlackMessage(alert.SUUID, alert.Content) | ||
|
||
|
@@ -78,6 +93,17 @@ func (am *alertManager) handleSlackPost(alert core.Alert) error { | |
return nil | ||
} | ||
|
||
// handleSlackPost ... Handles posting an alert to console log | ||
func (am *alertManager) handleLogPost(alert core.Alert) { | ||
logger := logging.WithContext(am.ctx) | ||
|
||
logger.Error("Pessimism Alert", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if a warning would be more appropriate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, i contemplated that. It essentially depends on how downstream monitoring of logs are setup. Figured usually errors are monitored and consumed, not so much warnings. But we can make the log type as an option in the future. |
||
zap.String("Invariant Condition", alert.SUUID.PID.InvType().String()), | ||
zap.String("Network", alert.SUUID.PID.Network().String()), | ||
zap.String("Session UUID", alert.SUUID.String()), | ||
zap.String("Assessment Content", alert.Content)) | ||
} | ||
|
||
// EventLoop ... Event loop for alert manager subsystem | ||
func (am *alertManager) EventLoop() error { | ||
logger := logging.WithContext(am.ctx) | ||
|
@@ -106,6 +132,11 @@ func (am *alertManager) EventLoop() error { | |
logger.Error("Could not post alert to slack", zap.Error(err)) | ||
} | ||
|
||
case core.Log: | ||
logger.Debug("Attempting to log alert to console") | ||
am.handleLogPost(alert) | ||
logger.Debug("Logging alert to console completed") | ||
anupsv-cb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
case core.ThirdParty: | ||
logger.Error("Attempting to post alert to third_party which is not yet supported") | ||
|
||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious to know the nature/rationale behind changing this name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially, there's a new
NewLogManager
, keepingNewManager
would indicate it can take in configuration of which type. Since that isn't the case now, specifying what the function can handle would be useful.