github.com/MetalBlockchain/metalgo@v1.11.9/api/health/service.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package health 5 6 import ( 7 "net/http" 8 9 "go.uber.org/zap" 10 11 "github.com/MetalBlockchain/metalgo/utils/logging" 12 ) 13 14 type Service struct { 15 log logging.Logger 16 health Reporter 17 } 18 19 // APIReply is the response for Readiness, Health, and Liveness. 20 type APIReply struct { 21 Checks map[string]Result `json:"checks"` 22 Healthy bool `json:"healthy"` 23 } 24 25 // APIArgs is the arguments for Readiness, Health, and Liveness. 26 type APIArgs struct { 27 Tags []string `json:"tags"` 28 } 29 30 // Readiness returns if the node has finished initialization 31 func (s *Service) Readiness(_ *http.Request, args *APIArgs, reply *APIReply) error { 32 s.log.Debug("API called", 33 zap.String("service", "health"), 34 zap.String("method", "readiness"), 35 zap.Strings("tags", args.Tags), 36 ) 37 reply.Checks, reply.Healthy = s.health.Readiness(args.Tags...) 38 return nil 39 } 40 41 // Health returns a summation of the health of the node 42 func (s *Service) Health(_ *http.Request, args *APIArgs, reply *APIReply) error { 43 s.log.Debug("API called", 44 zap.String("service", "health"), 45 zap.String("method", "health"), 46 zap.Strings("tags", args.Tags), 47 ) 48 49 reply.Checks, reply.Healthy = s.health.Health(args.Tags...) 50 return nil 51 } 52 53 // Liveness returns if the node is in need of a restart 54 func (s *Service) Liveness(_ *http.Request, args *APIArgs, reply *APIReply) error { 55 s.log.Debug("API called", 56 zap.String("service", "health"), 57 zap.String("method", "liveness"), 58 zap.Strings("tags", args.Tags), 59 ) 60 reply.Checks, reply.Healthy = s.health.Liveness(args.Tags...) 61 return nil 62 }