Specialized components
Background processing
Application configuration management
19 min
overview application configuration management is a system that provides a centralized approach to managing and accessing configuration settings for the ir engine's background processing application it enables the task server and its various tasks to retrieve operational parameters such as server ports, task intervals, database connection details, and other environment specific settings by separating configuration from code, this system enhances flexibility, maintainability, and operational clarity across different deployment environments purpose and functionality configuration management serves several essential purposes centralization provides a single source of truth for application settings environment adaptation allows the application to behave differently in development, testing, and production operational flexibility enables changing application behavior without modifying code consistency ensures all components use the same configuration values security separates sensitive information from application code the system manages various types of configuration values server settings ports, hostnames, and network parameters task parameters execution intervals and processing limits integration details connection information for databases, redis, and other services environment specific values different settings for development, testing, and production operational parameters logging levels, feature flags, and other runtime controls implementation configuration loading the configuration loading process begins in the application's entry point // src/index ts import { updateappconfig } from '@ir engine/server core/src/updateappconfig'; const init = async () => { // load all configurations before proceeding await updateappconfig(); // continue with application startup const { start } = await import(' /start'); start(); }; init(); the updateappconfig() function gathers configuration values from various sources merges them according to priority rules populates a central configuration object makes this object available through the appconfig module configuration sources the configuration system typically loads values from multiple sources default values hardcoded defaults defined in the application environment variables values set in the server's environment configuration files json or yaml files with settings kubernetes configmaps for kubernetes deployments secrets management for sensitive information like api keys these sources are processed in order of priority, with later sources overriding earlier ones configuration access once loaded, configuration values are accessible throughout the application // example from a task file import config from '@ir engine/server core/src/appconfig'; import multilogger from '@ir engine/server core/src/serverlogger'; const logger = multilogger child({ component 'taskserver\ collect analytics' }); // access configuration values const intervalseconds = config\['task server'] processinterval || 1800; // default 30 minutes const intervalmilliseconds = intervalseconds 1000; logger info(`analytics collection interval set to ${intervalseconds} seconds`); // use the configuration value setinterval(async () => { // task logic here }, intervalmilliseconds); this pattern imports the central configuration object accesses specific settings using property paths provides fallback values for missing configurations uses the retrieved values to control application behavior configuration structure the configuration object typically follows a structured format // simplified view of the configuration object const config = { server { port 3030, hostname 'localhost', namespace 'ir engine dev' }, 'task server' { port 5050, processinterval 1800 }, redis { host 'localhost', port 6379 }, kubernetes { incluster false, namespace 'ir engine dev' }, analytics { enabled true, storagelimit 10000 } // additional sections for other components }; this hierarchical structure groups related settings together provides clear namespacing for different components makes configuration values easy to locate and reference allows for partial updates of specific sections configuration workflow the complete configuration management workflow follows these steps sequencediagram participant appstart as application startup participant updateconfig as updateappconfig() participant envvars as environment variables participant defaults as default values participant configobj as central config object participant tasks as task modules appstart >>updateconfig call updateappconfig() updateconfig >>defaults load default values defaults >>updateconfig default configuration updateconfig >>envvars check for environment variables envvars >>updateconfig environment specific values updateconfig >>configobj merge and populate config object configobj >>updateconfig configuration complete updateconfig >>appstart configuration loaded appstart >>tasks initialize tasks tasks >>configobj import config; access settings configobj >>tasks provide configuration values tasks >>tasks use values to control behavior this diagram illustrates the application starts and calls updateappconfig() default values are loaded as a baseline environment variables and other sources are checked values are merged with defaults taking lowest priority the central configuration object is populated tasks and other components import and use the configuration configuration values control application behavior practical examples task interval configuration the analytics data collector uses configuration to determine how often it runs // simplified from src/collect analytics ts import config from '@ir engine/server core/src/appconfig'; export default (app) => { // get the configured interval or use default const intervalseconds = config\['task server'] processinterval || 1800; const intervalmilliseconds = intervalseconds 1000; // set up periodic execution const interval = setinterval(async () => { try { // analytics collection logic await collectandprocessanalytics(app); } catch (err) { logger error('error collecting analytics ', err); } }, intervalmilliseconds); // clean up on application shutdown app on('close', () => { clearinterval(interval); }); }; this example shows how the task imports the configuration object it retrieves the configured interval with a fallback the configuration value directly controls the task's behavior changes to the configuration will affect the task's execution frequency kubernetes namespace configuration the kubernetes event collector uses configuration to determine which namespace to monitor // simplified from src/collect events ts import config from '@ir engine/server core/src/appconfig'; const collectkubernetesevents = async (app) => { // get the configured namespace const namespace = config kubernetes namespace || 'default'; logger info(`collecting events from namespace ${namespace}`); // use the kubernetes client to watch events const k8sapi = app get('k8sapi'); const watch = new k8s watch(k8sapi config); watch watch( `/api/v1/namespaces/${namespace}/events`, {}, async (type, event) => { // process kubernetes events } ); }; this example demonstrates retrieving a namespace configuration value using the value to determine which kubernetes resources to monitor adapting the application's behavior based on configuration deployment considerations when deploying the application, configuration values can be provided in several ways environment variables for containerized deployments, environment variables are commonly used \# kubernetes deployment example apiversion apps/v1 kind deployment metadata name ir engine taskserver spec template spec containers \ name taskserver image ir engine/taskserver\ latest env \ name node env value production \ name task server process interval value "600" # 10 minutes instead of default 30 \ name kubernetes namespace value "ir engine prod" configmaps in kubernetes for more complex configurations, kubernetes configmaps can be used \# configmap definition apiversion v1 kind configmap metadata name ir engine config data task server json | { "port" 5050, "processinterval" 600 } analytics json | { "enabled" true, "storagelimit" 20000 } \# mounting in deployment spec containers \ name taskserver volumemounts \ name config volume mountpath /app/config volumes \ name config volume configmap name ir engine config benefits of centralized configuration the application configuration management system provides several key benefits separation of concerns keeps operational parameters separate from application logic environment adaptability allows the same code to run in different environments operational flexibility enables changing behavior without code modifications reduced errors eliminates hardcoded values scattered throughout the codebase simplified deployment makes it easier to deploy the application in new environments enhanced security keeps sensitive information out of the codebase improved maintainability centralizes all configuration in one logical location these benefits make configuration management a critical component of the ir engine's background processing system next steps with an understanding of how the task server application starts and how it accesses configuration, the next chapter explores one of the primary background tasks the analytics data collector next analytics data collector docid 83etf0hxkaf m fi8cha9