feat(eda): record every terminal binding outcome and flag failing bindings
This commit is contained in:
1 parent
83cc810e94
commit
dff26fe98b
6 files changed
+50
-21
No files matched your search
@@ -40,8 +40,7 @@ func (d *Daemon) workflowEnablement(ctx context.Context) (workflowtask.WorkflowE
|
||||
|
||||
// resolveBindingTarget checks a matched binding against the workflow it
|
||||
// targets and resolves the task's repository and inputs. A non-empty reason
|
||||
// means the binding does not dispatch and the reason is recorded on it; ok
|
||||
// false with no reason means resolveBindingRepo already logged why.
|
||||
// means the binding does not dispatch and the reason is recorded on it.
|
||||
func (d *Daemon) resolveBindingTarget(b binding.Binding, values map[string]any, workflows workflow.WorkflowDefinitionCollection) (target bindingTarget, reason string, ok bool) {
|
||||
entry, found := workflows.DefinitionByID(b.Workflow)
|
||||
if !found {
|
||||
@@ -72,9 +71,9 @@ func (d *Daemon) resolveBindingTarget(b binding.Binding, values map[string]any,
|
||||
case mode == workflowtask.RepositoryOptional && b.Owner == "":
|
||||
return target, "", true
|
||||
}
|
||||
owner, repo, resolved := d.resolveBindingRepo(b)
|
||||
if !resolved {
|
||||
return bindingTarget{}, "", false
|
||||
owner, repo, reason := d.resolveBindingRepo(b)
|
||||
if reason != "" {
|
||||
return bindingTarget{}, reason, false
|
||||
}
|
||||
target.owner, target.repo = owner, repo
|
||||
return target, "", true
|
||||
|
||||
@@ -617,8 +617,8 @@ func (d *Daemon) dispatchCapture(ctx context.Context, c storecontract.CapturedEv
|
||||
}
|
||||
|
||||
// bindingMapping returns b's mapping, or nil after logging why it is
|
||||
// unavailable.
|
||||
func (d *Daemon) bindingMapping(ctx context.Context, b binding.Binding) *mapping.Mapping {
|
||||
// unavailable. A mapping that no longer exists is a terminal outcome.
|
||||
func (d *Daemon) bindingMapping(ctx context.Context, b binding.Binding, c storecontract.CapturedEvent) *mapping.Mapping {
|
||||
if d.Mappings == nil {
|
||||
d.Log.Warn("binding dispatch: mapping store unavailable", "binding", b.ID)
|
||||
return nil
|
||||
@@ -629,7 +629,7 @@ func (d *Daemon) bindingMapping(ctx context.Context, b binding.Binding) *mapping
|
||||
return nil
|
||||
}
|
||||
if m == nil {
|
||||
d.Log.Warn("binding dispatch: mapping missing", "binding", b.ID, "mapping", b.MappingID)
|
||||
d.recordDispatchFailure(ctx, b, c, fmt.Sprintf("mapping %q does not exist", b.MappingID), nil)
|
||||
}
|
||||
return m
|
||||
}
|
||||
@@ -640,7 +640,7 @@ func (d *Daemon) bindingMapping(ctx context.Context, b binding.Binding) *mapping
|
||||
// dispatch is claimed in the ledger before the task is enqueued, so each
|
||||
// binding fires at most once per capture.
|
||||
func (d *Daemon) dispatchOneBinding(ctx context.Context, b binding.Binding, c storecontract.CapturedEvent, workflows workflow.WorkflowDefinitionCollection) {
|
||||
m := d.bindingMapping(ctx, b)
|
||||
m := d.bindingMapping(ctx, b, c)
|
||||
if m == nil || m.EventTypeID != c.EventType {
|
||||
return
|
||||
}
|
||||
@@ -665,10 +665,8 @@ func (d *Daemon) dispatchOneBinding(ctx context.Context, b binding.Binding, c st
|
||||
}
|
||||
|
||||
target, reason, ok := d.resolveBindingTarget(b, values, workflows)
|
||||
if reason != "" {
|
||||
d.recordDispatchFailure(ctx, b, c, reason, nil)
|
||||
}
|
||||
if !ok {
|
||||
d.recordDispatchFailure(ctx, b, c, reason, nil)
|
||||
return
|
||||
}
|
||||
// The chain decides dispatch: the workflow's identity may `run` this
|
||||
@@ -834,18 +832,15 @@ func renderBindingBody(values map[string]any, c storecontract.CapturedEvent) str
|
||||
|
||||
// resolveBindingRepo returns the binding's pinned owner/repo, or the only
|
||||
// configured repo. With zero or several repos and no pin it refuses.
|
||||
func (d *Daemon) resolveBindingRepo(b binding.Binding) (string, string, bool) {
|
||||
func (d *Daemon) resolveBindingRepo(b binding.Binding) (owner, repo, reason string) {
|
||||
if b.Owner != "" && b.Repo != "" {
|
||||
return b.Owner, b.Repo, true
|
||||
return b.Owner, b.Repo, ""
|
||||
}
|
||||
repos := d.Cfg.Get().Repos
|
||||
if len(repos) == 1 {
|
||||
return repos[0].Owner, repos[0].Name, true
|
||||
return repos[0].Owner, repos[0].Name, ""
|
||||
}
|
||||
d.Log.Warn("binding dispatch: cannot resolve target repo",
|
||||
"hint", "configure exactly one [[repos]] entry, or pin the binding to a specific owner/repo",
|
||||
"configured_repos", len(repos))
|
||||
return "", "", false
|
||||
return "", "", fmt.Sprintf("cannot pick a repository: %d are configured; pin the binding to one", len(repos))
|
||||
}
|
||||
|
||||
// drainReactions turns available review reactions into queued remediate
|
||||
|
||||
@@ -40,6 +40,9 @@ type bindingView struct {
|
||||
// WorkflowDisabled marks a binding whose org has disabled the workflow it
|
||||
// targets; it does not dispatch until the workflow is enabled again.
|
||||
WorkflowDisabled bool `json:"workflow_disabled"`
|
||||
// LastOutcome is the binding's newest ledger row: the task it started or
|
||||
// the reason it started none.
|
||||
LastOutcome *storecontract.Dispatch `json:"last_outcome,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Server) handleBindingsList(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -67,11 +70,28 @@ func (s *Server) handleBindingsList(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
views := make([]bindingView, 0, len(bindings))
|
||||
for _, b := range bindings {
|
||||
views = append(views, bindingView{Binding: b, Unsigned: unsigned[b.Matcher.Source], WorkflowDisabled: !enablement.Enabled(b.OrgID, b.Workflow)})
|
||||
views = append(views, bindingView{
|
||||
Binding: b, Unsigned: unsigned[b.Matcher.Source], WorkflowDisabled: !enablement.Enabled(b.OrgID, b.Workflow),
|
||||
LastOutcome: s.lastOutcome(r.Context(), b.ID),
|
||||
})
|
||||
}
|
||||
writeJSON(w, map[string]any{"bindings": views})
|
||||
}
|
||||
|
||||
// lastOutcome returns a binding's newest dispatch, or nil when it has none or
|
||||
// the ledger is unreadable.
|
||||
func (s *Server) lastOutcome(ctx context.Context, bindingID string) *storecontract.Dispatch {
|
||||
rows, err := s.Bindings.ListDispatches(ctx, storecontract.DispatchFilter{BindingID: bindingID, Limit: 1})
|
||||
if err != nil {
|
||||
s.Log.Warn("binding last outcome", "binding", bindingID, "err", err)
|
||||
return nil
|
||||
}
|
||||
if len(rows) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &rows[0]
|
||||
}
|
||||
|
||||
func (s *Server) handleBindingCreate(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.authorizeTaskMutation(w, r) {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user