Skip to content

fix: add back NewServer#2546

Merged
SkArchon merged 2 commits intomainfrom
milinda/eng-8988-router-clients-using-newserver-cannot-upgrade-to-latest
Feb 23, 2026
Merged

fix: add back NewServer#2546
SkArchon merged 2 commits intomainfrom
milinda/eng-8988-router-clients-using-newserver-cannot-upgrade-to-latest

Conversation

@SkArchon
Copy link
Copy Markdown
Contributor

@SkArchon SkArchon commented Feb 23, 2026

This PR adds back the NewServer function as it is needed by our AWS Lambda provider, additionally it could be used by external consumers.

Summary by CodeRabbit

  • Tests

    • Added integration tests validating server lifecycle: startup without a listener, health/ready checks, proper shutdown behavior and request failure after shutdown.
  • New Features

    • Added a new server initialization flow with improved bootstrap, observability (tracing/metrics) and config handling to support static and dynamic startup scenarios.

Checklist

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47fccb5 and 745fe1c.

📒 Files selected for processing (1)
  • router-tests/lifecycle/new_server_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • router-tests/lifecycle/new_server_test.go

Walkthrough

Adds Router.NewServer(ctx) to bootstrap and return a runnable server, enhances test utilities to allow client-aware GraphQL requests, and introduces integration tests that exercise server lifecycle, health endpoint, and shutdown behavior using a mocked subgraph.

Changes

Cohort / File(s) Summary
New Server Lifecycle Tests
router-tests/lifecycle/new_server_test.go
New integration test file that starts an in-memory router, queries a mocked Employees subgraph, verifies /health/ready returns 200, and asserts requests fail after shutdown.
Test environment helpers
router-tests/testenv/testenv.go
Exposed GqlURL, added MakeGraphQLRequestRawFromClient(request *http.Request, routerClient *http.Client) and refactored MakeGraphQLRequestRaw to call the new helper to allow explicit HTTP client usage.
Router initialization & bootstrap
router/core/router.go
Added exported Router.NewServer(ctx) (Server, error) to initialize bootstrap, health/config state, observability (tracing/metrics), control-plane registration logic, and to start the HTTP server with static or polled initial config flows. Also added a bootstrap guard to prevent double-bootstrap.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: reintroducing the NewServer method to the Router class.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 23, 2026

Router image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-b5ab7920b05a61e9c6c3b2b4b77d2817c5114cf2

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 60.60606% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.32%. Comparing base (c8a6a5d) to head (745fe1c).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
router/core/router.go 60.60% 11 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2546      +/-   ##
==========================================
+ Coverage   61.69%   62.32%   +0.62%     
==========================================
  Files         239      239              
  Lines       25423    25456      +33     
==========================================
+ Hits        15685    15865     +180     
+ Misses       8418     8241     -177     
- Partials     1320     1350      +30     
Files with missing lines Coverage Δ
router/core/router.go 68.48% <60.60%> (-0.90%) ⬇️

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SkArchon SkArchon marked this pull request as ready for review February 23, 2026 12:22
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
router/core/router.go (1)

731-787: Consider mirroring usage-tracking calls from Start().

NewServer configures usage tracking but doesn’t call trackRouterConfigUsage / trackExecutionConfigUsage, so usage telemetry is skipped when this path is used. If that’s unintentional, consider invoking those once the config (static or polled) is available.

💡 Possible alignment (illustrative)
 if r.staticExecutionConfig != nil {
+    r.trackRouterConfigUsage()
+    r.trackExecutionConfigUsage(r.staticExecutionConfig, true)
     r.logger.Info("Static execution config provided. Polling is disabled. Updating execution config is only possible by providing a config.")
     return r.httpServer, r.newServer(ctx, r.staticExecutionConfig)
 }
 ...
 cfg, err := r.configPoller.GetRouterConfig(ctx)
 if err != nil {
     return nil, fmt.Errorf("failed to get initial execution config: %w", err)
 }
+ r.trackRouterConfigUsage()
+ r.trackExecutionConfigUsage(cfg.Config, false)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@router/core/router.go` around lines 731 - 787, NewServer configures usage
tracking but never emits telemetry because it doesn't call
trackRouterConfigUsage and trackExecutionConfigUsage; update NewServer to invoke
r.trackRouterConfigUsage(...) and r.trackExecutionConfigUsage(...) once a config
is available: for the static path call them before returning after
r.newServer(ctx, r.staticExecutionConfig), and for the polled path call them
after retrieving cfg (and/or after successfully applying it via r.newServer(ctx,
cfg.Config)). Place these calls near the existing
r.reloadPersistentState.UpdateReloadPersistentState(&r.Config) / right after
successful r.newServer(...) so telemetry is recorded on both code paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@router-tests/lifecycle/new_server_test.go`:
- Around line 24-110: The subtest for shutdown only closes the httptest.Server
and never invokes the router/server shutdown, so update the "new server shutdown
prevents further requests" subtest to call rr.Shutdown (or the server shutdown
method) before asserting requests fail: after verifying the server works, call
rr.Shutdown(ctx) (or svr.Shutdown(ctx) if present) with a short timeout context,
then attempt the POST to ts.URL+"/graphql" and assert it errors; ensure you
still close ts (httptest.Server) and cancel the context to clean up.

---

Nitpick comments:
In `@router/core/router.go`:
- Around line 731-787: NewServer configures usage tracking but never emits
telemetry because it doesn't call trackRouterConfigUsage and
trackExecutionConfigUsage; update NewServer to invoke
r.trackRouterConfigUsage(...) and r.trackExecutionConfigUsage(...) once a config
is available: for the static path call them before returning after
r.newServer(ctx, r.staticExecutionConfig), and for the polled path call them
after retrieving cfg (and/or after successfully applying it via r.newServer(ctx,
cfg.Config)). Place these calls near the existing
r.reloadPersistentState.UpdateReloadPersistentState(&r.Config) / right after
successful r.newServer(...) so telemetry is recorded on both code paths.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d69be79 and 47fccb5.

📒 Files selected for processing (3)
  • router-tests/lifecycle/new_server_test.go
  • router-tests/testenv/testenv.go
  • router/core/router.go

Comment thread router-tests/lifecycle/new_server_test.go
Copy link
Copy Markdown
Contributor

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

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

LGTM

@SkArchon SkArchon merged commit 602e0ab into main Feb 23, 2026
42 of 43 checks passed
@SkArchon SkArchon deleted the milinda/eng-8988-router-clients-using-newserver-cannot-upgrade-to-latest branch February 23, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants