agent/config: support configuring alias check
This commit is contained in:
parent
10d68ec56f
commit
3cbdade3b8
|
@ -1046,6 +1046,8 @@ func (b *Builder) checkVal(v *CheckDefinition) *structs.CheckDefinition {
|
|||
GRPC: b.stringVal(v.GRPC),
|
||||
GRPCUseTLS: b.boolVal(v.GRPCUseTLS),
|
||||
TLSSkipVerify: b.boolVal(v.TLSSkipVerify),
|
||||
AliasNode: b.stringVal(v.AliasNode),
|
||||
AliasService: b.stringVal(v.AliasService),
|
||||
Timeout: b.durationVal(fmt.Sprintf("check[%s].timeout", id), v.Timeout),
|
||||
TTL: b.durationVal(fmt.Sprintf("check[%s].ttl", id), v.TTL),
|
||||
DeregisterCriticalServiceAfter: b.durationVal(fmt.Sprintf("check[%s].deregister_critical_service_after", id), v.DeregisterCriticalServiceAfter),
|
||||
|
|
|
@ -348,6 +348,8 @@ type CheckDefinition struct {
|
|||
GRPC *string `json:"grpc,omitempty" hcl:"grpc" mapstructure:"grpc"`
|
||||
GRPCUseTLS *bool `json:"grpc_use_tls,omitempty" hcl:"grpc_use_tls" mapstructure:"grpc_use_tls"`
|
||||
TLSSkipVerify *bool `json:"tls_skip_verify,omitempty" hcl:"tls_skip_verify" mapstructure:"tls_skip_verify"`
|
||||
AliasNode *string `json:"alias_node,omitempty" hcl:"alias_node" mapstructure:"alias_node"`
|
||||
AliasService *string `json:"alias_service,omitempty" hcl:"alias_service" mapstructure:"alias_service"`
|
||||
Timeout *string `json:"timeout,omitempty" hcl:"timeout" mapstructure:"timeout"`
|
||||
TTL *string `json:"ttl,omitempty" hcl:"ttl" mapstructure:"ttl"`
|
||||
DeregisterCriticalServiceAfter *string `json:"deregister_critical_service_after,omitempty" hcl:"deregister_critical_service_after" mapstructure:"deregister_critical_service_after"`
|
||||
|
|
|
@ -1941,6 +1941,24 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
|
|||
rt.DataDir = dataDir
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "alias check with no node",
|
||||
args: []string{
|
||||
`-data-dir=` + dataDir,
|
||||
},
|
||||
json: []string{
|
||||
`{ "check": { "name": "a", "alias_service": "foo" } }`,
|
||||
},
|
||||
hcl: []string{
|
||||
`check = { name = "a", alias_service = "foo" }`,
|
||||
},
|
||||
patch: func(rt *RuntimeConfig) {
|
||||
rt.Checks = []*structs.CheckDefinition{
|
||||
&structs.CheckDefinition{Name: "a", AliasService: "foo"},
|
||||
}
|
||||
rt.DataDir = dataDir
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "multiple service files",
|
||||
args: []string{
|
||||
|
@ -4271,6 +4289,8 @@ func TestSanitize(t *testing.T) {
|
|||
"CheckUpdateInterval": "0s",
|
||||
"Checks": [
|
||||
{
|
||||
"AliasNode": "",
|
||||
"AliasService": "",
|
||||
"DeregisterCriticalServiceAfter": "0s",
|
||||
"DockerContainerID": "",
|
||||
"GRPC": "",
|
||||
|
@ -4417,6 +4437,8 @@ func TestSanitize(t *testing.T) {
|
|||
{
|
||||
"Address": "",
|
||||
"Check": {
|
||||
"AliasNode": "",
|
||||
"AliasService": "",
|
||||
"CheckID": "",
|
||||
"DeregisterCriticalServiceAfter": "0s",
|
||||
"DockerContainerID": "",
|
||||
|
|
|
@ -32,6 +32,8 @@ type CheckDefinition struct {
|
|||
GRPC string
|
||||
GRPCUseTLS bool
|
||||
TLSSkipVerify bool
|
||||
AliasNode string
|
||||
AliasService string
|
||||
Timeout time.Duration
|
||||
TTL time.Duration
|
||||
DeregisterCriticalServiceAfter time.Duration
|
||||
|
@ -63,6 +65,8 @@ func (c *CheckDefinition) CheckType() *CheckType {
|
|||
Notes: c.Notes,
|
||||
|
||||
ScriptArgs: c.ScriptArgs,
|
||||
AliasNode: c.AliasNode,
|
||||
AliasService: c.AliasService,
|
||||
HTTP: c.HTTP,
|
||||
GRPC: c.GRPC,
|
||||
GRPCUseTLS: c.GRPCUseTLS,
|
||||
|
|
|
@ -9,10 +9,10 @@ import (
|
|||
)
|
||||
|
||||
// CheckType is used to create either the CheckMonitor or the CheckTTL.
|
||||
// Six types are supported: Script, HTTP, TCP, Docker, TTL and GRPC. Script,
|
||||
// The following types are supported: Script, HTTP, TCP, Docker, TTL, GRPC, Alias. Script,
|
||||
// HTTP, Docker, TCP and GRPC all require Interval. Only one of the types may
|
||||
// to be provided: TTL or Script/Interval or HTTP/Interval or TCP/Interval or
|
||||
// Docker/Interval or GRPC/Interval.
|
||||
// Docker/Interval or GRPC/Interval or AliasService.
|
||||
type CheckType struct {
|
||||
// fields already embedded in CheckDefinition
|
||||
// Note: CheckType.CheckID == CheckDefinition.ID
|
||||
|
@ -31,6 +31,8 @@ type CheckType struct {
|
|||
Method string
|
||||
TCP string
|
||||
Interval time.Duration
|
||||
AliasNode string
|
||||
AliasService string
|
||||
DockerContainerID string
|
||||
Shell string
|
||||
GRPC string
|
||||
|
@ -56,7 +58,13 @@ func (c *CheckType) Validate() error {
|
|||
if intervalCheck && c.Interval <= 0 {
|
||||
return fmt.Errorf("Interval must be > 0 for Script, HTTP, or TCP checks")
|
||||
}
|
||||
if !intervalCheck && c.TTL <= 0 {
|
||||
if intervalCheck && c.IsAlias() {
|
||||
return fmt.Errorf("Interval cannot be set for Alias checks")
|
||||
}
|
||||
if c.IsAlias() && c.TTL > 0 {
|
||||
return fmt.Errorf("TTL must be not be set for Alias checks")
|
||||
}
|
||||
if !intervalCheck && !c.IsAlias() && c.TTL <= 0 {
|
||||
return fmt.Errorf("TTL must be > 0 for TTL checks")
|
||||
}
|
||||
return nil
|
||||
|
@ -67,6 +75,11 @@ func (c *CheckType) Empty() bool {
|
|||
return reflect.DeepEqual(c, &CheckType{})
|
||||
}
|
||||
|
||||
// IsAlias checks if this is an alias check.
|
||||
func (c *CheckType) IsAlias() bool {
|
||||
return c.AliasService != ""
|
||||
}
|
||||
|
||||
// IsScript checks if this is a check that execs some kind of script.
|
||||
func (c *CheckType) IsScript() bool {
|
||||
return len(c.ScriptArgs) > 0
|
||||
|
|
Loading…
Reference in New Issue