/
cluster_health.go
63 lines (49 loc) · 1.6 KB
/
cluster_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"
)
// ClusterHealth represents cluster health.
type ClusterHealth struct {
options *Options
}
// NewClusterHealthWithOptions returns a health with the options provided.
func NewClusterHealthWithOptions(options *Options) *ClusterHealth {
return &ClusterHealth{options: options}
}
// NewClusterHealthWithConfigPath returns a health with options from config path.
func NewClusterHealthWithConfigPath(path string) (*ClusterHealth, error) {
o, err := NewOptionsWithPath(path)
if err != nil {
return nil, err
}
return NewClusterHealthWithOptions(o), nil
}
// NewClusterHealth returns a health with default options.
func NewClusterHealth() (*ClusterHealth, error) {
o, err := NewOptions()
if err != nil {
return nil, err
}
return NewClusterHealthWithOptions(o), nil
}
// Register registers a new ClusterClientChecker in the health package.
func (i *ClusterHealth) Register(ctx context.Context, client *redis.ClusterClient) error {
logger := log.FromContext(ctx).WithTypeOf(*i)
logger.Trace("integrating redis in health")
checker := NewClusterClientChecker(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 ClusterRegister(ctx context.Context, client *redis.ClusterClient) error {
o, err := NewOptions()
if err != nil {
return err
}
health := NewClusterHealthWithOptions(o)
return health.Register(ctx, client)
}