Files
tasks/service/history/queues/executable_factory.go
Yichao YangandGitHub ace58da650 Fix task executable metrics tags (#6742)
## What changed?
<!-- Describe what has changed in this PR -->
- Remove executable.taggedMetricsHandler. 
- Always init executable.metricsHandler with the full set of metric tags
needed to prevent tag mismatch issue.

## Why?
<!-- Tell your future self why have you made these changes -->
- Prevent tag mismatch issue.
- It looks like the task_errors_throttled metric could be emitted before
taggedMetricsHandler is really tagged with the right set of tags.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
- Run server locally.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2024-11-04 11:13:45 -08:00

123 lines
4.6 KiB
Go

// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package queues
import (
"go.temporal.io/server/common/clock"
"go.temporal.io/server/common/cluster"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/metrics"
"go.temporal.io/server/common/namespace"
"go.temporal.io/server/service/history/tasks"
)
type (
// ExecutableFactory and the related interfaces here are needed to make it possible to extend the functionality of
// task processing without changing its core logic. This is similar to ExecutorWrapper.
ExecutableFactory interface {
NewExecutable(task tasks.Task, readerID int64) Executable
}
// ExecutableFactoryFn is a convenience type to avoid having to create a struct that implements ExecutableFactory.
ExecutableFactoryFn func(readerID int64, t tasks.Task) Executable
executableFactoryImpl struct {
executor Executor
scheduler Scheduler
rescheduler Rescheduler
priorityAssigner PriorityAssigner
timeSource clock.TimeSource
namespaceRegistry namespace.Registry
clusterMetadata cluster.Metadata
logger log.Logger
metricsHandler metrics.Handler
dlqWriter *DLQWriter
dlqEnabled dynamicconfig.BoolPropertyFn
attemptsBeforeSendingToDlq dynamicconfig.IntPropertyFn
dlqInternalErrors dynamicconfig.BoolPropertyFn
dlqErrorPattern dynamicconfig.StringPropertyFn
}
)
func (f ExecutableFactoryFn) NewExecutable(task tasks.Task, readerID int64) Executable {
return f(readerID, task)
}
func NewExecutableFactory(
executor Executor,
scheduler Scheduler,
rescheduler Rescheduler,
priorityAssigner PriorityAssigner,
timeSource clock.TimeSource,
namespaceRegistry namespace.Registry,
clusterMetadata cluster.Metadata,
logger log.Logger,
metricsHandler metrics.Handler,
dlqWriter *DLQWriter,
dlqEnabled dynamicconfig.BoolPropertyFn,
attemptsBeforeSendingToDlq dynamicconfig.IntPropertyFn,
dlqInternalErrors dynamicconfig.BoolPropertyFn,
dlqErrorPattern dynamicconfig.StringPropertyFn,
) *executableFactoryImpl {
return &executableFactoryImpl{
executor: executor,
scheduler: scheduler,
rescheduler: rescheduler,
priorityAssigner: priorityAssigner,
timeSource: timeSource,
namespaceRegistry: namespaceRegistry,
clusterMetadata: clusterMetadata,
logger: logger,
metricsHandler: metricsHandler.WithTags(defaultExecutableMetricsTags...),
dlqWriter: dlqWriter,
dlqEnabled: dlqEnabled,
attemptsBeforeSendingToDlq: attemptsBeforeSendingToDlq,
dlqInternalErrors: dlqInternalErrors,
dlqErrorPattern: dlqErrorPattern,
}
}
func (f *executableFactoryImpl) NewExecutable(task tasks.Task, readerID int64) Executable {
return NewExecutable(
readerID,
task,
f.executor,
f.scheduler,
f.rescheduler,
f.priorityAssigner,
f.timeSource,
f.namespaceRegistry,
f.clusterMetadata,
f.logger,
f.metricsHandler,
func(params *ExecutableParams) {
params.DLQEnabled = f.dlqEnabled
params.DLQWriter = f.dlqWriter
params.MaxUnexpectedErrorAttempts = f.attemptsBeforeSendingToDlq
params.DLQInternalErrors = f.dlqInternalErrors
params.DLQErrorPattern = f.dlqErrorPattern
},
)
}