mirror of https://github.com/status-im/consul.git
Adding HealthCheck and an associated table
This commit is contained in:
parent
c40c2a9c1f
commit
266c6736bf
|
@ -11,6 +11,7 @@ import (
|
|||
const (
|
||||
dbNodes = "nodes"
|
||||
dbServices = "services"
|
||||
dbChecks = "checks"
|
||||
dbMaxMapSize = 1024 * 1024 * 1024 // 1GB maximum size
|
||||
)
|
||||
|
||||
|
@ -26,6 +27,7 @@ type StateStore struct {
|
|||
env *mdb.Env
|
||||
nodeTable *MDBTable
|
||||
serviceTable *MDBTable
|
||||
checkTable *MDBTable
|
||||
tables MDBTables
|
||||
}
|
||||
|
||||
|
@ -97,9 +99,17 @@ func (s *StateStore) initialize() error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Tables use a generic struct encoder
|
||||
encoder := func(obj interface{}) []byte {
|
||||
buf, err := structs.Encode(255, obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return buf[1:]
|
||||
}
|
||||
|
||||
// Setup our tables
|
||||
s.nodeTable = &MDBTable{
|
||||
Env: s.env,
|
||||
Name: dbNodes,
|
||||
Indexes: map[string]*MDBIndex{
|
||||
"id": &MDBIndex{
|
||||
|
@ -107,13 +117,6 @@ func (s *StateStore) initialize() error {
|
|||
Fields: []string{"Node"},
|
||||
},
|
||||
},
|
||||
Encoder: func(obj interface{}) []byte {
|
||||
buf, err := structs.Encode(255, obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return buf[1:]
|
||||
},
|
||||
Decoder: func(buf []byte) interface{} {
|
||||
out := new(structs.Node)
|
||||
if err := structs.Decode(buf, out); err != nil {
|
||||
|
@ -122,12 +125,8 @@ func (s *StateStore) initialize() error {
|
|||
return out
|
||||
},
|
||||
}
|
||||
if err := s.nodeTable.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.serviceTable = &MDBTable{
|
||||
Env: s.env,
|
||||
Name: dbServices,
|
||||
Indexes: map[string]*MDBIndex{
|
||||
"id": &MDBIndex{
|
||||
|
@ -139,13 +138,6 @@ func (s *StateStore) initialize() error {
|
|||
Fields: []string{"ServiceName", "ServiceTag"},
|
||||
},
|
||||
},
|
||||
Encoder: func(obj interface{}) []byte {
|
||||
buf, err := structs.Encode(255, obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return buf[1:]
|
||||
},
|
||||
Decoder: func(buf []byte) interface{} {
|
||||
out := new(structs.ServiceNode)
|
||||
if err := structs.Decode(buf, out); err != nil {
|
||||
|
@ -154,12 +146,44 @@ func (s *StateStore) initialize() error {
|
|||
return out
|
||||
},
|
||||
}
|
||||
if err := s.serviceTable.Init(); err != nil {
|
||||
return err
|
||||
|
||||
s.checkTable = &MDBTable{
|
||||
Name: dbChecks,
|
||||
Indexes: map[string]*MDBIndex{
|
||||
"id": &MDBIndex{
|
||||
Unique: true,
|
||||
Fields: []string{"Node", "CheckID"},
|
||||
},
|
||||
"status": &MDBIndex{
|
||||
Fields: []string{"Status"},
|
||||
},
|
||||
"service": &MDBIndex{
|
||||
AllowBlank: true,
|
||||
Fields: []string{"ServiceName"},
|
||||
},
|
||||
"node": &MDBIndex{
|
||||
AllowBlank: true,
|
||||
Fields: []string{"Node", "ServiceID"},
|
||||
},
|
||||
},
|
||||
Decoder: func(buf []byte) interface{} {
|
||||
out := new(structs.HealthCheck)
|
||||
if err := structs.Decode(buf, out); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return out
|
||||
},
|
||||
}
|
||||
|
||||
// Store the set of tables
|
||||
s.tables = []*MDBTable{s.nodeTable, s.serviceTable}
|
||||
s.tables = []*MDBTable{s.nodeTable, s.serviceTable, s.checkTable}
|
||||
for _, table := range s.tables {
|
||||
table.Env = s.env
|
||||
table.Encoder = encoder
|
||||
if err := table.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,13 @@ const (
|
|||
DeregisterRequestType
|
||||
)
|
||||
|
||||
const (
|
||||
HealthUnknown = "unknown"
|
||||
HealthPassing = "passing"
|
||||
HealthWarning = "warning"
|
||||
HealthCritical = "critical"
|
||||
)
|
||||
|
||||
// RegisterRequest is used for the Catalog.Register endpoint
|
||||
// to register a node as providing a service. If no service
|
||||
// is provided, the node is registered.
|
||||
|
@ -89,6 +96,17 @@ type NodeServices struct {
|
|||
Services map[string]*NodeService
|
||||
}
|
||||
|
||||
// HealthCheck represents a single check on a given node
|
||||
type HealthCheck struct {
|
||||
Node string
|
||||
CheckID string // Unique per-node ID
|
||||
Name string // Check name
|
||||
Status string // The current check status
|
||||
Notes string // Additional notes with the status
|
||||
ServiceID string // optional associated service
|
||||
ServiceName string // optional service name
|
||||
}
|
||||
|
||||
// Decode is used to decode a MsgPack encoded object
|
||||
func Decode(buf []byte, out interface{}) error {
|
||||
var handle codec.MsgpackHandle
|
||||
|
|
Loading…
Reference in New Issue