Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
6b174de
add config options
ysmolski Jan 22, 2026
25900b9
test how modules are support
ysmolski Jan 23, 2026
c899d24
test flooring of ListSize
ysmolski Jan 23, 2026
85897a0
update with race fix in the engine
ysmolski Jan 26, 2026
db1e637
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Jan 27, 2026
cbac743
bump the engine
ysmolski Jan 27, 2026
551b21d
use released engine
ysmolski Jan 27, 2026
98e96f3
fix the comment in a test
ysmolski Jan 27, 2026
e21a880
fix default config
ysmolski Jan 27, 2026
5783522
return cost struct instead of the plan value
ysmolski Jan 30, 2026
466a3ca
rename config variables
ysmolski Jan 30, 2026
f7eb41b
rename config vars
ysmolski Jan 30, 2026
56d8d35
rename for the engine with actual costs
ysmolski Feb 6, 2026
12c6675
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 9, 2026
b25430c
add rough metrics collection
ysmolski Feb 9, 2026
1e7e63a
remove test
ysmolski Feb 9, 2026
2f2bff7
use latest unreleased engine
ysmolski Feb 9, 2026
4793b16
add more metrics tests
ysmolski Feb 9, 2026
ca852d5
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 9, 2026
1d6fcb3
clarify tests
ysmolski Feb 9, 2026
0ed9f40
require EstimatedListSize and fix MaxEstimatedLimit
ysmolski Feb 16, 2026
c79d56f
add attributes check to metrics test
ysmolski Feb 16, 2026
b164ca8
fix small nits
ysmolski Feb 16, 2026
d6ae666
add checks to a test
ysmolski Feb 16, 2026
61138f2
throw error defensively
ysmolski Feb 16, 2026
de2eca3
calculate delta as estimated - actual
ysmolski Feb 16, 2026
7d922d5
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 16, 2026
02d359c
update gomod
ysmolski Feb 16, 2026
e7e410a
fix config
ysmolski Feb 16, 2026
02982bf
bump engine
ysmolski Feb 16, 2026
5a89487
hide telemetry under the switch
ysmolski Feb 17, 2026
275152a
add dedicated benchmark for the costs analysis
ysmolski Feb 17, 2026
5179643
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 17, 2026
7656c45
bump the engine
ysmolski Feb 17, 2026
af815be
fix configs
ysmolski Feb 17, 2026
751dad2
Merge branch 'main' into yury/eng-8636-router-expose-the-static-cost-…
ysmolski Feb 18, 2026
41a091e
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 19, 2026
aa6ab5e
bump engine to 253
ysmolski Feb 19, 2026
f470888
fix test check and add stack for debugging
ysmolski Feb 20, 2026
e503e8f
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 20, 2026
fe6fd28
Merge branch 'main' into yury/eng-8636-router-expose-the-static-cost-…
ysmolski Feb 20, 2026
3127219
implement interface from composition with configs
ysmolski Feb 23, 2026
ef8fc58
calculate costs only once & expose via headers
ysmolski Feb 23, 2026
19acb89
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 23, 2026
8ad9f94
remove unused var
ysmolski Feb 23, 2026
99edd25
diversify tests a little
ysmolski Feb 24, 2026
3e5e0c5
add directives to the schemas
ysmolski Feb 24, 2026
8dd3980
remove debug statement
ysmolski Feb 24, 2026
2e4eb46
remove delta metrics as redundant
ysmolski Feb 24, 2026
5c23d7e
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 24, 2026
76b1b0b
add special bucket boundaries for cost histograms
ysmolski Feb 25, 2026
df343a2
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 25, 2026
fdad133
tighten the range
ysmolski Feb 25, 2026
e601a8e
port the changes in composition
ysmolski Feb 27, 2026
445f8e5
feat(composition): support @cost and @listSize (#2484)
Aenimus Feb 27, 2026
ca941bf
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Feb 27, 2026
cc2df00
use Cost Control everywhere
ysmolski Feb 27, 2026
5e14201
rename leftovers
ysmolski Feb 27, 2026
e72353a
fix the last old name
ysmolski Feb 27, 2026
d7f4ae1
fix subtle edge cases
ysmolski Feb 27, 2026
be923bb
remove dupl entry
ysmolski Feb 27, 2026
59140e6
preserve requireOneSlicingArgument default (true)
ysmolski Feb 27, 2026
5c9a33b
emit actual-cost metric independently from estimated-cost
ysmolski Feb 27, 2026
878532f
dont ignore err in a test
ysmolski Feb 27, 2026
8084fd6
fix: listSize validation in composition
ysmolski Mar 2, 2026
0bd10e5
do not allow empty listSize on non-list types
ysmolski Mar 2, 2026
ba156cc
fix: reject costs defined on fields of interfaces
ysmolski Mar 2, 2026
c8afa3a
reject empty sizeField on non-list types
ysmolski Mar 2, 2026
1a8061e
tighten tests data
ysmolski Mar 2, 2026
1f8b392
add tests extension type
ysmolski Mar 2, 2026
32cda8c
update index
ysmolski Mar 2, 2026
febebbe
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 2, 2026
b2bf4eb
fix lint issues
ysmolski Mar 2, 2026
18c6b04
continue for wrong entries
ysmolski Mar 2, 2026
583bdb1
update index
ysmolski Mar 2, 2026
2e232d6
add type weight and slicingArguments tests
ysmolski Mar 2, 2026
b8dc37f
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 4, 2026
47df6d6
fix computation on cache hits
ysmolski Mar 9, 2026
1e04d27
add missing `cost_stats` in JSON schema
ysmolski Mar 9, 2026
523d665
be more strict in config validation
ysmolski Mar 9, 2026
5bd57c7
add test to verify both DS are used in Costs calc
ysmolski Mar 9, 2026
62cf79c
make the costHeaderSetter closure to use pw.writer.Header()
ysmolski Mar 9, 2026
a572d9a
remove redundant line
ysmolski Mar 9, 2026
568d06c
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 9, 2026
9ca28e6
make lint happy
ysmolski Mar 9, 2026
6a741bf
comp: test the same field in two different subgraphs
ysmolski Mar 10, 2026
3397ae4
update test configs
ysmolski Mar 10, 2026
1eb75e5
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 10, 2026
a3cf3bc
fixed typing issues
ysmolski Mar 10, 2026
992726b
use switch instead ifs in the handleListSizeDirective
ysmolski Mar 10, 2026
7165fec
update globals
ysmolski Mar 10, 2026
f001bb8
make lint
ysmolski Mar 10, 2026
61c787e
handle no parents case
ysmolski Mar 10, 2026
9077f1a
braces in switch
ysmolski Mar 11, 2026
63ff3e5
update global
ysmolski Mar 11, 2026
7bb3d37
fix bug in tests and add nil check
ysmolski Mar 11, 2026
a4ab87d
add parallel benchmark
ysmolski Mar 11, 2026
528f68d
add tests for negative weights
ysmolski Mar 11, 2026
a875c7d
use records
ysmolski Mar 11, 2026
af61281
handle costs in controlplane
ysmolski Mar 11, 2026
748122c
add else to if
ysmolski Mar 11, 2026
1fc29b8
update global
ysmolski Mar 11, 2026
35c36ad
fix small nits
ysmolski Mar 12, 2026
a87a413
use maps in the Costs type
ysmolski Mar 12, 2026
ef7e973
make argumentWeights as a map
ysmolski Mar 12, 2026
79b37ff
update global
ysmolski Mar 12, 2026
97c8062
make two properties defined always
ysmolski Mar 12, 2026
1c1f262
strict testing messages
ysmolski Mar 12, 2026
66d55fa
update global
ysmolski Mar 12, 2026
f5f57a1
make requireOneSlicingArgument set to true by default
ysmolski Mar 12, 2026
52ba20b
use toStrictEqual in all tests
ysmolski Mar 12, 2026
26297a9
check the argument type for weights on the directives arguments
ysmolski Mar 12, 2026
d78f088
sort the props
ysmolski Mar 12, 2026
884d2fc
remove ternary operator
ysmolski Mar 12, 2026
b8f768e
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 13, 2026
cde508d
fix small things
ysmolski Mar 13, 2026
3218c53
fix lint for shared
ysmolski Mar 13, 2026
33159a5
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 13, 2026
6bd6cb5
bump engine to 264
ysmolski Mar 13, 2026
374f111
fix tests
ysmolski Mar 13, 2026
cc7421a
add docs for sizedFields and enable cost control page
ysmolski Mar 13, 2026
d5e0a30
add tests for sizedFields
ysmolski Mar 16, 2026
1d3dad2
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 16, 2026
c3c6db2
move config validation to the json schema layer
ysmolski Mar 16, 2026
612e9d4
reduce cardinality of histograms
ysmolski Mar 16, 2026
5676a71
test websockets both for queries and subs
ysmolski Mar 16, 2026
4ce7ad0
remove for for old controlplane
ysmolski Mar 16, 2026
a80e85a
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 16, 2026
71398c6
add costs back to controlplane
ysmolski Mar 16, 2026
22eeec2
fix test affected by sizedFields and move costs_test.go
ysmolski Mar 17, 2026
92377ef
forbid listSize.sizedFields on lists returning types
ysmolski Mar 17, 2026
23067e7
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 17, 2026
7b85244
update global
ysmolski Mar 17, 2026
037d6c9
add a deep lists test
ysmolski Mar 17, 2026
a701d0b
pnpm lint
ysmolski Mar 17, 2026
68713ca
Merge branch 'main' of github.com:wundergraph/cosmo into yury/eng-863…
ysmolski Mar 17, 2026
864dfa3
bump engine to 265
ysmolski Mar 17, 2026
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
2 changes: 1 addition & 1 deletion router-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/wundergraph/cosmo/demo/pkg/subgraphs/projects v0.0.0-20250715110703-10f2e5f9c79e
github.com/wundergraph/cosmo/router v0.0.0-20251125205644-175f80c4e6d9
github.com/wundergraph/cosmo/router-plugin v0.0.0-20250808194725-de123ba1c65e
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.245
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.246
go.opentelemetry.io/otel v1.36.0
go.opentelemetry.io/otel/sdk v1.36.0
go.opentelemetry.io/otel/sdk/metric v1.36.0
Expand Down
4 changes: 2 additions & 2 deletions router-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083 h1:8/D7f8gKxTBjW+SZK4mhxTTBVpxcqeBgWF1Rfmltbfk=
github.com/wundergraph/astjson v0.0.0-20250106123708-be463c97e083/go.mod h1:eOTL6acwctsN4F3b7YE+eE2t8zcJ/doLm9sZzsxxxrE=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.245 h1:MYewlXgIhI9jusocPUeyo346J3M5cqzc6ddru1qp+S8=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.245/go.mod h1:mX25ASEQiKamxaFSK6NZihh0oDCigIuzro30up4mFH4=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.246 h1:B4/E6zJ5PbHNqcNw4Bvki7o+alcgyz8L5+Nlq1FZbLM=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.246/go.mod h1:mX25ASEQiKamxaFSK6NZihh0oDCigIuzro30up4mFH4=
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
Expand Down
2 changes: 1 addition & 1 deletion router-tests/modules/custom_trace_propagator_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package module
package module_test

import (
"encoding/json"
Expand Down
5 changes: 3 additions & 2 deletions router-tests/modules/streams_hooks_combined_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package module
package module_test

import (
"encoding/json"
Expand All @@ -8,6 +8,8 @@ import (
"github.com/hasura/go-graphql-client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/wundergraph/cosmo/router-tests/events"
stream_publish "github.com/wundergraph/cosmo/router-tests/modules/stream-publish"
stream_receive "github.com/wundergraph/cosmo/router-tests/modules/stream-receive"
Expand All @@ -16,7 +18,6 @@ import (
"github.com/wundergraph/cosmo/router/pkg/config"
"github.com/wundergraph/cosmo/router/pkg/pubsub/datasource"
"github.com/wundergraph/cosmo/router/pkg/pubsub/kafka"
"go.uber.org/zap/zapcore"
)

func TestStreamsHooksCombined(t *testing.T) {
Expand Down
63 changes: 63 additions & 0 deletions router-tests/modules/verify-cost-analysis/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package verify_cost_analysis

import (
"net/http"

"go.uber.org/zap"

"github.com/wundergraph/cosmo/router/core"
)

const myModuleID = "verifyCost"

// CapturedCost holds the captured cost from operation context
type CapturedCost struct {
Cost core.OperationCost
Error error
}

// VerifyCostModule captures cost for verification in tests
type VerifyCostModule struct {
ResultsChan chan CapturedCost
Logger *zap.Logger
}

func (m *VerifyCostModule) Provision(ctx *core.ModuleContext) error {
m.Logger = ctx.Logger
if m.ResultsChan == nil {
m.ResultsChan = make(chan CapturedCost, 1)
}
return nil
}

func (m *VerifyCostModule) Middleware(ctx core.RequestContext, next http.Handler) {
operation := ctx.Operation()

cost, err := operation.Cost()
captured := CapturedCost{Cost: cost, Error: err}

// Send the captured values to the test
select {
case m.ResultsChan <- captured:
default:
// Channel is full, skip
}

next.ServeHTTP(ctx.ResponseWriter(), ctx.Request())
}

func (m *VerifyCostModule) Module() core.ModuleInfo {
return core.ModuleInfo{
ID: myModuleID,
Priority: 1,
New: func() core.Module {
return &VerifyCostModule{
ResultsChan: make(chan CapturedCost, 1),
}
},
}
}

var (
_ core.RouterMiddlewareHandler = (*VerifyCostModule)(nil)
)
103 changes: 103 additions & 0 deletions router-tests/modules/verify_cost_analysis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package module_test

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

verifyModule "github.com/wundergraph/cosmo/router-tests/modules/verify-cost-analysis"
"github.com/wundergraph/cosmo/router-tests/testenv"
"github.com/wundergraph/cosmo/router/core"
"github.com/wundergraph/cosmo/router/pkg/config"
)

func TestCostModuleExposition(t *testing.T) {
t.Parallel()

t.Run("module can access cost when cost analysis is enabled", func(t *testing.T) {
t.Parallel()

resultsChan := make(chan verifyModule.CapturedCost, 1)

cfg := config.Config{
Graph: config.Graph{},
Modules: map[string]any{
"verifyCost": verifyModule.VerifyCostModule{
ResultsChan: resultsChan,
},
},
}

testenv.Run(t, &testenv.Config{
RouterOptions: []core.Option{
core.WithModulesConfig(cfg.Modules),
core.WithCustomModules(&verifyModule.VerifyCostModule{}),
},
ModifySecurityConfiguration: func(securityConfiguration *config.SecurityConfiguration) {
securityConfiguration.CostAnalysis = &config.CostAnalysis{
Enabled: true,
Mode: config.CostAnalysisModeMeasure,
EstimatedListSize: 10,
}
},
}, func(t *testing.T, xEnv *testenv.Environment) {
res, err := xEnv.MakeGraphQLRequest(testenv.GraphQLRequest{
Query: `query GetEmployee { employee(id: 1) { id } }`,
})
require.NoError(t, err)
assert.Equal(t, 200, res.Response.StatusCode)

testenv.AwaitChannelWithT(t, 10*time.Second, resultsChan, func(t *testing.T, captured verifyModule.CapturedCost) {
assert.NoError(t, captured.Error, "Cost() should not return an error when cost analysis is enabled")
assert.Greater(t, captured.Cost.Estimated, 0, "Estimated cost should be greater than 0 for a query with object fields")

// Log the cost for demonstration purposes
t.Logf("Query estimated cost: %d (could be used for rate limiting)", captured.Cost.Estimated)
// In a real module, you could use this cost for:
// - Rate limiting (deduct from user's cost budget)
// - Logging/metrics
// - Custom rejection logic
// - Billing/monetization

})
})
})

t.Run("module receives error when cost analysis is disabled", func(t *testing.T) {
t.Parallel()

resultsChan := make(chan verifyModule.CapturedCost, 1)

cfg := config.Config{
Graph: config.Graph{},
Modules: map[string]any{
"verifyCost": verifyModule.VerifyCostModule{
ResultsChan: resultsChan,
},
},
}

testenv.Run(t, &testenv.Config{
RouterOptions: []core.Option{
core.WithModulesConfig(cfg.Modules),
core.WithCustomModules(&verifyModule.VerifyCostModule{}),
},
ModifySecurityConfiguration: func(securityConfiguration *config.SecurityConfiguration) {
securityConfiguration.CostAnalysis = nil
},
}, func(t *testing.T, xEnv *testenv.Environment) {
res, err := xEnv.MakeGraphQLRequest(testenv.GraphQLRequest{
Query: `query GetEmployee { employee(id: 1) { id } }`,
})
require.NoError(t, err)
assert.Equal(t, 200, res.Response.StatusCode)

testenv.AwaitChannelWithT(t, 10*time.Second, resultsChan, func(t *testing.T, captured verifyModule.CapturedCost) {
assert.Error(t, captured.Error, "Cost() should return an error when cost analysis is disabled")
assert.Equal(t, 0, captured.Cost.Estimated, "Estimated cost should be 0 when cost analysis is disabled")
})
})
})
}
Loading
Loading