userver: components::DynamicConfig Class Reference
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts

#include <userver/dynamic_config/storage/component.hpp>

Detailed Description

Component that stores the dynamic config.

Note that the service with updates-enabled: true and without configs cache requires successful update to start. See dynamic_config_fallback for details and explanation.

Behavior on missing configs

If a config variable is entirely missing the fetched config, the value from dynamic_config_fallback.json is used (see fallback-path static config option).

Behavior on config parsing failure

If a config variable from the fetched config fails to be parsed (the parser fails with an exception), then the whole config update fails. It means that:

  • If the service is just starting, it will shut down
  • If the service is already running, the config updates will stop until the config in the config service changes to a valid one. You can monitor this situation using the metric at path cache.any.time.time-from-last-successful-start-ms

Static options

Name Description Default value
updates-enabled should be set to 'true' if there is an updater component false
defaults overrides the defaults from dynamic_config::Key definitions in code {}
fallback-path a path to the fallback config defaults are taken from dynamic_config::Key definitions
fs-cache-path path to the file to read and dump a config cache; set to empty string to disable reading and dumping configs to FS cache is disabled
fs-task-processor name of the task processor to run the blocking file write operations required if fs-cache-path is present

Static configuration example:

    dynamic-config:
      updates-enabled: true
      fs-cache-path: $dynamic-config-cache-path
      fs-task-processor: fs-task-processor

Usage example:

namespace myservice::smth {
inline const dynamic_config::Key kMyConfig{"SAMPLE_INTEGER_FROM_RUNTIME_CONFIG",
42};
int Component::DoSomething() const {
// Getting a snapshot of dynamic config.
const auto runtime_config = config_.GetSnapshot();
return runtime_config[kMyConfig];
}
} // namespace myservice::smth
Examples
components/component_sample_test.cpp.

Definition at line 67 of file component.hpp.

+ Inheritance diagram for components::DynamicConfig:
+ Collaboration diagram for components::DynamicConfig:

Classes

class  NoblockSubscriber
 Allows to subscribe to DynamicConfig updates without waiting for the first update to complete. Primarily intended for internal use. More...
 

Public Member Functions

 DynamicConfig (const ComponentConfig &, const ComponentContext &)
 
dynamic_config::Source GetSource ()
 
const dynamic_config::DocsMapGetDefaultDocsMap () const
 
- Public Member Functions inherited from components::DynamicConfigUpdatesSinkBase
 DynamicConfigUpdatesSinkBase (const components::ComponentConfig &, const components::ComponentContext &)
 
- Public Member Functions inherited from components::LoggableComponentBase
 LoggableComponentBase (const ComponentConfig &, const ComponentContext &)
 
 LoggableComponentBase (LoggableComponentBase &&)=delete
 
 LoggableComponentBase (const LoggableComponentBase &)=delete
 
 ~LoggableComponentBase () override=default
 
ComponentHealth GetComponentHealth () const override
 
void OnLoadingCancelled () override
 
void OnAllComponentsLoaded () override
 
void OnAllComponentsAreStopping () override
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from components::LoggableComponentBase
static yaml_config::Schema GetStaticConfigSchema ()
 

Static Public Attributes

static constexpr std::string_view kName = "dynamic-config"
 The default name of components::DynamicConfig.
 

Member Function Documentation

◆ GetDefaultDocsMap()

const dynamic_config::DocsMap & components::DynamicConfig::GetDefaultDocsMap ( ) const

Get config defaults with overrides applied. Useful in the implementation of custom config clients. Most code does not need to deal with these

◆ GetSource()

dynamic_config::Source components::DynamicConfig::GetSource ( )

Use dynamic_config::Source to get up-to-date config values, or to do something special on config updates

Examples
components/component_sample_test.cpp.

The documentation for this class was generated from the following file: