From 91ac66527099e9511d0aaecbc939d98529ff3271 Mon Sep 17 00:00:00 2001 From: Pravin Pushkar Date: Fri, 21 Jul 2023 16:19:23 +0530 Subject: [PATCH] fix time format to time.duration Signed-off-by: Pravin Pushkar --- configuration/azure/appconfig/appconfig.go | 16 +++---- .../azure/appconfig/appconfig_test.go | 48 +++++++++---------- configuration/azure/appconfig/metadata.go | 14 +++--- configuration/azure/appconfig/metadata.yaml | 32 ++++++------- 4 files changed, 55 insertions(+), 55 deletions(-) diff --git a/configuration/azure/appconfig/appconfig.go b/configuration/azure/appconfig/appconfig.go index a18f5d367c..cf32830ead 100644 --- a/configuration/azure/appconfig/appconfig.go +++ b/configuration/azure/appconfig/appconfig.go @@ -144,17 +144,17 @@ func parseMetadata(meta configuration.Metadata) (metadata, error) { return m, fmt.Errorf("azure appconfig error: specify %s or %s field in metadata", host, connectionString) } - if m.MaxRetryDelay != nil { - m.internalMaxRetryDelay = time.Duration(*m.MaxRetryDelay) + if m.MaxRetryDelay != 0 { + m.internalMaxRetryDelay = m.MaxRetryDelay } - if m.RetryDelay != nil { - m.internalRetryDelay = time.Duration(*m.RetryDelay) + if m.RetryDelay != 0 { + m.internalRetryDelay = m.RetryDelay } - if m.SubscribePollInterval != nil { - m.internalSubscribePollInterval = time.Duration(*m.SubscribePollInterval) + if m.SubscribePollInterval != 0 { + m.internalSubscribePollInterval = m.SubscribePollInterval } - if m.RequestTimeout != nil { - m.internalRequestTimeout = time.Duration(*m.RequestTimeout) + if m.RequestTimeout != 0 { + m.internalRequestTimeout = m.RequestTimeout } return m, nil diff --git a/configuration/azure/appconfig/appconfig_test.go b/configuration/azure/appconfig/appconfig_test.go index 371f0e1f7d..cffee44b09 100644 --- a/configuration/azure/appconfig/appconfig_test.go +++ b/configuration/azure/appconfig/appconfig_test.go @@ -192,10 +192,10 @@ func TestInit(t *testing.T) { testProperties := make(map[string]string) testProperties[host] = "testHost" testProperties[maxRetries] = "3" - testProperties[retryDelay] = "4000000000" - testProperties[maxRetryDelay] = "120000000000" - testProperties[subscribePollInterval] = "30000000000" - testProperties[requestTimeout] = "30000000000" + testProperties[retryDelay] = "4s" + testProperties[maxRetryDelay] = "120s" + testProperties[subscribePollInterval] = "30s" + testProperties[requestTimeout] = "30s" m := configuration.Metadata{Base: mdata.Base{ Properties: testProperties, @@ -217,10 +217,10 @@ func TestInit(t *testing.T) { testProperties := make(map[string]string) testProperties[connectionString] = "Endpoint=https://foo.azconfig.io;Id=osOX-l9-s0:sig;Secret=00000000000000000000000000000000000000000000" testProperties[maxRetries] = "3" - testProperties[retryDelay] = "4000000000" - testProperties[maxRetryDelay] = "120000000000" - testProperties[subscribePollInterval] = "30000000000" - testProperties[requestTimeout] = "30000000000" + testProperties[retryDelay] = "4s" + testProperties[maxRetryDelay] = "120s" + testProperties[subscribePollInterval] = "30s" + testProperties[requestTimeout] = "30s" m := configuration.Metadata{Base: mdata.Base{ Properties: testProperties, @@ -244,10 +244,10 @@ func Test_parseMetadata(t *testing.T) { testProperties := make(map[string]string) testProperties[host] = "testHost" testProperties[maxRetries] = "3" - testProperties[retryDelay] = "4000000000" - testProperties[maxRetryDelay] = "120000000000" - testProperties[subscribePollInterval] = "30000000000" - testProperties[requestTimeout] = "30000000000" + testProperties[retryDelay] = "4s" + testProperties[maxRetryDelay] = "120s" + testProperties[subscribePollInterval] = "30s" + testProperties[requestTimeout] = "30s" meta := configuration.Metadata{Base: mdata.Base{ Properties: testProperties, @@ -276,10 +276,10 @@ func Test_parseMetadata(t *testing.T) { testProperties := make(map[string]string) testProperties[connectionString] = "testConnectionString" testProperties[maxRetries] = "3" - testProperties[retryDelay] = "4000000000" - testProperties[maxRetryDelay] = "120000000000" - testProperties[subscribePollInterval] = "30000000000" - testProperties[requestTimeout] = "30000000000" + testProperties[retryDelay] = "4s" + testProperties[maxRetryDelay] = "120s" + testProperties[subscribePollInterval] = "30s" + testProperties[requestTimeout] = "30s" meta := configuration.Metadata{Base: mdata.Base{ Properties: testProperties, @@ -309,10 +309,10 @@ func Test_parseMetadata(t *testing.T) { testProperties[host] = "testHost" testProperties[connectionString] = "testConnectionString" testProperties[maxRetries] = "3" - testProperties[retryDelay] = "4000000000" - testProperties[maxRetryDelay] = "120000000000" - testProperties[subscribePollInterval] = "30000000000" - testProperties[requestTimeout] = "30000000000" + testProperties[retryDelay] = "4s" + testProperties[maxRetryDelay] = "120s" + testProperties[subscribePollInterval] = "30s" + testProperties[requestTimeout] = "30s" meta := configuration.Metadata{Base: mdata.Base{ Properties: testProperties, @@ -327,10 +327,10 @@ func Test_parseMetadata(t *testing.T) { testProperties[host] = "" testProperties[connectionString] = "" testProperties[maxRetries] = "3" - testProperties[retryDelay] = "4000000000" - testProperties[maxRetryDelay] = "120000000000" - testProperties[subscribePollInterval] = "30000000000" - testProperties[requestTimeout] = "30000000000" + testProperties[retryDelay] = "4s" + testProperties[maxRetryDelay] = "120s" + testProperties[subscribePollInterval] = "30s" + testProperties[requestTimeout] = "30s" meta := configuration.Metadata{Base: mdata.Base{ Properties: testProperties, diff --git a/configuration/azure/appconfig/metadata.go b/configuration/azure/appconfig/metadata.go index 75d7de35a4..69d543f206 100644 --- a/configuration/azure/appconfig/metadata.go +++ b/configuration/azure/appconfig/metadata.go @@ -16,13 +16,13 @@ package appconfig import "time" type metadata struct { - Host string `mapstructure:"host"` - ConnectionString string `mapstructure:"connectionString"` - MaxRetries int `mapstructure:"maxRetries"` - MaxRetryDelay *int `mapstructure:"maxRetryDelay"` - RetryDelay *int `mapstructure:"retryDelay"` - SubscribePollInterval *int `mapstructure:"subscribePollInterval"` - RequestTimeout *int `mapstructure:"requestTimeout"` + Host string `mapstructure:"host"` + ConnectionString string `mapstructure:"connectionString"` + MaxRetries int `mapstructure:"maxRetries"` + MaxRetryDelay time.Duration `mapstructure:"maxRetryDelay"` + RetryDelay time.Duration `mapstructure:"retryDelay"` + SubscribePollInterval time.Duration `mapstructure:"subscribePollInterval"` + RequestTimeout time.Duration `mapstructure:"requestTimeout"` internalRequestTimeout time.Duration `mapstructure:"-"` internalMaxRetryDelay time.Duration `mapstructure:"-"` diff --git a/configuration/azure/appconfig/metadata.yaml b/configuration/azure/appconfig/metadata.yaml index 040b72fb5d..ec1027ff04 100644 --- a/configuration/azure/appconfig/metadata.yaml +++ b/configuration/azure/appconfig/metadata.yaml @@ -35,22 +35,22 @@ metadata: default: '3' example: '10' - name: retryDelay - description: "Specifies the initial amount of delay to use before retrying an operation, in nanoseconds. The delay increases exponentially with each retry up to the maximum specified by MaxRetryDelay. Defaults to 4 seconds. -1 disables delay between retries." - type: number - default: '4000000000' - example: '5000000000' + description: "Specifies the initial amount of delay to use before retrying an operation. The delay increases exponentially with each retry up to the maximum specified by MaxRetryDelay. Defaults to 4 seconds." + type: duration + default: '4s' + example: '5s' - name: maxRetryDelay - description: "Specifies the maximum delay allowed before retrying an operation, in nanoseconds. Typically the value is greater than or equal to the value specified in RetryDelay. Defaults to 120 seconds. -1 disables the limit." - type: number - default: '120000000000' - example: '180000000000' + description: "Specifies the maximum delay allowed before retrying an operation. Typically the value is greater than or equal to the value specified in RetryDelay. Defaults to 120 seconds." + type: duration + default: '120s' + example: '180s' - name: subscribePollInterval - description: "Specifies the poll interval for polling the subscribed keys for any changes, in nanoseconds. Default polling interval is set to 24 hours." - type: number - default: '86400000000000' - example: '240000000000' + description: "Specifies the poll interval for polling the subscribed keys for any changes. Default polling interval is set to 24 hours." + type: duration + default: '24h' + example: '5m' - name: requesttimeout - description: "Specifies the time allowed to pass until a request is failed, in nanoseconds. Default timeout is set to 15 seconds." - type: number - default: '15000000000' - example: '30000000000' \ No newline at end of file + description: "Specifies the time allowed to pass until a request is failed. Default timeout is set to 15 seconds." + type: duration + default: '15s' + example: '30s' \ No newline at end of file