Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ffm 3677 #96

Merged
merged 4 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -101,6 +102,7 @@ func NewCfClient(sdkKey string, options ...ConfigOption) (*CfClient, error) {
}

func (c *CfClient) start() {

ctx, cancel := context.WithCancel(context.Background())
go func() {
<-c.stop
Expand Down Expand Up @@ -389,7 +391,15 @@ func (c *CfClient) retrieveSegments(ctx context.Context) error {
}

func (c *CfClient) setAnalyticsServiceClient(ctx context.Context) {

<-c.authenticated
c.mux.RLock()
defer c.mux.RUnlock()
if !c.config.enableAnalytics {
log.Println(time.Now().Format("2006-01-02 15:04:05") + " Posting analytics data disabled.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for consistency we should use the c.config.Logger that gets used elsewhere in this client code for here and the line below. I think it logs out timestamp info for us as well so all you'll need to do is include the message https://github.com/harness/ff-golang-server-sdk/pull/96/files#diff-bd3a55a72186f59e2e63efb4951573b2f9e4a7cc98086e922b0859f8ccc1dd09L387

return
}
log.Println(time.Now().Format("2006-01-02 15:04:05") + " Posting analytics data enabled.")
c.analyticsService.Start(ctx, &c.metricsapi, c.environmentID)
}

Expand Down
20 changes: 11 additions & 9 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type config struct {
enableStore bool
target evaluation.Target
eventStreamListener stream.EventStreamListener
enableAnalytics bool
}

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

return &config{
url: "https://config.ff.harness.io/api/1.0",
eventsURL: "https://events.ff.harness.io/api/1.0",
pullInterval: 60,
Cache: defaultCache,
Store: defaultStore,
Logger: defaultLogger,
httpClient: retryClient.StandardClient(),
enableStream: true,
enableStore: true,
url: "https://config.ff.harness.io/api/1.0",
eventsURL: "https://events.ff.harness.io/api/1.0",
pullInterval: 60,
Cache: defaultCache,
Store: defaultStore,
Logger: defaultLogger,
httpClient: retryClient.StandardClient(),
enableStream: true,
enableStore: true,
enableAnalytics: true,
}
}
7 changes: 7 additions & 0 deletions client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import (
// using options pattern
type ConfigOption func(config *config)

// WithAnalyticsEnabled en/disable cache and analytics data being sent.
func WithAnalyticsEnabled(val bool) ConfigOption {
return func(config *config) {
config.enableAnalytics = val
}
}

// WithURL set baseUrl for communicating with ff server
func WithURL(url string) ConfigOption {
return func(config *config) {
Expand Down