Skip to content

Commit

Permalink
refactor: introduce isyncstore interface (#660)
Browse files Browse the repository at this point in the history
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->

## This PR
<!-- add the description of the PR here -->

- decouples the sync store from sync server startup, allowing for
alternative sync store implementations to be introduced

### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->

### Notes
<!-- any additional notes for this PR -->

### Follow-up Tasks
<!-- anything that is related to this PR but not done here should be
noted under this section -->
<!-- if there is a need for a new issue, please link it here -->

### How to test
<!-- if applicable, add testing instructions under this section -->

---------

Signed-off-by: James Milligan <[email protected]>
  • Loading branch information
james-milligan authored May 17, 2023
1 parent 93e708e commit c0e2fa0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/pkg/service/sync/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type handler struct {
rpc.UnimplementedFlagSyncServiceServer
syncStore *syncStore.SyncStore
syncStore syncStore.ISyncStore
logger *logger.Logger
}

Expand Down
5 changes: 2 additions & 3 deletions core/pkg/service/sync/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ type Server struct {
config iservice.Configuration
}

func NewServer(ctx context.Context, logger *logger.Logger) *Server {
syncStore := syncStore.NewSyncStore(ctx, logger)
func NewServer(logger *logger.Logger, store syncStore.ISyncStore) *Server {
return &Server{
handler: &handler{
logger: logger,
syncStore: syncStore,
syncStore: store,
},
Logger: logger,
}
Expand Down
26 changes: 26 additions & 0 deletions core/pkg/sync-store/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package store

import (
"context"

isync "github.com/open-feature/flagd/core/pkg/sync"
)

// ISyncStore defines the interface for the sync store
type ISyncStore interface {
FetchAllFlags(
ctx context.Context,
key interface{},
target string,
) (isync.DataSync, error)
RegisterSubscription(
ctx context.Context,
target string,
key interface{},
dataSync chan isync.DataSync,
errChan chan error,
)

// metrics hooks
GetActiveSubscriptionsInt64() int64
}
4 changes: 3 additions & 1 deletion flagd-proxy/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/open-feature/flagd/core/pkg/logger"
"github.com/open-feature/flagd/core/pkg/service"
syncServer "github.com/open-feature/flagd/core/pkg/service/sync"
syncStore "github.com/open-feature/flagd/core/pkg/sync-store"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -61,7 +62,8 @@ var startCmd = &cobra.Command{

ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)

s := syncServer.NewServer(ctx, logger)
syncStore := syncStore.NewSyncStore(ctx, logger)
s := syncServer.NewServer(logger, syncStore)
cfg := service.Configuration{
ReadinessProbe: func() bool { return true },
Port: viper.GetUint16(portFlagName),
Expand Down

1 comment on commit c0e2fa0

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Go Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: c0e2fa0 Previous: 93e708e Ratio
BenchmarkResolveBooleanValue/test_staticBoolFlag 3116 ns/op 304 B/op 7 allocs/op 1557 ns/op 304 B/op 7 allocs/op 2.00
BenchmarkResolveBooleanValue/test_targetingBoolFlag 19718 ns/op 5025 B/op 83 allocs/op 12312 ns/op 5025 B/op 83 allocs/op 1.60
BenchmarkResolveBooleanValue/test_staticObjectFlag 2272 ns/op 304 B/op 7 allocs/op 1452 ns/op 304 B/op 7 allocs/op 1.56
BenchmarkResolveBooleanValue/test_missingFlag 2483 ns/op 368 B/op 9 allocs/op 1618 ns/op 368 B/op 9 allocs/op 1.53
BenchmarkResolveBooleanValue/test_disabledFlag 2451 ns/op 368 B/op 9 allocs/op 1625 ns/op 368 B/op 9 allocs/op 1.51
BenchmarkResolveStringValue/test_staticStringFlag 2383 ns/op 336 B/op 9 allocs/op 1569 ns/op 336 B/op 9 allocs/op 1.52
BenchmarkResolveStringValue/test_targetingStringFlag 20343 ns/op 5049 B/op 85 allocs/op 12276 ns/op 5049 B/op 85 allocs/op 1.66
BenchmarkResolveStringValue/test_staticObjectFlag 2206 ns/op 304 B/op 7 allocs/op 1448 ns/op 304 B/op 7 allocs/op 1.52
BenchmarkResolveStringValue/test_missingFlag 2401 ns/op 368 B/op 9 allocs/op 1601 ns/op 368 B/op 9 allocs/op 1.50
BenchmarkResolveStringValue/test_disabledFlag 2383 ns/op 368 B/op 9 allocs/op 1599 ns/op 368 B/op 9 allocs/op 1.49
BenchmarkResolveFloatValue/test:_staticFloatFlag 2471 ns/op 320 B/op 9 allocs/op 1540 ns/op 320 B/op 9 allocs/op 1.60
BenchmarkResolveFloatValue/test:_targetingFloatFlag 20376 ns/op 5049 B/op 85 allocs/op 12563 ns/op 5049 B/op 85 allocs/op 1.62
BenchmarkResolveFloatValue/test:_staticObjectFlag 2220 ns/op 304 B/op 7 allocs/op 1453 ns/op 304 B/op 7 allocs/op 1.53
BenchmarkResolveFloatValue/test:_missingFlag 2501 ns/op 368 B/op 9 allocs/op 1605 ns/op 368 B/op 9 allocs/op 1.56
BenchmarkResolveFloatValue/test:_disabledFlag 2445 ns/op 368 B/op 9 allocs/op 1596 ns/op 368 B/op 9 allocs/op 1.53
BenchmarkResolveIntValue/test_staticIntFlag 2353 ns/op 304 B/op 7 allocs/op 1533 ns/op 304 B/op 7 allocs/op 1.53
BenchmarkResolveIntValue/test_targetingNumberFlag 19099 ns/op 5033 B/op 83 allocs/op 11266 ns/op 5033 B/op 83 allocs/op 1.70
BenchmarkResolveIntValue/test_staticObjectFlag 2212 ns/op 304 B/op 7 allocs/op 1437 ns/op 304 B/op 7 allocs/op 1.54
BenchmarkResolveIntValue/test_missingFlag 2400 ns/op 352 B/op 9 allocs/op 1591 ns/op 352 B/op 9 allocs/op 1.51
BenchmarkResolveIntValue/test_disabledFlag 2361 ns/op 368 B/op 9 allocs/op 1596 ns/op 368 B/op 9 allocs/op 1.48
BenchmarkResolveObjectValue/test_staticObjectFlag 7803 ns/op 1600 B/op 35 allocs/op 4979 ns/op 1600 B/op 35 allocs/op 1.57
BenchmarkResolveObjectValue/test_targetingObjectFlag 27597 ns/op 6314 B/op 107 allocs/op 15781 ns/op 6314 B/op 107 allocs/op 1.75
BenchmarkResolveObjectValue/test_staticBoolFlag 2182 ns/op 304 B/op 7 allocs/op 1454 ns/op 304 B/op 7 allocs/op 1.50
BenchmarkResolveObjectValue/test_missingFlag 2426 ns/op 368 B/op 9 allocs/op 1612 ns/op 368 B/op 9 allocs/op 1.50
BenchmarkResolveObjectValue/test_disabledFlag 2431 ns/op 368 B/op 9 allocs/op 1611 ns/op 368 B/op 9 allocs/op 1.51
BenchmarkFlag_Evaluation_ResolveBoolean/happy_path 13982 ns/op 3232 B/op 35 allocs/op 8947 ns/op 3232 B/op 35 allocs/op 1.56
BenchmarkFlag_Evaluation_ResolveString/happy_path 13857 ns/op 3248 B/op 35 allocs/op 9212 ns/op 3248 B/op 35 allocs/op 1.50
BenchmarkFlag_Evaluation_ResolveFloat/happy_path 13820 ns/op 3232 B/op 35 allocs/op 9000 ns/op 3232 B/op 35 allocs/op 1.54
BenchmarkFlag_Evaluation_ResolveInt/happy_path 14415 ns/op 3232 B/op 35 allocs/op 8908 ns/op 3232 B/op 35 allocs/op 1.62
BenchmarkFlag_Evaluation_ResolveObject/happy_path 17731 ns/op 3656 B/op 42 allocs/op 10770 ns/op 3656 B/op 42 allocs/op 1.65

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.