Skip to content

Commit 8c2e47a

Browse files
author
akiraqb
committed
FFM-3677: making posting analytics configurable depending on the boolean passed
1 parent c9a7643 commit 8c2e47a

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

client/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"log"
89
"net/http"
910
"strings"
1011
"sync"
@@ -101,6 +102,7 @@ func NewCfClient(sdkKey string, options ...ConfigOption) (*CfClient, error) {
101102
}
102103

103104
func (c *CfClient) start() {
105+
104106
ctx, cancel := context.WithCancel(context.Background())
105107
go func() {
106108
<-c.stop
@@ -110,6 +112,7 @@ func (c *CfClient) start() {
110112
go c.initAuthentication(ctx)
111113
go c.setAnalyticsServiceClient(ctx)
112114
go c.pullCronJob(ctx)
115+
go c.pullCronJob(ctx)
113116
}
114117

115118
// PostEvaluateProcessor push the data to the analytics service
@@ -389,7 +392,13 @@ func (c *CfClient) retrieveSegments(ctx context.Context) error {
389392
}
390393

391394
func (c *CfClient) setAnalyticsServiceClient(ctx context.Context) {
395+
392396
<-c.authenticated
397+
if !c.config.enableAnalytics {
398+
log.Println(time.Now().Format("2006-01-02 15:04:05") + " Posting analytics data disabled.")
399+
return
400+
}
401+
log.Println(time.Now().Format("2006-01-02 15:04:05") + " Posting analytics data enabled.")
393402
c.analyticsService.Start(ctx, &c.metricsapi, c.environmentID)
394403
}
395404

client/config.go

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

3031
func newDefaultConfig() *config {
3132
defaultLogger, err := logger.NewZapLogger(false)
3233
if err != nil {
3334
log.Printf("Error creating zap logger instance, %v", err)
3435
}
35-
defaultCache, _ := cache.NewLruCache(10000, defaultLogger) // size of cache
36+
defaultCache, _ := cache.NewLruCache(10000, defaultLogger) // size of cache
3637
defaultStore := storage.NewFileStore("defaultProject", storage.GetHarnessDir(), defaultLogger)
3738

3839
retryClient := retryablehttp.NewClient()
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)