Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve issues from #132 #133

Merged
merged 1 commit into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions storage/appinsights/appinsights.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
}
}
Expand Down
14 changes: 7 additions & 7 deletions storage/appinsights/appinsights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down