Skip to content

Commit

Permalink
Operations Maintainer (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickyMateev authored Feb 11, 2020
1 parent 16e3799 commit 0d61cd6
Show file tree
Hide file tree
Showing 27 changed files with 1,295 additions and 316 deletions.
40 changes: 20 additions & 20 deletions Gopkg.lock

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

6 changes: 3 additions & 3 deletions application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ websocket:
ping_timeout: 6000ms
write_timeout: 6000ms
log:
level: error
level: debug
format: kibana
storage:
# name: sm-postgres
Expand All @@ -27,8 +27,8 @@ api:
client_id: cf
operations:
cleanup_interval: 30m
job_timeout: 12m
scheduled_deletion_timeout: 12h
action_timeout: 12m
reconciliation_operation_timeout: 12h
polling_interval: 5s
rescheduling_interval: 5s
pools:
Expand Down
11 changes: 2 additions & 9 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ var _ = Describe("config", func() {

Context("when operation job timeout is < 0", func() {
It("returns an error", func() {
config.Operations.JobTimeout = -time.Second
config.Operations.ActionTimeout = -time.Second
assertErrorDuringValidate()
})
})
Expand All @@ -254,16 +254,9 @@ var _ = Describe("config", func() {
})
})

Context("when operation mark orphans interval is < 0", func() {
It("returns an error", func() {
config.Operations.MarkOrphansInterval = -time.Second
assertErrorDuringValidate()
})
})

Context("when operation scheduled deletion timeoutt is < 0", func() {
It("returns an error", func() {
config.Operations.ScheduledDeletionTimeout = -time.Second
config.Operations.ReconciliationOperationTimeout = -time.Second
assertErrorDuringValidate()
})
})
Expand Down
57 changes: 27 additions & 30 deletions operations/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,52 @@ import (
const (
minTimePeriod = time.Nanosecond

defaultMarkOrphansInterval = 24 * time.Hour
defaultJobTimeout = 7*24*time.Hour - 1*time.Hour
defaultActionTimeout = 12 * time.Hour
defaultOperationLifespan = 7 * 24 * time.Hour

defaultCleanupInterval = 1 * time.Hour
defaultExpirationTime = 7 * 24 * time.Hour
defaultCleanupInterval = 24 * time.Hour
)

// Settings type to be loaded from the environment
type Settings struct {
JobTimeout time.Duration `mapstructure:"job_timeout" description:"timeout for async operations"`
MarkOrphansInterval time.Duration `mapstructure:"mark_orphans_interval" description:"interval denoting how often to mark orphan operations as failed"`
CleanupInterval time.Duration `mapstructure:"cleanup_interval" description:"cleanup interval of old operations"`
ExpirationTime time.Duration `mapstructure:"expiration_time" description:"after that time is passed since its creation, the operation can be cleaned up by the maintainer"`
DefaultPoolSize int `mapstructure:"default_pool_size" description:"default worker pool size"`
Pools []PoolSettings `mapstructure:"pools" description:"defines the different available worker pools"`

ScheduledDeletionTimeout time.Duration `mapstructure:"scheduled_deletion_timeout" description:"the maximum allowed timeout for auto rescheduling of operation actions"`
ReschedulingInterval time.Duration `mapstructure:"rescheduling_interval" description:"the interval between auto rescheduling of operation actions"`
PollingInterval time.Duration `mapstructure:"polling_interval" description:"the interval between polls for async requests"`
ActionTimeout time.Duration `mapstructure:"action_timeout" description:"timeout for async operations"`
ReconciliationOperationTimeout time.Duration `mapstructure:"reconciliation_operation_timeout" description:"the maximum allowed timeout for auto rescheduling of operation actions"`

CleanupInterval time.Duration `mapstructure:"cleanup_interval" description:"cleanup interval of old operations"`
Lifespan time.Duration `mapstructure:"lifespan" description:"after that time is passed since its creation, the operation can be cleaned up by the maintainer"`

ReschedulingInterval time.Duration `mapstructure:"rescheduling_interval" description:"the interval between auto rescheduling of operation actions"`
PollingInterval time.Duration `mapstructure:"polling_interval" description:"the interval between polls for async requests"`

DefaultPoolSize int `mapstructure:"default_pool_size" description:"default worker pool size"`
Pools []PoolSettings `mapstructure:"pools" description:"defines the different available worker pools"`
}

// DefaultSettings returns default values for API settings
func DefaultSettings() *Settings {
return &Settings{
JobTimeout: defaultJobTimeout,
MarkOrphansInterval: defaultMarkOrphansInterval,
CleanupInterval: defaultCleanupInterval,
ExpirationTime: defaultExpirationTime,
DefaultPoolSize: 20,
Pools: []PoolSettings{},
ScheduledDeletionTimeout: 12 * time.Hour,
ReschedulingInterval: 1 * time.Second,
PollingInterval: 1 * time.Second,
ActionTimeout: defaultActionTimeout,
CleanupInterval: defaultCleanupInterval,
Lifespan: defaultOperationLifespan,
DefaultPoolSize: 20,
Pools: []PoolSettings{},
ReconciliationOperationTimeout: defaultOperationLifespan,

ReschedulingInterval: 1 * time.Second,
PollingInterval: 1 * time.Second,
}
}

// Validate validates the Operations settings
func (s *Settings) Validate() error {
if s.JobTimeout <= minTimePeriod {
return fmt.Errorf("validate Settings: JobTimeout must be larger than %s", minTimePeriod)
}
if s.MarkOrphansInterval <= minTimePeriod {
return fmt.Errorf("validate Settings: MarkOrphanscInterval must be larger than %s", minTimePeriod)
if s.ActionTimeout <= minTimePeriod {
return fmt.Errorf("validate Settings: ActionTimeout must be larger than %s", minTimePeriod)
}
if s.CleanupInterval <= minTimePeriod {
return fmt.Errorf("validate Settings: CleanupInterval must be larger than %s", minTimePeriod)
}
if s.ScheduledDeletionTimeout <= minTimePeriod {
return fmt.Errorf("validate Settings: ScheduledDeletionTimeout must be larger than %s", minTimePeriod)
if s.ReconciliationOperationTimeout <= minTimePeriod {
return fmt.Errorf("validate Settings: ReconciliationOperationTimeout must be larger than %s", minTimePeriod)
}
if s.ReschedulingInterval <= minTimePeriod {
return fmt.Errorf("validate Settings: ReschedulingInterval must be larger than %s", minTimePeriod)
Expand Down
Loading

0 comments on commit 0d61cd6

Please sign in to comment.