Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
57b3128
Use structs instead of pointers for evaluation context
rolodato Mar 22, 2025
78027a2
v5
rolodato Mar 22, 2025
0fbb714
Revert WithDefaultFlagHandler
rolodato Mar 22, 2025
1e23a8c
Revert change to NewTransientEvaluationContext
rolodato Mar 22, 2025
dd7e12a
Remove atomics + more improvements
rolodato Mar 22, 2025
f7bb917
flush
rolodato Mar 22, 2025
e79acfd
use logger group
rolodato Mar 22, 2025
5c61285
store environment + overrides together without atomics
rolodato Mar 22, 2025
b65322a
restore TraitModel
rolodato Mar 22, 2025
7de1240
default logger
rolodato Mar 22, 2025
0a6c698
MustNewClient
rolodato Mar 22, 2025
527d1b7
refactor
rolodato Mar 22, 2025
e101db8
undeprecate
rolodato Mar 22, 2025
bcc3e1c
log
rolodato Mar 23, 2025
cf672ff
more logs
rolodato Mar 23, 2025
0521abe
logs
rolodato Mar 23, 2025
1966d3c
debug logs in tests
rolodato Mar 23, 2025
d0e37a1
more logs + pass EnvironmentContext structs and not pointers
rolodato Mar 23, 2025
813dd1b
remove unused
rolodato Mar 23, 2025
ba818e3
ci disable cache
rolodato Mar 23, 2025
c79c51e
disable actions/setup-go cache
rolodato Mar 23, 2025
f40dfb4
remove environment from EC
rolodato Mar 23, 2025
f3a98df
lint
rolodato Mar 23, 2025
8edb88d
misc
rolodato Mar 23, 2025
28bdcd9
simpler offline mode
rolodato Mar 23, 2025
bf31c3e
simplify error types
rolodato Mar 23, 2025
c8a6d18
refactor
rolodato Mar 23, 2025
1e79009
Docs
rolodato Mar 24, 2025
21ec13f
revert to pointer EnvironmentModel
rolodato Mar 24, 2025
eae8a45
goimports
rolodato Mar 24, 2025
4704300
remove codegen
rolodato Mar 24, 2025
f3f75d0
goimports
rolodato Mar 24, 2025
02e81f9
fix GetIdentityOverride data race
rolodato Mar 24, 2025
588a5fb
restore ci changes
rolodato Mar 24, 2025
d5bfe23
re-add analytics
rolodato Mar 25, 2025
7d61b9d
feedback
rolodato Mar 25, 2025
7dcb4a0
more feedback
rolodato Mar 25, 2025
7f3bd06
feedback
rolodato Mar 26, 2025
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
3 changes: 0 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ jobs:
with:
submodules: recursive

- name: Build evaluation context struct
run: make generate-evaluation-context

- name: Get dependencies
run: |
go get -v -t -d ./...
Expand Down
14 changes: 0 additions & 14 deletions Makefile

This file was deleted.

26 changes: 15 additions & 11 deletions analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package flagsmith
import (
"context"
"fmt"
"log/slog"
"net/http"
"sync"
"time"

Expand All @@ -20,10 +22,10 @@ type AnalyticsProcessor struct {
client *resty.Client
store *analyticDataStore
endpoint string
log Logger
log *slog.Logger
}

func NewAnalyticsProcessor(ctx context.Context, client *resty.Client, baseURL string, timerInMilli *int, log Logger) *AnalyticsProcessor {
func NewAnalyticsProcessor(ctx context.Context, client *resty.Client, baseURL string, timerInMilli *int, log *slog.Logger) *AnalyticsProcessor {
data := make(map[string]int)
dataStore := analyticDataStore{data: data}
tickerInterval := AnalyticsTimerInMilli
Expand All @@ -45,32 +47,34 @@ func (a *AnalyticsProcessor) start(ctx context.Context, tickerInterval int) {
for {
select {
case <-ticker.C:
if err := a.Flush(ctx); err != nil {
a.log.Warnf("Failed to send analytics data: %s", err)
if resp, err := a.Flush(ctx); err != nil {
a.log.Warn("failed to send analytics data",
"error", err,
slog.Int("status", resp.StatusCode),
slog.String("url", resp.Request.URL.String()),
)
}
case <-ctx.Done():
return
}
}
}

func (a *AnalyticsProcessor) Flush(ctx context.Context) error {
func (a *AnalyticsProcessor) Flush(ctx context.Context) (*http.Response, error) {
a.store.mu.Lock()
defer a.store.mu.Unlock()
if len(a.store.data) == 0 {
return nil
return nil, nil
}
resp, err := a.client.R().SetContext(ctx).SetBody(a.store.data).Post(a.endpoint)
if err != nil {
return err
return nil, err
}
if !resp.IsSuccess() {
return fmt.Errorf("received unexpected response from server: %s", resp.Status())
return resp.RawResponse, fmt.Errorf("AnalyticsProcessor.Flush received error response %d %s", resp.StatusCode(), resp.Status())
}

// Clear the cache in case of success.
a.store.data = make(map[string]int)
return nil
return resp.RawResponse, nil
}

func (a *AnalyticsProcessor) TrackFeature(featureName string) {
Expand Down
4 changes: 2 additions & 2 deletions analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flagsmith
import (
"context"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"sync"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/go-resty/resty/v2"
)

const BaseURL = "http://localhost:8000/api/v1/"
const EnvironmentAPIKey = "test_key"

func TestAnalytics(t *testing.T) {
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestAnalytics(t *testing.T) {
client.SetHeader("X-Environment-Key", EnvironmentAPIKey)

// Now let's create the processor
processor := NewAnalyticsProcessor(context.Background(), client, server.URL+"/api/v1/", &analyticsTimer, createLogger())
processor := NewAnalyticsProcessor(context.Background(), client, server.URL+"/api/v1/", &analyticsTimer, slog.Default())

// and, track some features
processor.TrackFeature("feature_1")
Expand Down
Loading
Loading