-
Notifications
You must be signed in to change notification settings - Fork 28
Feature flag BaseTrigger retransmit + Add Metrics #1936
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
29d66a3
Add retry config
DylanTinianov 653a8e7
Merge branch 'main' into base-trigger-retry-config
DylanTinianov a2902d1
Merge branch 'main' into base-trigger-retry-config
DylanTinianov 16aec8b
Update README.md
DylanTinianov 9cfb0ea
Merge branch 'base-trigger-retry-config' of https://github.com/smartc…
DylanTinianov 898d5c2
Resolve baseTrigger retransmit enabled
DylanTinianov 99b52ac
Update defaults.json
DylanTinianov 961849c
Merge branch 'main' into base-trigger-retry-config
DylanTinianov f31328e
Add logging and metrics
DylanTinianov 5d8f163
Fix tests
DylanTinianov 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 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 |
|---|---|---|
|
|
@@ -39,6 +39,10 @@ type BaseTriggerMetrics interface { | |
| IncInboxFull(triggerID string) | ||
| EmitUndeliveredWarning(triggerID, eventID string) | ||
| EmitUndeliveredCritical(triggerID, eventID string) | ||
| // IncAckError counts ACK paths that return an error (e.g. store delete failure). reason is a stable identifier for dashboards. | ||
| IncAckError(reason string) | ||
| // IncAckMemoryOutcome records how an ACK related to the in-memory pending map: hit, miss_no_trigger_bucket, miss_no_event, miss_nil_record. | ||
| IncAckMemoryOutcome(outcome string) | ||
| } | ||
|
|
||
| type undeliveredState struct { | ||
|
|
@@ -192,8 +196,12 @@ func (b *BaseTriggerCapability[T]) DeliverEvent( | |
| } | ||
|
|
||
| if err := b.store.Insert(ctx, rec); err != nil { | ||
| b.lggr.Errorw("base trigger failed to persist pending event", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerID, "eventID", te.ID, "err", err) | ||
| return err | ||
| } | ||
| b.lggr.Infow("base trigger persisted pending event for ACK tracking", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerID, "eventID", te.ID) | ||
|
|
||
| b.mu.Lock() | ||
| if b.pending[triggerID] == nil { | ||
|
|
@@ -236,27 +244,45 @@ func (b *BaseTriggerCapability[T]) sendToInbox(triggerID, eventID string, payloa | |
| func (b *BaseTriggerCapability[T]) AckEvent(ctx context.Context, triggerId string, eventId string) error { | ||
| b.lggr.Infow("Event ACK", "triggerID", triggerId, "eventID", eventId) | ||
| if !b.retransmitEnabled() { | ||
| b.lggr.Debugw("base trigger ACK skipped (retransmit disabled, no persistence/ACK tracking)", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerId, "eventID", eventId) | ||
| b.metrics.IncAckMemoryOutcome("skipped_retransmit_disabled") | ||
| return nil | ||
| } | ||
|
|
||
| var ( | ||
| attempts int | ||
| firstAt time.Time | ||
| found bool | ||
| attempts int | ||
| firstAt time.Time | ||
| found bool | ||
| hadTriggerBucket bool | ||
| hadEventKey bool | ||
| hadNilPendingRecord bool | ||
| ) | ||
|
|
||
| b.mu.Lock() | ||
| if eventsForTrigger, ok := b.pending[triggerId]; ok && eventsForTrigger != nil { | ||
| if rec, recOk := eventsForTrigger[eventId]; recOk && rec != nil { | ||
| eventsForTrigger, ok := b.pending[triggerId] | ||
| hadTriggerBucket = ok && eventsForTrigger != nil | ||
| if hadTriggerBucket { | ||
| rec, recOk := eventsForTrigger[eventId] | ||
| hadEventKey = recOk | ||
| switch { | ||
| case recOk && rec != nil: | ||
| attempts = rec.Attempts | ||
| firstAt = rec.FirstAt | ||
| found = true | ||
| case recOk && rec == nil: | ||
| hadNilPendingRecord = true | ||
| b.metrics.IncAckMemoryOutcome("miss_nil_record") | ||
| default: | ||
| b.metrics.IncAckMemoryOutcome("miss_no_event") | ||
| } | ||
|
|
||
| delete(eventsForTrigger, eventId) | ||
| if len(eventsForTrigger) == 0 { | ||
| delete(b.pending, triggerId) | ||
| } | ||
| } else { | ||
| b.metrics.IncAckMemoryOutcome("miss_no_trigger_bucket") | ||
| } | ||
|
|
||
| if m, ok := b.undeliveredAlertStates[triggerId]; ok { | ||
|
|
@@ -267,12 +293,40 @@ func (b *BaseTriggerCapability[T]) AckEvent(ctx context.Context, triggerId strin | |
| } | ||
| b.mu.Unlock() | ||
|
|
||
| if found { | ||
| switch { | ||
| case found: | ||
| b.lggr.Infow("base trigger ACK matched in-memory pending event", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerId, "eventID", eventId, | ||
| "attempts", attempts, "firstAt", firstAt) | ||
| b.metrics.IncAckMemoryOutcome("hit") | ||
| b.metrics.IncAck(triggerId, eventId) | ||
| b.metrics.ObserveTimeToAck(triggerId, eventId, time.Since(firstAt), attempts) | ||
| case hadNilPendingRecord: | ||
| b.lggr.Warnw("base trigger ACK: pending map had nil record for event (treating as miss; reconciling store)", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerId, "eventID", eventId) | ||
| case hadTriggerBucket && !hadEventKey: | ||
| b.lggr.Infow("base trigger ACK: event id not in in-memory pending map for trigger (may exist only in store; reconciling)", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerId, "eventID", eventId) | ||
| case !hadTriggerBucket: | ||
| b.lggr.Infow("base trigger ACK: no in-memory pending bucket for trigger (not pending here; still deleting from store if row exists)", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerId, "eventID", eventId) | ||
| } | ||
|
|
||
| return b.store.DeleteEvent(ctx, triggerId, eventId) | ||
| if err := b.store.DeleteEvent(ctx, triggerId, eventId); err != nil { | ||
| b.lggr.Errorw("base trigger ACK failed to delete event from store", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerId, "eventID", eventId, | ||
| "foundInMemory", found, "err", err) | ||
| b.metrics.IncAckError("store_delete_failed") | ||
| return err | ||
| } | ||
| if found { | ||
|
Contributor
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. sorry, why not just add found to Infow? I.e., |
||
| b.lggr.Debugw("base trigger ACK store delete succeeded", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerId, "eventID", eventId) | ||
| } else { | ||
| b.lggr.Infow("base trigger ACK store delete succeeded (memory miss path; store row removed if present)", | ||
| "capabilityID", b.capabilityId, "triggerID", triggerId, "eventID", eventId) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (b *BaseTriggerCapability[T]) retransmitLoop() { | ||
|
|
||
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,61 @@ | ||
| package capabilities | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "google.golang.org/protobuf/proto" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
| "github.com/smartcontractkit/chainlink-common/pkg/settings" | ||
| "github.com/smartcontractkit/chainlink-common/pkg/settings/cresettings" | ||
| ) | ||
|
|
||
| // ResolveBaseTriggerRetryInterval returns the retransmit ticker interval for [BaseTriggerCapability]. | ||
| // When [cresettings.Default.BaseTriggerRetransmitEnabled] is false, it returns (0, nil) so the base | ||
| // trigger delivers fire-and-forget without persistence or ACK tracking. | ||
| // When enabled, [cresettings.Default.BaseTriggerRetryInterval] must be positive. | ||
| func ResolveBaseTriggerRetryInterval(ctx context.Context, g settings.Getter, lggr logger.Logger) (retryInterval time.Duration, err error) { | ||
| enabled, gerr := cresettings.Default.BaseTriggerRetransmitEnabled.GetOrDefault(ctx, g) | ||
| if gerr != nil { | ||
| lggr.Errorw("CRE settings read failed for base trigger retransmit flag; using default", "err", gerr) | ||
| } | ||
| if !enabled { | ||
| return 0, nil | ||
| } | ||
| retryInterval, gerr = cresettings.Default.BaseTriggerRetryInterval.GetOrDefault(ctx, g) | ||
| if gerr != nil { | ||
| lggr.Errorw("CRE settings read failed for base trigger retry interval; using default", "err", gerr) | ||
| } | ||
| if retryInterval <= 0 { | ||
| return 0, fmt.Errorf( | ||
| "BaseTriggerRetransmitEnabled is true but BaseTriggerRetryInterval must be positive (got %s)", | ||
| retryInterval, | ||
| ) | ||
| } | ||
| return retryInterval, nil | ||
| } | ||
|
|
||
| // NewBaseTriggerCapabilityWithCRESettings builds a [BaseTriggerCapability] using global CRE settings | ||
| // for retransmit enablement and interval. Undelivered warning/critical thresholds are derived from | ||
| // the resolved interval when retransmit is enabled. | ||
| func NewBaseTriggerCapabilityWithCRESettings[T proto.Message]( | ||
| ctx context.Context, | ||
| store EventStore, | ||
| newMsg func() T, | ||
| lggr logger.Logger, | ||
| capabilityID string, | ||
| getter settings.Getter, | ||
| ) (*BaseTriggerCapability[T], error) { | ||
| retry, err := ResolveBaseTriggerRetryInterval(ctx, getter, lggr) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| var undeliveredWarning, undeliveredCritical time.Duration | ||
| if retry > 0 { | ||
| undeliveredWarning = 5 * retry | ||
| undeliveredCritical = 20 * retry | ||
| } | ||
| return NewBaseTriggerCapability(store, newMsg, lggr, capabilityID, retry, undeliveredWarning, undeliveredCritical), 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
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
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.
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.
similarly, here - can't you just output "hadTriggerBucket", hadTriggerBucket (and other params) in the
Infowparams?