diff --git a/agent/config/builder.go b/agent/config/builder.go index c27cb1866a..ec98130e91 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -1541,6 +1541,13 @@ func (b *builder) checkVal(v *CheckDefinition) *structs.CheckDefinition { return nil } + var H2PingUseTLSVal bool + if stringVal(v.H2PING) != "" { + H2PingUseTLSVal = boolValWithDefault(v.H2PingUseTLS, true) + } else { + H2PingUseTLSVal = boolVal(v.H2PingUseTLS) + } + id := types.CheckID(stringVal(v.ID)) return &structs.CheckDefinition{ @@ -1571,7 +1578,7 @@ func (b *builder) checkVal(v *CheckDefinition) *structs.CheckDefinition { FailuresBeforeCritical: intVal(v.FailuresBeforeCritical), FailuresBeforeWarning: intValWithDefault(v.FailuresBeforeWarning, intVal(v.FailuresBeforeCritical)), H2PING: stringVal(v.H2PING), - H2PingUseTLS: boolValWithDefault(v.H2PingUseTLS, true), + H2PingUseTLS: H2PingUseTLSVal, DeregisterCriticalServiceAfter: b.durationVal(fmt.Sprintf("check[%s].deregister_critical_service_after", id), v.DeregisterCriticalServiceAfter), OutputMaxSize: intValWithDefault(v.OutputMaxSize, checks.DefaultBufSize), EnterpriseMeta: v.EnterpriseMeta.ToStructs(), diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index b7a7c5079b..a939e96e89 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -5638,7 +5638,6 @@ func TestLoad_FullConfig(t *testing.T) { Timeout: 4868 * time.Second, TTL: 11222 * time.Second, DeregisterCriticalServiceAfter: 68482 * time.Second, - H2PingUseTLS: true, }, }, Connect: &structs.ServiceConnect{}, diff --git a/agent/http_decode_test.go b/agent/http_decode_test.go index 8560945444..ba8f060410 100644 --- a/agent/http_decode_test.go +++ b/agent/http_decode_test.go @@ -729,7 +729,7 @@ var translateH2PingUseTLS = []translateKeyTestCase{ desc: "H2PingUseTLS: neither set", in: []interface{}{}, want: true, // zero value - jsonFmtStr: "{}", + jsonFmtStr: "{" + `"h2ping":"testing"` + "}", equalityFn: h2pingUseTLSEqFn, }, } diff --git a/agent/structs/check_definition.go b/agent/structs/check_definition.go index d9d54dcb4d..9c0f007975 100644 --- a/agent/structs/check_definition.go +++ b/agent/structs/check_definition.go @@ -76,7 +76,7 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) { }{ Alias: (*Alias)(t), } - + // Set default values aux.H2PingUseTLS = true aux.H2PingUseTLSSnake = true if err = lib.UnmarshalJSON(data, &aux); err != nil { @@ -111,6 +111,11 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) { if !aux.H2PingUseTLSSnake { t.H2PingUseTLS = aux.H2PingUseTLSSnake } + // unset default values if it is not an H2Ping check + if t.H2PING == "" { + aux.H2PingUseTLS = false + aux.H2PingUseTLSSnake = false + } // Parse special values if aux.Interval != nil { diff --git a/agent/structs/check_type.go b/agent/structs/check_type.go index 00eff8e23e..13a06e0aab 100644 --- a/agent/structs/check_type.go +++ b/agent/structs/check_type.go @@ -93,8 +93,10 @@ func (t *CheckType) UnmarshalJSON(data []byte) (err error) { }{ Alias: (*Alias)(t), } + // set default values aux.H2PingUseTLS = true aux.H2PingUseTLSSnake = true + if err = lib.UnmarshalJSON(data, aux); err != nil { return err } @@ -162,6 +164,11 @@ func (t *CheckType) UnmarshalJSON(data []byte) (err error) { if !aux.H2PingUseTLSSnake { t.H2PingUseTLS = aux.H2PingUseTLSSnake } + // unset default values if it is not an H2Ping check + if t.H2PING == "" { + aux.H2PingUseTLS = false + aux.H2PingUseTLSSnake = false + } return nil