Skip to content

Commit f946242

Browse files
Merge pull request #342 from sdcio/exposeDeviationFrequency
Expose the default Deviation calc Frequency
2 parents 403d56b + ea676fe commit f946242

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

pkg/config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Config struct {
4040
Prometheus *PromConfig `yaml:"prometheus,omitempty" json:"prometheus,omitempty"`
4141
DefaultTransactionTimeout time.Duration `yaml:"transaction-timeout,omitempty" json:"transaction-timeout,omitempty"`
4242
Validation *Validation `yaml:"validation-defaults,omitempty" json:"validation-defaults,omitempty"`
43+
Deviation *DeviationConfig `yaml:"deviation-defaults,omitempty" json:"deviation-defaults,omitempty"`
4344
}
4445

4546
type TLS struct {
@@ -141,6 +142,13 @@ func (c *Config) validateSetDefaults() error {
141142
return err
142143
}
143144

145+
if c.Deviation == nil {
146+
c.Deviation = &DeviationConfig{}
147+
}
148+
if err = c.Deviation.validateSetDefaults(); err != nil {
149+
return err
150+
}
151+
144152
return nil
145153
}
146154

pkg/config/datastore.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,30 @@ const (
3131
)
3232

3333
type DatastoreConfig struct {
34-
Name string `yaml:"name,omitempty" json:"name,omitempty"`
35-
Schema *SchemaConfig `yaml:"schema,omitempty" json:"schema,omitempty"`
36-
SBI *SBI `yaml:"sbi,omitempty" json:"sbi,omitempty"`
37-
Sync *Sync `yaml:"sync,omitempty" json:"sync,omitempty"`
38-
Validation *Validation `yaml:"validation,omitempty" json:"validation,omitempty"`
34+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
35+
Schema *SchemaConfig `yaml:"schema,omitempty" json:"schema,omitempty"`
36+
SBI *SBI `yaml:"sbi,omitempty" json:"sbi,omitempty"`
37+
Sync *Sync `yaml:"sync,omitempty" json:"sync,omitempty"`
38+
Validation *Validation `yaml:"validation,omitempty" json:"validation,omitempty"`
39+
Deviation *DeviationConfig `yaml:"deviation,omitempty" json:"deviation,omitempty"`
40+
}
41+
42+
type DeviationConfig struct {
43+
Interval time.Duration `yaml:"interval,omitempty" json:"interval,omitempty"`
44+
}
45+
46+
func (d *DeviationConfig) validateSetDefaults() error {
47+
if d.Interval == 0 {
48+
d.Interval = 30 * time.Second
49+
}
50+
return nil
51+
}
52+
53+
func (d *DeviationConfig) DeepCopy() *DeviationConfig {
54+
result := &DeviationConfig{
55+
Interval: d.Interval,
56+
}
57+
return result
3958
}
4059

4160
type SBI struct {
@@ -122,7 +141,12 @@ func (ds *DatastoreConfig) ValidateSetDefaults() error {
122141
if err := ds.Validation.validateSetDefaults(); err != nil {
123142
return err
124143
}
125-
144+
if ds.Deviation == nil {
145+
ds.Deviation = &DeviationConfig{}
146+
}
147+
if err = ds.Deviation.validateSetDefaults(); err != nil {
148+
return err
149+
}
126150
return nil
127151
}
128152

pkg/datastore/datastore_rpc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func New(ctx context.Context, c *config.DatastoreConfig, sc schema.Client, cc ca
131131
go ds.Sync(ctx)
132132
}
133133
// start deviation goroutine
134-
ds.DeviationMgr(ctx)
134+
ds.DeviationMgr(ctx, c.Deviation)
135135
}()
136136
return ds, nil
137137
}
@@ -328,9 +328,9 @@ func (d *Datastore) StopDeviationsWatch(peer string) {
328328
log.Debugf("deviation watcher %s removed", peer)
329329
}
330330

331-
func (d *Datastore) DeviationMgr(ctx context.Context) {
331+
func (d *Datastore) DeviationMgr(ctx context.Context, c *config.DeviationConfig) {
332332
log.Infof("%s: starting deviationMgr...", d.Name())
333-
ticker := time.NewTicker(30 * time.Second)
333+
ticker := time.NewTicker(c.Interval)
334334
defer func() {
335335
ticker.Stop()
336336
}()

pkg/datastore/transaction_rpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (d *Datastore) LoadAllButRunningIntents(ctx context.Context, root *tree.Roo
171171
continue
172172
}
173173
intentNames = append(intentNames, intent.GetIntentName())
174-
log.Debugf("adding intent %s to tree", intent.GetIntentName())
174+
log.Debugf("%s: adding intent %s to tree", d.Name(), intent.GetIntentName())
175175
protoLoader := treeproto.NewProtoTreeImporter(intent)
176176
log.Tracef("%s", intent.String())
177177
err := root.ImportConfig(ctx, nil, protoLoader, intent.GetIntentName(), intent.GetPriority(), treetypes.NewUpdateInsertFlags())

pkg/server/datastore.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func (s *Server) CreateDataStore(ctx context.Context, req *sdcpb.CreateDataStore
134134
},
135135
SBI: sbi,
136136
Validation: s.config.Validation.DeepCopy(),
137+
Deviation: s.config.Deviation.DeepCopy(),
137138
}
138139
if req.GetSync() != nil {
139140
dsConfig.Sync = &config.Sync{

0 commit comments

Comments
 (0)