Files
tasks/service/history/queues/mitigator.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

107 lines
2.3 KiB
Go

package queues
import (
"sync"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/common/metrics"
)
var _ Mitigator = (*mitigatorImpl)(nil)
type (
// Mitigator generates and runs an Action for resolving the given Alert
Mitigator interface {
Mitigate(Alert)
}
actionRunner func(Action, *ReaderGroup, metrics.Handler, log.Logger)
mitigatorImpl struct {
sync.Mutex
readerGroup *ReaderGroup
monitor Monitor
logger log.Logger
metricsHandler metrics.Handler
maxReaderCount dynamicconfig.IntPropertyFn
// this is for overriding the behavior in unit tests
// since we don't really want to run the action in Mitigator unit tests
actionRunner actionRunner
grouper Grouper
}
)
func newMitigator(
readerGroup *ReaderGroup,
monitor Monitor,
logger log.Logger,
metricsHandler metrics.Handler,
maxReaderCount dynamicconfig.IntPropertyFn,
grouper Grouper,
) *mitigatorImpl {
return &mitigatorImpl{
readerGroup: readerGroup,
monitor: monitor,
logger: logger,
metricsHandler: metricsHandler,
maxReaderCount: maxReaderCount,
actionRunner: runAction,
grouper: grouper,
}
}
func (m *mitigatorImpl) Mitigate(alert Alert) {
m.Lock()
defer m.Unlock()
var action Action
switch alert.AlertType {
case AlertTypeQueuePendingTaskCount:
action = newQueuePendingTaskAction(
alert.AlertAttributesQueuePendingTaskCount,
m.monitor,
m.maxReaderCount(),
m.grouper,
)
case AlertTypeReaderStuck:
action = newReaderStuckAction(
alert.AlertAttributesReaderStuck,
m.logger,
)
case AlertTypeSliceCount:
action = newSliceCountAction(
alert.AlertAttributesSliceCount,
m.monitor,
)
default:
m.logger.Error("Unknown queue alert type", tag.QueueAlert(alert))
return
}
m.actionRunner(
action,
m.readerGroup,
m.metricsHandler,
log.With(m.logger, tag.QueueAlert(alert)),
)
m.monitor.ResolveAlert(alert.AlertType)
}
func runAction(
action Action,
readerGroup *ReaderGroup,
metricsHandler metrics.Handler,
logger log.Logger,
) {
metricsHandler = metricsHandler.WithTags(metrics.QueueActionTag(action.Name()))
metrics.QueueActionCounter.With(metricsHandler).Record(1)
action.Run(readerGroup)
}