mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? - The `ChasmRequestInterceptor` has been split in two! `ChasmRequestEngineInterceptor` does everything except inject `chasm.VisibilityManager`, which is done by `ChasmRequestVisibilityInterceptor`. - Note that the test doesn't include a matching `hasVisibilityCtx` assert to `hasEngineCtx` because I think making that getter public would make the public API earnestly more confusing for consumers ## Why? - Frontend needs visibilityMgr injected so that it can handle FE->Vis queries without hopping through history. The previous interceptor assumed `chasm.Engine` was always available, which it isn't, for history. I'd also workshopped making engine an optional fx parameter, but eh. ## How did you test it? - Validated with scheduler functional tests, which use `chasm.ListExecutions` directly in frontend's `WorkflowHandler`.
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package chasm
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/metrics"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
const chasmRequestPrefix = "/temporal.server.chasm"
|
|
|
|
// ChasmEngineInterceptor Interceptor that intercepts RPC requests,
|
|
// detects CHASM-specific calls and does additional boilerplate processing before
|
|
// handing off. Visibility is injected separately with
|
|
// ChasmVisibilityInterceptor.
|
|
type ChasmEngineInterceptor struct {
|
|
engine Engine
|
|
logger log.Logger
|
|
metricsHandler metrics.Handler
|
|
}
|
|
|
|
func (i *ChasmEngineInterceptor) Intercept(
|
|
ctx context.Context,
|
|
req interface{},
|
|
info *grpc.UnaryServerInfo,
|
|
handler grpc.UnaryHandler,
|
|
) (resp interface{}, retError error) {
|
|
if strings.HasPrefix(info.FullMethod, chasmRequestPrefix) {
|
|
defer metrics.CapturePanic(i.logger, i.metricsHandler, &retError)
|
|
}
|
|
|
|
ctx = NewEngineContext(ctx, i.engine)
|
|
return handler(ctx, req)
|
|
}
|
|
|
|
func ChasmEngineInterceptorProvider(
|
|
engine Engine,
|
|
logger log.Logger,
|
|
metricsHandler metrics.Handler,
|
|
) *ChasmEngineInterceptor {
|
|
return &ChasmEngineInterceptor{
|
|
engine: engine,
|
|
logger: logger,
|
|
metricsHandler: metricsHandler,
|
|
}
|
|
}
|
|
|
|
// ChasmVisibilityInterceptor intercepts RPC requests and adds the CHASM
|
|
// VisibilityManager to their context.
|
|
type ChasmVisibilityInterceptor struct {
|
|
visibilityMgr VisibilityManager
|
|
}
|
|
|
|
func (i *ChasmVisibilityInterceptor) Intercept(
|
|
ctx context.Context,
|
|
req interface{},
|
|
info *grpc.UnaryServerInfo,
|
|
handler grpc.UnaryHandler,
|
|
) (resp interface{}, retError error) {
|
|
ctx = NewVisibilityManagerContext(ctx, i.visibilityMgr)
|
|
return handler(ctx, req)
|
|
}
|
|
|
|
func ChasmVisibilityInterceptorProvider(visibilityMgr VisibilityManager) *ChasmVisibilityInterceptor {
|
|
return &ChasmVisibilityInterceptor{
|
|
visibilityMgr: visibilityMgr,
|
|
}
|
|
}
|