cosmo
cosmo copied to clipboard
feat: add demo configuration
This pull request introduces a "demo mode" feature to the router, allowing it to start with a demo execution configuration if no other configuration is found. Additionally, it includes minor refactoring and cleanup in the codebase. Below are the key changes grouped by theme:
Demo Mode Implementation:
- Added a
Demofield to theConfigstructs in various files, enabling the router to be launched in demo mode. (router-tests/testenv/testenv.go[1]router/pkg/config/config.go[2]router/core/router.go[3] - Updated the configuration schema and test fixtures to include the
Demofield. (router/pkg/config/config.schema.json[1]router/pkg/config/fixtures/full.yaml[2]router/pkg/config/testdata/config_defaults.json[3] - Modified the router's initialization logic to handle the
Demoflag and use a demo execution configuration if no other configuration is found. (router/core/init_config_poller.go[1] [2] [3]router/pkg/routerconfig/cdn/client.go[4]router/pkg/routerconfig/s3/client.go[5]
Test Enhancements:
- Updated integration tests to include the
Demoflag in test configurations. (router-tests/integration_test.gorouter-tests/integration_test.goL56-R59) - Adjusted validation error tests to use
require.Containsfor more flexible error message matching. (router/pkg/config/config_test.go[1] [2] [3] [4]
Code Refactoring:
- Cleaned up import statements in several files for better organization. (
router-tests/testenv/testexec.go[1] [2]router/pkg/routerconfig/cdn/client.go[3]
These changes collectively enhance the router's flexibility and maintainability while introducing a useful demo mode for specific scenarios.
Motivation and Context
When the execution config is retrieved from a CDN or S3, and it’s not found, the router will start with a default configuration and repeatedly poll for the correct one. This behavior allows the router to start even if the configuration hasn’t been published yet.
However, in some cases, the configuration not being found could indicate an actual error (e.g., a misconfigured path or missing file). In such situations, silently starting with a default config can be misleading.
To address this, we decided that by default if a config is not found, the router should give an error (and don't even start if no config is found), but I've added a new config, demo, that if set will allow the router to start with a demo configuration.
Checklist
- [X] I have discussed my proposed changes in an issue and have received approval to proceed.
- [X] I have followed the coding standards of the project.
- [x] Tests or benchmarks have been added or updated.
- [X] Documentation has been updated on https://github.com/wundergraph/cosmo-docs/pull/54.
- [X] I have read the Contributors Guide.
Router image scan passed
:white_check_mark: No security vulnerabilities found in image:
ghcr.io/wundergraph/cosmo/router:sha-22062c145dc5a9effd7a0780c8fe627f35fb3c8f