TODO use Context to pass labels and a queue name
(ctx context.Context, t task.Task)
| 602 | |
| 603 | // TODO use Context to pass labels and a queue name |
| 604 | func (op *ShellOperator) taskHandleHookRun(ctx context.Context, t task.Task) queue.TaskResult { |
| 605 | ctx, span := otel.Tracer(serviceName).Start(ctx, "taskHandleHookRun") |
| 606 | defer span.End() |
| 607 | |
| 608 | hookMeta, ok := task_metadata.HookMetadataAccessor(t) |
| 609 | if !ok { |
| 610 | op.logger.Error("Possible Bug! cannot access hook metadata", |
| 611 | slog.String(pkg.LogKeyType, string(t.GetType()))) |
| 612 | return queue.TaskResult{Status: queue.Fail} |
| 613 | } |
| 614 | taskHook := op.HookManager.GetHook(hookMeta.HookName) |
| 615 | if taskHook == nil { |
| 616 | op.logger.Error("hook not found in hook manager, dropping HookRun task", |
| 617 | slog.String(pkg.LogKeyHook, hookMeta.HookName), |
| 618 | slog.String(pkg.LogKeyType, string(t.GetType()))) |
| 619 | return queue.TaskResult{Status: queue.Fail} |
| 620 | } |
| 621 | |
| 622 | err := taskHook.RateLimitWait(ctx) |
| 623 | if err != nil { |
| 624 | // Context cancellation (e.g. shutdown) lands here; repeat so a future |
| 625 | // task handler tick can decide whether to keep going. |
| 626 | return queue.TaskResult{ |
| 627 | Status: queue.Repeat, |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | metricLabels := map[string]string{ |
| 632 | pkg.MetricKeyHook: hookMeta.HookName, |
| 633 | pkg.MetricKeyBinding: hookMeta.Binding, |
| 634 | pkg.MetricKeyQueue: t.GetQueueName(), |
| 635 | } |
| 636 | taskWaitTime := time.Since(t.GetQueuedAt()).Seconds() |
| 637 | op.MetricStorage.CounterAdd(metrics.TaskWaitInQueueSecondsTotal, taskWaitTime, metricLabels) |
| 638 | |
| 639 | defer measure.Duration(func(d time.Duration) { |
| 640 | op.MetricStorage.HistogramObserve(metrics.HookRunSeconds, d.Seconds(), metricLabels, nil) |
| 641 | })() |
| 642 | |
| 643 | hookLogLabels := map[string]string{} |
| 644 | hookLogLabels[pkg.LogKeyHook] = hookMeta.HookName |
| 645 | hookLogLabels[pkg.LogKeyBinding] = hookMeta.Binding |
| 646 | hookLogLabels[pkg.LogKeyEvent] = string(hookMeta.BindingType) |
| 647 | hookLogLabels[pkg.LogKeyTask] = "HookRun" |
| 648 | hookLogLabels[pkg.LogKeyQueue] = t.GetQueueName() |
| 649 | |
| 650 | taskLogEntry := utils.EnrichLoggerWithLabels(op.logger, hookLogLabels) |
| 651 | |
| 652 | isSynchronization := hookMeta.IsSynchronization() |
| 653 | shouldRunHook := true |
| 654 | if isSynchronization { |
| 655 | // There were no Synchronization for v0 hooks, skip hook execution. |
| 656 | if taskHook.Config.Version == "v0" { |
| 657 | shouldRunHook = false |
| 658 | } |
| 659 | // Explicit "executeOnSynchronization: false" |
| 660 | if !hookMeta.ExecuteOnSynchronization { |
| 661 | shouldRunHook = false |
nothing calls this directly
no test coverage detected