Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,29 @@ clean:
$(MAKE) -C openfeature-provider/go clean
$(MAKE) -C openfeature-provider/ruby clean

.PHONY: js-build
js-build:
$(MAKE) -C openfeature-provider/js build

.PHONY: go-bench js-bench
go-bench:
@status=0; \
docker compose up --build \
--abort-on-container-exit \
--exit-code-from go-bench \
--attach go-bench --attach mock-go \
go-bench mock-go || status=$$?; \
docker compose down --remove-orphans --volumes; \
exit $$status

js-bench: js-build
@status=0; \
docker compose up --build \
--abort-on-container-exit \
--exit-code-from js-bench \
--attach js-bench --attach mock-js \
js-bench mock-js || status=$$?; \
docker compose down --remove-orphans --volumes; \
exit $$status

.DEFAULT_GOAL := all
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ make cloudflare

You can then integrate with Wrangler using `confidence-cloudflare-resolver/wrangler.toml`.

## Benchmarks (WIP)

Small local benchmarks exist for Go and Node.js to validate end-to-end wiring. They are a work-in-progress and do not produce meaningful or representative performance numbers yet.

Run with Docker (streams all logs, cleans up containers afterward):

```bash
# Go benchmark
make go-bench

# Node.js benchmark
make js-bench
```

Notes:
- Each target starts a dedicated mock server container and a one-shot bench container, then tears everything down.
- Use `docker compose up ... go-bench` or `... js-bench` to run them individually without Make.

## License

See `LICENSE` for details.
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
services:
mock-go:
build:
context: .
dockerfile: mock-support-server/Dockerfile
environment:
- PORT=8081
- RESOLVER_STATE_PB=/data/resolver_state_current.pb
- SIGNED_STATE_URI=http://mock-go:8081/state

go-bench:
build:
context: .
dockerfile: openfeature-provider/go/bench/Dockerfile
depends_on:
- mock-go
command: ["-mock-grpc", "mock-go:8081", "-threads", "1", "-flag", "tutorial-feature", "-client-secret", "mkjJruAATQWjeY7foFIWfVAcBWnci2YF"]

mock-js:
build:
context: .
dockerfile: mock-support-server/Dockerfile
environment:
- PORT=8081
- RESOLVER_STATE_PB=/data/resolver_state_current.pb
- SIGNED_STATE_URI=https://storage.googleapis.com/state

js-bench:
build:
context: .
dockerfile: openfeature-provider/js/bench/Dockerfile
depends_on:
- mock-js
command: ["-mock-http", "http://mock-js:8081", "-flag", "tutorial-feature", "-client-secret", "mkjJruAATQWjeY7foFIWfVAcBWnci2YF"]


27 changes: 27 additions & 0 deletions openfeature-provider/go/bench/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM golang:1.24-alpine3.22 AS build
WORKDIR /src

# Prepare module files in correct relative locations to satisfy the replace directive
COPY openfeature-provider/go/bench/go.mod openfeature-provider/go/bench/go.sum ./openfeature-provider/go/bench/
COPY openfeature-provider/go/confidence/go.mod openfeature-provider/go/confidence/go.sum ./openfeature-provider/go/confidence/

# Prime module cache
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download -C ./openfeature-provider/go/bench

# Copy sources (bench + local provider, including embedded wasm)
COPY openfeature-provider/go/confidence ./openfeature-provider/go/confidence
COPY openfeature-provider/go/bench ./openfeature-provider/go/bench

# Build static bench binary
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 \
go build -C ./openfeature-provider/go/bench -o /out/bench .

FROM alpine:3.22
RUN apk add --no-cache ca-certificates
COPY --from=build /out/bench /bench
ENTRYPOINT ["/bench"]


25 changes: 25 additions & 0 deletions openfeature-provider/go/bench/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module github.com/spotify/confidence-resolver-rust/openfeature-provider/go/bench

go 1.24.0

require (
github.com/open-feature/go-sdk v1.16.0
github.com/spotify/confidence-resolver-rust/openfeature-provider/go/confidence v0.0.0
google.golang.org/grpc v1.75.1
)

require (
github.com/go-logr/logr v1.4.3 // indirect
github.com/spotify/confidence-resolver/openfeature-provider/go/confidence v0.1.0 // indirect
github.com/tetratelabs/wazero v1.9.0 // indirect
go.uber.org/mock v0.6.0 // indirect
golang.org/x/net v0.44.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/text v0.29.0 // indirect
google.golang.org/genproto v0.0.0-20251029180050-ab9386a59fda // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20251029180050-ab9386a59fda // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251014184007-4626949a642f // indirect
google.golang.org/protobuf v1.36.10 // indirect
)

replace github.com/spotify/confidence-resolver-rust/openfeature-provider/go/confidence => ../confidence
48 changes: 48 additions & 0 deletions openfeature-provider/go/bench/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/open-feature/go-sdk v1.16.0 h1:5NCHYv5slvNBIZhYXAzAufo0OI59OACZ5tczVqSE+Tg=
github.com/open-feature/go-sdk v1.16.0/go.mod h1:EIF40QcoYT1VbQkMPy2ZJH4kvZeY+qGUXAorzSWgKSo=
github.com/spotify/confidence-resolver/openfeature-provider/go/confidence v0.1.0 h1:U5iXqBFZ/9mXQ0wFEpOetiwJKVCcLL5oAtN5xnFC4+Y=
github.com/spotify/confidence-resolver/openfeature-provider/go/confidence v0.1.0/go.mod h1:NkvUpOOTuAlmsfQ3WfqYkIVL+G3pVds4HuwXhbupnLY=
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE=
go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E=
go.opentelemetry.io/otel/sdk v1.37.0 h1:ItB0QUqnjesGRvNcmAcU0LyvkVyGJ2xftD29bWdDvKI=
go.opentelemetry.io/otel/sdk v1.37.0/go.mod h1:VredYzxUvuo2q3WRcDnKDjbdvmO0sCzOvVAiY+yUkAg=
go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFhbjxHHspCPc=
go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps=
go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
google.golang.org/genproto v0.0.0-20251029180050-ab9386a59fda h1:fQ3VVQ11pb84nu0o/8wD6oZq13Q6+HK30P+9GSRlrqk=
google.golang.org/genproto v0.0.0-20251029180050-ab9386a59fda/go.mod h1:1Ic78BnpzY8OaTCmzxJDP4qC9INZPbGZl+54RKjtyeI=
google.golang.org/genproto/googleapis/api v0.0.0-20251029180050-ab9386a59fda h1:+2XxjfsAu6vqFxwGBRcHiMaDCuZiqXGDUDVWVtrFAnE=
google.golang.org/genproto/googleapis/api v0.0.0-20251029180050-ab9386a59fda/go.mod h1:fDMmzKV90WSg1NbozdqrE64fkuTv6mlq2zxo9ad+3yo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20251014184007-4626949a642f h1:1FTH6cpXFsENbPR5Bu8NQddPSaUUE6NA2XdZdDSAJK4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20251014184007-4626949a642f/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
166 changes: 166 additions & 0 deletions openfeature-provider/go/bench/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package main

import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"runtime"
"sync"
"sync/atomic"
"syscall"
"time"

openfeature "github.com/open-feature/go-sdk/openfeature"
confidence "github.com/spotify/confidence-resolver-rust/openfeature-provider/go/confidence"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

type stats struct {
completed uint64
errors uint64
}

