diff --git a/storage/appinsights/appinsights.go b/storage/appinsights/appinsights.go index 9b3077c..6d97214 100644 --- a/storage/appinsights/appinsights.go +++ b/storage/appinsights/appinsights.go @@ -30,18 +30,18 @@ type Storage struct { // MaxRetries specifies the number of retries before returning error // from close(). To enable retries, both RetryInterval and MaxRetries // must be greater than 0. Default is 0 (disabled). - MaxRetries time.Duration `json:"max_retries,omitempty"` + MaxRetries int `json:"max_retries,omitempty"` // RetryInterval specifies the time between retries in seconds. To enable retries, // both RetryInterval and MaxRetries must // be greater than 0. Default is 0 (disabled). - RetryInterval time.Duration `json:"retry_interval,omitempty"` + RetryInterval int `json:"retry_interval,omitempty"` // Timeout specifies the number of seconds to wait for telemetry submission // before returning error from close() if retries are disabled. If omitted or // set to 0, timeout will be 2 seconds. If retries are enabled, this setting // is ignored. - Timeout time.Duration `json:"timeout,omitempty"` + Timeout int `json:"timeout,omitempty"` // telemetryConfig defines the settings for client telemetryConfig *appinsights.TelemetryConfiguration @@ -62,9 +62,6 @@ func New(config json.RawMessage) (Storage, error) { if storage.MaxRetries < 0 { err = fmt.Errorf("Invalid storage max_retries: %d", storage.MaxRetries) } - if storage.MaxRetries < 0 { - err = fmt.Errorf("Invalid storage max_retries: %d", storage.MaxRetries) - } if storage.RetryInterval < 0 { err = fmt.Errorf("Invalid storage retry_interval: %d", storage.RetryInterval) } @@ -113,14 +110,14 @@ func (c Storage) close() error { select { case <-c.client.Channel().Close(): return nil - case <-time.After(c.Timeout * time.Second): + case <-time.After(time.Duration(c.Timeout) * time.Second): return fmt.Errorf("Failed to submit telemetry before timeout expired") } } select { - case <-c.client.Channel().Close(c.RetryInterval * time.Second): + case <-c.client.Channel().Close(time.Duration(c.RetryInterval) * time.Second): return nil - case <-time.After((c.MaxRetries + 1) * c.RetryInterval * time.Second): + case <-time.After((time.Duration(c.MaxRetries) + 1) * time.Duration(c.RetryInterval) * time.Second): return fmt.Errorf("Failed to submit telemetry after retries") } } diff --git a/storage/appinsights/appinsights_test.go b/storage/appinsights/appinsights_test.go index 6b89341..0f6c0b9 100644 --- a/storage/appinsights/appinsights_test.go +++ b/storage/appinsights/appinsights_test.go @@ -30,9 +30,9 @@ var results = []types.Result{{ func TestNew(t *testing.T) { type test struct { - retries time.Duration - interval time.Duration - timeout time.Duration + retries int + interval int + timeout int wantErr bool } tests := []test{ @@ -64,9 +64,9 @@ func TestNew(t *testing.T) { } func TestStoreNoRetry(t *testing.T) { type test struct { - retries time.Duration - interval time.Duration - timeout time.Duration + retries int + interval int + timeout int } tests := []test{ {retries: 0, interval: 0, timeout: 0}, @@ -106,7 +106,7 @@ func TestStoreWithRetry(t *testing.T) { } } -func setup(delay time.Duration, retries time.Duration, interval time.Duration, timeout time.Duration, results []types.Result) (Storage, *httptest.Server) { +func setup(delay time.Duration, retries int, interval int, timeout int, results []types.Result) (Storage, *httptest.Server) { forceRetry := false if interval > 0 && retries > 0 { forceRetry = true