mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +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`.
104 lines
2.7 KiB
Go
104 lines
2.7 KiB
Go
package metricstest
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/metrics"
|
|
)
|
|
|
|
func TestBasic(t *testing.T) {
|
|
t.Parallel()
|
|
logger := log.NewTestLogger()
|
|
handler, err := NewHandler(logger, metrics.ClientConfig{})
|
|
require.NoError(t, err)
|
|
|
|
counterName := "counter1"
|
|
counterTags := []metrics.Tag{
|
|
metrics.StringTag("l2", "v2"),
|
|
metrics.StringTag("l1", "v1"),
|
|
}
|
|
expectedSystemTags := []metrics.Tag{
|
|
metrics.StringTag("otel_scope_name", "temporal"),
|
|
metrics.StringTag("otel_scope_version", ""),
|
|
}
|
|
expectedCounterTags := append(expectedSystemTags, counterTags...)
|
|
counter := handler.WithTags(counterTags...).Counter(counterName)
|
|
counter.Record(1)
|
|
counter.Record(1)
|
|
|
|
s1, err := handler.Snapshot()
|
|
require.NoError(t, err)
|
|
|
|
counterVal, err := s1.Counter(counterName+"_total", expectedCounterTags...)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, float64(2), counterVal)
|
|
|
|
gaugeName := "gauge1"
|
|
gaugeTags := []metrics.Tag{
|
|
metrics.StringTag("l3", "v3"),
|
|
metrics.StringTag("l4", "v4"),
|
|
}
|
|
expectedGaugeTags := append(expectedSystemTags, gaugeTags...)
|
|
gauge := handler.WithTags(gaugeTags...).Gauge(gaugeName)
|
|
gauge.Record(-2)
|
|
gauge.Record(10)
|
|
|
|
s2, err := handler.Snapshot()
|
|
require.NoError(t, err)
|
|
|
|
counterVal, err = s2.Counter(counterName+"_total", expectedCounterTags...)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, float64(2), counterVal)
|
|
|
|
gaugeVal, err := s2.Gauge(gaugeName, expectedGaugeTags...)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, float64(10), gaugeVal)
|
|
}
|
|
|
|
func TestHistogram(t *testing.T) {
|
|
t.Parallel()
|
|
logger := log.NewTestLogger()
|
|
handler, err := NewHandler(logger, metrics.ClientConfig{
|
|
PerUnitHistogramBoundaries: map[string][]float64{
|
|
metrics.Dimensionless: {
|
|
1,
|
|
2,
|
|
5,
|
|
},
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
histogramName := "histogram1"
|
|
histogramTags := []metrics.Tag{
|
|
metrics.StringTag("l2", "v2"),
|
|
metrics.StringTag("l1", "v1"),
|
|
}
|
|
expectedSystemTags := []metrics.Tag{
|
|
metrics.StringTag("otel_scope_name", "temporal"),
|
|
metrics.StringTag("otel_scope_version", ""),
|
|
}
|
|
expectedHistogramTags := append(expectedSystemTags, histogramTags...)
|
|
histogram := handler.WithTags(histogramTags...).Histogram(histogramName, metrics.Dimensionless)
|
|
histogram.Record(1)
|
|
histogram.Record(3)
|
|
|
|
s1, err := handler.Snapshot()
|
|
require.NoError(t, err)
|
|
|
|
expectedBuckets := []HistogramBucket{
|
|
{value: 1, upperBound: 1},
|
|
{value: 1, upperBound: 2},
|
|
{value: 2, upperBound: 5},
|
|
{value: 2, upperBound: math.Inf(1)},
|
|
}
|
|
|
|
histogramVal, err := s1.Histogram(histogramName+"_ratio", expectedHistogramTags...)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, expectedBuckets, histogramVal)
|
|
}
|