userver: components::DynamicConfig Class Reference
Loading...
Searching...
No Matches
components::DynamicConfig Class Referencefinal

#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:

# yaml
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:

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
 
ComponentHealth GetComponentHealth () const override
 
void OnAllComponentsLoaded () override
 
void OnAllComponentsAreStopping () override
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 

Static Public Attributes

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

Protected Types

using LoggableComponentBase = ComponentBase
 Legacy alias, use ComponentBase instead.
 

Member Typedef Documentation

◆ LoggableComponentBase

Legacy alias, use ComponentBase instead.

Definition at line 69 of file component_base.hpp.

Member Function Documentation

◆ GetComponentHealth()

ComponentHealth components::ComponentBase::GetComponentHealth ( ) const
inlineoverridevirtualinherited

Override this function to inform the world of the state of your component.

Warning
The function is called concurrently from multiple threads.

Reimplemented from components::RawComponentBase.

Definition at line 35 of file component_base.hpp.

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

◆ OnAllComponentsAreStopping()

void components::ComponentBase::OnAllComponentsAreStopping ( )
inlineoverridevirtualinherited

Component may use this function to stop doing work before the stop of the components that depend on it.

Base components may override it and make final to do some work before the derived object constructor is called. Don't use it otherwise.

Reimplemented from components::RawComponentBase.

Reimplemented in urabbitmq::ConsumerComponentBase, and components::Server.

Definition at line 60 of file component_base.hpp.

◆ OnAllComponentsLoaded()

void components::ComponentBase::OnAllComponentsLoaded ( )
inlineoverridevirtualinherited

Component may use this function to finalize registration of other components that depend on it (for example, handler components register in server component, and the latter uses OnAllComponentsLoaded() to start processing requests).

Base components may override it and make final to do some work after the derived object constructor is called. Don't use it otherwise.

Reimplemented from components::RawComponentBase.

Reimplemented in urabbitmq::ConsumerComponentBase, components::Server, and server::handlers::Ping.

Definition at line 53 of file component_base.hpp.


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