-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
92 lines (78 loc) · 2.07 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package graphmetrics
import (
"context"
"time"
"github.com/graphmetrics/logger-go"
"github.com/graphmetrics/graphmetrics-go/client"
)
const (
defaultEndpoint = "api.graphmetrics.io"
defaultFieldBufferSize = 1000
defaultOperationBufferSize = 20
defaultStopTimeout = 10 * time.Second
)
type Configuration struct {
ApiKey string
ServerVersion string
ClientExtractor client.Extractor
Logger logger.Logger
Advanced *AdvancedConfiguration
}
type AdvancedConfiguration struct {
FieldBufferSize int // If field metrics are dropped consider increasing it
OperationBufferSize int // If operation metrics are dropped consider increasing it
Endpoint string
Http bool
Debug bool
StopTimeout time.Duration
}
func (c *Configuration) GetEndpoint() string {
if c.Advanced != nil && c.Advanced.Endpoint != "" {
return c.Advanced.Endpoint
}
return defaultEndpoint
}
func (c *Configuration) GetProtocol() string {
if c.Advanced != nil && c.Advanced.Http {
return "http"
}
return "https"
}
func (c *Configuration) GetFieldBufferSize() int {
if c.Advanced != nil && c.Advanced.FieldBufferSize != 0 {
return c.Advanced.FieldBufferSize
}
return defaultFieldBufferSize
}
func (c *Configuration) GetOperationBufferSize() int {
if c.Advanced != nil && c.Advanced.OperationBufferSize != 0 {
return c.Advanced.OperationBufferSize
}
return defaultOperationBufferSize
}
func (c *Configuration) GetDebug() bool {
if c.Advanced != nil {
return c.Advanced.Debug
}
return false
}
func (c *Configuration) GetStopTimeout() time.Duration {
if c.Advanced != nil && c.Advanced.StopTimeout != 0 {
return c.Advanced.StopTimeout
}
return defaultStopTimeout
}
func (c *Configuration) GetLogger() logger.Logger {
if c.Logger != nil {
return c.Logger
}
return logger.NewDefault(c.GetDebug())
}
func (c *Configuration) GetClientExtractor() client.Extractor {
if c.ClientExtractor != nil {
return c.ClientExtractor
}
return func(context.Context) client.Details {
return client.Details{}
}
}