[Proposal] Standardize Environment Variable Prefix Across Gateway Components #821
renuka-fernando
started this conversation in
Ideas
Replies: 1 comment
-
|
Done the changes to go with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
This proposal standardizes the environment variable prefix used by gateway-controller and policy-engine into a single unified prefix scheme. Currently, gateway-controller uses
GATEWAY_and policy-engine usesPE_, forcing operators to maintain two separate naming conventions when configuring the gateway as a unit. A unified prefix eliminates this inconsistency, simplifies deployment configurations, and reduces operator error.Motivation
Problem Statement
The WSO2 API Platform gateway is composed of two tightly co-deployed components -- gateway-controller and policy-engine -- that share a single TOML configuration file (
config.toml) but use completely different environment variable prefixes for overrides:GATEWAY_(defined ingateway/gateway-controller/pkg/config/config.go, line 37)PE_(defined ingateway/policy-engine/internal/config/config.go, line 35)This causes several concrete problems:
Duplicated configuration logic in deployments. In Kubernetes, operators must create separate ConfigMap entries or separate environment variable blocks for each prefix, even though both components are configured from the same logical configuration tree. For example,
docker-compose.yamlcurrently mixes both conventions:Inconsistent naming creates cognitive load. Operators must remember which prefix applies to which sub-component, and the mapping rules differ (e.g.,
GATEWAY_uses double-underscore for nested keys differently thanPE_).Who Benefits
Why Now
config.tomlpattern (introduced recently with the unified TOML configuration) makes this the natural time to also unify environment variable overrides.Industry Patterns
Research into how popular tools name their environment variables shows two distinct patterns:
Full Names (No Abbreviations)
TESTCONTAINERS_RYUK_DISABLED,TESTCONTAINERS_DOCKER_SOCKET_OVERRIDEMONGO_INITDB_ROOT_USERNAME,MONGO_INITDB_ROOT_PASSWORDGITHUB_REPOSITORY,GITHUB_WORKSPACE,GITHUB_ACTIONSGOOGLE_CLOUD_PROJECT(also supports shorterGCP_PROJECT)Established Abbreviations
AWS_ACCESS_KEY_ID,AWS_REGION,AWS_PROFILE(not AMAZON_WEB_SERVICES_)ES_NETWORK_HOST,ES_CLUSTER_NAME(not ELASTICSEARCH_)POSTGRES_USER,POSTGRES_PASSWORD(not POSTGRESQL_)DOCKER_HOST,DOCKER_TLS_VERIFYKey Observations
Recommendation: While modern tools favor full names, we must balance clarity with practicality. Configuration keys can be deeply nested (e.g.,
gateway_controller.router.policy_engine.timeout_ms), resulting in very long environment variable names.APIP_GW_provides clear namespacing while keeping variable names manageable.Proposed Prefix Options
APIP_GW_(8 chars) - Recommended - Platform namespaced, conciseAPIP_GW_GATEWAY__CONTROLLER_STORAGE_TYPE=sqliteAPIP= API Platform (clear product identity)GW= Gateway (widely understood abbreviation)APIPLATFORM_GW_(15 chars) - Full product name with component abbreviationAPIPLATFORM_GW_GATEWAY__CONTROLLER_STORAGE_TYPE=sqliteAPIP_GATEWAY_(13 chars) - Abbreviated platform with full component nameAPIP_GATEWAY_GATEWAY__CONTROLLER_STORAGE_TYPE=sqliteAPIPLATFORM_GATEWAY_(19 chars) - Fully explicit, no abbreviationsAPIPLATFORM_GATEWAY_GATEWAY__CONTROLLER_STORAGE_TYPE=sqliteGW_(3 chars) - Bare minimum, high collision riskGW_GATEWAY__CONTROLLER_STORAGE_TYPE=sqliteUnderstanding the Double Underscore Convention
You'll notice examples like
APIP_GW_GATEWAY__CONTROLLER_STORAGE_TYPE=sqliteuse double underscores (__) in the middle of the variable name. This is intentional and follows a standard convention for mapping environment variables to nested configuration structures.Mapping Rules
Both gateway components use the Koanf configuration library, which maps environment variables to TOML configuration keys using these rules:
_) → Converts to a dot (.) in the TOML path (nested sections)__) → Converts to a single underscore (_) in the TOML key (literal underscore)Examples
APIP_GW_GATEWAY__CONTROLLER_STORAGE_TYPEgateway_controller.storage.typeAPIP_GW_POLICY__ENGINE_METRICS_PORTpolicy_engine.metrics.portAPIP_GW_GATEWAY__CONTROLLER_LOGGING_LEVELgateway_controller.logging.levelWhy This Pattern?
The TOML configuration structure uses underscores in section names (e.g.,
gateway_controller,policy_engine). To preserve these literal underscores when setting values via environment variables, we use double underscores. The single underscores between words then represent the nested hierarchy (section → subsection → key).TOML structure:
Environment variable equivalent:
This convention is standard across many configuration tools (including Spring Boot, .NET, and other frameworks using hierarchical configuration).
Example Configuration Impact
Current state (split prefixes):
Proposed (unified prefix with
APIP_GW_):Kubernetes ConfigMap (unified):
References
Codebase
GATEWAY_prefix definitionPE_prefix definitionIndustry Research - Environment Variable Naming Patterns
TESTCONTAINERS_prefixGITHUB_prefixAWS_prefixGOOGLE_CLOUD_PROJECT,GCP_PROJECTES_prefixMONGO_prefixBeta Was this translation helpful? Give feedback.
All reactions