mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## 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`.
131 lines
3.4 KiB
Go
131 lines
3.4 KiB
Go
package metrics
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/uber-go/tally/v4"
|
|
"go.temporal.io/server/common/log"
|
|
)
|
|
|
|
var sanitizer = tally.NewSanitizer(tally.SanitizeOptions{
|
|
NameCharacters: tally.ValidCharacters{Ranges: tally.AlphanumericRange, Characters: tally.UnderscoreCharacters},
|
|
KeyCharacters: tally.ValidCharacters{Ranges: tally.AlphanumericRange, Characters: tally.UnderscoreCharacters},
|
|
ValueCharacters: tally.ValidCharacters{Ranges: tally.AlphanumericRange, Characters: tally.UnderscoreCharacters},
|
|
ReplacementCharacter: '_',
|
|
})
|
|
|
|
type (
|
|
excludeTags map[string]map[string]struct{}
|
|
|
|
tallyMetricsHandler struct {
|
|
scope tally.Scope
|
|
perUnitBuckets map[MetricUnit]tally.Buckets
|
|
excludeTags excludeTags
|
|
}
|
|
)
|
|
|
|
var _ Handler = (*tallyMetricsHandler)(nil)
|
|
|
|
func NewTallyMetricsHandler(cfg ClientConfig, scope tally.Scope) *tallyMetricsHandler {
|
|
perUnitBuckets := make(map[MetricUnit]tally.Buckets)
|
|
|
|
for unit, boundariesList := range cfg.PerUnitHistogramBoundaries {
|
|
perUnitBuckets[MetricUnit(unit)] = tally.ValueBuckets(boundariesList)
|
|
}
|
|
|
|
return &tallyMetricsHandler{
|
|
scope: scope,
|
|
perUnitBuckets: perUnitBuckets,
|
|
excludeTags: configExcludeTags(cfg),
|
|
}
|
|
}
|
|
|
|
// WithTags creates a new MetricProvder with provided []Tag
|
|
// Tags are merged with registered Tags from the source MetricsHandler
|
|
func (tmh *tallyMetricsHandler) WithTags(tags ...Tag) Handler {
|
|
return &tallyMetricsHandler{
|
|
scope: tmh.scope.Tagged(tagsToMap(tags, tmh.excludeTags)),
|
|
perUnitBuckets: tmh.perUnitBuckets,
|
|
excludeTags: tmh.excludeTags,
|
|
}
|
|
}
|
|
|
|
// Counter obtains a counter for the given name.
|
|
func (tmh *tallyMetricsHandler) Counter(counter string) CounterIface {
|
|
return CounterFunc(func(i int64, t ...Tag) {
|
|
scope := tmh.scope
|
|
if len(t) > 0 {
|
|
scope = tmh.scope.Tagged(tagsToMap(t, tmh.excludeTags))
|
|
}
|
|
scope.Counter(counter).Inc(i)
|
|
})
|
|
}
|
|
|
|
// Gauge obtains a gauge for the given name.
|
|
func (tmh *tallyMetricsHandler) Gauge(gauge string) GaugeIface {
|
|
return GaugeFunc(func(f float64, t ...Tag) {
|
|
scope := tmh.scope
|
|
if len(t) > 0 {
|
|
scope = tmh.scope.Tagged(tagsToMap(t, tmh.excludeTags))
|
|
}
|
|
scope.Gauge(gauge).Update(f)
|
|
})
|
|
}
|
|
|
|
// Timer obtains a timer for the given name.
|
|
func (tmh *tallyMetricsHandler) Timer(timer string) TimerIface {
|
|
return TimerFunc(func(d time.Duration, t ...Tag) {
|
|
scope := tmh.scope
|
|
if len(t) > 0 {
|
|
scope = tmh.scope.Tagged(tagsToMap(t, tmh.excludeTags))
|
|
}
|
|
scope.Timer(timer).Record(d)
|
|
})
|
|
}
|
|
|
|
// Histogram obtains a histogram for the given name.
|
|
func (tmh *tallyMetricsHandler) Histogram(histogram string, unit MetricUnit) HistogramIface {
|
|
return HistogramFunc(func(i int64, t ...Tag) {
|
|
scope := tmh.scope
|
|
if len(t) > 0 {
|
|
scope = tmh.scope.Tagged(tagsToMap(t, tmh.excludeTags))
|
|
}
|
|
scope.Histogram(histogram, tmh.perUnitBuckets[unit]).RecordValue(float64(i))
|
|
})
|
|
}
|
|
|
|
func (*tallyMetricsHandler) Stop(log.Logger) {}
|
|
|
|
func (*tallyMetricsHandler) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (tmh *tallyMetricsHandler) StartBatch(_ string) BatchHandler {
|
|
return tmh
|
|
}
|
|
|
|
func tagsToMap(t1 []Tag, e excludeTags) map[string]string {
|
|
if len(t1) == 0 {
|
|
return nil
|
|
}
|
|
|
|
m := make(map[string]string, len(t1))
|
|
|
|
convert := func(tag Tag) {
|
|
if vals, ok := e[tag.Key()]; ok {
|
|
if _, ok := vals[tag.Value()]; !ok {
|
|
m[tag.Key()] = tagExcludedValue
|
|
return
|
|
}
|
|
}
|
|
|
|
m[tag.Key()] = tag.Value()
|
|
}
|
|
|
|
for i := range t1 {
|
|
convert(t1[i])
|
|
}
|
|
|
|
return m
|
|
}
|