forked from facebookarchive/dvara
/
main.go
96 lines (86 loc) · 3.04 KB
/
main.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
93
94
95
96
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/facebookgo/gangliamr"
"github.com/facebookgo/inject"
"github.com/facebookgo/startstop"
"github.com/facebookgo/stats"
"github.com/shutej/dvara"
)
func main() {
if err := Main(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func Main() error {
addrs := flag.String("addrs", "localhost:27017", "comma separated list of mongo addresses")
certFile := flag.String("cert_file", "", "path to the certificate file")
clientIdleTimeout := flag.Duration("client_idle_timeout", 60*time.Minute, "idle timeout for client connections")
getLastErrorTimeout := flag.Duration("get_last_error_timeout", time.Minute, "timeout for getLastError pinning")
keyFile := flag.String("key_file", "", "path to the key file")
maxConnections := flag.Uint("max_connections", 100, "maximum number of connections per mongo")
maxPerClientConnections := flag.Uint("max_per_client_connections", 1, "maximum number of connections from a single client")
messageTimeout := flag.Duration("message_timeout", 2*time.Minute, "timeout for one message to be proxied")
password := flag.String("password", "", "")
portEnd := flag.Int("port_end", 6010, "end of port range")
portStart := flag.Int("port_start", 6000, "start of port range")
serverClosePoolSize := flag.Uint("server_close_pool_size", 1, "number of goroutines that will handle closing server connections.")
serverIdleTimeout := flag.Duration("server_idle_timeout", 60*time.Minute, "duration after which a server connection will be considered idle")
username := flag.String("username", "", "")
flag.Parse()
replicaSet := dvara.ReplicaSet{
Addrs: *addrs,
CertFile: *certFile,
ClientIdleTimeout: *clientIdleTimeout,
GetLastErrorTimeout: *getLastErrorTimeout,
KeyFile: *keyFile,
MaxConnections: *maxConnections,
MaxPerClientConnections: *maxPerClientConnections,
MessageTimeout: *messageTimeout,
Password: *password,
PortEnd: *portEnd,
PortStart: *portStart,
ServerClosePoolSize: *serverClosePoolSize,
ServerIdleTimeout: *serverIdleTimeout,
Username: *username,
}
var log stdLogger
var graph inject.Graph
err := graph.Provide(
&inject.Object{Value: &log},
&inject.Object{Value: &replicaSet},
&inject.Object{Value: &stats.HookClient{}},
)
if err != nil {
return err
}
if err := graph.Populate(); err != nil {
return err
}
objects := graph.Objects()
// Temporarily setup the metrics against a test registry.
gregistry := gangliamr.NewTestRegistry()
for _, o := range objects {
if rmO, ok := o.Value.(registerMetrics); ok {
rmO.RegisterMetrics(gregistry)
}
}
if err := startstop.Start(objects, &log); err != nil {
return err
}
defer startstop.Stop(objects, &log)
ch := make(chan os.Signal, 2)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT)
<-ch
signal.Stop(ch)
return nil
}
type registerMetrics interface {
RegisterMetrics(r *gangliamr.Registry)
}