-
Notifications
You must be signed in to change notification settings - Fork 2
/
providers.go
69 lines (57 loc) · 2.06 KB
/
providers.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
package vshard_router
import (
"context"
"log"
"time"
)
var (
_ MetricsProvider = (*EmptyMetrics)(nil)
_ LogProvider = (*EmptyLogger)(nil)
_ LogProvider = (*StdoutLogger)(nil)
)
type LogProvider interface {
Info(context.Context, string)
Debug(context.Context, string)
Error(context.Context, string)
Warn(context.Context, string)
}
type EmptyLogger struct{}
func (e *EmptyLogger) Info(_ context.Context, _ string) {}
func (e *EmptyLogger) Debug(_ context.Context, _ string) {}
func (e *EmptyLogger) Error(_ context.Context, _ string) {}
func (e *EmptyLogger) Warn(_ context.Context, _ string) {}
type StdoutLogger struct{}
func (e *StdoutLogger) Info(_ context.Context, msg string) {
log.Println(msg)
}
func (e *StdoutLogger) Debug(_ context.Context, msg string) {
log.Println(msg)
}
func (e *StdoutLogger) Error(_ context.Context, msg string) {
log.Println(msg)
}
func (e *StdoutLogger) Warn(_ context.Context, msg string) {
log.Println(msg)
}
// Metrics
// MetricsProvider is an interface for passing library metrics to your prometheus/graphite and other metrics
type MetricsProvider interface {
CronDiscoveryEvent(ok bool, duration time.Duration, reason string)
RetryOnCall(reason string)
RequestDuration(duration time.Duration, ok bool, mapReduce bool)
}
// EmptyMetrics is default empty metrics provider
// you can embed this type and realize just some metrics
type EmptyMetrics struct{}
func (e *EmptyMetrics) CronDiscoveryEvent(_ bool, _ time.Duration, _ string) {}
func (e *EmptyMetrics) RetryOnCall(_ string) {}
func (e *EmptyMetrics) RequestDuration(_ time.Duration, _ bool, _ bool) {}
// TopologyProvider is external module that can lookup current topology of cluster
// it might be etcd/config/consul or smth else
type TopologyProvider interface {
// Init should create the current topology at the beginning
// and change the state during the process of changing the point of receiving the cluster configuration
Init(t TopologyController) error
// Close closes all connections if the provider created them
Close()
}