Skip to content

Commit 3c43ebc

Browse files
author
eweziyi
committed
Change poller interval field to int
1 parent 20009ce commit 3c43ebc

File tree

5 files changed

+11
-24
lines changed

5 files changed

+11
-24
lines changed

treatment-service/config/config.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ package config
22

33
import (
44
"fmt"
5-
"strconv"
6-
"time"
7-
85
"github.com/caraml-dev/mlp/api/pkg/instrumentation/newrelic"
96
"github.com/caraml-dev/mlp/api/pkg/instrumentation/sentry"
107
common_config "github.com/caraml-dev/xp/common/config"
118
common_mq_config "github.com/caraml-dev/xp/common/messagequeue"
129
"github.com/caraml-dev/xp/treatment-service/models"
10+
"strconv"
1311
)
1412

1513
type AssignedTreatmentLoggerKind = string
@@ -96,8 +94,8 @@ type ManagementServiceConfig struct {
9694
}
9795

9896
type ManagementServicePollerConfig struct {
99-
Enabled bool `json:"enabled" default:"false"`
100-
PollInterval time.Duration `json:"poll_interval" default:"30s"`
97+
Enabled bool `json:"enabled" default:"false"`
98+
PollIntervalSeconds int `json:"poll_interval" default:"30"`
10199
}
102100

103101
func (c *Config) GetProjectIds() []models.ProjectId {

treatment-service/config/config_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package config
22

33
import (
4-
"testing"
5-
"time"
6-
74
"github.com/caraml-dev/mlp/api/pkg/instrumentation/newrelic"
85
"github.com/caraml-dev/mlp/api/pkg/instrumentation/sentry"
96
"github.com/stretchr/testify/assert"
107
"github.com/stretchr/testify/require"
8+
"testing"
119

1210
common_mq_config "github.com/caraml-dev/xp/common/messagequeue"
1311
)
@@ -66,8 +64,8 @@ func TestDefaultConfigs(t *testing.T) {
6664
SentryConfig: sentry.Config{Enabled: false, Labels: emptyStringMap},
6765
SegmenterConfig: make(map[string]interface{}),
6866
ManagementServicePollerConfig: ManagementServicePollerConfig{
69-
Enabled: false,
70-
PollInterval: 30 * time.Second,
67+
Enabled: false,
68+
PollIntervalSeconds: 30,
7169
},
7270
}
7371
cfg, err := Load()
@@ -133,8 +131,8 @@ func TestLoadMultipleConfigs(t *testing.T) {
133131
SentryConfig: sentry.Config{Enabled: true, DSN: "my.amazing.sentry.dsn", Labels: map[string]string{"app": "xp-treatment-service"}},
134132
SegmenterConfig: map[string]interface{}{"s2_ids": map[string]interface{}{"mins2celllevel": 9, "maxs2celllevel": 15}},
135133
ManagementServicePollerConfig: ManagementServicePollerConfig{
136-
Enabled: false,
137-
PollInterval: 30 * time.Second,
134+
Enabled: false,
135+
PollIntervalSeconds: 30,
138136
},
139137
}
140138

treatment-service/go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ require (
1414
github.com/deepmap/oapi-codegen v1.11.0
1515
github.com/getkin/kin-openapi v0.94.0
1616
github.com/go-chi/chi/v5 v5.0.7
17-
github.com/go-playground/validator/v10 v10.11.1
1817
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
1918
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551
2019
github.com/google/go-cmp v0.6.0
@@ -104,8 +103,6 @@ require (
104103
github.com/go-openapi/jsonpointer v0.19.6 // indirect
105104
github.com/go-openapi/jsonreference v0.20.2 // indirect
106105
github.com/go-openapi/swag v0.22.3 // indirect
107-
github.com/go-playground/locales v0.14.0 // indirect
108-
github.com/go-playground/universal-translator v0.18.0 // indirect
109106
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
110107
github.com/goccy/go-json v0.9.11 // indirect
111108
github.com/gofrs/flock v0.8.1 // indirect
@@ -139,7 +136,6 @@ require (
139136
github.com/klauspost/asmfmt v1.3.2 // indirect
140137
github.com/klauspost/compress v1.17.4 // indirect
141138
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
142-
github.com/leodido/go-urn v1.2.1 // indirect
143139
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
144140
github.com/magiconair/properties v1.8.7 // indirect
145141
github.com/mailru/easyjson v0.7.7 // indirect

treatment-service/go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,13 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
333333
github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
334334
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
335335
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
336-
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
337336
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
338337
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
339-
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
340338
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
341339
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
342-
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
343340
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
344341
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
345342
github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
346-
github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
347-
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
348343
github.com/go-sql-driver/mysql v1.3.0 h1:pgwjLi/dvffoP9aabwkT3AKpXQM93QARkjFhDDqC1UE=
349344
github.com/go-sql-driver/mysql v1.3.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
350345
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
@@ -604,7 +599,6 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
604599
github.com/labstack/echo/v4 v4.7.2/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
605600
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
606601
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
607-
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
608602
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
609603
github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y=
610604
github.com/lestrrat-go/blackmagic v1.0.0/go.mod h1:TNgH//0vYSs8VXDCfkZLgIrVTTXQELZffUV0tz3MtdQ=

treatment-service/server/poller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ func NewPoller(pollerConfig config.ManagementServicePollerConfig, localStorage *
2626
}
2727

2828
func (p *Poller) Start() {
29-
ticker := time.NewTicker(p.pollerConfig.PollInterval)
29+
pollInterval := time.Duration(p.pollerConfig.PollIntervalSeconds) * time.Second
30+
ticker := time.NewTicker(pollInterval)
3031
go func() {
3132
for {
3233
select {
3334
case <-ticker.C:
3435
err := p.Refresh()
35-
log.Printf("Polling at %v with interval %v", time.Now(), p.pollerConfig.PollInterval)
36+
log.Printf("Polling at %v with interval %v", time.Now(), pollInterval)
3637
if err != nil {
3738
log.Printf("Error updating local storage: %v", err)
3839
continue

0 commit comments

Comments
 (0)