forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
service.go
62 lines (51 loc) · 1.61 KB
/
service.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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package health
import (
"net/http"
"go.uber.org/zap"
"github.com/MetalBlockchain/metalgo/utils/logging"
)
type Service struct {
log logging.Logger
health Reporter
}
// APIReply is the response for Readiness, Health, and Liveness.
type APIReply struct {
Checks map[string]Result `json:"checks"`
Healthy bool `json:"healthy"`
}
// APIArgs is the arguments for Readiness, Health, and Liveness.
type APIArgs struct {
Tags []string `json:"tags"`
}
// Readiness returns if the node has finished initialization
func (s *Service) Readiness(_ *http.Request, args *APIArgs, reply *APIReply) error {
s.log.Debug("API called",
zap.String("service", "health"),
zap.String("method", "readiness"),
zap.Strings("tags", args.Tags),
)
reply.Checks, reply.Healthy = s.health.Readiness(args.Tags...)
return nil
}
// Health returns a summation of the health of the node
func (s *Service) Health(_ *http.Request, args *APIArgs, reply *APIReply) error {
s.log.Debug("API called",
zap.String("service", "health"),
zap.String("method", "health"),
zap.Strings("tags", args.Tags),
)
reply.Checks, reply.Healthy = s.health.Health(args.Tags...)
return nil
}
// Liveness returns if the node is in need of a restart
func (s *Service) Liveness(_ *http.Request, args *APIArgs, reply *APIReply) error {
s.log.Debug("API called",
zap.String("service", "health"),
zap.String("method", "liveness"),
zap.Strings("tags", args.Tags),
)
reply.Checks, reply.Healthy = s.health.Liveness(args.Tags...)
return nil
}