Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/phlare/appender_test.go
4094 views
1
package phlare
2
3
import (
4
"context"
5
"errors"
6
"testing"
7
8
"github.com/prometheus/client_golang/prometheus"
9
"github.com/prometheus/prometheus/model/labels"
10
"github.com/stretchr/testify/require"
11
"go.uber.org/atomic"
12
)
13
14
func Test_FanOut(t *testing.T) {
15
totalAppend := atomic.NewInt32(0)
16
lbls := labels.Labels{
17
{Name: "foo", Value: "bar"},
18
}
19
f := NewFanout([]Appendable{
20
AppendableFunc(func(_ context.Context, labels labels.Labels, _ []*RawSample) error {
21
require.Equal(t, lbls, labels)
22
totalAppend.Inc()
23
return nil
24
}),
25
AppendableFunc(func(_ context.Context, labels labels.Labels, _ []*RawSample) error {
26
require.Equal(t, lbls, labels)
27
totalAppend.Inc()
28
return nil
29
}),
30
AppendableFunc(func(_ context.Context, labels labels.Labels, _ []*RawSample) error {
31
require.Equal(t, lbls, labels)
32
totalAppend.Inc()
33
return nil
34
}),
35
}, "foo", prometheus.NewRegistry())
36
require.NoError(t, f.Appender().Append(context.Background(), lbls, []*RawSample{}))
37
require.Equal(t, int32(3), totalAppend.Load())
38
f.UpdateChildren([]Appendable{
39
AppendableFunc(func(_ context.Context, labels labels.Labels, _ []*RawSample) error {
40
require.Equal(t, lbls, labels)
41
totalAppend.Inc()
42
return errors.New("foo")
43
}),
44
AppendableFunc(func(_ context.Context, labels labels.Labels, _ []*RawSample) error {
45
require.Equal(t, lbls, labels)
46
totalAppend.Inc()
47
return nil
48
}),
49
})
50
totalAppend.Store(0)
51
require.Error(t, f.Appender().Append(context.Background(), lbls, []*RawSample{}))
52
require.Equal(t, int32(2), totalAppend.Load())
53
}
54
55