-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_health.go
63 lines (49 loc) · 1.57 KB
/
client_health.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
package health
import (
"context"
"github.com/americanas-go/health"
"github.com/americanas-go/log"
"github.com/go-redis/redis/v8"
)
// ClientHealth represents client health.
type ClientHealth struct {
options *Options
}
// NewClientHealthWithOptions returns a health with the options provided.
func NewClientHealthWithOptions(options *Options) *ClientHealth {
return &ClientHealth{options: options}
}
// NewClientHealthWithConfigPath returns a client health with options from config path.
func NewClientHealthWithConfigPath(path string) (*ClientHealth, error) {
o, err := NewOptionsWithPath(path)
if err != nil {
return nil, err
}
return NewClientHealthWithOptions(o), nil
}
// NewClientHealth returns a client health with default options.
func NewClientHealth() (*ClientHealth, error) {
o, err := NewOptions()
if err != nil {
return nil, err
}
return NewClientHealthWithOptions(o), nil
}
// Register registers a new ClientChecker in the health package.
func (i *ClientHealth) Register(ctx context.Context, client *redis.Client) error {
logger := log.FromContext(ctx).WithTypeOf(*i)
logger.Trace("integrating redis in health")
checker := NewClientChecker(client)
hc := health.NewHealthChecker(i.options.Name, i.options.Description, checker, i.options.Required, i.options.Enabled)
health.Add(hc)
logger.Debug("redis successfully integrated in health")
return nil
}
func ClientRegister(ctx context.Context, client *redis.Client) error {
o, err := NewOptions()
if err != nil {
return err
}
health := NewClientHealthWithOptions(o)
return health.Register(ctx, client)
}