Skip to content

Commit ad5712c

Browse files
authored
Merge pull request #96 from harness/FFM-3677
Ffm 3677
2 parents c9a7643 + cc75717 commit ad5712c

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

client/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func NewCfClient(sdkKey string, options ...ConfigOption) (*CfClient, error) {
101101
}
102102

103103
func (c *CfClient) start() {
104+
104105
ctx, cancel := context.WithCancel(context.Background())
105106
go func() {
106107
<-c.stop
@@ -389,7 +390,15 @@ func (c *CfClient) retrieveSegments(ctx context.Context) error {
389390
}
390391

391392
func (c *CfClient) setAnalyticsServiceClient(ctx context.Context) {
393+
392394
<-c.authenticated
395+
c.mux.RLock()
396+
defer c.mux.RUnlock()
397+
if !c.config.enableAnalytics {
398+
c.config.Logger.Info("Posting analytics data disabled")
399+
return
400+
}
401+
c.config.Logger.Info("Posting analytics data enabled")
393402
c.analyticsService.Start(ctx, &c.metricsapi, c.environmentID)
394403
}
395404

client/config.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type config struct {
2525
enableStore bool
2626
target evaluation.Target
2727
eventStreamListener stream.EventStreamListener
28+
enableAnalytics bool
2829
}
2930

3031
func newDefaultConfig() *config {
@@ -39,14 +40,15 @@ func newDefaultConfig() *config {
3940
retryClient.RetryMax = 10
4041

4142
return &config{
42-
url: "https://config.ff.harness.io/api/1.0",
43-
eventsURL: "https://events.ff.harness.io/api/1.0",
44-
pullInterval: 60,
45-
Cache: defaultCache,
46-
Store: defaultStore,
47-
Logger: defaultLogger,
48-
httpClient: retryClient.StandardClient(),
49-
enableStream: true,
50-
enableStore: true,
43+
url: "https://config.ff.harness.io/api/1.0",
44+
eventsURL: "https://events.ff.harness.io/api/1.0",
45+
pullInterval: 60,
46+
Cache: defaultCache,
47+
Store: defaultStore,
48+
Logger: defaultLogger,
49+
httpClient: retryClient.StandardClient(),
50+
enableStream: true,
51+
enableStore: true,
52+
enableAnalytics: true,
5153
}
5254
}

client/options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import (
1414
// using options pattern
1515
type ConfigOption func(config *config)
1616

17+
// WithAnalyticsEnabled en/disable cache and analytics data being sent.
18+
func WithAnalyticsEnabled(val bool) ConfigOption {
19+
return func(config *config) {
20+
config.enableAnalytics = val
21+
}
22+
}
23+
1724
// WithURL set baseUrl for communicating with ff server
1825
func WithURL(url string) ConfigOption {
1926
return func(config *config) {

0 commit comments

Comments
 (0)