Skip to content

feat: make storage providers configurable via envars#2740

Open
SkArchon wants to merge 6 commits intomainfrom
milinda/eng-9112-router-add-environment-variable-support-for-s3-storage
Open

feat: make storage providers configurable via envars#2740
SkArchon wants to merge 6 commits intomainfrom
milinda/eng-9112-router-add-environment-variable-support-for-s3-storage

Conversation

@SkArchon
Copy link
Copy Markdown
Contributor

@SkArchon SkArchon commented Apr 6, 2026

This PR adds envar support allowing the configuration of storage providers of envars. It uses the already existing slice / struct semantics provided by the carlos0/env library we use.

STORAGE_PROVIDER_REDIS_0_ID=1
STORAGE_PROVIDER_REDIS_1_ID=2

The above index will create successful entries. (Note that if you skip an index, only indexes starting from 0 until the index before the skipped index will be included, which means if someone adds index 17 in the above example it then will be ignored and not utilized).

Summary by CodeRabbit

  • Chores

    • Improved storage provider environment-variable handling to use provider-specific prefixes and indexed notation for multiple providers, ensuring per-provider fields map under consistent prefixed names.
  • Tests

    • Added unit tests validating environment-driven loading of S3, CDN, Redis, and File System provider entries, including list parsing and boolean handling.
  • Documentation

    • Updated docs with indexed env-var configuration guidance, reordered provider sections, and revised displayed defaults.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/docs-website.
  • I have read the Contributors Guide.

Open Source AI Manifesto

This project follows the principles of the Open Source AI Manifesto. Please ensure your contribution aligns with its principles.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 153d7d80-485f-4d49-bbe9-19c99f0f5e18

📥 Commits

Reviewing files that changed from the base of the PR and between 7651cfe and a39e040.

📒 Files selected for processing (1)
  • docs-website/router/configuration.mdx

Walkthrough

Added provider-specific envPrefix and env struct tags to storage provider config structs to enable indexed environment-variable mapping (e.g., STORAGE_PROVIDER_S3_0_*), added unit tests for each provider type, and updated docs to document indexed env-var configuration and provider ordering.

Changes

Cohort / File(s) Summary
Config struct tag updates
router/pkg/config/config.go
Added envPrefix:"STORAGE_PROVIDER_" on Config.StorageProviders and provider-specific envPrefix values (S3_, CDN_, REDIS_, FS_) plus explicit env tags for provider fields to support indexed env-var mapping. No exported signatures changed.
Storage provider tests
router/pkg/config/config_test.go
Added tests TestS3StorageProviderFromEnv, TestCDNStorageProviderFromEnv, TestRedisStorageProviderFromEnv, TestFileSystemStorageProviderFromEnv verifying LoadConfig reads STORAGE_PROVIDER_{TYPE}_{INDEX}_{FIELD} env-vars into provider arrays and parses booleans/CSV as expected.
Documentation updates
docs-website/router/configuration.mdx, docs-website/router/storage-providers.mdx
Documented indexed environment-variable configuration (STORAGE_PROVIDER_{TYPE}_{INDEX}_{FIELD}), updated provider tables/examples to indexed notation, reordered provider sections, and added a new section describing full env-var configuration support.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 'feat: make storage providers configurable via envars' directly reflects the main change: adding environment-variable support for storage provider configuration across the codebase.

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


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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

❌ Internal Query Planner CI failed to run.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.45%. Comparing base (65e05e3) to head (a39e040).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2740      +/-   ##
==========================================
- Coverage   63.46%   63.45%   -0.01%     
==========================================
  Files         251      251              
  Lines       26767    26767              
==========================================
- Hits        16987    16986       -1     
- Misses       8414     8417       +3     
+ Partials     1366     1364       -2     
Files with missing lines Coverage Δ
router/pkg/config/config.go 80.51% <ø> (ø)

... and 7 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.

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.

🧹 Nitpick comments (1)
router/pkg/config/config_test.go (1)

598-718: Add a regression test for non-contiguous provider indexes.

Great coverage for contiguous indexes (0, 1). Please also lock in the “stop at first gap” behavior (e.g., 0 and 2 should load only index 0) since that behavior is called out in the PR description.

