Skip to content

Commit

Permalink
make running objects dump interval configurable & modify default inte…
Browse files Browse the repository at this point in the history
…rval one hour (#833)
  • Loading branch information
jthann committed Oct 20, 2022
1 parent 86043bf commit c42e220
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Options struct {
Debug bool `yaml:"debug"`
DisableAccessLog bool `yaml:"disable-access-log"`
InitialObjectConfigFiles []string `yaml:"initial-object-config-files"`
ObjectsDumpInterval string `yaml:"objects-dump-interval"`

// cluster options
UseStandaloneEtcd bool `yaml:"use-standalone-etcd"`
Expand Down Expand Up @@ -139,6 +140,7 @@ func New() *Options {
opt.flags.StringVar(&opt.APIAddr, "api-addr", "localhost:2381", "Address([host]:port) to listen on for administration traffic.")
opt.flags.BoolVar(&opt.Debug, "debug", false, "Flag to set lowest log level from INFO downgrade DEBUG.")
opt.flags.StringSliceVar(&opt.InitialObjectConfigFiles, "initial-object-config-files", nil, "List of configuration files for initial objects, these objects will be created at startup if not already exist.")
opt.flags.StringVar(&opt.ObjectsDumpInterval, "objects-dump-interval", "", "The time interval to dump running objects config, for example: 30m")

opt.flags.StringVar(&opt.HomeDir, "home-dir", "./", "Path to the home directory.")
opt.flags.StringVar(&opt.DataDir, "data-dir", "data", "Path to the data directory.")
Expand Down
17 changes: 12 additions & 5 deletions pkg/supervisor/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ type (
)

const (
syncInternal = 1 * time.Minute
configFilePrefix = "running_objects"
defaultDumpInterval = 1 * time.Hour
configFilePrefix = "running_objects"
)

// FilterCategory returns a bool function to check if the object entity is filtered by category or not
Expand Down Expand Up @@ -118,7 +118,7 @@ func newObjectEntityWatcherEvent() *ObjectEntityWatcherEvent {
}
}

func newObjectRegistry(super *Supervisor, initObjs map[string]string) *ObjectRegistry {
func newObjectRegistry(super *Supervisor, initObjs map[string]string, interval string) *ObjectRegistry {
cls := super.Cluster()
prefix := cls.Layout().ConfigObjectPrefix()
objs, err := cls.GetPrefix(prefix)
Expand All @@ -135,8 +135,15 @@ func newObjectRegistry(super *Supervisor, initObjs map[string]string) *ObjectReg
panic(fmt.Errorf("add initial object %s to config failed: %v", k, err))
}
}

syncer, err := cls.Syncer(syncInternal)
dumpInterval := defaultDumpInterval
if len(interval) != 0 {
if confInterval, err := time.ParseDuration(interval); err == nil {
dumpInterval = confInterval
} else {
logger.Errorf("parse objects dump interval [%s] as time.Duration error", confInterval)
}
}
syncer, err := cls.Syncer(dumpInterval)
if err != nil {
panic(fmt.Errorf("get syncer failed: %v", err))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func MustNew(opt *option.Options, cls cluster.Cluster) *Supervisor {

initObjs := loadInitialObjects(s, opt.InitialObjectConfigFiles)

s.objectRegistry = newObjectRegistry(s, initObjs)
s.objectRegistry = newObjectRegistry(s, initObjs, opt.ObjectsDumpInterval)
s.watcher = s.objectRegistry.NewWatcher(watcherName, FilterCategory(
// NOTE: SystemController is only initialized internally.
// CategorySystemController,
Expand Down

0 comments on commit c42e220

Please sign in to comment.