forked from compose/transporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrethinkdb.go
70 lines (58 loc) · 1.38 KB
/
rethinkdb.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
package rethinkdb
import (
"sync"
"github.com/compose/transporter/adaptor"
"github.com/compose/transporter/client"
)
const (
sampleConfig = `{
"uri": "${RETHINKDB_URI}"
// "timeout": "30s",
// "tail": false,
// "ssl": false,
// "cacerts": ["/path/to/cert.pem"]
}`
description = "a rethinkdb adaptor that functions as both a source and a sink"
)
var (
_ adaptor.Adaptor = &rethinkDB{}
)
// RethinkDB is an adaptor that writes metrics to rethinkdb (http://rethinkdb.com/)
// An open-source distributed database
type rethinkDB struct {
adaptor.BaseConfig
Tail bool `json:"tail"`
SSL bool `json:"ssl"`
CACerts []string `json:"cacerts"`
}
func init() {
adaptor.Add(
"rethinkdb",
func() adaptor.Adaptor {
return &rethinkDB{}
},
)
}
func (r *rethinkDB) Client() (client.Client, error) {
// TODO: pull db from the URI
return NewClient(
WithURI(r.URI),
WithSessionTimeout(r.Timeout),
WithSSL(r.SSL),
WithCACerts(r.CACerts),
)
}
func (r *rethinkDB) Reader() (client.Reader, error) {
return newReader(r.Tail), nil
}
func (r *rethinkDB) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) {
return newWriter(done, wg), nil
}
// Description for rethinkdb adaptor
func (r *rethinkDB) Description() string {
return description
}
// SampleConfig for rethinkdb adaptor
func (r *rethinkDB) SampleConfig() string {
return sampleConfig
}