forked from veepee-oss/influxdb-relay
-
Notifications
You must be signed in to change notification settings - Fork 25
/
httpbackend.go
88 lines (71 loc) · 1.78 KB
/
httpbackend.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
package backend
import (
"fmt"
"time"
"github.com/rs/zerolog"
"github.com/toni-moreno/influxdb-srelay/pkg/config"
)
type DbBackend struct {
cfg *config.InfluxDBBackend
clusterid string
poster
log *zerolog.Logger
admin string
}
func (b *DbBackend) GetRetryBuffer() *retryBuffer {
if p, ok := b.poster.(*retryBuffer); ok {
return p
}
return nil
}
func (b *DbBackend) Name() string {
return b.cfg.Name
}
func (b *DbBackend) URL(uri string) string {
return b.cfg.Location + uri
}
func (b *DbBackend) PingURI() string {
if len(b.cfg.PingURI) > 0 {
return b.cfg.PingURI
}
return "ping"
}
/*func (b *DbBackend) GetStats() map[string]string {
return b.poster.getStats()
}*/
func NewDBBackend(cfg *config.InfluxDBBackend, l *zerolog.Logger, clustername string) (*DbBackend, error) {
ret := &DbBackend{cfg: cfg, log: l}
// Set a timeout
timeout := DefaultHTTPTimeout
if cfg.Timeout != "" {
t, err := time.ParseDuration(cfg.Timeout)
if err != nil {
return nil, fmt.Errorf("error parsing HTTP timeout '%v'", err)
}
timeout = t
}
// Get underlying Poster instance
var p poster = newSimplePoster(cfg.Name, cfg.Location, clustername, timeout, cfg.SkipTLSVerification)
// If configured, create a retryBuffer per backend.
// This way we serialize retries against each backend.
if cfg.BufferSizeMB > 0 {
max := DefaultMaxDelayInterval
if cfg.MaxDelayInterval != "" {
m, err := time.ParseDuration(cfg.MaxDelayInterval)
if err != nil {
return nil, fmt.Errorf("error parsing max retry time %v", err)
}
max = m
}
batch := DefaultBatchSizeKB * KB
if cfg.MaxBatchKB > 0 {
batch = cfg.MaxBatchKB * KB
}
p = newRetryBuffer(cfg.BufferSizeMB*MB, batch, max, p)
}
/*return &DbBackend{
poster: p,
}, nil*/
ret.poster = p
return ret, nil
}