✅ Suggested test addition
+func TestStorageProviderFromEnvStopsAtFirstIndexGap(t *testing.T) {
+	t.Setenv("STORAGE_PROVIDER_S3_0_ID", "s3-zero")
+	t.Setenv("STORAGE_PROVIDER_S3_0_ENDPOINT", "s3-zero.example.com:9000")
+	t.Setenv("STORAGE_PROVIDER_S3_0_BUCKET", "bucket-zero")
+	t.Setenv("STORAGE_PROVIDER_S3_0_ACCESS_KEY", "accessKey0")
+	t.Setenv("STORAGE_PROVIDER_S3_0_SECRET_KEY", "secretKey0")
+	t.Setenv("STORAGE_PROVIDER_S3_0_REGION", "us-east-1")
+	t.Setenv("STORAGE_PROVIDER_S3_0_SECURE", "true")
+
+	// Intentionally skip index 1
+	t.Setenv("STORAGE_PROVIDER_S3_2_ID", "s3-two")
+	t.Setenv("STORAGE_PROVIDER_S3_2_ENDPOINT", "s3-two.example.com:9000")
+	t.Setenv("STORAGE_PROVIDER_S3_2_BUCKET", "bucket-two")
+	t.Setenv("STORAGE_PROVIDER_S3_2_ACCESS_KEY", "accessKey2")
+	t.Setenv("STORAGE_PROVIDER_S3_2_SECRET_KEY", "secretKey2")
+	t.Setenv("STORAGE_PROVIDER_S3_2_REGION", "eu-west-1")
+	t.Setenv("STORAGE_PROVIDER_S3_2_SECURE", "false")
+
+	f := createTempFileFromFixture(t, `
+version: "1"
+`)
+	cfg, err := LoadConfig([]string{f})
+	require.NoError(t, err)
+
+	require.Len(t, cfg.Config.StorageProviders.S3, 1)
+	require.Equal(t, "s3-zero", cfg.Config.StorageProviders.S3[0].ID)
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@router/pkg/config/config_test.go` around lines 598 - 718, Add regression
tests that verify "stop at first gap" behavior for each provider type by
creating new test functions (e.g.,
TestS3StorageProviderFromEnv_NonContiguousIndexes,
TestCDNStorageProviderFromEnv_NonContiguousIndexes,
TestRedisStorageProviderFromEnv_NonContiguousIndexes,
TestFileSystemStorageProviderFromEnv_NonContiguousIndexes) that set environment
variables for index 0 and index 2 (skip index 1), call LoadConfig, and assert
that cfg.Config.StorageProviders.<S3|CDN|Redis|FileSystem> has length 1 and
contains only the values from index 0; mirror the existing tests' assertions
(IDs, endpoints/URLs/URLs list/paths, Secure/ClusterEnabled, etc.) to ensure
only the first contiguous block is loaded.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@router/pkg/config/config_test.go`:
- Around line 598-718: Add regression tests that verify "stop at first gap"
behavior for each provider type by creating new test functions (e.g.,
TestS3StorageProviderFromEnv_NonContiguousIndexes,
TestCDNStorageProviderFromEnv_NonContiguousIndexes,
TestRedisStorageProviderFromEnv_NonContiguousIndexes,
TestFileSystemStorageProviderFromEnv_NonContiguousIndexes) that set environment
variables for index 0 and index 2 (skip index 1), call LoadConfig, and assert
that cfg.Config.StorageProviders.<S3|CDN|Redis|FileSystem> has length 1 and
contains only the values from index 0; mirror the existing tests' assertions
(IDs, endpoints/URLs/URLs list/paths, Secure/ClusterEnabled, etc.) to ensure
only the first contiguous block is loaded.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4e80f63-4cf9-4bb6-af5d-2ac4a5cd06ae

📥 Commits

Reviewing files that changed from the base of the PR and between 2326f9c and bbaad00.

📒 Files selected for processing (2)
  • router/pkg/config/config.go
  • router/pkg/config/config_test.go

@SkArchon SkArchon requested review from a team as code owners April 6, 2026 11:44
@SkArchon SkArchon requested a review from wilsonrivera April 6, 2026 11:44
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)
docs-website/router/configuration.mdx (1)

1094-1094: Split the indexing rules into a short list for better reference readability.

Line 1094 contains multiple distinct rules in one paragraph. A short bullet list is easier to scan in reference docs.

Proposed doc edit
-Storage providers are configured as arrays, so environment variables use indexed notation: `STORAGE_PROVIDER_{TYPE}_{INDEX}_{FIELD}`. Indexes must start from `0` and be sequential. If an index is skipped, all indexes after the gap are ignored. See [Storage Providers](/router/storage-providers) for more details.
+Storage providers are configured as arrays.
+
+- Use indexed environment variables: `STORAGE_PROVIDER_{TYPE}_{INDEX}_{FIELD}`.
+- Indexes start at `0`.
+- Indexes must be sequential. If an index is skipped, all following indexes are ignored.
+
+See [Storage Providers](/router/storage-providers) for more details.

As per coding guidelines, "Use structured lists when presenting multiple distinct items. Do not pack them into a single paragraph."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs-website/router/configuration.mdx` at line 1094, The paragraph describing
storage provider indexing should be split into a short, structured list for
readability: extract the distinct rules about the environment variable format
(STORAGE_PROVIDER_{TYPE}_{INDEX}_{FIELD}), that indexes must start at 0, that
indexes must be sequential, and that any skipped index causes following indexes
to be ignored, and render those as separate bullet points (with a final line
linking to the Storage Providers page for details) instead of one combined
sentence.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs-website/router/configuration.mdx`:
- Around line 1108-1117: Update the docs to reflect the actual defaults and
requirements: change the STORAGE_PROVIDER_S3_{n}_SECURE table row to show
default "false" (fix by ensuring S3StorageProvider.Secure's envDefault is
represented as false), and update the STORAGE_PROVIDER_CDN_{n}_URL row to mark
the field as optional (remove the required check icon) while keeping the default
value "https://cosmo-cdn.wundergraph.com" (reflecting CDNStorageProvider.URL's
envDefault). Ensure the environment variable names and YAML keys remain
unchanged.

---

Nitpick comments:
In `@docs-website/router/configuration.mdx`:
- Line 1094: The paragraph describing storage provider indexing should be split
into a short, structured list for readability: extract the distinct rules about
the environment variable format (STORAGE_PROVIDER_{TYPE}_{INDEX}_{FIELD}), that
indexes must start at 0, that indexes must be sequential, and that any skipped
index causes following indexes to be ignored, and render those as separate
bullet points (with a final line linking to the Storage Providers page for
details) instead of one combined sentence.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d55a8334-597d-4f87-9dab-1e44eb2e7944

📥 Commits

Reviewing files that changed from the base of the PR and between bbaad00 and f9d6e3b.

📒 Files selected for processing (2)
  • docs-website/router/configuration.mdx
  • docs-website/router/storage-providers.mdx
✅ Files skipped from review due to trivial changes (1)
  • docs-website/router/storage-providers.mdx

Copy link
Copy Markdown
Contributor

@dkorittki dkorittki left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants