Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
eae1b57
feat: circuit breakers
SkArchon Jun 16, 2025
0f8e6cd
feat: circuit breakers
SkArchon Jun 17, 2025
e6bd119
fix: tests
SkArchon Jun 17, 2025
75af19f
fix: changes
SkArchon Jun 17, 2025
8c3fb84
fix: circuit breaker
SkArchon Jun 17, 2025
d1288b2
fix: circuit breaker
SkArchon Jun 17, 2025
3a7317a
fix: cleanup mod
SkArchon Jun 17, 2025
6c1a657
fix: dependencies
SkArchon Jun 17, 2025
6a85b7a
fix: revert testenv
SkArchon Jun 17, 2025
213ef83
fix: linting
SkArchon Jun 17, 2025
6a9449d
fix: reset defaults
SkArchon Jun 17, 2025
eb41fff
fix: linter changes
SkArchon Jun 17, 2025
6ecb667
fix: added prometheus tests
SkArchon Jun 17, 2025
b18751d
fix: refactoring
SkArchon Jun 17, 2025
c5640d2
chore: temporary skip
SkArchon Jun 18, 2025
59905c5
chore: temp skip
SkArchon Jun 18, 2025
49e0cf2
chore: temp skip
SkArchon Jun 18, 2025
64dafb2
fix: temp skips
SkArchon Jun 18, 2025
3810736
fix: add enable
SkArchon Jun 18, 2025
981bfe0
fix: review comments
SkArchon Jun 18, 2025
1da66af
fix: update go.mod
SkArchon Jun 18, 2025
d0ff492
fix: tests
SkArchon Jun 20, 2025
5851867
fix: review comments
SkArchon Jun 21, 2025
fadc186
fix: review comments
SkArchon Jun 30, 2025
c4eefb6
fix: review comments
SkArchon Jun 30, 2025
e5ae625
fix: review comments
SkArchon Jun 30, 2025
6892dc5
fix: review comments
SkArchon Jun 30, 2025
4d53170
Merge remote-tracking branch 'origin/main' into milinda/eng-7100-simp…
SkArchon Jun 30, 2025
070875c
fix: review comments
SkArchon Jun 30, 2025
bd82262
fix: typo comment
SkArchon Jun 30, 2025
b2e966f
Merge branch 'main' into milinda/eng-7100-simple-circuit-breaker-for-…
StarpTech Jul 1, 2025
df2da77
fix: reflect optional
SkArchon Jul 1, 2025
0dc59d8
fix: review comments
SkArchon Jul 1, 2025
590af7b
fix: review comments
SkArchon Jul 1, 2025
7006d26
fix: refactoring
SkArchon Jul 1, 2025
b0280f7
fix: added context package
SkArchon Jul 1, 2025
6d32f83
fix: review comments
SkArchon Jul 1, 2025
44747e4
fix: subgraph name
SkArchon Jul 1, 2025
841e48e
fix: tests
SkArchon Jul 1, 2025
25e8ee0
fix: configuration
SkArchon Jul 1, 2025
9a2f4ec
fix: tests
SkArchon Jul 1, 2025
fa3ad6e
fix: add lock
SkArchon Jul 1, 2025
4f5349d
fix: review comments
SkArchon Jul 4, 2025
e467a2d
fix: updates
SkArchon Jul 6, 2025
fb990ca
Merge remote-tracking branch 'origin/main' into milinda/eng-7100-simp…
SkArchon Jul 6, 2025
f1ad2b5
fix: tests
SkArchon Jul 6, 2025
9d9d193
fix: tests
SkArchon Jul 6, 2025
ea9f922
fix: linter
SkArchon Jul 6, 2025
351a65c
fix: update tests
SkArchon Jul 6, 2025
da3200f
fix: refactoring
SkArchon Jul 6, 2025
b3e972f
fix: tests
SkArchon Jul 7, 2025
43e1292
fix: enable cbs for all tests
SkArchon Jul 7, 2025
737eb02
fix: set the concurrent max requests
SkArchon Jul 7, 2025
2410e15
fix: update configurations
SkArchon Jul 7, 2025
8082187
fix: metric updates
SkArchon Jul 7, 2025
326a2c2
fix: tests
SkArchon Jul 7, 2025
ffa5d4f
fix: circuit breaker
SkArchon Jul 7, 2025
004983d
fix: revert commit
SkArchon Jul 7, 2025
08b8624
fix: revert testenv
SkArchon Jul 7, 2025
e0a4af0
fix: revert testenv
SkArchon Jul 7, 2025
c646ca4
fix: revert
SkArchon Jul 7, 2025
fe51c0e
fix: updates
SkArchon Jul 7, 2025
cef2aba
fix: enable
SkArchon Jul 7, 2025
003aedf
fix: comments
SkArchon Jul 7, 2025
5145c35
fix: comments
SkArchon Jul 7, 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
1,318 changes: 1,318 additions & 0 deletions router-tests/circuit_breaker_test.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions router-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
github.com/bufbuild/protocompile v0.14.1 // indirect
github.com/caarlos0/env/v11 v11.3.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cep21/circuit/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cilium/ebpf v0.16.0 // indirect
github.com/coder/websocket v1.8.13 // indirect
Expand Down
2 changes: 2 additions & 0 deletions router-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5m
github.com/caarlos0/env/v11 v11.3.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cep21/circuit/v4 v4.0.0 h1:g1AzMmRLuwCst0eccy1nGsD/CL2XKbDnaPUHVHDvVmI=
github.com/cep21/circuit/v4 v4.0.0/go.mod h1:Bb1fHpuiRu+AIgKf7DTM1c5U94qTZtKouKcDwtZYCXk=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cilium/ebpf v0.16.0 h1:+BiEnHL6Z7lXnlGUsXQPPAE7+kenAd4ES8MQ5min0Ok=
Expand Down
23 changes: 14 additions & 9 deletions router-tests/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,17 @@ type EngineStatOptions struct {
}

type MetricOptions struct {
MetricExclusions MetricExclusions
EnableRuntimeMetrics bool
EnableOTLPRouterCache bool
EnablePrometheusRouterCache bool
OTLPEngineStatsOptions EngineStatOptions
PrometheusEngineStatsOptions EngineStatOptions
PrometheusSchemaFieldUsage PrometheusSchemaFieldUsage
EnableOTLPConnectionMetrics bool
EnablePrometheusConnectionMetrics bool
MetricExclusions MetricExclusions
EnableRuntimeMetrics bool
EnableOTLPRouterCache bool
EnablePrometheusRouterCache bool
OTLPEngineStatsOptions EngineStatOptions
PrometheusEngineStatsOptions EngineStatOptions
PrometheusSchemaFieldUsage PrometheusSchemaFieldUsage
EnableOTLPConnectionMetrics bool
EnableOTLPCircuitBreakerMetrics bool
EnablePrometheusConnectionMetrics bool
EnablePrometheusCircuitBreakerMetrics bool
}

type PrometheusSchemaFieldUsage struct {
Expand Down Expand Up @@ -1416,6 +1418,7 @@ func configureRouter(listenerAddr string, testConfig *Config, routerConfig *node
core.WithQueryPlans(true),
core.WithEvents(eventsConfiguration),
}

routerOpts = append(routerOpts, testConfig.RouterOptions...)

if testConfig.RouterConfig != nil {
Expand Down Expand Up @@ -1496,6 +1499,7 @@ func configureRouter(listenerAddr string, testConfig *Config, routerConfig *node
EngineStats: rmetric.EngineStatsConfig{
Subscription: testConfig.MetricOptions.PrometheusEngineStatsOptions.EnableSubscription,
},
CircuitBreaker: testConfig.MetricOptions.EnablePrometheusCircuitBreakerMetrics,
ExcludeMetrics: testConfig.MetricOptions.MetricExclusions.ExcludedPrometheusMetrics,
ExcludeMetricLabels: testConfig.MetricOptions.MetricExclusions.ExcludedPrometheusMetricLabels,
ExcludeScopeInfo: testConfig.MetricOptions.MetricExclusions.ExcludeScopeInfo,
Expand Down Expand Up @@ -1524,6 +1528,7 @@ func configureRouter(listenerAddr string, testConfig *Config, routerConfig *node
EngineStats: config.EngineStats{
Subscriptions: testConfig.MetricOptions.OTLPEngineStatsOptions.EnableSubscription,
},
CircuitBreaker: testConfig.MetricOptions.EnableOTLPCircuitBreakerMetrics,
ExcludeMetrics: testConfig.MetricOptions.MetricExclusions.ExcludedOTLPMetrics,
ExcludeMetricLabels: testConfig.MetricOptions.MetricExclusions.ExcludedOTLPMetricLabels,
},
Expand Down
19 changes: 7 additions & 12 deletions router/core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"context"
"errors"
rcontext "github.com/wundergraph/cosmo/router/internal/context"
"net/http"
"net/url"
"strconv"
Expand All @@ -27,14 +28,6 @@ import (
ctrace "github.com/wundergraph/cosmo/router/pkg/trace"
)

type contextKey int

const (
requestContextKey contextKey = iota
subgraphResolverContextKey
engineLoaderHooksContextKey
)

var _ RequestContext = (*requestContext)(nil)

type Subgraph struct {
Expand Down Expand Up @@ -288,14 +281,14 @@ func (c *requestContext) Request() *http.Request {
}

func withRequestContext(ctx context.Context, operation *requestContext) context.Context {
return context.WithValue(ctx, requestContextKey, operation)
return context.WithValue(ctx, rcontext.RequestContextKey, operation)
}

func getRequestContext(ctx context.Context) *requestContext {
if ctx == nil {
return nil
}
op := ctx.Value(requestContextKey)
op := ctx.Value(rcontext.RequestContextKey)
if op == nil {
return nil
}
Expand Down Expand Up @@ -664,6 +657,8 @@ func NewSubgraphResolver(subgraphs []Subgraph) *SubgraphResolver {
Url: subgraphs[i].Url,
UrlString: subgraphs[i].UrlString,
}
// TODO: In case there are multiple subgraphs with the same URL, the previous
// one will be overwritten. To investigate if this causes an issue.
if sg.UrlString != "" {
resolver.subgraphsByURL[sg.UrlString] = &sg
}
Expand Down Expand Up @@ -691,11 +686,11 @@ func (s *SubgraphResolver) BySubgraphURL(u string) *Subgraph {
}

func withSubgraphResolver(ctx context.Context, resolver *SubgraphResolver) context.Context {
return context.WithValue(ctx, subgraphResolverContextKey, resolver)
return context.WithValue(ctx, rcontext.SubgraphResolverContextKey, resolver)
}

func subgraphResolverFromContext(ctx context.Context) *SubgraphResolver {
resolver, _ := ctx.Value(subgraphResolverContextKey).(*SubgraphResolver)
resolver, _ := ctx.Value(rcontext.SubgraphResolverContextKey).(*SubgraphResolver)
return resolver
}

Expand Down
8 changes: 4 additions & 4 deletions router/core/engine_loader_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"errors"
"fmt"
rcontext "github.com/wundergraph/cosmo/router/internal/context"
"github.com/wundergraph/cosmo/router/internal/requestlogger"
"github.com/wundergraph/cosmo/router/internal/traceclient"
"github.com/wundergraph/cosmo/router/internal/unique"
"github.com/wundergraph/cosmo/router/pkg/metric"
rotel "github.com/wundergraph/cosmo/router/pkg/otel"
Expand Down Expand Up @@ -86,7 +86,7 @@ func (f *engineLoaderHooks) OnLoad(ctx context.Context, ds resolve.DataSourceInf

start := time.Now()

ctx = context.WithValue(ctx, traceclient.CurrentSubgraphContextKey{}, ds.Name)
ctx = context.WithValue(ctx, rcontext.CurrentSubgraphContextKey{}, ds.Name)

reqContext := getRequestContext(ctx)
if reqContext == nil {
Expand All @@ -100,7 +100,7 @@ func (f *engineLoaderHooks) OnLoad(ctx context.Context, ds resolve.DataSourceInf
}...),
)

return context.WithValue(ctx, engineLoaderHooksContextKey, &engineLoaderHooksRequestContext{
return context.WithValue(ctx, rcontext.EngineLoaderHooksContextKey, &engineLoaderHooksRequestContext{
startTime: start,
})
}
Expand All @@ -117,7 +117,7 @@ func (f *engineLoaderHooks) OnFinished(ctx context.Context, ds resolve.DataSourc
return
}

hookCtx, ok := ctx.Value(engineLoaderHooksContextKey).(*engineLoaderHooksRequestContext)
hookCtx, ok := ctx.Value(rcontext.EngineLoaderHooksContextKey).(*engineLoaderHooksRequestContext)
if !ok {
return
}
Expand Down
Loading
Loading