mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +00:00
Goes from 135 MB binary with 1153 files importing go.temporal.io and 224
importing google.golang.org/grpc to a 10 MB native binary with ZERO of
either.
Deleted:
- tasks/, tasktests/, service/, chasm/, client/, api/, proto/, tools/
- cmd/tools/, components/, docker/
- schema/{cassandra,elasticsearch,mysql,postgresql,sqlite}/
- 40 tainted common/ subdirs + 7 top-level common files
- tests/testutils (no longer referenced after surviving deps drop common)
New cmd/tasksd (~100 lines) boots tasks.Embed (zap.Node) + http.Server.
New pkg/tasks/embed.go registers ZAP handlers for the SDK opcode surface
(0x0060-0x00A5). Workflow handlers return a 501 "not yet implemented"
envelope; native engine lands behind this contract.
Build: go build ./cmd/tasksd → 10 MB
Vet: go vet ./... → clean
Boot: tasksd --zap-port 9999 --http :7243
Probes: /healthz, /v1/tasks/health → 200
UI: /_/tasks/, / → 200 (embedded Vite bundle)
ZAP: _tasks._tcp on :9999 (mDNS disabled; direct connect)
go.mod: tidy. No go.temporal.io. No google.golang.org/grpc.
186 lines
5.9 KiB
Go
186 lines
5.9 KiB
Go
package visibility
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"go.temporal.io/server/api/visibilityservice/v1"
|
|
"go.temporal.io/server/common/dynamicconfig"
|
|
"go.temporal.io/server/common/headers"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.temporal.io/server/common/persistence"
|
|
"go.temporal.io/server/common/persistence/visibility/manager"
|
|
"go.temporal.io/server/common/quotas"
|
|
)
|
|
|
|
const (
|
|
RateLimitDefaultToken = 1
|
|
)
|
|
|
|
var _ manager.VisibilityManager = (*visibilityManagerRateLimited)(nil)
|
|
|
|
type visibilityManagerRateLimited struct {
|
|
delegate manager.VisibilityManager
|
|
readRateLimiter quotas.RequestRateLimiter
|
|
writeRateLimiter quotas.RequestRateLimiter
|
|
}
|
|
|
|
func NewVisibilityManagerRateLimited(
|
|
delegate manager.VisibilityManager,
|
|
readMaxQPS dynamicconfig.IntPropertyFn,
|
|
writeMaxQPS dynamicconfig.IntPropertyFn,
|
|
operatorRPSRatio dynamicconfig.FloatPropertyFn,
|
|
) *visibilityManagerRateLimited {
|
|
return &visibilityManagerRateLimited{
|
|
delegate: delegate,
|
|
readRateLimiter: newPriorityRateLimiter(readMaxQPS, operatorRPSRatio),
|
|
writeRateLimiter: newPriorityRateLimiter(writeMaxQPS, operatorRPSRatio),
|
|
}
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) Close() {
|
|
m.delegate.Close()
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) GetReadStoreName(nsName namespace.Name) string {
|
|
return m.delegate.GetReadStoreName(nsName)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) GetStoreNames() []string {
|
|
return m.delegate.GetStoreNames()
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) HasStoreName(stName string) bool {
|
|
return m.delegate.HasStoreName(stName)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) GetIndexName() string {
|
|
return m.delegate.GetIndexName()
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) ValidateCustomSearchAttributes(
|
|
searchAttributes map[string]any,
|
|
) (map[string]any, error) {
|
|
return m.delegate.ValidateCustomSearchAttributes(searchAttributes)
|
|
}
|
|
|
|
// Below are write APIs.
|
|
|
|
func (m *visibilityManagerRateLimited) RecordWorkflowExecutionStarted(
|
|
ctx context.Context,
|
|
request *manager.RecordWorkflowExecutionStartedRequest,
|
|
) error {
|
|
if ok := allow(ctx, "RecordWorkflowExecutionStarted", m.writeRateLimiter); !ok {
|
|
return persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.RecordWorkflowExecutionStarted(ctx, request)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) RecordWorkflowExecutionClosed(
|
|
ctx context.Context,
|
|
request *manager.RecordWorkflowExecutionClosedRequest,
|
|
) error {
|
|
if ok := allow(ctx, "RecordWorkflowExecutionClosed", m.writeRateLimiter); !ok {
|
|
return persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.RecordWorkflowExecutionClosed(ctx, request)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) UpsertWorkflowExecution(
|
|
ctx context.Context,
|
|
request *manager.UpsertWorkflowExecutionRequest,
|
|
) error {
|
|
if ok := allow(ctx, "UpsertWorkflowExecution", m.writeRateLimiter); !ok {
|
|
return persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.UpsertWorkflowExecution(ctx, request)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) DeleteWorkflowExecution(
|
|
ctx context.Context,
|
|
request *manager.VisibilityDeleteWorkflowExecutionRequest,
|
|
) error {
|
|
if ok := allow(ctx, "DeleteWorkflowExecution", m.writeRateLimiter); !ok {
|
|
return persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.DeleteWorkflowExecution(ctx, request)
|
|
}
|
|
|
|
// Below are read APIs.
|
|
func (m *visibilityManagerRateLimited) ListWorkflowExecutions(
|
|
ctx context.Context,
|
|
request *manager.ListWorkflowExecutionsRequestV2,
|
|
) (*manager.ListWorkflowExecutionsResponse, error) {
|
|
if ok := allow(ctx, "ListWorkflowExecutions", m.readRateLimiter); !ok {
|
|
return nil, persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.ListWorkflowExecutions(ctx, request)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) ListChasmExecutions(
|
|
ctx context.Context,
|
|
request *visibilityservice.ListChasmExecutionsRequest,
|
|
) (*visibilityservice.ListChasmExecutionsResponse, error) {
|
|
if ok := allow(ctx, "ListChasmExecutions", m.readRateLimiter); !ok {
|
|
return nil, persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.ListChasmExecutions(ctx, request)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) CountWorkflowExecutions(
|
|
ctx context.Context,
|
|
request *manager.CountWorkflowExecutionsRequest,
|
|
) (*manager.CountWorkflowExecutionsResponse, error) {
|
|
if ok := allow(ctx, "CountWorkflowExecutions", m.readRateLimiter); !ok {
|
|
return nil, persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.CountWorkflowExecutions(ctx, request)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) CountChasmExecutions(
|
|
ctx context.Context,
|
|
request *visibilityservice.CountChasmExecutionsRequest,
|
|
) (*visibilityservice.CountChasmExecutionsResponse, error) {
|
|
if ok := allow(ctx, "CountChasmExecutions", m.readRateLimiter); !ok {
|
|
return nil, persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.CountChasmExecutions(ctx, request)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) GetWorkflowExecution(
|
|
ctx context.Context,
|
|
request *manager.GetWorkflowExecutionRequest,
|
|
) (*manager.GetWorkflowExecutionResponse, error) {
|
|
if ok := allow(ctx, "GetWorkflowExecution", m.readRateLimiter); !ok {
|
|
return nil, persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.GetWorkflowExecution(ctx, request)
|
|
}
|
|
|
|
func (m *visibilityManagerRateLimited) AddSearchAttributes(
|
|
ctx context.Context,
|
|
request *manager.AddSearchAttributesRequest,
|
|
) error {
|
|
if ok := allow(ctx, "AddSearchAttributes", m.readRateLimiter); !ok {
|
|
return persistence.ErrPersistenceSystemLimitExceeded
|
|
}
|
|
return m.delegate.AddSearchAttributes(ctx, request)
|
|
}
|
|
|
|
func allow(
|
|
ctx context.Context,
|
|
api string,
|
|
rateLimiter quotas.RequestRateLimiter,
|
|
) bool {
|
|
callerInfo := headers.GetCallerInfo(ctx)
|
|
// Currently only CallerType is used. See common/persistence/visibility/quotas.go for rate limiter details.
|
|
return rateLimiter.Allow(time.Now().UTC(), quotas.NewRequest(
|
|
api,
|
|
RateLimitDefaultToken,
|
|
callerInfo.CallerName,
|
|
callerInfo.CallerType,
|
|
-1,
|
|
callerInfo.CallOrigin,
|
|
))
|
|
}
|