Skip to content

Commit

Permalink
cloudapi: Refresh log tail connection
Browse files Browse the repository at this point in the history
It makes the log tail connection more fault-tolerant:
  * it tries to acquire a new connection in case of error.
  * it allows to set a config option to refresh the connection on
    a defined interval, this will avoid to hit the timeout set
    from the log provider.
  * the dial operation retries some times, based on config
    options, before return an error.
  • Loading branch information
codebien committed Jul 13, 2021
1 parent 0b730ce commit d831fc8
Show file tree
Hide file tree
Showing 7 changed files with 509 additions and 31 deletions.
24 changes: 12 additions & 12 deletions cloudapi/cloudapi_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 21 additions & 6 deletions cloudapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ type Config struct {
ProjectID null.Int `json:"projectID" envconfig:"K6_CLOUD_PROJECT_ID"`
Name null.String `json:"name" envconfig:"K6_CLOUD_NAME"`

Host null.String `json:"host" envconfig:"K6_CLOUD_HOST"`
LogsTailURL null.String `json:"-" envconfig:"K6_CLOUD_LOGS_TAIL_URL"`
PushRefID null.String `json:"pushRefID" envconfig:"K6_CLOUD_PUSH_REF_ID"`
WebAppURL null.String `json:"webAppURL" envconfig:"K6_CLOUD_WEB_APP_URL"`
NoCompress null.Bool `json:"noCompress" envconfig:"K6_CLOUD_NO_COMPRESS"`
StopOnError null.Bool `json:"stopOnError" envconfig:"K6_CLOUD_STOP_ON_ERROR"`
Host null.String `json:"host" envconfig:"K6_CLOUD_HOST"`
LogsTailURL null.String `json:"-" envconfig:"K6_CLOUD_LOGS_TAIL_URL"`
LogsTailRefreshAfter types.NullDuration `json:"-" envconfig:"K6_CLOUD_LOGS_TAIL_REFRESH_AFTER"`
LogsTailDialRetryAttempts null.Int `json:"-" envconfig:"K6_CLOUD_LOGS_TAIL_DIAL_RETRY_ATTEMPTS"`
LogsTailDialRetryInterval types.NullDuration `json:"-" envconfig:"K6_CLOUD_LOGS_TAIL_DIAL_RETRY_INTERVAL"`
PushRefID null.String `json:"pushRefID" envconfig:"K6_CLOUD_PUSH_REF_ID"`
WebAppURL null.String `json:"webAppURL" envconfig:"K6_CLOUD_WEB_APP_URL"`
NoCompress null.Bool `json:"noCompress" envconfig:"K6_CLOUD_NO_COMPRESS"`
StopOnError null.Bool `json:"stopOnError" envconfig:"K6_CLOUD_STOP_ON_ERROR"`

MaxMetricSamplesPerPackage null.Int `json:"maxMetricSamplesPerPackage" envconfig:"K6_CLOUD_MAX_METRIC_SAMPLES_PER_PACKAGE"`

Expand Down Expand Up @@ -161,6 +164,9 @@ func NewConfig() Config {
return Config{
Host: null.NewString("https://ingest.k6.io", false),
LogsTailURL: null.NewString("wss://cloudlogs.k6.io/api/v1/tail", false),
LogsTailRefreshAfter: types.NewNullDuration(50*time.Minute, false),
LogsTailDialRetryAttempts: null.NewInt(2, false),
LogsTailDialRetryInterval: types.NewNullDuration(5*time.Second, false),
WebAppURL: null.NewString("https://app.k6.io", false),
MetricPushInterval: types.NewNullDuration(1*time.Second, false),
MetricPushConcurrency: null.NewInt(1, false),
Expand Down Expand Up @@ -201,6 +207,15 @@ func (c Config) Apply(cfg Config) Config {
if cfg.LogsTailURL.Valid && cfg.LogsTailURL.String != "" {
c.LogsTailURL = cfg.LogsTailURL
}
if cfg.LogsTailRefreshAfter.Valid && cfg.LogsTailRefreshAfter.Duration > 0 {
c.LogsTailRefreshAfter = cfg.LogsTailRefreshAfter
}
if cfg.LogsTailDialRetryAttempts.Valid && cfg.LogsTailDialRetryAttempts.Int64 > 0 {
c.LogsTailDialRetryAttempts = cfg.LogsTailDialRetryAttempts
}
if cfg.LogsTailDialRetryInterval.Valid && cfg.LogsTailDialRetryInterval.Duration >= 0 {
c.LogsTailDialRetryInterval = cfg.LogsTailDialRetryInterval
}
if cfg.PushRefID.Valid {
c.PushRefID = cfg.PushRefID
}
Expand Down
3 changes: 3 additions & 0 deletions cloudapi/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func TestConfigApply(t *testing.T) {
Name: null.NewString("Name", true),
Host: null.NewString("Host", true),
LogsTailURL: null.NewString("LogsTailURL", true),
LogsTailRefreshAfter: types.NewNullDuration(50*time.Minute, true),
LogsTailDialRetryAttempts: null.NewInt(2, true),
LogsTailDialRetryInterval: types.NewNullDuration(5*time.Second, true),
PushRefID: null.NewString("PushRefID", true),
WebAppURL: null.NewString("foo", true),
NoCompress: null.NewBool(true, true),
Expand Down
Loading

0 comments on commit d831fc8

Please sign in to comment.