diff --git a/agent/config/config.go b/agent/config/config.go index 1106916e..adf1f457 100644 --- a/agent/config/config.go +++ b/agent/config/config.go @@ -270,6 +270,15 @@ func NewAgentEnvConfig() AgentConfig { httpPort = p } + webhookPort := WebhookServerPort + if webhookPortStr := os.Getenv("WEBHOOK_PORT"); webhookPortStr != "" { + p, err := strconv.Atoi(webhookPortStr) + if err != nil { + panic(err) + } + webhookPort = p + } + snykBrokerPort := 0 if snykBrokerPortStr := os.Getenv("SNYK_BROKER_PORT"); snykBrokerPortStr != "" { p, err := strconv.Atoi(snykBrokerPortStr) @@ -349,7 +358,7 @@ func NewAgentEnvConfig() AgentConfig { InstanceId: getInstanceId(), IntegrationAlias: identifier, HttpServerPort: httpPort, - WebhookServerPort: WebhookServerPort, + WebhookServerPort: webhookPort, SnykBrokerPort: snykBrokerPort, EnableApiProxy: true, EnablePprof: enablePprof, diff --git a/agent/proto/cortex-axon-agent.proto b/agent/proto/cortex-axon-agent.proto index 760e5a7f..11cc86c3 100644 --- a/agent/proto/cortex-axon-agent.proto +++ b/agent/proto/cortex-axon-agent.proto @@ -12,6 +12,13 @@ service AxonAgent { rpc GetHandlerHistory(GetHandlerHistoryRequest) returns (GetHandlerHistoryResponse); rpc Dispatch (stream DispatchRequest) returns (stream DispatchMessage); rpc ReportInvocation(ReportInvocationRequest) returns (ReportInvocationResponse); + + // DispatchEvents sends the client every failed invocation, and the client + // answers each with what to do about it. It is its own stream so a client + // that has stopped reading Dispatch because every handler is busy still + // hears about failures. An event the client has not answered when the + // stream ends is sent again on the next one. + rpc DispatchEvents(stream DispatchEventsRequest) returns (stream DispatchEvent); } @@ -86,6 +93,9 @@ message ListHandlersResponse { message DispatchRequest { string dispatch_id = 1; string client_version = 2; + // The client handles failure events. The agent only keeps them for clients + // that ask, so an older client never has events pile up for it. + bool failure_events = 3; } message DispatchMessage { @@ -111,6 +121,71 @@ message DispatchHandlerInvoke{ int32 timeout_ms = 10; HandlerInvokeType reason = 11; map args = 20; + // 1 for the first attempt; 0 means the agent didn't say, so treat it as 1. + int32 attempt = 30; + // When the agent stops waiting for this invocation's result and reports + // the failure itself. A client must not start a handler after it, since + // the failure has already been reported. Unset from older agents. + google.protobuf.Timestamp deadline = 31; +} + +// +// Failure events +// + +enum FailureReason { + FAILURE_REASON_UNSPECIFIED = 0; + // The handler returned an error or raised. + HANDLER_ERROR = 1; + // The invocation did not finish within its timeout. + TIMEOUT = 2; + // The invocation could not be dispatched: the queue was full, or it expired + // while waiting for a free handler. + NO_RESOURCES = 3; +} + +enum FailureSource { + FAILURE_SOURCE_UNSPECIFIED = 0; + // The failure came from handler code. + APPLICATION = 1; + // The failure came from Axon: the agent, the SDK, or a Cortex API call. + RUNTIME = 2; +} + +message InvocationFailure { + FailureReason reason = 1; + FailureSource source = 2; + string message = 3; + // Whoever submitted the invocation was told it was not accepted (e.g. a + // webhook sender got a 503), so it may be sent again. + bool caller_rejected = 4; +} + +message DispatchEvent { + DispatchHandlerInvoke invoke = 1; + InvocationFailure failure = 2; +} + +enum FailureAction { + // Treated as DROP. + FAILURE_ACTION_UNSPECIFIED = 0; + // Do nothing more with the invocation. + FAILURE_ACTION_DROP = 1; + // Queue the invocation again as its next attempt. + FAILURE_ACTION_RETRY = 2; +} + +message FailureResolution { + string invocation_id = 1; + FailureAction action = 2; +} + +message DispatchEventsRequest { + // Identifies the client on the first message of the stream. + string dispatch_id = 1; + string client_version = 2; + // The client's answer to a DispatchEvent; unset on the first message. + FailureResolution resolution = 3; } // @@ -131,6 +206,10 @@ message ReportInvocationRequest { InvokeResult result = 200; Error error = 201; } + // Why the invocation failed, from a client that classifies its failures. + // The agent passes it on as a failure event; an error without it is only + // recorded. + InvocationFailure failure = 202; repeated Log logs = 300; } diff --git a/agent/server/handler/handler_invoke.go b/agent/server/handler/handler_invoke.go index 1bc3804a..c5f2abc7 100644 --- a/agent/server/handler/handler_invoke.go +++ b/agent/server/handler/handler_invoke.go @@ -2,7 +2,9 @@ package handler import ( "context" + "errors" "fmt" + "slices" "sync/atomic" "time" @@ -19,6 +21,45 @@ type Invocable interface { Complete(result string, err error) error Done() <-chan struct{} GetResult() (string, error) + + // SetState moves the invocation to a new state, and reports false when + // that transition isn't allowed from where it is now. + SetState(state InvokeState) bool + State() InvokeState +} + +type InvokeState int32 + +const ( + // InvokeQueued is waiting for a client to take it. + InvokeQueued InvokeState = iota + // InvokeDispatched has been sent to a client. + InvokeDispatched + // InvokeExpired ran out of time before a client took it. + InvokeExpired + // InvokeRejected was refused because the queue was full. + InvokeRejected +) + +// invokeTransitions lists the states each state may move to. A queued +// invocation leaves the queue exactly once, one way or another. +var invokeTransitions = map[InvokeState][]InvokeState{ + InvokeQueued: {InvokeDispatched, InvokeExpired, InvokeRejected}, +} + +// FailureError completes an invocation that failed in a way its handler's +// failure hook should hear about. Every such failure, wherever it is +// detected, reaches the failure manager this one way. +type FailureError struct { + Failure *pb.InvocationFailure +} + +func (e *FailureError) Error() string { + return fmt.Sprintf("%s (%s): %s", e.Failure.GetReason(), e.Failure.GetSource(), e.Failure.GetMessage()) +} + +func NewFailureError(reason pb.FailureReason, source pb.FailureSource, message string) *FailureError { + return &FailureError{Failure: &pb.InvocationFailure{Reason: reason, Source: source, Message: message}} } type HandlerInvoke struct { @@ -28,6 +69,7 @@ type HandlerInvoke struct { Args map[string]string Timeout time.Duration Timestamp time.Time + Attempt int32 result string err error @@ -35,6 +77,7 @@ type HandlerInvoke struct { started *atomic.Bool finished *atomic.Bool + state *atomic.Int32 } func NewHandlerInvoke( @@ -49,32 +92,42 @@ func NewHandlerInvoke( Args: args, Timeout: entry.Timeout(), Timestamp: time.Now(), + Attempt: 1, done: make(chan struct{}), started: &atomic.Bool{}, finished: &atomic.Bool{}, + state: &atomic.Int32{}, } } -func (h HandlerInvoke) GetEntry() HandlerEntry { +func (h *HandlerInvoke) GetEntry() HandlerEntry { return h.Entry } -func (h HandlerInvoke) GetName() string { +func (h *HandlerInvoke) GetName() string { return h.Entry.Name() } -func (h HandlerInvoke) GetReason() pb.HandlerInvokeType { +func (h *HandlerInvoke) GetReason() pb.HandlerInvokeType { return h.Reason } +// Start bounds how long the invocation may wait in the queue. Once a client +// has it, its result comes from the client's report or the agent's own +// timeout instead. func (h *HandlerInvoke) Start(ctx context.Context) { if h.started.CompareAndSwap(false, true) { go func() { select { case <-ctx.Done(): - err := ctx.Err() - if err == nil { - err = fmt.Errorf("context cancelled") + if !h.SetState(InvokeExpired) { + return + } + var err error = ctx.Err() + if errors.Is(err, context.DeadlineExceeded) { + err = NewFailureError(pb.FailureReason_NO_RESOURCES, pb.FailureSource_RUNTIME, + fmt.Sprintf("expired after %v waiting for a free handler", + time.Since(h.Timestamp).Round(time.Millisecond))) } h.Complete("", err) case <-h.done: @@ -96,18 +149,34 @@ func (h *HandlerInvoke) Complete(result string, err error) error { return fmt.Errorf("handler already finished") } -func (h HandlerInvoke) GetResult() (string, error) { +func (h *HandlerInvoke) GetResult() (string, error) { if h.finished.Load() { return h.result, h.err } return "", fmt.Errorf("handler not finished") } -func (h HandlerInvoke) Done() <-chan struct{} { +func (h *HandlerInvoke) Done() <-chan struct{} { return h.done } -func (h HandlerInvoke) ToDispatchInvoke() *pb.DispatchHandlerInvoke { +func (h *HandlerInvoke) SetState(to InvokeState) bool { + for { + from := InvokeState(h.state.Load()) + if !slices.Contains(invokeTransitions[from], to) { + return false + } + if h.state.CompareAndSwap(int32(from), int32(to)) { + return true + } + } +} + +func (h *HandlerInvoke) State() InvokeState { + return InvokeState(h.state.Load()) +} + +func (h *HandlerInvoke) ToDispatchInvoke() *pb.DispatchHandlerInvoke { return &pb.DispatchHandlerInvoke{ InvocationId: h.Id, DispatchId: h.Entry.DispatchId(), @@ -116,5 +185,6 @@ func (h HandlerInvoke) ToDispatchInvoke() *pb.DispatchHandlerInvoke { Reason: h.Reason, Args: h.Args, TimeoutMs: int32(h.Entry.Timeout().Milliseconds()), + Attempt: h.Attempt, } } diff --git a/agent/server/handler/handler_manager_test.go b/agent/server/handler/handler_manager_test.go index 7bf7c2c7..51f0e4ca 100644 --- a/agent/server/handler/handler_manager_test.go +++ b/agent/server/handler/handler_manager_test.go @@ -100,7 +100,7 @@ func TestTriggerAndDequeue(t *testing.T) { invoke := NewScheduledHandlerInvoke(entry, pb.HandlerInvokeType_RUN_NOW) err = mgr.Trigger(invoke) require.NoError(t, err) - h, err := mgr.Dequeue(context.Background(), "1", 500*time.Millisecond) + h, err := dequeueWithin(mgr, 500*time.Millisecond) require.NoError(t, err) require.NotNil(t, h) require.Equal(t, "handler1", h.GetEntry().Name()) @@ -165,7 +165,7 @@ func TestTriggerAndDequeueCustomTimeout(t *testing.T) { err = mgr.Trigger(invoke) require.NoError(t, err) - h, err := mgr.Dequeue(context.Background(), "1", 500*time.Millisecond) + h, err := dequeueWithin(mgr, 500*time.Millisecond) require.NoError(t, err) require.NotNil(t, h) require.Equal(t, "handler1", h.GetEntry().Name()) @@ -180,8 +180,8 @@ func TestTriggerAndDequeueTimeout(t *testing.T) { _, err := mgr.RegisterHandler("1", "handler1", defaultTimeout, FixtureHandlerOption()) require.NoError(t, err) - h, err := mgr.Dequeue(context.Background(), "1", time.Millisecond) - require.NoError(t, err) + h, err := dequeueWithin(mgr, time.Millisecond) + require.ErrorIs(t, err, context.DeadlineExceeded) require.Nil(t, h) } @@ -195,8 +195,8 @@ func TestTriggerAndDequeueTimeoutContext(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond) defer cancel() - h, err := mgr.Dequeue(ctx, "1", time.Hour) - require.NoError(t, err) + h, err := mgr.Dequeue(ctx, "1") + require.ErrorIs(t, err, context.DeadlineExceeded) require.Nil(t, h) } diff --git a/agent/server/handler/invoke_state_test.go b/agent/server/handler/invoke_state_test.go new file mode 100644 index 00000000..bbbdff6c --- /dev/null +++ b/agent/server/handler/invoke_state_test.go @@ -0,0 +1,175 @@ +package handler + +import ( + "context" + "fmt" + "testing" + "time" + + pb "github.com/cortexapps/axon/.generated/proto/github.com/cortexapps/axon" + "github.com/cortexapps/axon/server/cron" + "github.com/stretchr/testify/require" + "go.uber.org/zap" +) + +// recordingNotifier collects the failures the manager hands on. +type recordingNotifier struct { + events chan *pb.DispatchEvent +} + +func newRecordingNotifier() *recordingNotifier { + return &recordingNotifier{events: make(chan *pb.DispatchEvent, 100)} +} + +func (r *recordingNotifier) Notify(invoke *pb.DispatchHandlerInvoke, failure *pb.InvocationFailure) { + // Never block the manager's watcher. A test reads the failures it + // expects, so one past the buffer is one no test is waiting for. + select { + case r.events <- &pb.DispatchEvent{Invoke: invoke, Failure: failure}: + default: + } +} + +func (r *recordingNotifier) next(t *testing.T) *pb.DispatchEvent { + select { + case ev := <-r.events: + return ev + case <-time.After(5 * time.Second): + require.FailNow(t, "expected a failure") + return nil + } +} + +func (r *recordingNotifier) requireNone(t *testing.T) { + select { + case ev := <-r.events: + require.FailNow(t, "unexpected failure", "%v", ev) + case <-time.After(200 * time.Millisecond): + } +} + +func webhookOnlyOption() *pb.HandlerOption { + return &pb.HandlerOption{ + Option: &pb.HandlerOption_Invoke{ + Invoke: &pb.HandlerInvokeOption{ + Type: pb.HandlerInvokeType_WEBHOOK, + }, + }, + } +} + +func startNotifiedWebhookHandler(t *testing.T, timeout time.Duration) (Manager, *recordingNotifier, HandlerEntry) { + logger, _ := zap.NewDevelopment() + mgr := NewHandlerManager(logger, cron.New(), nil) + notifier := newRecordingNotifier() + mgr.SetFailureNotifier(notifier) + _, err := mgr.RegisterHandler("1", "handler1", timeout, webhookOnlyOption()) + require.NoError(t, err) + require.NoError(t, mgr.Start("1")) + return mgr, notifier, mgr.ListHandlers()[0] +} + +// dequeueWithin waits up to wait for src's next item. +func dequeueWithin[T any](src InvocationSource[T], wait time.Duration) (T, error) { + ctx, cancel := context.WithTimeout(context.Background(), wait) + defer cancel() + return src.Dequeue(ctx, "1") +} + +func requireNoInvoke(t *testing.T, mgr Manager) { + h, err := dequeueWithin(mgr, 200*time.Millisecond) + require.ErrorIs(t, err, context.DeadlineExceeded, "unexpected invocation %v", h) +} + +func TestInvokeStateTransitions(t *testing.T) { + _, _, entry := startNotifiedWebhookHandler(t, defaultTimeout) + invoke := NewHandlerInvoke(entry, pb.HandlerInvokeType_WEBHOOK, nil) + + require.Equal(t, InvokeQueued, invoke.State()) + require.True(t, invoke.SetState(InvokeDispatched)) + // It leaves the queue once: it can't then expire or be rejected. + require.False(t, invoke.SetState(InvokeExpired)) + require.False(t, invoke.SetState(InvokeRejected)) + require.Equal(t, InvokeDispatched, invoke.State()) +} + +func TestQueueFullIsAFailure(t *testing.T) { + mgr, notifier, entry := startNotifiedWebhookHandler(t, defaultTimeout) + + for i := 0; i < dispatchQueueDepth; i++ { + require.NoError(t, mgr.Trigger(NewHandlerInvoke(entry, pb.HandlerInvokeType_WEBHOOK, nil))) + } + + rejected := NewHandlerInvoke(entry, pb.HandlerInvokeType_WEBHOOK, map[string]string{"body": "payload"}) + require.ErrorIs(t, mgr.Trigger(rejected), ErrDispatchQueueFull) + require.Equal(t, InvokeRejected, rejected.State()) + + ev := notifier.next(t) + require.Equal(t, rejected.Id, ev.Invoke.InvocationId) + require.Equal(t, "payload", ev.Invoke.Args["body"]) + require.Equal(t, pb.FailureReason_NO_RESOURCES, ev.Failure.Reason) + require.Equal(t, pb.FailureSource_RUNTIME, ev.Failure.Source) + require.True(t, ev.Failure.CallerRejected) +} + +func TestExpiredInQueueIsAFailure(t *testing.T) { + mgr, notifier, entry := startNotifiedWebhookHandler(t, 50*time.Millisecond) + + invoke := NewHandlerInvoke(entry, pb.HandlerInvokeType_WEBHOOK, nil) + require.NoError(t, mgr.Trigger(invoke)) + + // Nothing takes it, so it expires in the queue. + ev := notifier.next(t) + require.Equal(t, invoke.Id, ev.Invoke.InvocationId) + require.Equal(t, pb.FailureReason_NO_RESOURCES, ev.Failure.Reason) + require.False(t, ev.Failure.CallerRejected) + + // And it is never handed out afterwards. + requireNoInvoke(t, mgr) +} + +func TestDispatchedInvocationDoesNotExpire(t *testing.T) { + mgr, notifier, entry := startNotifiedWebhookHandler(t, 50*time.Millisecond) + + invoke := NewHandlerInvoke(entry, pb.HandlerInvokeType_WEBHOOK, nil) + require.NoError(t, mgr.Trigger(invoke)) + h, err := dequeueWithin(mgr, time.Second) + require.NoError(t, err) + require.Equal(t, InvokeDispatched, h.State()) + + // Once a client has it, only its report or the agent's timeout ends it. + time.Sleep(200 * time.Millisecond) + notifier.requireNone(t) + select { + case <-invoke.Done(): + require.Fail(t, "a dispatched invocation completed on its queue timeout") + default: + } +} + +func TestReportedFailureIsAFailure(t *testing.T) { + mgr, notifier, entry := startNotifiedWebhookHandler(t, defaultTimeout) + + invoke := NewHandlerInvoke(entry, pb.HandlerInvokeType_WEBHOOK, nil) + require.NoError(t, mgr.Trigger(invoke)) + _, err := dequeueWithin(mgr, time.Second) + require.NoError(t, err) + + invoke.Complete("", NewFailureError(pb.FailureReason_HANDLER_ERROR, pb.FailureSource_APPLICATION, "boom")) + ev := notifier.next(t) + require.Equal(t, invoke.Id, ev.Invoke.InvocationId) + require.Equal(t, pb.FailureReason_HANDLER_ERROR, ev.Failure.Reason) +} + +func TestPlainErrorIsNotAFailure(t *testing.T) { + mgr, notifier, entry := startNotifiedWebhookHandler(t, defaultTimeout) + + invoke := NewHandlerInvoke(entry, pb.HandlerInvokeType_WEBHOOK, nil) + require.NoError(t, mgr.Trigger(invoke)) + _, err := dequeueWithin(mgr, time.Second) + require.NoError(t, err) + + // An older client reports errors without a failure; that is only recorded. + invoke.Complete("", fmt.Errorf("invocation error: boom")) + notifier.requireNone(t) +} diff --git a/agent/server/handler/manager.go b/agent/server/handler/manager.go index 10358e10..81b4942a 100644 --- a/agent/server/handler/manager.go +++ b/agent/server/handler/manager.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "sync" "time" pb "github.com/cortexapps/axon/.generated/proto/github.com/cortexapps/axon" @@ -31,13 +32,26 @@ type Manager interface { Stop(id string) error Trigger(handler Invocable) error GetByTag(tag string) HandlerEntry - Dequeue(ctx context.Context, id string, waitTime time.Duration) (Invocable, error) + // Dequeue hands out the next queued invocation, already moved to + // InvokeDispatched; ones that expired while queued are skipped. + InvocationSource[Invocable] Close() error IsFinished() bool + + // SetFailureNotifier sets where invocations that complete with a + // FailureError are sent. + SetFailureNotifier(notifier FailureNotifier) +} + +// FailureNotifier receives every invocation that completed with a +// FailureError. +type FailureNotifier interface { + Notify(invoke *pb.DispatchHandlerInvoke, failure *pb.InvocationFailure) } type handlerManager struct { logger *zap.Logger + queuesMu sync.Mutex dispatchQueues map[string]chan Invocable outstandingRequests map[string]Invocable handlers map[string]HandlerEntry @@ -47,6 +61,7 @@ type handlerManager struct { invokeCounter *prometheus.CounterVec queueDepthGauge *prometheus.GaugeVec handlerLatencyGauge *prometheus.HistogramVec + failures FailureNotifier } func NewHandlerManager(logger *zap.Logger, cron cron.Cron, metrics *prometheus.Registry) Manager { @@ -203,16 +218,23 @@ func (s *handlerManager) removeHandler(entry HandlerEntry) { delete(s.handlers, entry.Id()) } -func (s *handlerManager) Dequeue(ctx context.Context, dispatchId string, waitTime time.Duration) (Invocable, error) { +func (s *handlerManager) SetFailureNotifier(notifier FailureNotifier) { + s.failures = notifier +} + +func (s *handlerManager) Dequeue(ctx context.Context, dispatchId string) (Invocable, error) { queue := s.getDispatchQueue(dispatchId) - select { - case <-time.After(waitTime): - s.checkFinished() - return nil, nil - case response := <-queue: - return response, nil - case <-ctx.Done(): - return nil, nil + for { + select { + case invoke := <-queue: + if invoke.SetState(InvokeDispatched) { + return invoke, nil + } + // It expired while queued, and that failure has been reported; + // handing it out now would run stale work. + case <-ctx.Done(): + return nil, ctx.Err() + } } } @@ -247,28 +269,39 @@ func (s *handlerManager) Trigger(handler Invocable) error { entry.OnTrigger(message.GetReason()) - startTime := time.Now() queue := s.getDispatchQueue(entry.DispatchId()) + go s.watch(message, logger, cancel) select { case queue <- message: default: // Never block here: Trigger runs on the inbound HTTP goroutine for a // webhook, and a blocked send holds that request open with no timeout. - // Cancelling completes the invocation rather than leaking it. - cancel() - s.queueDepthGauge.WithLabelValues(handlerName).Set(float64(len(queue))) - s.invokeCounter.WithLabelValues(handlerName, "rejected").Inc() + message.SetState(InvokeRejected) + failure := NewFailureError(pb.FailureReason_NO_RESOURCES, pb.FailureSource_RUNTIME, + fmt.Sprintf("dispatch queue is full (%d waiting)", len(queue))) + failure.Failure.CallerRejected = true + message.Complete("", failure) logger.Warn("Dispatch queue is full, rejecting invocation", zap.Int("depth", len(queue))) return ErrDispatchQueueFull } s.queueDepthGauge.WithLabelValues(handlerName).Set(float64(len(queue))) + return nil +} + +// watch waits for an invocation to finish, however that happens, and is the +// one place a failed invocation is handed to the failure manager. +func (s *handlerManager) watch(invoke Invocable, logger *zap.Logger, cancel context.CancelFunc) { + defer cancel() + startTime := time.Now() + handlerName := invoke.GetEntry().Name() + <-invoke.Done() + result, err := invoke.GetResult() - go func() { - defer cancel() - <-message.Done() - result, err := message.GetResult() - s.queueDepthGauge.WithLabelValues(handlerName).Set(float64(len(queue))) + s.queueDepthGauge.WithLabelValues(handlerName).Set(float64(len(s.getDispatchQueue(invoke.GetEntry().DispatchId())))) + if invoke.State() == InvokeRejected { + s.invokeCounter.WithLabelValues(handlerName, "rejected").Inc() + } else { s.handlerLatencyGauge.WithLabelValues(handlerName, result).Observe(float64(time.Since(startTime).Milliseconds())) if err != nil { logger.Error("handler error", zap.Error(err)) @@ -277,13 +310,22 @@ func (s *handlerManager) Trigger(handler Invocable) error { logger.Info("Handler completed", zap.Int("result-length", len(result))) s.invokeCounter.WithLabelValues(handlerName, "success").Inc() } - }() + } - return nil + var failure *FailureError + if errors.As(err, &failure) { + if s.failures == nil { + logger.Warn("Invocation failed, no failure manager", zap.Error(err)) + return + } + s.failures.Notify(invoke.ToDispatchInvoke(), failure.Failure) + } } func (s *handlerManager) getDispatchQueue(DispatchId string) chan Invocable { - + // Webhook goroutines trigger while client streams dequeue. + s.queuesMu.Lock() + defer s.queuesMu.Unlock() queue, ok := s.dispatchQueues[DispatchId] if !ok { queue = make(chan Invocable, dispatchQueueDepth) @@ -326,6 +368,10 @@ func TriggerInvoke(context context.Context, manager Manager, handlerName string, return "", err } - <-handlerInvoke.Done() - return handlerInvoke.GetResult() + select { + case <-handlerInvoke.Done(): + return handlerInvoke.GetResult() + case <-context.Done(): + return "", context.Err() + } } diff --git a/agent/server/handler/scheduled_handler_entry_test.go b/agent/server/handler/scheduled_handler_entry_test.go index 5d43e462..7065785e 100644 --- a/agent/server/handler/scheduled_handler_entry_test.go +++ b/agent/server/handler/scheduled_handler_entry_test.go @@ -253,7 +253,7 @@ func (fhm *fakeManager) Trigger(handler Invocable) error { return os.ErrNotExist } -func (fhm *fakeManager) Dequeue(ctx context.Context, id string, waitTime time.Duration) (Invocable, error) { +func (fhm *fakeManager) Dequeue(ctx context.Context, id string) (Invocable, error) { panic("not implemented") // TODO: Implement } @@ -287,3 +287,6 @@ func (fc *fakeCron) Add(spec string, cmd func()) (string, error) { func (fc *fakeCron) Remove(id string) { delete(fc.handlers, id) } + +func (fhm *fakeManager) SetFailureNotifier(notifier FailureNotifier) { +} diff --git a/agent/server/handler/source.go b/agent/server/handler/source.go new file mode 100644 index 00000000..4dec3b78 --- /dev/null +++ b/agent/server/handler/source.go @@ -0,0 +1,9 @@ +package handler + +import "context" + +// InvocationSource hands out work for one dispatch id. Dequeue blocks until +// there is some or ctx ends, in which case it returns ctx's error. +type InvocationSource[T any] interface { + Dequeue(ctx context.Context, dispatchId string) (T, error) +} diff --git a/agent/server/http/axon_handler_test.go b/agent/server/http/axon_handler_test.go index 39060050..2f7bb0e2 100644 --- a/agent/server/http/axon_handler_test.go +++ b/agent/server/http/axon_handler_test.go @@ -1,7 +1,6 @@ package http import ( - "context" "fmt" "io" "net/http" @@ -53,7 +52,7 @@ func TestInvokeEndpoint(t *testing.T) { response := `{"status":"ok"}` go func() { - handlerInvocation, err := manager.Dequeue(context.Background(), "1", 500*time.Millisecond) + handlerInvocation, err := dequeueWithin(manager, 500*time.Millisecond) require.NoError(t, err) require.NotNil(t, handlerInvocation) require.Equal(t, "test-handler", handlerInvocation.GetEntry().Name()) @@ -111,7 +110,7 @@ func TestInvokeEndpointErr(t *testing.T) { payload := `{"body":"payload"}` go func() { - handlerInvocation, err := manager.Dequeue(context.Background(), "1", 500*time.Millisecond) + handlerInvocation, err := dequeueWithin(manager, 500*time.Millisecond) require.NoError(t, err) require.Equal(t, "test-handler", handlerInvocation.GetEntry().Name()) require.Equal(t, payload, handlerInvocation.ToDispatchInvoke().Args["body"]) diff --git a/agent/server/http/http_server_webhook_test.go b/agent/server/http/http_server_webhook_test.go index 2d34de04..dcd9b902 100644 --- a/agent/server/http/http_server_webhook_test.go +++ b/agent/server/http/http_server_webhook_test.go @@ -32,7 +32,7 @@ func TestHandleWebhook(t *testing.T) { }, } - _, err := manager.RegisterHandler("1", "test", 1, option) + _, err := manager.RegisterHandler("1", "test", time.Minute, option) require.NoError(t, err) err = manager.Start("1") @@ -61,7 +61,7 @@ func TestHandleWebhook(t *testing.T) { Ensure that the handler was invoked */ assert.NotNil(t, manager.GetByTag("my-webhook-id").LastInvoked()) - handlerInvocation, err := manager.Dequeue(context.Background(), "1", 500*time.Millisecond) + handlerInvocation, err := dequeueWithin(manager, 500*time.Millisecond) require.NoError(t, err) require.Equal(t, "test", handlerInvocation.GetEntry().Name()) @@ -122,3 +122,10 @@ func TestHandleWebhookRejectsWhenQueueIsFull(t *testing.T) { require.Fail(t, "webhook request hung on a full queue instead of returning 503") } } + +// dequeueWithin waits up to wait for src's next item. +func dequeueWithin[T any](src handler.InvocationSource[T], wait time.Duration) (T, error) { + ctx, cancel := context.WithTimeout(context.Background(), wait) + defer cancel() + return src.Dequeue(ctx, "1") +} diff --git a/agent/server/invocation_failure_test.go b/agent/server/invocation_failure_test.go new file mode 100644 index 00000000..d5bdf7bd --- /dev/null +++ b/agent/server/invocation_failure_test.go @@ -0,0 +1,207 @@ +package server + +import ( + "context" + "errors" + "net/url" + "path/filepath" + "testing" + "time" + + pb "github.com/cortexapps/axon/.generated/proto/github.com/cortexapps/axon" + "github.com/cortexapps/axon/config" + "github.com/cortexapps/axon/server/cron" + "github.com/cortexapps/axon/server/handler" + "github.com/stretchr/testify/require" + "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +const invocationFailureWebhook = "invocation-failure-hook" + +// recordingNotifier collects the failures the manager hands on. +type recordingNotifier struct { + failures chan *pb.DispatchEvent +} + +func (r *recordingNotifier) Notify(invoke *pb.DispatchHandlerInvoke, failure *pb.InvocationFailure) { + // Never block the manager's watcher. A test reads the failures it + // expects, so one past the buffer is one no test is waiting for. + select { + case r.failures <- &pb.DispatchEvent{Invoke: invoke, Failure: failure}: + default: + } +} + +type invocationFailureFixture struct { + t *testing.T + ctx context.Context + manager handler.Manager + client *testAxonClient + notifier *recordingNotifier + received chan *pb.DispatchHandlerInvoke +} + +// startInvocationFailureFixture runs an agent and a client with one webhook +// handler. respond decides what the client does with each invocation. +func startInvocationFailureFixture(t *testing.T, timeout time.Duration, respond func(*pb.DispatchHandlerInvoke) (clientResult, error)) *invocationFailureFixture { + oldGrace := reportGrace + reportGrace = 100 * time.Millisecond + t.Cleanup(func() { reportGrace = oldGrace }) + + port := getRandomPort() + cfg := config.AgentConfig{ + GrpcPort: port, + CortexApiBaseUrl: "http://localhost", + CortexApiToken: "test-token", + DequeueWaitTime: 100 * time.Millisecond, + HandlerHistoryPath: filepath.Join(t.TempDir(), "history"), + } + + logger, _ := zap.NewDevelopment() + manager := handler.NewHandlerManager(logger, cron.New(), nil) + notifier := &recordingNotifier{failures: make(chan *pb.DispatchEvent, 10)} + manager.SetFailureNotifier(notifier) + agent := NewAxonAgent(Params{Logger: logger, Config: cfg, Manager: manager}) + require.NoError(t, agent.Start(context.Background())) + t.Cleanup(agent.Close) + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + t.Cleanup(cancel) + + f := &invocationFailureFixture{ + t: t, + ctx: ctx, + manager: manager, + notifier: notifier, + received: make(chan *pb.DispatchHandlerInvoke, 10), + } + + f.client = NewTestAxonClient(t, int32(port), func(msg *pb.DispatchMessage) (clientResult, error) { + invoke := msg.GetInvoke() + if invoke == nil { + return clientResult{}, nil + } + f.received <- invoke + return respond(invoke) + }) + t.Cleanup(f.client.Close) + + _, err := f.client.client.RegisterHandler(ctx, &pb.RegisterHandlerRequest{ + DispatchId: f.client.dispatchId, + HandlerName: "hook", + TimeoutMs: int32(timeout.Milliseconds()), + Options: []*pb.HandlerOption{{ + Option: &pb.HandlerOption_Invoke{ + Invoke: &pb.HandlerInvokeOption{Type: pb.HandlerInvokeType_WEBHOOK, Value: invocationFailureWebhook}, + }, + }}, + }) + require.NoError(t, err) + + go f.client.Run(ctx) + require.Eventually(t, func() bool { return manager.GetByTag(invocationFailureWebhook) != nil }, + 5*time.Second, 10*time.Millisecond, "handler never started") + return f +} + +func (f *invocationFailureFixture) postWebhook(body string) { + u, _ := url.Parse("http://localhost/webhook/" + invocationFailureWebhook) + entry := f.manager.GetByTag(invocationFailureWebhook) + require.NoError(f.t, f.manager.Trigger(handler.NewWebhookHandlerInvoke(entry, u, body, "application/json"))) +} + +func (f *invocationFailureFixture) nextInvoke() *pb.DispatchHandlerInvoke { + select { + case invoke := <-f.received: + return invoke + case <-time.After(5 * time.Second): + require.FailNow(f.t, "client never received an invocation") + return nil + } +} + +func (f *invocationFailureFixture) nextFailure() *pb.DispatchEvent { + select { + case ev := <-f.notifier.failures: + return ev + case <-time.After(5 * time.Second): + require.FailNow(f.t, "no failure was reported") + return nil + } +} + +func (f *invocationFailureFixture) requireNoFailure(wait time.Duration) { + select { + case ev := <-f.notifier.failures: + require.FailNow(f.t, "unexpected failure", "%v", ev) + case <-time.After(wait): + } +} + +func TestUnreportedInvocationIsAnAgentTimeout(t *testing.T) { + f := startInvocationFailureFixture(t, 200*time.Millisecond, func(*pb.DispatchHandlerInvoke) (clientResult, error) { + return clientResult{noReport: true}, nil + }) + + before := time.Now() + f.postWebhook(`{"id": 1}`) + invoke := f.nextInvoke() + require.Equal(t, int32(1), invoke.Attempt) + // The deadline is the timeout plus the grace, from when it was sent. + require.NotNil(t, invoke.Deadline) + require.WithinRange(t, invoke.Deadline.AsTime(), before.Add(300*time.Millisecond), time.Now().Add(300*time.Millisecond)) + + ev := f.nextFailure() + require.Equal(t, invoke.InvocationId, ev.Invoke.InvocationId) + require.Equal(t, `{"id": 1}`, ev.Invoke.Args["body"]) + require.Equal(t, pb.FailureReason_TIMEOUT, ev.Failure.Reason) + require.Equal(t, pb.FailureSource_RUNTIME, ev.Failure.Source) +} + +func TestClientReportedFailureIsHandedOnOnce(t *testing.T) { + f := startInvocationFailureFixture(t, 200*time.Millisecond, func(*pb.DispatchHandlerInvoke) (clientResult, error) { + return clientResult{failure: &pb.InvocationFailure{ + Reason: pb.FailureReason_HANDLER_ERROR, + Source: pb.FailureSource_APPLICATION, + Message: "handler blew up", + }}, errors.New("handler blew up") + }) + + f.postWebhook(`{}`) + invoke := f.nextInvoke() + + ev := f.nextFailure() + require.Equal(t, invoke.InvocationId, ev.Invoke.InvocationId) + require.Equal(t, pb.FailureReason_HANDLER_ERROR, ev.Failure.Reason) + require.Equal(t, pb.FailureSource_APPLICATION, ev.Failure.Source) + + // Past the timeout and grace, the agent must not report it again. + f.requireNoFailure(time.Second) +} + +func TestClientErrorWithoutFailureIsOnlyRecorded(t *testing.T) { + f := startInvocationFailureFixture(t, 200*time.Millisecond, func(*pb.DispatchHandlerInvoke) (clientResult, error) { + // An older client reports an error without classifying it. + return clientResult{}, errors.New("handler blew up") + }) + + f.postWebhook(`{}`) + f.nextInvoke() + + f.requireNoFailure(time.Second) +} + +func TestDispatchEventsIsUnimplemented(t *testing.T) { + f := startInvocationFailureFixture(t, 200*time.Millisecond, func(*pb.DispatchHandlerInvoke) (clientResult, error) { + return clientResult{result: "ok"}, nil + }) + + stream, err := f.client.client.DispatchEvents(f.ctx) + require.NoError(t, err) + // The agent may end the stream before this arrives; Recv has its answer. + _ = stream.Send(&pb.DispatchEventsRequest{DispatchId: f.client.dispatchId}) + _, err = stream.Recv() + require.Equal(t, codes.Unimplemented, status.Code(err)) +} diff --git a/agent/server/server.go b/agent/server/server.go index 3c0d74eb..151ff7d5 100644 --- a/agent/server/server.go +++ b/agent/server/server.go @@ -2,6 +2,7 @@ package server import ( "context" + "errors" "fmt" "io" "log" @@ -45,6 +46,10 @@ type AxonAgent struct { historyManager handler.HistoryManager } +// reportGrace is how long past an invocation's timeout the agent waits for +// the client's report before deciding the client never answered. +var reportGrace = 5 * time.Second + type inflightRequest struct { invocable handler.Invocable sentAt time.Time @@ -149,6 +154,39 @@ func (s *AxonAgent) sendComplete(stream pb.AxonAgent_DispatchServer) error { return nil } +// drain sends whatever src hands out for a dispatch id until ctx ends or a +// send fails. With a wait, idle runs whenever src has had nothing for that +// long; returning true ends the drain. +func drain[T any](ctx context.Context, src handler.InvocationSource[T], dispatchId string, send func(T) error, wait time.Duration, idle func() bool) error { + for { + item, err := dequeue(ctx, src, dispatchId, wait) + switch { + case err == nil: + if err := send(item); err != nil { + return err + } + case ctx.Err() != nil: + return nil + case errors.Is(err, context.DeadlineExceeded): + if idle != nil && idle() { + return nil + } + default: + return err + } + } +} + +// dequeue waits for src's next item, for at most wait if it is set. +func dequeue[T any](ctx context.Context, src handler.InvocationSource[T], dispatchId string, wait time.Duration) (T, error) { + if wait > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, wait) + defer cancel() + } + return src.Dequeue(ctx, dispatchId) +} + func (s *AxonAgent) sendInvocations(dispatchId string, stream pb.AxonAgent_DispatchServer) error { s.logger.Info("starting handler set", zap.String("dispatch-id", dispatchId)) @@ -158,69 +196,67 @@ func (s *AxonAgent) sendInvocations(dispatchId string, stream pb.AxonAgent_Dispa return err } - finished := false - go func() { - <-stream.Context().Done() - s.logger.Info("stream context closed", zap.String("dispatch-id", dispatchId), zap.Error(stream.Context().Err())) - finished = true - }() - go func() { defer func() { s.logger.Info("closing handler set", zap.String("dispatch-id", dispatchId)) s.Manager.Stop(dispatchId) }() - for !finished { - invoke, err := s.Manager.Dequeue(stream.Context(), dispatchId, s.config.DequeueWaitTime) - if err != nil { - s.logger.Error("failed to dequeue message", zap.Error(err)) - continue - } - - if invoke == nil { - - if s.Manager.IsFinished() && len(s.outstandingRequests) == 0 { - s.sendComplete(stream) - finished = true - } - continue - } - - now := time.Now() - msg := invoke.ToDispatchInvoke() - - dispatchMessage := &pb.DispatchMessage{ + send := func(invoke handler.Invocable) error { + return stream.Send(&pb.DispatchMessage{ Type: pb.DispatchMessageType_DISPATCH_MESSAGE_INVOKE, - Message: &pb.DispatchMessage_Invoke{Invoke: msg}, - } - - if err := stream.Send(dispatchMessage); err != nil { - s.logger.Error("failed to send dispatch message to client", zap.Error(err)) - return - } - - s.setOutstandingRequest(msg.InvocationId, &inflightRequest{ - invocable: invoke, - sentAt: now, + Message: &pb.DispatchMessage_Invoke{Invoke: s.track(invoke)}, }) - go func(requestId string) { - <-time.After(time.Duration(msg.TimeoutMs) * time.Millisecond) - s.ReportInvocation(context.Background(), &pb.ReportInvocationRequest{ - HandlerInvoke: msg, - Message: &pb.ReportInvocationRequest_Error{Error: &pb.Error{ - Code: "timeout", - Message: fmt.Sprintf( - "handler did not report a result within %dms", - msg.TimeoutMs), - }}, - }) - }(msg.InvocationId) + } + idle := func() bool { + if s.Manager.IsFinished() && s.outstandingCount() == 0 { + s.sendComplete(stream) + return true + } + return false + } + err := drain(stream.Context(), s.Manager, dispatchId, send, s.config.DequeueWaitTime, idle) + if err != nil { + s.logger.Error("failed to send dispatch message to client", zap.Error(err)) } }() return nil } +// track records an invocation as sent and gives it a deadline. If no report +// comes back by then, the agent completes it as a timeout, which it reports +// like any other failure. The grace lets a client that enforces the timeout +// itself report it first, so it is described by the side that saw it. +func (s *AxonAgent) track(invoke handler.Invocable) *pb.DispatchHandlerInvoke { + now := time.Now() + msg := invoke.ToDispatchInvoke() + // The client may not read this for a while if every handler is busy, so + // it gets an absolute deadline rather than only a timeout. + deadline := now.Add(time.Duration(msg.TimeoutMs)*time.Millisecond + reportGrace) + msg.Deadline = timestamppb.New(deadline) + + s.setOutstandingRequest(msg.InvocationId, &inflightRequest{invocable: invoke, sentAt: now}) + time.AfterFunc(time.Until(deadline), func() { + message := fmt.Sprintf("handler did not report a result within %dms", msg.TimeoutMs) + s.completeInvocation(context.Background(), &pb.ReportInvocationRequest{ + HandlerInvoke: msg, + Message: &pb.ReportInvocationRequest_Error{Error: &pb.Error{Code: "timeout", Message: message}}, + Failure: &pb.InvocationFailure{ + Reason: pb.FailureReason_TIMEOUT, + Source: pb.FailureSource_RUNTIME, + Message: message, + }, + }) + }) + return msg +} + +func (s *AxonAgent) outstandingCount() int { + s.inflightLock.RLock() + defer s.inflightLock.RUnlock() + return len(s.outstandingRequests) +} + func (s *AxonAgent) setOutstandingRequest(id string, req *inflightRequest) { s.inflightLock.Lock() defer s.inflightLock.Unlock() @@ -252,20 +288,32 @@ func describeError(e *pb.Error) string { // ReportInvocation is called by the client to report the result of an invocation, which will // log the result of an invocation into the history path. func (s *AxonAgent) ReportInvocation(ctx context.Context, req *pb.ReportInvocationRequest) (*pb.ReportInvocationResponse, error) { - s.inflightLock.RLock() + s.completeInvocation(ctx, req) + return &pb.ReportInvocationResponse{}, nil +} + +// completeInvocation records the result of an outstanding invocation, once: +// a later report for the same invocation is ignored. A report that carries a +// failure completes the invocation with a FailureError, which is how both +// client and agent failures reach the failure manager. +func (s *AxonAgent) completeInvocation(ctx context.Context, req *pb.ReportInvocationRequest) { + s.inflightLock.Lock() ifr, ok := s.outstandingRequests[req.HandlerInvoke.InvocationId] - s.inflightLock.RUnlock() + delete(s.outstandingRequests, req.HandlerInvoke.InvocationId) + s.inflightLock.Unlock() if !ok { - return &pb.ReportInvocationResponse{}, nil + return } - defer s.setOutstandingRequest(req.HandlerInvoke.InvocationId, nil) var requestErr error if e := req.GetError(); e != nil { requestErr = fmt.Errorf("invocation error: %s", describeError(e)) } + if f := req.GetFailure(); f != nil { + requestErr = &handler.FailureError{Failure: f} + } requestResult := "" if rr := req.GetResult(); rr != nil { @@ -278,7 +326,12 @@ func (s *AxonAgent) ReportInvocation(ctx context.Context, req *pb.ReportInvocati if err != nil { s.logger.Error("failed to write history file", zap.Error(err)) } - return &pb.ReportInvocationResponse{}, nil +} + +// DispatchEvents is not served yet. A client that asks for failure events +// gets Unimplemented, which it treats as an agent without them. +func (s *AxonAgent) DispatchEvents(stream pb.AxonAgent_DispatchEventsServer) error { + return status.Error(codes.Unimplemented, "failure events are not enabled") } // ListHandlers returns a list of all registered handlers diff --git a/agent/server/test_axon_client.go b/agent/server/test_axon_client.go index 362a07b9..d9a075e6 100644 --- a/agent/server/test_axon_client.go +++ b/agent/server/test_axon_client.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "sync/atomic" "testing" "time" @@ -21,6 +22,11 @@ type clientResult struct { done bool err error result string + // noReport skips ReportInvocation, like a client that hung. + noReport bool + // failure is reported with an error, as a client that classifies its + // failures does. + failure *pb.InvocationFailure } type testAxonClient struct { @@ -28,8 +34,10 @@ type testAxonClient struct { conn *grpc.ClientConn dispatchId string callback clientCallback - finished bool + finished atomic.Bool t *testing.T + + failureEvents bool } func NewTestAxonClient(t *testing.T, port int32, callback clientCallback) *testAxonClient { @@ -76,7 +84,8 @@ func (c *testAxonClient) Run(ctx context.Context) error { } dispatchReq := &pb.DispatchRequest{ - DispatchId: c.dispatchId, + DispatchId: c.dispatchId, + FailureEvents: c.failureEvents, } logger.Info("sending dispatch request") @@ -86,7 +95,7 @@ func (c *testAxonClient) Run(ctx context.Context) error { return err } - for !c.finished { + for !c.finished.Load() { m, err := stream.Recv() if err != nil { @@ -103,7 +112,7 @@ func (c *testAxonClient) Run(ctx context.Context) error { end := time.Now() invoke := m.GetInvoke() - if invoke != nil { + if invoke != nil && !result.noReport { report := &pb.ReportInvocationRequest{ HandlerInvoke: invoke, @@ -117,6 +126,7 @@ func (c *testAxonClient) Run(ctx context.Context) error { Message: err.Error(), }, } + report.Failure = result.failure } else { report.Message = &pb.ReportInvocationRequest_Result{ Result: &pb.InvokeResult{ @@ -126,6 +136,10 @@ func (c *testAxonClient) Run(ctx context.Context) error { } _, err = c.client.ReportInvocation(ctx, report) + if ctx.Err() != nil { + // The test finished while this report was in flight. + return nil + } require.NoError(c.t, err) } } @@ -133,7 +147,7 @@ func (c *testAxonClient) Run(ctx context.Context) error { } func (c *testAxonClient) Close() { - c.finished = true + c.finished.Store(true) c.conn.Close() } diff --git a/sdks/go/.generated/proto/github.com/cortexapps/axon/cortex-axon-agent.pb.go b/sdks/go/.generated/proto/github.com/cortexapps/axon/cortex-axon-agent.pb.go index ea8b32af..15bb5669 100644 --- a/sdks/go/.generated/proto/github.com/cortexapps/axon/cortex-axon-agent.pb.go +++ b/sdks/go/.generated/proto/github.com/cortexapps/axon/cortex-axon-agent.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.6 -// protoc v3.21.12 +// protoc v7.35.0 // source: cortex-axon-agent.proto package axon @@ -126,6 +126,165 @@ func (DispatchMessageType) EnumDescriptor() ([]byte, []int) { return file_cortex_axon_agent_proto_rawDescGZIP(), []int{1} } +type FailureReason int32 + +const ( + FailureReason_FAILURE_REASON_UNSPECIFIED FailureReason = 0 + // The handler returned an error or raised. + FailureReason_HANDLER_ERROR FailureReason = 1 + // The invocation did not finish within its timeout. + FailureReason_TIMEOUT FailureReason = 2 + // The invocation could not be dispatched: the queue was full, or it expired + // while waiting for a free handler. + FailureReason_NO_RESOURCES FailureReason = 3 +) + +// Enum value maps for FailureReason. +var ( + FailureReason_name = map[int32]string{ + 0: "FAILURE_REASON_UNSPECIFIED", + 1: "HANDLER_ERROR", + 2: "TIMEOUT", + 3: "NO_RESOURCES", + } + FailureReason_value = map[string]int32{ + "FAILURE_REASON_UNSPECIFIED": 0, + "HANDLER_ERROR": 1, + "TIMEOUT": 2, + "NO_RESOURCES": 3, + } +) + +func (x FailureReason) Enum() *FailureReason { + p := new(FailureReason) + *p = x + return p +} + +func (x FailureReason) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (FailureReason) Descriptor() protoreflect.EnumDescriptor { + return file_cortex_axon_agent_proto_enumTypes[2].Descriptor() +} + +func (FailureReason) Type() protoreflect.EnumType { + return &file_cortex_axon_agent_proto_enumTypes[2] +} + +func (x FailureReason) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use FailureReason.Descriptor instead. +func (FailureReason) EnumDescriptor() ([]byte, []int) { + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{2} +} + +type FailureSource int32 + +const ( + FailureSource_FAILURE_SOURCE_UNSPECIFIED FailureSource = 0 + // The failure came from handler code. + FailureSource_APPLICATION FailureSource = 1 + // The failure came from Axon: the agent, the SDK, or a Cortex API call. + FailureSource_RUNTIME FailureSource = 2 +) + +// Enum value maps for FailureSource. +var ( + FailureSource_name = map[int32]string{ + 0: "FAILURE_SOURCE_UNSPECIFIED", + 1: "APPLICATION", + 2: "RUNTIME", + } + FailureSource_value = map[string]int32{ + "FAILURE_SOURCE_UNSPECIFIED": 0, + "APPLICATION": 1, + "RUNTIME": 2, + } +) + +func (x FailureSource) Enum() *FailureSource { + p := new(FailureSource) + *p = x + return p +} + +func (x FailureSource) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (FailureSource) Descriptor() protoreflect.EnumDescriptor { + return file_cortex_axon_agent_proto_enumTypes[3].Descriptor() +} + +func (FailureSource) Type() protoreflect.EnumType { + return &file_cortex_axon_agent_proto_enumTypes[3] +} + +func (x FailureSource) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use FailureSource.Descriptor instead. +func (FailureSource) EnumDescriptor() ([]byte, []int) { + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{3} +} + +type FailureAction int32 + +const ( + // Treated as DROP. + FailureAction_FAILURE_ACTION_UNSPECIFIED FailureAction = 0 + // Do nothing more with the invocation. + FailureAction_FAILURE_ACTION_DROP FailureAction = 1 + // Queue the invocation again as its next attempt. + FailureAction_FAILURE_ACTION_RETRY FailureAction = 2 +) + +// Enum value maps for FailureAction. +var ( + FailureAction_name = map[int32]string{ + 0: "FAILURE_ACTION_UNSPECIFIED", + 1: "FAILURE_ACTION_DROP", + 2: "FAILURE_ACTION_RETRY", + } + FailureAction_value = map[string]int32{ + "FAILURE_ACTION_UNSPECIFIED": 0, + "FAILURE_ACTION_DROP": 1, + "FAILURE_ACTION_RETRY": 2, + } +) + +func (x FailureAction) Enum() *FailureAction { + p := new(FailureAction) + *p = x + return p +} + +func (x FailureAction) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (FailureAction) Descriptor() protoreflect.EnumDescriptor { + return file_cortex_axon_agent_proto_enumTypes[4].Descriptor() +} + +func (FailureAction) Type() protoreflect.EnumType { + return &file_cortex_axon_agent_proto_enumTypes[4] +} + +func (x FailureAction) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use FailureAction.Descriptor instead. +func (FailureAction) EnumDescriptor() ([]byte, []int) { + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{4} +} + type RegisterHandlerRequest struct { state protoimpl.MessageState `protogen:"open.v1"` DispatchId string `protobuf:"bytes,1,opt,name=dispatch_id,json=dispatchId,proto3" json:"dispatch_id,omitempty"` @@ -628,6 +787,9 @@ type DispatchRequest struct { state protoimpl.MessageState `protogen:"open.v1"` DispatchId string `protobuf:"bytes,1,opt,name=dispatch_id,json=dispatchId,proto3" json:"dispatch_id,omitempty"` ClientVersion string `protobuf:"bytes,2,opt,name=client_version,json=clientVersion,proto3" json:"client_version,omitempty"` + // The client handles failure events. The agent only keeps them for clients + // that ask, so an older client never has events pile up for it. + FailureEvents bool `protobuf:"varint,3,opt,name=failure_events,json=failureEvents,proto3" json:"failure_events,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -676,6 +838,13 @@ func (x *DispatchRequest) GetClientVersion() string { return "" } +func (x *DispatchRequest) GetFailureEvents() bool { + if x != nil { + return x.FailureEvents + } + return false +} + type DispatchMessage struct { state protoimpl.MessageState `protogen:"open.v1"` Type DispatchMessageType `protobuf:"varint,1,opt,name=type,proto3,enum=cortex.axon.DispatchMessageType" json:"type,omitempty"` @@ -751,14 +920,20 @@ type DispatchMessage_Invoke struct { func (*DispatchMessage_Invoke) isDispatchMessage_Message() {} type DispatchHandlerInvoke struct { - state protoimpl.MessageState `protogen:"open.v1"` - InvocationId string `protobuf:"bytes,1,opt,name=invocation_id,json=invocationId,proto3" json:"invocation_id,omitempty"` - DispatchId string `protobuf:"bytes,2,opt,name=dispatch_id,json=dispatchId,proto3" json:"dispatch_id,omitempty"` - HandlerId string `protobuf:"bytes,3,opt,name=handler_id,json=handlerId,proto3" json:"handler_id,omitempty"` - HandlerName string `protobuf:"bytes,4,opt,name=handler_name,json=handlerName,proto3" json:"handler_name,omitempty"` - TimeoutMs int32 `protobuf:"varint,10,opt,name=timeout_ms,json=timeoutMs,proto3" json:"timeout_ms,omitempty"` - Reason HandlerInvokeType `protobuf:"varint,11,opt,name=reason,proto3,enum=cortex.axon.HandlerInvokeType" json:"reason,omitempty"` - Args map[string]string `protobuf:"bytes,20,rep,name=args,proto3" json:"args,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + state protoimpl.MessageState `protogen:"open.v1"` + InvocationId string `protobuf:"bytes,1,opt,name=invocation_id,json=invocationId,proto3" json:"invocation_id,omitempty"` + DispatchId string `protobuf:"bytes,2,opt,name=dispatch_id,json=dispatchId,proto3" json:"dispatch_id,omitempty"` + HandlerId string `protobuf:"bytes,3,opt,name=handler_id,json=handlerId,proto3" json:"handler_id,omitempty"` + HandlerName string `protobuf:"bytes,4,opt,name=handler_name,json=handlerName,proto3" json:"handler_name,omitempty"` + TimeoutMs int32 `protobuf:"varint,10,opt,name=timeout_ms,json=timeoutMs,proto3" json:"timeout_ms,omitempty"` + Reason HandlerInvokeType `protobuf:"varint,11,opt,name=reason,proto3,enum=cortex.axon.HandlerInvokeType" json:"reason,omitempty"` + Args map[string]string `protobuf:"bytes,20,rep,name=args,proto3" json:"args,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + // 1 for the first attempt; 0 means the agent didn't say, so treat it as 1. + Attempt int32 `protobuf:"varint,30,opt,name=attempt,proto3" json:"attempt,omitempty"` + // When the agent stops waiting for this invocation's result and reports + // the failure itself. A client must not start a handler after it, since + // the failure has already been reported. Unset from older agents. + Deadline *timestamppb.Timestamp `protobuf:"bytes,31,opt,name=deadline,proto3" json:"deadline,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -842,6 +1017,256 @@ func (x *DispatchHandlerInvoke) GetArgs() map[string]string { return nil } +func (x *DispatchHandlerInvoke) GetAttempt() int32 { + if x != nil { + return x.Attempt + } + return 0 +} + +func (x *DispatchHandlerInvoke) GetDeadline() *timestamppb.Timestamp { + if x != nil { + return x.Deadline + } + return nil +} + +type InvocationFailure struct { + state protoimpl.MessageState `protogen:"open.v1"` + Reason FailureReason `protobuf:"varint,1,opt,name=reason,proto3,enum=cortex.axon.FailureReason" json:"reason,omitempty"` + Source FailureSource `protobuf:"varint,2,opt,name=source,proto3,enum=cortex.axon.FailureSource" json:"source,omitempty"` + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` + // Whoever submitted the invocation was told it was not accepted (e.g. a + // webhook sender got a 503), so it may be sent again. + CallerRejected bool `protobuf:"varint,4,opt,name=caller_rejected,json=callerRejected,proto3" json:"caller_rejected,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *InvocationFailure) Reset() { + *x = InvocationFailure{} + mi := &file_cortex_axon_agent_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *InvocationFailure) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InvocationFailure) ProtoMessage() {} + +func (x *InvocationFailure) ProtoReflect() protoreflect.Message { + mi := &file_cortex_axon_agent_proto_msgTypes[12] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use InvocationFailure.ProtoReflect.Descriptor instead. +func (*InvocationFailure) Descriptor() ([]byte, []int) { + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{12} +} + +func (x *InvocationFailure) GetReason() FailureReason { + if x != nil { + return x.Reason + } + return FailureReason_FAILURE_REASON_UNSPECIFIED +} + +func (x *InvocationFailure) GetSource() FailureSource { + if x != nil { + return x.Source + } + return FailureSource_FAILURE_SOURCE_UNSPECIFIED +} + +func (x *InvocationFailure) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *InvocationFailure) GetCallerRejected() bool { + if x != nil { + return x.CallerRejected + } + return false +} + +type DispatchEvent struct { + state protoimpl.MessageState `protogen:"open.v1"` + Invoke *DispatchHandlerInvoke `protobuf:"bytes,1,opt,name=invoke,proto3" json:"invoke,omitempty"` + Failure *InvocationFailure `protobuf:"bytes,2,opt,name=failure,proto3" json:"failure,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DispatchEvent) Reset() { + *x = DispatchEvent{} + mi := &file_cortex_axon_agent_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DispatchEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DispatchEvent) ProtoMessage() {} + +func (x *DispatchEvent) ProtoReflect() protoreflect.Message { + mi := &file_cortex_axon_agent_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DispatchEvent.ProtoReflect.Descriptor instead. +func (*DispatchEvent) Descriptor() ([]byte, []int) { + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{13} +} + +func (x *DispatchEvent) GetInvoke() *DispatchHandlerInvoke { + if x != nil { + return x.Invoke + } + return nil +} + +func (x *DispatchEvent) GetFailure() *InvocationFailure { + if x != nil { + return x.Failure + } + return nil +} + +type FailureResolution struct { + state protoimpl.MessageState `protogen:"open.v1"` + InvocationId string `protobuf:"bytes,1,opt,name=invocation_id,json=invocationId,proto3" json:"invocation_id,omitempty"` + Action FailureAction `protobuf:"varint,2,opt,name=action,proto3,enum=cortex.axon.FailureAction" json:"action,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FailureResolution) Reset() { + *x = FailureResolution{} + mi := &file_cortex_axon_agent_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FailureResolution) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FailureResolution) ProtoMessage() {} + +func (x *FailureResolution) ProtoReflect() protoreflect.Message { + mi := &file_cortex_axon_agent_proto_msgTypes[14] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FailureResolution.ProtoReflect.Descriptor instead. +func (*FailureResolution) Descriptor() ([]byte, []int) { + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{14} +} + +func (x *FailureResolution) GetInvocationId() string { + if x != nil { + return x.InvocationId + } + return "" +} + +func (x *FailureResolution) GetAction() FailureAction { + if x != nil { + return x.Action + } + return FailureAction_FAILURE_ACTION_UNSPECIFIED +} + +type DispatchEventsRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Identifies the client on the first message of the stream. + DispatchId string `protobuf:"bytes,1,opt,name=dispatch_id,json=dispatchId,proto3" json:"dispatch_id,omitempty"` + ClientVersion string `protobuf:"bytes,2,opt,name=client_version,json=clientVersion,proto3" json:"client_version,omitempty"` + // The client's answer to a DispatchEvent; unset on the first message. + Resolution *FailureResolution `protobuf:"bytes,3,opt,name=resolution,proto3" json:"resolution,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DispatchEventsRequest) Reset() { + *x = DispatchEventsRequest{} + mi := &file_cortex_axon_agent_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DispatchEventsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DispatchEventsRequest) ProtoMessage() {} + +func (x *DispatchEventsRequest) ProtoReflect() protoreflect.Message { + mi := &file_cortex_axon_agent_proto_msgTypes[15] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DispatchEventsRequest.ProtoReflect.Descriptor instead. +func (*DispatchEventsRequest) Descriptor() ([]byte, []int) { + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{15} +} + +func (x *DispatchEventsRequest) GetDispatchId() string { + if x != nil { + return x.DispatchId + } + return "" +} + +func (x *DispatchEventsRequest) GetClientVersion() string { + if x != nil { + return x.ClientVersion + } + return "" +} + +func (x *DispatchEventsRequest) GetResolution() *FailureResolution { + if x != nil { + return x.Resolution + } + return nil +} + type Log struct { state protoimpl.MessageState `protogen:"open.v1"` Level string `protobuf:"bytes,1,opt,name=level,proto3" json:"level,omitempty"` @@ -853,7 +1278,7 @@ type Log struct { func (x *Log) Reset() { *x = Log{} - mi := &file_cortex_axon_agent_proto_msgTypes[12] + mi := &file_cortex_axon_agent_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -865,7 +1290,7 @@ func (x *Log) String() string { func (*Log) ProtoMessage() {} func (x *Log) ProtoReflect() protoreflect.Message { - mi := &file_cortex_axon_agent_proto_msgTypes[12] + mi := &file_cortex_axon_agent_proto_msgTypes[16] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -878,7 +1303,7 @@ func (x *Log) ProtoReflect() protoreflect.Message { // Deprecated: Use Log.ProtoReflect.Descriptor instead. func (*Log) Descriptor() ([]byte, []int) { - return file_cortex_axon_agent_proto_rawDescGZIP(), []int{12} + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{16} } func (x *Log) GetLevel() string { @@ -911,15 +1336,19 @@ type ReportInvocationRequest struct { // // *ReportInvocationRequest_Result // *ReportInvocationRequest_Error - Message isReportInvocationRequest_Message `protobuf_oneof:"message"` - Logs []*Log `protobuf:"bytes,300,rep,name=logs,proto3" json:"logs,omitempty"` + Message isReportInvocationRequest_Message `protobuf_oneof:"message"` + // Why the invocation failed, from a client that classifies its failures. + // The agent passes it on as a failure event; an error without it is only + // recorded. + Failure *InvocationFailure `protobuf:"bytes,202,opt,name=failure,proto3" json:"failure,omitempty"` + Logs []*Log `protobuf:"bytes,300,rep,name=logs,proto3" json:"logs,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *ReportInvocationRequest) Reset() { *x = ReportInvocationRequest{} - mi := &file_cortex_axon_agent_proto_msgTypes[13] + mi := &file_cortex_axon_agent_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -931,7 +1360,7 @@ func (x *ReportInvocationRequest) String() string { func (*ReportInvocationRequest) ProtoMessage() {} func (x *ReportInvocationRequest) ProtoReflect() protoreflect.Message { - mi := &file_cortex_axon_agent_proto_msgTypes[13] + mi := &file_cortex_axon_agent_proto_msgTypes[17] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -944,7 +1373,7 @@ func (x *ReportInvocationRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ReportInvocationRequest.ProtoReflect.Descriptor instead. func (*ReportInvocationRequest) Descriptor() ([]byte, []int) { - return file_cortex_axon_agent_proto_rawDescGZIP(), []int{13} + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{17} } func (x *ReportInvocationRequest) GetHandlerInvoke() *DispatchHandlerInvoke { @@ -993,6 +1422,13 @@ func (x *ReportInvocationRequest) GetError() *Error { return nil } +func (x *ReportInvocationRequest) GetFailure() *InvocationFailure { + if x != nil { + return x.Failure + } + return nil +} + func (x *ReportInvocationRequest) GetLogs() []*Log { if x != nil { return x.Logs @@ -1025,7 +1461,7 @@ type ReportInvocationResponse struct { func (x *ReportInvocationResponse) Reset() { *x = ReportInvocationResponse{} - mi := &file_cortex_axon_agent_proto_msgTypes[14] + mi := &file_cortex_axon_agent_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1037,7 +1473,7 @@ func (x *ReportInvocationResponse) String() string { func (*ReportInvocationResponse) ProtoMessage() {} func (x *ReportInvocationResponse) ProtoReflect() protoreflect.Message { - mi := &file_cortex_axon_agent_proto_msgTypes[14] + mi := &file_cortex_axon_agent_proto_msgTypes[18] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1050,7 +1486,7 @@ func (x *ReportInvocationResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ReportInvocationResponse.ProtoReflect.Descriptor instead. func (*ReportInvocationResponse) Descriptor() ([]byte, []int) { - return file_cortex_axon_agent_proto_rawDescGZIP(), []int{14} + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{18} } func (x *ReportInvocationResponse) GetError() *Error { @@ -1069,7 +1505,7 @@ type InvokeResult struct { func (x *InvokeResult) Reset() { *x = InvokeResult{} - mi := &file_cortex_axon_agent_proto_msgTypes[15] + mi := &file_cortex_axon_agent_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1081,7 +1517,7 @@ func (x *InvokeResult) String() string { func (*InvokeResult) ProtoMessage() {} func (x *InvokeResult) ProtoReflect() protoreflect.Message { - mi := &file_cortex_axon_agent_proto_msgTypes[15] + mi := &file_cortex_axon_agent_proto_msgTypes[19] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1094,7 +1530,7 @@ func (x *InvokeResult) ProtoReflect() protoreflect.Message { // Deprecated: Use InvokeResult.ProtoReflect.Descriptor instead. func (*InvokeResult) Descriptor() ([]byte, []int) { - return file_cortex_axon_agent_proto_rawDescGZIP(), []int{15} + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{19} } func (x *InvokeResult) GetValue() string { @@ -1117,7 +1553,7 @@ type GetHandlerHistoryRequest struct { func (x *GetHandlerHistoryRequest) Reset() { *x = GetHandlerHistoryRequest{} - mi := &file_cortex_axon_agent_proto_msgTypes[16] + mi := &file_cortex_axon_agent_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1129,7 +1565,7 @@ func (x *GetHandlerHistoryRequest) String() string { func (*GetHandlerHistoryRequest) ProtoMessage() {} func (x *GetHandlerHistoryRequest) ProtoReflect() protoreflect.Message { - mi := &file_cortex_axon_agent_proto_msgTypes[16] + mi := &file_cortex_axon_agent_proto_msgTypes[20] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1142,7 +1578,7 @@ func (x *GetHandlerHistoryRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetHandlerHistoryRequest.ProtoReflect.Descriptor instead. func (*GetHandlerHistoryRequest) Descriptor() ([]byte, []int) { - return file_cortex_axon_agent_proto_rawDescGZIP(), []int{16} + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{20} } func (x *GetHandlerHistoryRequest) GetHandlerName() string { @@ -1198,7 +1634,7 @@ type HandlerExecution struct { func (x *HandlerExecution) Reset() { *x = HandlerExecution{} - mi := &file_cortex_axon_agent_proto_msgTypes[17] + mi := &file_cortex_axon_agent_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1210,7 +1646,7 @@ func (x *HandlerExecution) String() string { func (*HandlerExecution) ProtoMessage() {} func (x *HandlerExecution) ProtoReflect() protoreflect.Message { - mi := &file_cortex_axon_agent_proto_msgTypes[17] + mi := &file_cortex_axon_agent_proto_msgTypes[21] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1223,7 +1659,7 @@ func (x *HandlerExecution) ProtoReflect() protoreflect.Message { // Deprecated: Use HandlerExecution.ProtoReflect.Descriptor instead. func (*HandlerExecution) Descriptor() ([]byte, []int) { - return file_cortex_axon_agent_proto_rawDescGZIP(), []int{17} + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{21} } func (x *HandlerExecution) GetHandlerName() string { @@ -1306,7 +1742,7 @@ type GetHandlerHistoryResponse struct { func (x *GetHandlerHistoryResponse) Reset() { *x = GetHandlerHistoryResponse{} - mi := &file_cortex_axon_agent_proto_msgTypes[18] + mi := &file_cortex_axon_agent_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1318,7 +1754,7 @@ func (x *GetHandlerHistoryResponse) String() string { func (*GetHandlerHistoryResponse) ProtoMessage() {} func (x *GetHandlerHistoryResponse) ProtoReflect() protoreflect.Message { - mi := &file_cortex_axon_agent_proto_msgTypes[18] + mi := &file_cortex_axon_agent_proto_msgTypes[22] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1331,7 +1767,7 @@ func (x *GetHandlerHistoryResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetHandlerHistoryResponse.ProtoReflect.Descriptor instead. func (*GetHandlerHistoryResponse) Descriptor() ([]byte, []int) { - return file_cortex_axon_agent_proto_rawDescGZIP(), []int{18} + return file_cortex_axon_agent_proto_rawDescGZIP(), []int{22} } func (x *GetHandlerHistoryResponse) GetError() *Error { @@ -1384,16 +1820,17 @@ const file_cortex_axon_agent_proto_rawDesc = "" + "\tis_active\x18e \x01(\bR\bisActive\"v\n" + "\x14ListHandlersResponse\x12(\n" + "\x05error\x18\x01 \x01(\v2\x12.cortex.axon.ErrorR\x05error\x124\n" + - "\bhandlers\x18\x02 \x03(\v2\x18.cortex.axon.HandlerInfoR\bhandlers\"Y\n" + + "\bhandlers\x18\x02 \x03(\v2\x18.cortex.axon.HandlerInfoR\bhandlers\"\x80\x01\n" + "\x0fDispatchRequest\x12\x1f\n" + "\vdispatch_id\x18\x01 \x01(\tR\n" + "dispatchId\x12%\n" + - "\x0eclient_version\x18\x02 \x01(\tR\rclientVersion\"\x90\x01\n" + + "\x0eclient_version\x18\x02 \x01(\tR\rclientVersion\x12%\n" + + "\x0efailure_events\x18\x03 \x01(\bR\rfailureEvents\"\x90\x01\n" + "\x0fDispatchMessage\x124\n" + "\x04type\x18\x01 \x01(\x0e2 .cortex.axon.DispatchMessageTypeR\x04type\x12<\n" + "\x06invoke\x18\n" + " \x01(\v2\".cortex.axon.DispatchHandlerInvokeH\x00R\x06invokeB\t\n" + - "\amessage\"\xf1\x02\n" + + "\amessage\"\xc3\x03\n" + "\x15DispatchHandlerInvoke\x12#\n" + "\rinvocation_id\x18\x01 \x01(\tR\finvocationId\x12\x1f\n" + "\vdispatch_id\x18\x02 \x01(\tR\n" + @@ -1405,21 +1842,42 @@ const file_cortex_axon_agent_proto_rawDesc = "" + "timeout_ms\x18\n" + " \x01(\x05R\ttimeoutMs\x126\n" + "\x06reason\x18\v \x01(\x0e2\x1e.cortex.axon.HandlerInvokeTypeR\x06reason\x12@\n" + - "\x04args\x18\x14 \x03(\v2,.cortex.axon.DispatchHandlerInvoke.ArgsEntryR\x04args\x1a7\n" + + "\x04args\x18\x14 \x03(\v2,.cortex.axon.DispatchHandlerInvoke.ArgsEntryR\x04args\x12\x18\n" + + "\aattempt\x18\x1e \x01(\x05R\aattempt\x126\n" + + "\bdeadline\x18\x1f \x01(\v2\x1a.google.protobuf.TimestampR\bdeadline\x1a7\n" + "\tArgsEntry\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + - "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"o\n" + + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\xbe\x01\n" + + "\x11InvocationFailure\x122\n" + + "\x06reason\x18\x01 \x01(\x0e2\x1a.cortex.axon.FailureReasonR\x06reason\x122\n" + + "\x06source\x18\x02 \x01(\x0e2\x1a.cortex.axon.FailureSourceR\x06source\x12\x18\n" + + "\amessage\x18\x03 \x01(\tR\amessage\x12'\n" + + "\x0fcaller_rejected\x18\x04 \x01(\bR\x0ecallerRejected\"\x85\x01\n" + + "\rDispatchEvent\x12:\n" + + "\x06invoke\x18\x01 \x01(\v2\".cortex.axon.DispatchHandlerInvokeR\x06invoke\x128\n" + + "\afailure\x18\x02 \x01(\v2\x1e.cortex.axon.InvocationFailureR\afailure\"l\n" + + "\x11FailureResolution\x12#\n" + + "\rinvocation_id\x18\x01 \x01(\tR\finvocationId\x122\n" + + "\x06action\x18\x02 \x01(\x0e2\x1a.cortex.axon.FailureActionR\x06action\"\x9f\x01\n" + + "\x15DispatchEventsRequest\x12\x1f\n" + + "\vdispatch_id\x18\x01 \x01(\tR\n" + + "dispatchId\x12%\n" + + "\x0eclient_version\x18\x02 \x01(\tR\rclientVersion\x12>\n" + + "\n" + + "resolution\x18\x03 \x01(\v2\x1e.cortex.axon.FailureResolutionR\n" + + "resolution\"o\n" + "\x03Log\x12\x14\n" + "\x05level\x18\x01 \x01(\tR\x05level\x128\n" + "\ttimestamp\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\ttimestamp\x12\x18\n" + - "\amessage\x18\x03 \x01(\tR\amessage\"\xec\x02\n" + + "\amessage\x18\x03 \x01(\tR\amessage\"\xa7\x03\n" + "\x17ReportInvocationRequest\x12I\n" + "\x0ehandler_invoke\x18\x01 \x01(\v2\".cortex.axon.DispatchHandlerInvokeR\rhandlerInvoke\x12P\n" + "\x16start_client_timestamp\x18d \x01(\v2\x1a.google.protobuf.TimestampR\x14startClientTimestamp\x12\x1f\n" + "\vduration_ms\x18e \x01(\x05R\n" + "durationMs\x124\n" + "\x06result\x18\xc8\x01 \x01(\v2\x19.cortex.axon.InvokeResultH\x00R\x06result\x12+\n" + - "\x05error\x18\xc9\x01 \x01(\v2\x12.cortex.axon.ErrorH\x00R\x05error\x12%\n" + + "\x05error\x18\xc9\x01 \x01(\v2\x12.cortex.axon.ErrorH\x00R\x05error\x129\n" + + "\afailure\x18\xca\x01 \x01(\v2\x1e.cortex.axon.InvocationFailureR\afailure\x12%\n" + "\x04logs\x18\xac\x02 \x03(\v2\x10.cortex.axon.LogR\x04logsB\t\n" + "\amessage\"D\n" + "\x18ReportInvocationResponse\x12(\n" + @@ -1462,14 +1920,28 @@ const file_cortex_axon_agent_proto_rawDesc = "" + "\x13DispatchMessageType\x12\x1e\n" + "\x1aDISPATCH_MESSAGE_TYPE_NONE\x10\x00\x12\x1b\n" + "\x17DISPATCH_MESSAGE_INVOKE\x10\x01\x12#\n" + - "\x1fDISPATCH_MESSAGE_WORK_COMPLETED\x10\x022\xb3\x04\n" + + "\x1fDISPATCH_MESSAGE_WORK_COMPLETED\x10\x02*a\n" + + "\rFailureReason\x12\x1e\n" + + "\x1aFAILURE_REASON_UNSPECIFIED\x10\x00\x12\x11\n" + + "\rHANDLER_ERROR\x10\x01\x12\v\n" + + "\aTIMEOUT\x10\x02\x12\x10\n" + + "\fNO_RESOURCES\x10\x03*M\n" + + "\rFailureSource\x12\x1e\n" + + "\x1aFAILURE_SOURCE_UNSPECIFIED\x10\x00\x12\x0f\n" + + "\vAPPLICATION\x10\x01\x12\v\n" + + "\aRUNTIME\x10\x02*b\n" + + "\rFailureAction\x12\x1e\n" + + "\x1aFAILURE_ACTION_UNSPECIFIED\x10\x00\x12\x17\n" + + "\x13FAILURE_ACTION_DROP\x10\x01\x12\x18\n" + + "\x14FAILURE_ACTION_RETRY\x10\x022\x89\x05\n" + "\tAxonAgent\x12\\\n" + "\x0fRegisterHandler\x12#.cortex.axon.RegisterHandlerRequest\x1a$.cortex.axon.RegisterHandlerResponse\x12b\n" + "\x11UnregisterHandler\x12%.cortex.axon.UnregisterHandlerRequest\x1a&.cortex.axon.UnregisterHandlerResponse\x12S\n" + "\fListHandlers\x12 .cortex.axon.ListHandlersRequest\x1a!.cortex.axon.ListHandlersResponse\x12b\n" + "\x11GetHandlerHistory\x12%.cortex.axon.GetHandlerHistoryRequest\x1a&.cortex.axon.GetHandlerHistoryResponse\x12J\n" + "\bDispatch\x12\x1c.cortex.axon.DispatchRequest\x1a\x1c.cortex.axon.DispatchMessage(\x010\x01\x12_\n" + - "\x10ReportInvocation\x12$.cortex.axon.ReportInvocationRequest\x1a%.cortex.axon.ReportInvocationResponseB\x1cZ\x1agithub.com/cortexapps/axonb\x06proto3" + "\x10ReportInvocation\x12$.cortex.axon.ReportInvocationRequest\x1a%.cortex.axon.ReportInvocationResponse\x12T\n" + + "\x0eDispatchEvents\x12\".cortex.axon.DispatchEventsRequest\x1a\x1a.cortex.axon.DispatchEvent(\x010\x01B\x1cZ\x1agithub.com/cortexapps/axonb\x06proto3" var ( file_cortex_axon_agent_proto_rawDescOnce sync.Once @@ -1483,81 +1955,98 @@ func file_cortex_axon_agent_proto_rawDescGZIP() []byte { return file_cortex_axon_agent_proto_rawDescData } -var file_cortex_axon_agent_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_cortex_axon_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 20) +var file_cortex_axon_agent_proto_enumTypes = make([]protoimpl.EnumInfo, 5) +var file_cortex_axon_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 24) var file_cortex_axon_agent_proto_goTypes = []any{ (HandlerInvokeType)(0), // 0: cortex.axon.HandlerInvokeType (DispatchMessageType)(0), // 1: cortex.axon.DispatchMessageType - (*RegisterHandlerRequest)(nil), // 2: cortex.axon.RegisterHandlerRequest - (*HandlerInvokeOption)(nil), // 3: cortex.axon.HandlerInvokeOption - (*HandlerOption)(nil), // 4: cortex.axon.HandlerOption - (*RegisterHandlerResponse)(nil), // 5: cortex.axon.RegisterHandlerResponse - (*UnregisterHandlerRequest)(nil), // 6: cortex.axon.UnregisterHandlerRequest - (*UnregisterHandlerResponse)(nil), // 7: cortex.axon.UnregisterHandlerResponse - (*ListHandlersRequest)(nil), // 8: cortex.axon.ListHandlersRequest - (*HandlerInfo)(nil), // 9: cortex.axon.HandlerInfo - (*ListHandlersResponse)(nil), // 10: cortex.axon.ListHandlersResponse - (*DispatchRequest)(nil), // 11: cortex.axon.DispatchRequest - (*DispatchMessage)(nil), // 12: cortex.axon.DispatchMessage - (*DispatchHandlerInvoke)(nil), // 13: cortex.axon.DispatchHandlerInvoke - (*Log)(nil), // 14: cortex.axon.Log - (*ReportInvocationRequest)(nil), // 15: cortex.axon.ReportInvocationRequest - (*ReportInvocationResponse)(nil), // 16: cortex.axon.ReportInvocationResponse - (*InvokeResult)(nil), // 17: cortex.axon.InvokeResult - (*GetHandlerHistoryRequest)(nil), // 18: cortex.axon.GetHandlerHistoryRequest - (*HandlerExecution)(nil), // 19: cortex.axon.HandlerExecution - (*GetHandlerHistoryResponse)(nil), // 20: cortex.axon.GetHandlerHistoryResponse - nil, // 21: cortex.axon.DispatchHandlerInvoke.ArgsEntry - (*Error)(nil), // 22: cortex.axon.Error - (*timestamppb.Timestamp)(nil), // 23: google.protobuf.Timestamp + (FailureReason)(0), // 2: cortex.axon.FailureReason + (FailureSource)(0), // 3: cortex.axon.FailureSource + (FailureAction)(0), // 4: cortex.axon.FailureAction + (*RegisterHandlerRequest)(nil), // 5: cortex.axon.RegisterHandlerRequest + (*HandlerInvokeOption)(nil), // 6: cortex.axon.HandlerInvokeOption + (*HandlerOption)(nil), // 7: cortex.axon.HandlerOption + (*RegisterHandlerResponse)(nil), // 8: cortex.axon.RegisterHandlerResponse + (*UnregisterHandlerRequest)(nil), // 9: cortex.axon.UnregisterHandlerRequest + (*UnregisterHandlerResponse)(nil), // 10: cortex.axon.UnregisterHandlerResponse + (*ListHandlersRequest)(nil), // 11: cortex.axon.ListHandlersRequest + (*HandlerInfo)(nil), // 12: cortex.axon.HandlerInfo + (*ListHandlersResponse)(nil), // 13: cortex.axon.ListHandlersResponse + (*DispatchRequest)(nil), // 14: cortex.axon.DispatchRequest + (*DispatchMessage)(nil), // 15: cortex.axon.DispatchMessage + (*DispatchHandlerInvoke)(nil), // 16: cortex.axon.DispatchHandlerInvoke + (*InvocationFailure)(nil), // 17: cortex.axon.InvocationFailure + (*DispatchEvent)(nil), // 18: cortex.axon.DispatchEvent + (*FailureResolution)(nil), // 19: cortex.axon.FailureResolution + (*DispatchEventsRequest)(nil), // 20: cortex.axon.DispatchEventsRequest + (*Log)(nil), // 21: cortex.axon.Log + (*ReportInvocationRequest)(nil), // 22: cortex.axon.ReportInvocationRequest + (*ReportInvocationResponse)(nil), // 23: cortex.axon.ReportInvocationResponse + (*InvokeResult)(nil), // 24: cortex.axon.InvokeResult + (*GetHandlerHistoryRequest)(nil), // 25: cortex.axon.GetHandlerHistoryRequest + (*HandlerExecution)(nil), // 26: cortex.axon.HandlerExecution + (*GetHandlerHistoryResponse)(nil), // 27: cortex.axon.GetHandlerHistoryResponse + nil, // 28: cortex.axon.DispatchHandlerInvoke.ArgsEntry + (*Error)(nil), // 29: cortex.axon.Error + (*timestamppb.Timestamp)(nil), // 30: google.protobuf.Timestamp } var file_cortex_axon_agent_proto_depIdxs = []int32{ - 4, // 0: cortex.axon.RegisterHandlerRequest.options:type_name -> cortex.axon.HandlerOption + 7, // 0: cortex.axon.RegisterHandlerRequest.options:type_name -> cortex.axon.HandlerOption 0, // 1: cortex.axon.HandlerInvokeOption.type:type_name -> cortex.axon.HandlerInvokeType - 3, // 2: cortex.axon.HandlerOption.invoke:type_name -> cortex.axon.HandlerInvokeOption - 22, // 3: cortex.axon.RegisterHandlerResponse.error:type_name -> cortex.axon.Error - 22, // 4: cortex.axon.UnregisterHandlerResponse.error:type_name -> cortex.axon.Error - 4, // 5: cortex.axon.HandlerInfo.options:type_name -> cortex.axon.HandlerOption - 23, // 6: cortex.axon.HandlerInfo.last_invoked_client_timestamp:type_name -> google.protobuf.Timestamp - 22, // 7: cortex.axon.ListHandlersResponse.error:type_name -> cortex.axon.Error - 9, // 8: cortex.axon.ListHandlersResponse.handlers:type_name -> cortex.axon.HandlerInfo + 6, // 2: cortex.axon.HandlerOption.invoke:type_name -> cortex.axon.HandlerInvokeOption + 29, // 3: cortex.axon.RegisterHandlerResponse.error:type_name -> cortex.axon.Error + 29, // 4: cortex.axon.UnregisterHandlerResponse.error:type_name -> cortex.axon.Error + 7, // 5: cortex.axon.HandlerInfo.options:type_name -> cortex.axon.HandlerOption + 30, // 6: cortex.axon.HandlerInfo.last_invoked_client_timestamp:type_name -> google.protobuf.Timestamp + 29, // 7: cortex.axon.ListHandlersResponse.error:type_name -> cortex.axon.Error + 12, // 8: cortex.axon.ListHandlersResponse.handlers:type_name -> cortex.axon.HandlerInfo 1, // 9: cortex.axon.DispatchMessage.type:type_name -> cortex.axon.DispatchMessageType - 13, // 10: cortex.axon.DispatchMessage.invoke:type_name -> cortex.axon.DispatchHandlerInvoke + 16, // 10: cortex.axon.DispatchMessage.invoke:type_name -> cortex.axon.DispatchHandlerInvoke 0, // 11: cortex.axon.DispatchHandlerInvoke.reason:type_name -> cortex.axon.HandlerInvokeType - 21, // 12: cortex.axon.DispatchHandlerInvoke.args:type_name -> cortex.axon.DispatchHandlerInvoke.ArgsEntry - 23, // 13: cortex.axon.Log.timestamp:type_name -> google.protobuf.Timestamp - 13, // 14: cortex.axon.ReportInvocationRequest.handler_invoke:type_name -> cortex.axon.DispatchHandlerInvoke - 23, // 15: cortex.axon.ReportInvocationRequest.start_client_timestamp:type_name -> google.protobuf.Timestamp - 17, // 16: cortex.axon.ReportInvocationRequest.result:type_name -> cortex.axon.InvokeResult - 22, // 17: cortex.axon.ReportInvocationRequest.error:type_name -> cortex.axon.Error - 14, // 18: cortex.axon.ReportInvocationRequest.logs:type_name -> cortex.axon.Log - 22, // 19: cortex.axon.ReportInvocationResponse.error:type_name -> cortex.axon.Error - 23, // 20: cortex.axon.GetHandlerHistoryRequest.start_time:type_name -> google.protobuf.Timestamp - 23, // 21: cortex.axon.GetHandlerHistoryRequest.end_time:type_name -> google.protobuf.Timestamp - 23, // 22: cortex.axon.HandlerExecution.publish_server_timestamp:type_name -> google.protobuf.Timestamp - 23, // 23: cortex.axon.HandlerExecution.receive_server_timestamp:type_name -> google.protobuf.Timestamp - 23, // 24: cortex.axon.HandlerExecution.start_client_timestamp:type_name -> google.protobuf.Timestamp - 22, // 25: cortex.axon.HandlerExecution.error:type_name -> cortex.axon.Error - 14, // 26: cortex.axon.HandlerExecution.logs:type_name -> cortex.axon.Log - 22, // 27: cortex.axon.GetHandlerHistoryResponse.error:type_name -> cortex.axon.Error - 19, // 28: cortex.axon.GetHandlerHistoryResponse.history:type_name -> cortex.axon.HandlerExecution - 2, // 29: cortex.axon.AxonAgent.RegisterHandler:input_type -> cortex.axon.RegisterHandlerRequest - 6, // 30: cortex.axon.AxonAgent.UnregisterHandler:input_type -> cortex.axon.UnregisterHandlerRequest - 8, // 31: cortex.axon.AxonAgent.ListHandlers:input_type -> cortex.axon.ListHandlersRequest - 18, // 32: cortex.axon.AxonAgent.GetHandlerHistory:input_type -> cortex.axon.GetHandlerHistoryRequest - 11, // 33: cortex.axon.AxonAgent.Dispatch:input_type -> cortex.axon.DispatchRequest - 15, // 34: cortex.axon.AxonAgent.ReportInvocation:input_type -> cortex.axon.ReportInvocationRequest - 5, // 35: cortex.axon.AxonAgent.RegisterHandler:output_type -> cortex.axon.RegisterHandlerResponse - 7, // 36: cortex.axon.AxonAgent.UnregisterHandler:output_type -> cortex.axon.UnregisterHandlerResponse - 10, // 37: cortex.axon.AxonAgent.ListHandlers:output_type -> cortex.axon.ListHandlersResponse - 20, // 38: cortex.axon.AxonAgent.GetHandlerHistory:output_type -> cortex.axon.GetHandlerHistoryResponse - 12, // 39: cortex.axon.AxonAgent.Dispatch:output_type -> cortex.axon.DispatchMessage - 16, // 40: cortex.axon.AxonAgent.ReportInvocation:output_type -> cortex.axon.ReportInvocationResponse - 35, // [35:41] is the sub-list for method output_type - 29, // [29:35] is the sub-list for method input_type - 29, // [29:29] is the sub-list for extension type_name - 29, // [29:29] is the sub-list for extension extendee - 0, // [0:29] is the sub-list for field type_name + 28, // 12: cortex.axon.DispatchHandlerInvoke.args:type_name -> cortex.axon.DispatchHandlerInvoke.ArgsEntry + 30, // 13: cortex.axon.DispatchHandlerInvoke.deadline:type_name -> google.protobuf.Timestamp + 2, // 14: cortex.axon.InvocationFailure.reason:type_name -> cortex.axon.FailureReason + 3, // 15: cortex.axon.InvocationFailure.source:type_name -> cortex.axon.FailureSource + 16, // 16: cortex.axon.DispatchEvent.invoke:type_name -> cortex.axon.DispatchHandlerInvoke + 17, // 17: cortex.axon.DispatchEvent.failure:type_name -> cortex.axon.InvocationFailure + 4, // 18: cortex.axon.FailureResolution.action:type_name -> cortex.axon.FailureAction + 19, // 19: cortex.axon.DispatchEventsRequest.resolution:type_name -> cortex.axon.FailureResolution + 30, // 20: cortex.axon.Log.timestamp:type_name -> google.protobuf.Timestamp + 16, // 21: cortex.axon.ReportInvocationRequest.handler_invoke:type_name -> cortex.axon.DispatchHandlerInvoke + 30, // 22: cortex.axon.ReportInvocationRequest.start_client_timestamp:type_name -> google.protobuf.Timestamp + 24, // 23: cortex.axon.ReportInvocationRequest.result:type_name -> cortex.axon.InvokeResult + 29, // 24: cortex.axon.ReportInvocationRequest.error:type_name -> cortex.axon.Error + 17, // 25: cortex.axon.ReportInvocationRequest.failure:type_name -> cortex.axon.InvocationFailure + 21, // 26: cortex.axon.ReportInvocationRequest.logs:type_name -> cortex.axon.Log + 29, // 27: cortex.axon.ReportInvocationResponse.error:type_name -> cortex.axon.Error + 30, // 28: cortex.axon.GetHandlerHistoryRequest.start_time:type_name -> google.protobuf.Timestamp + 30, // 29: cortex.axon.GetHandlerHistoryRequest.end_time:type_name -> google.protobuf.Timestamp + 30, // 30: cortex.axon.HandlerExecution.publish_server_timestamp:type_name -> google.protobuf.Timestamp + 30, // 31: cortex.axon.HandlerExecution.receive_server_timestamp:type_name -> google.protobuf.Timestamp + 30, // 32: cortex.axon.HandlerExecution.start_client_timestamp:type_name -> google.protobuf.Timestamp + 29, // 33: cortex.axon.HandlerExecution.error:type_name -> cortex.axon.Error + 21, // 34: cortex.axon.HandlerExecution.logs:type_name -> cortex.axon.Log + 29, // 35: cortex.axon.GetHandlerHistoryResponse.error:type_name -> cortex.axon.Error + 26, // 36: cortex.axon.GetHandlerHistoryResponse.history:type_name -> cortex.axon.HandlerExecution + 5, // 37: cortex.axon.AxonAgent.RegisterHandler:input_type -> cortex.axon.RegisterHandlerRequest + 9, // 38: cortex.axon.AxonAgent.UnregisterHandler:input_type -> cortex.axon.UnregisterHandlerRequest + 11, // 39: cortex.axon.AxonAgent.ListHandlers:input_type -> cortex.axon.ListHandlersRequest + 25, // 40: cortex.axon.AxonAgent.GetHandlerHistory:input_type -> cortex.axon.GetHandlerHistoryRequest + 14, // 41: cortex.axon.AxonAgent.Dispatch:input_type -> cortex.axon.DispatchRequest + 22, // 42: cortex.axon.AxonAgent.ReportInvocation:input_type -> cortex.axon.ReportInvocationRequest + 20, // 43: cortex.axon.AxonAgent.DispatchEvents:input_type -> cortex.axon.DispatchEventsRequest + 8, // 44: cortex.axon.AxonAgent.RegisterHandler:output_type -> cortex.axon.RegisterHandlerResponse + 10, // 45: cortex.axon.AxonAgent.UnregisterHandler:output_type -> cortex.axon.UnregisterHandlerResponse + 13, // 46: cortex.axon.AxonAgent.ListHandlers:output_type -> cortex.axon.ListHandlersResponse + 27, // 47: cortex.axon.AxonAgent.GetHandlerHistory:output_type -> cortex.axon.GetHandlerHistoryResponse + 15, // 48: cortex.axon.AxonAgent.Dispatch:output_type -> cortex.axon.DispatchMessage + 23, // 49: cortex.axon.AxonAgent.ReportInvocation:output_type -> cortex.axon.ReportInvocationResponse + 18, // 50: cortex.axon.AxonAgent.DispatchEvents:output_type -> cortex.axon.DispatchEvent + 44, // [44:51] is the sub-list for method output_type + 37, // [37:44] is the sub-list for method input_type + 37, // [37:37] is the sub-list for extension type_name + 37, // [37:37] is the sub-list for extension extendee + 0, // [0:37] is the sub-list for field type_name } func init() { file_cortex_axon_agent_proto_init() } @@ -1572,7 +2061,7 @@ func file_cortex_axon_agent_proto_init() { file_cortex_axon_agent_proto_msgTypes[10].OneofWrappers = []any{ (*DispatchMessage_Invoke)(nil), } - file_cortex_axon_agent_proto_msgTypes[13].OneofWrappers = []any{ + file_cortex_axon_agent_proto_msgTypes[17].OneofWrappers = []any{ (*ReportInvocationRequest_Result)(nil), (*ReportInvocationRequest_Error)(nil), } @@ -1581,8 +2070,8 @@ func file_cortex_axon_agent_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_cortex_axon_agent_proto_rawDesc), len(file_cortex_axon_agent_proto_rawDesc)), - NumEnums: 2, - NumMessages: 20, + NumEnums: 5, + NumMessages: 24, NumExtensions: 0, NumServices: 1, }, diff --git a/sdks/go/.generated/proto/github.com/cortexapps/axon/cortex-axon-agent_grpc.pb.go b/sdks/go/.generated/proto/github.com/cortexapps/axon/cortex-axon-agent_grpc.pb.go index 3d53df53..4125fee0 100644 --- a/sdks/go/.generated/proto/github.com/cortexapps/axon/cortex-axon-agent_grpc.pb.go +++ b/sdks/go/.generated/proto/github.com/cortexapps/axon/cortex-axon-agent_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.5.1 -// - protoc v3.21.12 +// - protoc v7.35.0 // source: cortex-axon-agent.proto package axon @@ -25,6 +25,7 @@ const ( AxonAgent_GetHandlerHistory_FullMethodName = "/cortex.axon.AxonAgent/GetHandlerHistory" AxonAgent_Dispatch_FullMethodName = "/cortex.axon.AxonAgent/Dispatch" AxonAgent_ReportInvocation_FullMethodName = "/cortex.axon.AxonAgent/ReportInvocation" + AxonAgent_DispatchEvents_FullMethodName = "/cortex.axon.AxonAgent/DispatchEvents" ) // AxonAgentClient is the client API for AxonAgent service. @@ -37,6 +38,12 @@ type AxonAgentClient interface { GetHandlerHistory(ctx context.Context, in *GetHandlerHistoryRequest, opts ...grpc.CallOption) (*GetHandlerHistoryResponse, error) Dispatch(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[DispatchRequest, DispatchMessage], error) ReportInvocation(ctx context.Context, in *ReportInvocationRequest, opts ...grpc.CallOption) (*ReportInvocationResponse, error) + // DispatchEvents sends the client every failed invocation, and the client + // answers each with what to do about it. It is its own stream so a client + // that has stopped reading Dispatch because every handler is busy still + // hears about failures. An event the client has not answered when the + // stream ends is sent again on the next one. + DispatchEvents(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[DispatchEventsRequest, DispatchEvent], error) } type axonAgentClient struct { @@ -110,6 +117,19 @@ func (c *axonAgentClient) ReportInvocation(ctx context.Context, in *ReportInvoca return out, nil } +func (c *axonAgentClient) DispatchEvents(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[DispatchEventsRequest, DispatchEvent], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &AxonAgent_ServiceDesc.Streams[1], AxonAgent_DispatchEvents_FullMethodName, cOpts...) + if err != nil { + return nil, err + } + x := &grpc.GenericClientStream[DispatchEventsRequest, DispatchEvent]{ClientStream: stream} + return x, nil +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type AxonAgent_DispatchEventsClient = grpc.BidiStreamingClient[DispatchEventsRequest, DispatchEvent] + // AxonAgentServer is the server API for AxonAgent service. // All implementations must embed UnimplementedAxonAgentServer // for forward compatibility. @@ -120,6 +140,12 @@ type AxonAgentServer interface { GetHandlerHistory(context.Context, *GetHandlerHistoryRequest) (*GetHandlerHistoryResponse, error) Dispatch(grpc.BidiStreamingServer[DispatchRequest, DispatchMessage]) error ReportInvocation(context.Context, *ReportInvocationRequest) (*ReportInvocationResponse, error) + // DispatchEvents sends the client every failed invocation, and the client + // answers each with what to do about it. It is its own stream so a client + // that has stopped reading Dispatch because every handler is busy still + // hears about failures. An event the client has not answered when the + // stream ends is sent again on the next one. + DispatchEvents(grpc.BidiStreamingServer[DispatchEventsRequest, DispatchEvent]) error mustEmbedUnimplementedAxonAgentServer() } @@ -148,6 +174,9 @@ func (UnimplementedAxonAgentServer) Dispatch(grpc.BidiStreamingServer[DispatchRe func (UnimplementedAxonAgentServer) ReportInvocation(context.Context, *ReportInvocationRequest) (*ReportInvocationResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ReportInvocation not implemented") } +func (UnimplementedAxonAgentServer) DispatchEvents(grpc.BidiStreamingServer[DispatchEventsRequest, DispatchEvent]) error { + return status.Errorf(codes.Unimplemented, "method DispatchEvents not implemented") +} func (UnimplementedAxonAgentServer) mustEmbedUnimplementedAxonAgentServer() {} func (UnimplementedAxonAgentServer) testEmbeddedByValue() {} @@ -266,6 +295,13 @@ func _AxonAgent_ReportInvocation_Handler(srv interface{}, ctx context.Context, d return interceptor(ctx, in, info, handler) } +func _AxonAgent_DispatchEvents_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(AxonAgentServer).DispatchEvents(&grpc.GenericServerStream[DispatchEventsRequest, DispatchEvent]{ServerStream: stream}) +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type AxonAgent_DispatchEventsServer = grpc.BidiStreamingServer[DispatchEventsRequest, DispatchEvent] + // AxonAgent_ServiceDesc is the grpc.ServiceDesc for AxonAgent service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -301,6 +337,12 @@ var AxonAgent_ServiceDesc = grpc.ServiceDesc{ ServerStreams: true, ClientStreams: true, }, + { + StreamName: "DispatchEvents", + Handler: _AxonAgent_DispatchEvents_Handler, + ServerStreams: true, + ClientStreams: true, + }, }, Metadata: "cortex-axon-agent.proto", } diff --git a/sdks/go/mock_axon/mocks.go b/sdks/go/mock_axon/mocks.go index 5672198c..738818ec 100644 --- a/sdks/go/mock_axon/mocks.go +++ b/sdks/go/mock_axon/mocks.go @@ -106,6 +106,26 @@ func (mr *MockAxonAgentClientMockRecorder) Dispatch(ctx any, opts ...any) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Dispatch", reflect.TypeOf((*MockAxonAgentClient)(nil).Dispatch), varargs...) } +// DispatchEvents mocks base method. +func (m *MockAxonAgentClient) DispatchEvents(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[axon.DispatchEventsRequest, axon.DispatchEvent], error) { + m.ctrl.T.Helper() + varargs := []any{ctx} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "DispatchEvents", varargs...) + ret0, _ := ret[0].(grpc.BidiStreamingClient[axon.DispatchEventsRequest, axon.DispatchEvent]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DispatchEvents indicates an expected call of DispatchEvents. +func (mr *MockAxonAgentClientMockRecorder) DispatchEvents(ctx any, opts ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{ctx}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DispatchEvents", reflect.TypeOf((*MockAxonAgentClient)(nil).DispatchEvents), varargs...) +} + // GetHandlerHistory mocks base method. func (m *MockAxonAgentClient) GetHandlerHistory(ctx context.Context, in *axon.GetHandlerHistoryRequest, opts ...grpc.CallOption) (*axon.GetHandlerHistoryResponse, error) { m.ctrl.T.Helper()