Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/common/loki/client/config_test.go
4096 views
1
package client
2
3
// This code is copied from Promtail. The client package is used to configure
4
// and run the clients that can send log entries to a Loki instance.
5
6
import (
7
"net/url"
8
"reflect"
9
"testing"
10
"time"
11
12
"github.com/grafana/dskit/backoff"
13
"github.com/grafana/dskit/flagext"
14
"github.com/stretchr/testify/require"
15
16
"gopkg.in/yaml.v2"
17
)
18
19
var clientConfig = Config{}
20
21
var clientDefaultConfig = (`
22
url: http://localhost:3100/loki/api/v1/push
23
`)
24
25
var clientCustomConfig = `
26
url: http://localhost:3100/loki/api/v1/push
27
backoff_config:
28
max_retries: 20
29
min_period: 5s
30
max_period: 1m
31
batchwait: 5s
32
batchsize: 204800
33
timeout: 5s
34
`
35
36
func Test_Config(t *testing.T) {
37
u, err := url.Parse("http://localhost:3100/loki/api/v1/push")
38
require.NoError(t, err)
39
tests := []struct {
40
configValues string
41
expectedConfig Config
42
}{
43
{
44
clientDefaultConfig,
45
Config{
46
URL: flagext.URLValue{
47
URL: u,
48
},
49
BackoffConfig: backoff.Config{
50
MaxBackoff: MaxBackoff,
51
MaxRetries: MaxRetries,
52
MinBackoff: MinBackoff,
53
},
54
BatchSize: BatchSize,
55
BatchWait: BatchWait,
56
Timeout: Timeout,
57
},
58
},
59
{
60
clientCustomConfig,
61
Config{
62
URL: flagext.URLValue{
63
URL: u,
64
},
65
BackoffConfig: backoff.Config{
66
MaxBackoff: 1 * time.Minute,
67
MaxRetries: 20,
68
MinBackoff: 5 * time.Second,
69
},
70
BatchSize: 100 * 2048,
71
BatchWait: 5 * time.Second,
72
Timeout: 5 * time.Second,
73
},
74
},
75
}
76
for _, tc := range tests {
77
err := yaml.Unmarshal([]byte(tc.configValues), &clientConfig)
78
require.NoError(t, err)
79
80
if !reflect.DeepEqual(tc.expectedConfig, clientConfig) {
81
t.Errorf("Configs does not match, expected: %v, received: %v", tc.expectedConfig, clientConfig)
82
}
83
}
84
}
85
86