func main() {
var (
mockGRPCAddr string
durationSeconds int
warmupSeconds int
threads int
gomaxprocs int
flagKey string
clientSecret string
apiClientID string
apiClientSecret string
pollInterval int
)

flag.StringVar(&mockGRPCAddr, "mock-grpc", "localhost:8081", "mock support server gRPC address host:port")
flag.IntVar(&durationSeconds, "duration", 30, "benchmark duration in seconds (excludes warmup)")
flag.IntVar(&warmupSeconds, "warmup", 5, "warmup duration in seconds before measurement")
flag.IntVar(&threads, "threads", runtime.NumCPU(), "number of concurrent worker goroutines")
flag.IntVar(&gomaxprocs, "gomaxprocs", 0, "set GOMAXPROCS (0=leave default)")
flag.StringVar(&flagKey, "flag", "example-flag", "flag key (without 'flags/' prefix)")
flag.StringVar(&clientSecret, "client-secret", "secret", "client secret for request signing")
flag.StringVar(&apiClientID, "api-client-id", "mock-client", "API client ID for token requests")
flag.StringVar(&apiClientSecret, "api-client-secret", "mock-secret", "API client secret for token requests")
flag.IntVar(&pollInterval, "poll-interval", 10, "resolver state/log poll interval in seconds (env override)")
flag.Parse()

if gomaxprocs > 0 {
runtime.GOMAXPROCS(gomaxprocs)
}
if threads < 1 {
threads = 1
}
if warmupSeconds < 0 {
warmupSeconds = 0
}
if durationSeconds < 1 {
durationSeconds = 1
}

// Ensure state/log polling is exercised during the run
// os.Setenv("CONFIDENCE_RESOLVER_POLL_INTERVAL_SECONDS", fmt.Sprintf("%d", pollInterval))

ctx := context.Background()

// Build a provider wired to the mock server via ConnFactory. The factory ignores the
// target passed by the provider and always dials the mock address with insecure creds,
// while preserving any supplied interceptors (e.g., JWT auth).
connFactory := func(ctx context.Context, _ string, defaultOpts []grpc.DialOption) (grpc.ClientConnInterface, error) {
// Keep the default options (notably auth interceptors), but ensure we use insecure transport
// to match the mock server and override any TLS transport credentials.
opts := append([]grpc.DialOption{}, defaultOpts...)
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
return grpc.NewClient(mockGRPCAddr, opts...)
}

provider, err := confidence.NewProvider(ctx, confidence.ProviderConfig{
APIClientID: apiClientID,
APIClientSecret: apiClientSecret,
ClientSecret: clientSecret,
ConnFactory: connFactory,
})
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create provider: %v\n", err)
os.Exit(1)
}

// Minimal evaluation context; you can extend with attributes to exercise targeting
evalCtx := openfeature.FlattenedContext{"targetingKey": "tutorial_visitor", "visitor_id": "tutorial_visitor"}

// Prepare cancellation on SIGINT/SIGTERM
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

// Warmup (abort on first error)
if warmupSeconds > 0 {
warmupCtx, cancel := context.WithTimeout(ctx, time.Duration(warmupSeconds)*time.Second)
var warm stats
runWorkers(warmupCtx, provider, flagKey, evalCtx, threads, &warm, cancel, true)
cancel()
if atomic.LoadUint64(&warm.errors) > 0 {
fmt.Fprintf(os.Stderr, "aborting: error during warmup\n")
os.Exit(1)
}
}

// Measurement
measureCtx, cancelMeasure := context.WithTimeout(ctx, time.Duration(durationSeconds)*time.Second)
defer cancelMeasure()

var s stats
// Abort early on signal
go func() {
select {
case <-sigCh:
cancelMeasure()
case <-measureCtx.Done():
}
}()

start := time.Now()
runWorkers(measureCtx, provider, flagKey, evalCtx, threads, &s, cancelMeasure, true)
elapsed := time.Since(start)
provider.Shutdown()

completed := atomic.LoadUint64(&s.completed)
errs := atomic.LoadUint64(&s.errors)
qps := float64(completed) / elapsed.Seconds()

fmt.Printf("flag=%s threads=%d duration=%s ops=%d errors=%d throughput=%.0f ops/s\n",
flagKey, threads, elapsed.Truncate(time.Millisecond), completed, errs, qps)
}

func runWorkers(ctx context.Context, provider *confidence.LocalResolverProvider, flagKey string, evalCtx openfeature.FlattenedContext, threads int, s *stats, cancel context.CancelFunc, abortOnError bool) {
wg := sync.WaitGroup{}
wg.Add(threads)
for i := 0; i < threads; i++ {
go func() {
defer wg.Done()
for {
select {
case <-ctx.Done():
return
default:
res := provider.ObjectEvaluation(context.Background(), flagKey, nil, evalCtx)
if s != nil {
atomic.AddUint64(&s.completed, 1)
// fmt.Printf("reason %s", res.Reason)
if res.Reason == openfeature.ErrorReason {
atomic.AddUint64(&s.errors, 1)
if abortOnError && cancel != nil {
cancel()
return
}
}
}
}
}
}()
}
wg.Wait()
}
19 changes: 19 additions & 0 deletions openfeature-provider/js/bench/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:20-alpine3.22

WORKDIR /app

# Install runtime deps
COPY openfeature-provider/js/bench/package.json ./package.json
RUN npm install --omit=dev

# Copy provider dist (JS + WASM)
COPY openfeature-provider/js/dist ./dist

# Copy entire bench directory so relative imports (../dist) remain valid
COPY openfeature-provider/js/bench ./bench

ENV NODE_ENV=production

ENTRYPOINT ["node", "bench/bench.mjs"]


Loading
Loading