mirror of
https://github.com/status-im/consul.git
synced 2025-02-26 04:15:25 +00:00
Include RequestTimeout in marshal/unmarshal of ServiceResolverConfigE… (#19031)
This commit is contained in:
parent
7ce6ebaeb3
commit
5e45db18b7
3
.changelog/19031.txt
Normal file
3
.changelog/19031.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
api: add custom marshal/unmarshal for ServiceResolverConfigEntry.RequestTimeout so config entries that set this field can be read using the API.
|
||||||
|
```
|
@ -15,6 +15,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/go-bexpr"
|
"github.com/hashicorp/go-bexpr"
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/mitchellh/copystructure"
|
"github.com/mitchellh/copystructure"
|
||||||
"github.com/mitchellh/hashstructure"
|
"github.com/mitchellh/hashstructure"
|
||||||
|
|
||||||
@ -929,21 +930,22 @@ func (e *ServiceResolverConfigEntry) UnmarshalJSON(data []byte) error {
|
|||||||
}{
|
}{
|
||||||
Alias: (*Alias)(e),
|
Alias: (*Alias)(e),
|
||||||
}
|
}
|
||||||
if err := lib.UnmarshalJSON(data, &aux); err != nil {
|
var err error
|
||||||
|
if err = lib.UnmarshalJSON(data, &aux); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var err error
|
var merr *multierror.Error
|
||||||
if aux.ConnectTimeout != "" {
|
if aux.ConnectTimeout != "" {
|
||||||
if e.ConnectTimeout, err = time.ParseDuration(aux.ConnectTimeout); err != nil {
|
if e.ConnectTimeout, err = time.ParseDuration(aux.ConnectTimeout); err != nil {
|
||||||
return err
|
merr = multierror.Append(merr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if aux.RequestTimeout != "" {
|
if aux.RequestTimeout != "" {
|
||||||
if e.RequestTimeout, err = time.ParseDuration(aux.RequestTimeout); err != nil {
|
if e.RequestTimeout, err = time.ParseDuration(aux.RequestTimeout); err != nil {
|
||||||
return err
|
merr = multierror.Append(merr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return merr.ErrorOrNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ServiceResolverConfigEntry) SubsetExists(name string) bool {
|
func (e *ServiceResolverConfigEntry) SubsetExists(name string) bool {
|
||||||
|
@ -1571,6 +1571,15 @@ func TestServiceResolverConfigEntry(t *testing.T) {
|
|||||||
},
|
},
|
||||||
validateErr: "Bad ConnectTimeout",
|
validateErr: "Bad ConnectTimeout",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "bad request timeout",
|
||||||
|
entry: &ServiceResolverConfigEntry{
|
||||||
|
Kind: ServiceResolver,
|
||||||
|
Name: "test",
|
||||||
|
RequestTimeout: -1 * time.Second,
|
||||||
|
},
|
||||||
|
validateErr: "Bad RequestTimeout",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bulk add a bunch of similar validation cases.
|
// Bulk add a bunch of similar validation cases.
|
||||||
|
@ -6,6 +6,8 @@ package api
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceRouterConfigEntry struct {
|
type ServiceRouterConfigEntry struct {
|
||||||
@ -189,14 +191,19 @@ func (e *ServiceResolverConfigEntry) MarshalJSON() ([]byte, error) {
|
|||||||
type Alias ServiceResolverConfigEntry
|
type Alias ServiceResolverConfigEntry
|
||||||
exported := &struct {
|
exported := &struct {
|
||||||
ConnectTimeout string `json:",omitempty"`
|
ConnectTimeout string `json:",omitempty"`
|
||||||
|
RequestTimeout string `json:",omitempty"`
|
||||||
*Alias
|
*Alias
|
||||||
}{
|
}{
|
||||||
ConnectTimeout: e.ConnectTimeout.String(),
|
ConnectTimeout: e.ConnectTimeout.String(),
|
||||||
|
RequestTimeout: e.RequestTimeout.String(),
|
||||||
Alias: (*Alias)(e),
|
Alias: (*Alias)(e),
|
||||||
}
|
}
|
||||||
if e.ConnectTimeout == 0 {
|
if e.ConnectTimeout == 0 {
|
||||||
exported.ConnectTimeout = ""
|
exported.ConnectTimeout = ""
|
||||||
}
|
}
|
||||||
|
if e.RequestTimeout == 0 {
|
||||||
|
exported.RequestTimeout = ""
|
||||||
|
}
|
||||||
|
|
||||||
return json.Marshal(exported)
|
return json.Marshal(exported)
|
||||||
}
|
}
|
||||||
@ -205,20 +212,27 @@ func (e *ServiceResolverConfigEntry) UnmarshalJSON(data []byte) error {
|
|||||||
type Alias ServiceResolverConfigEntry
|
type Alias ServiceResolverConfigEntry
|
||||||
aux := &struct {
|
aux := &struct {
|
||||||
ConnectTimeout string
|
ConnectTimeout string
|
||||||
|
RequestTimeout string
|
||||||
*Alias
|
*Alias
|
||||||
}{
|
}{
|
||||||
Alias: (*Alias)(e),
|
Alias: (*Alias)(e),
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(data, &aux); err != nil {
|
var err error
|
||||||
|
if err = json.Unmarshal(data, &aux); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var err error
|
var merr *multierror.Error
|
||||||
if aux.ConnectTimeout != "" {
|
if aux.ConnectTimeout != "" {
|
||||||
if e.ConnectTimeout, err = time.ParseDuration(aux.ConnectTimeout); err != nil {
|
if e.ConnectTimeout, err = time.ParseDuration(aux.ConnectTimeout); err != nil {
|
||||||
return err
|
merr = multierror.Append(merr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
if aux.RequestTimeout != "" {
|
||||||
|
if e.RequestTimeout, err = time.ParseDuration(aux.RequestTimeout); err != nil {
|
||||||
|
merr = multierror.Append(merr, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return merr.ErrorOrNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ServiceResolverConfigEntry) GetKind() string { return e.Kind }
|
func (e *ServiceResolverConfigEntry) GetKind() string { return e.Kind }
|
||||||
|
@ -173,6 +173,7 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
ConnectTimeout: 5 * time.Second,
|
ConnectTimeout: 5 * time.Second,
|
||||||
|
RequestTimeout: 10 * time.Second,
|
||||||
Meta: map[string]string{
|
Meta: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"gir": "zim",
|
"gir": "zim",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user