userver: components::DynamicConfigClientUpdater Class Reference
Loading...
Searching...
No Matches
components::DynamicConfigClientUpdater Class Reference

Component that does a periodic update of runtime configs. More...

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

+ Inheritance diagram for components::DynamicConfigClientUpdater:
+ Collaboration diagram for components::DynamicConfigClientUpdater:

Public Member Functions

 DynamicConfigClientUpdater (const ComponentConfig &, const ComponentContext &)
 
dynamic_config::AdditionalKeysToken SetAdditionalKeys (std::vector< std::string > keys)
 
void Update (cache::UpdateType update_type, const std::chrono::system_clock::time_point &last_update, const std::chrono::system_clock::time_point &now, cache::UpdateStatisticsScope &) override
 Should be overridden in a derived class to align the stored data with some data source.
 
- Public Member Functions inherited from components::CachingComponentBase< dynamic_config::DocsMap >
 CachingComponentBase (const ComponentConfig &config, const ComponentContext &)
 
utils::SharedReadablePtr< dynamic_config::DocsMapGet () const
 
utils::SharedReadablePtr< dynamic_config::DocsMapGetUnsafe () const
 
concurrent::AsyncEventSubscriberScope UpdateAndListen (Class *obj, std::string name, void(Class::*func)(const std::shared_ptr< const dynamic_config::DocsMap > &))
 
concurrent::AsyncEventChannel< const std::shared_ptr< const dynamic_config::DocsMap > & > & GetEventChannel ()
 
- 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::CachingComponentBase< dynamic_config::DocsMap >
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-client-updater"
 The default name of components::DynamicConfigClientUpdater.
 

Additional Inherited Members

- Public Types inherited from components::CachingComponentBase< dynamic_config::DocsMap >
using DataType = dynamic_config::DocsMap
 
- Protected Types inherited from cache::CacheUpdateTrait
enum class  Flag {
  kNone = 0 ,
  kNoFirstUpdate = 1 << 0
}
 Periodic update flags. More...
 
- Protected Member Functions inherited from components::CachingComponentBase< dynamic_config::DocsMap >
void Set (std::unique_ptr< const dynamic_config::DocsMap > value_ptr)
 
void Set (dynamic_config::DocsMap &&value)
 
void Emplace (Args &&... args)
 
void Clear ()
 
virtual bool MayReturnNull () const
 
virtual void WriteContents (dump::Writer &writer, const dynamic_config::DocsMap &contents) const
 
virtual std::unique_ptr< const dynamic_config::DocsMapReadContents (dump::Reader &reader) const
 
- Protected Member Functions inherited from cache::CacheUpdateTrait
AllowedUpdateTypes GetAllowedUpdateTypes () const
 Update types configured for the cache.
 
void StartPeriodicUpdates (utils::Flags< Flag > flags={})
 Starts periodic updates.
 
void StopPeriodicUpdates ()
 Stops periodic updates.
 
void AssertPeriodicUpdateStarted ()
 
void OnCacheModified ()
 
 CacheUpdateTrait (CacheUpdateTrait &&)=delete
 
CacheUpdateTraitoperator= (CacheUpdateTrait &&)=delete
 
void InvalidateAsync (UpdateType update_type)
 Non-blocking forced cache update of specified type.
 
void UpdateSyncDebug (UpdateType update_type)
 Forces a cache update of specified type.
 
const std::string & Name () const
 

Detailed Description

Component that does a periodic update of runtime configs.

Optional update event deduplication

Config update types to deduplicate. If enabled, JSON of the whole config is compared to the previous one; if same, no config update event is sent to the subscribers of dynamic_config::Source (OnConfigUpdate functions).

deduplicate-update-types static config option specifies the update types of the config cache, for which event deduplication should be performed. Possible values:

  • none (the default)
  • only-full
  • only-incremental
  • full-and-incremental

Full updates will always send an event unless deduplicated. Incremental updates may send an extra event for some config service implementations.

Note: This is not a silver bullet against extra events, because the events will be sent to every dynamic config subscriber if any part of the config has updated, not if the interesting part has updated.

Static options:

Name Description Default value
updates-sink name of the component derived from components::DynamicConfigUpdatesSinkBase to be used for storing received updates dynamic-config
store-enabled store the retrieved values into the updates sink determined by the updates-sink option -
load-only-my-values request from the client only the values used by this service -
fallback-path a path to the fallback config to load the required config names from it -
fs-task-processor name of the task processor to run the blocking file write operations -
deduplicate-update-types update types for best-effort update event deduplication, see above full-and-incremental

See also the options for components::CachingComponentBase.

Static configuration example:

# yaml
dynamic-config-client-updater:
store-enabled: true
load-only-my-values: true
fallback-path: $runtime_config_path
fallback-path#fallback: /some/path/to/runtime_config.json
fs-task-processor: fs-task-processor
# options from components::CachingComponentBase
update-types: full-and-incremental
update-interval: 5s
update-jitter: 2s
full-update-interval: 5m
first-update-fail-ok: false
config-settings: true
additional-cleanup-interval: 5m
testsuite-force-periodic-update: true

Definition at line 73 of file component.hpp.

Member Function Documentation

◆ Update()

void components::DynamicConfigClientUpdater::Update ( cache::UpdateType  type,
const std::chrono::system_clock::time_point &  last_update,
const std::chrono::system_clock::time_point &  now,
cache::UpdateStatisticsScope stats_scope 
)
overridevirtual

Should be overridden in a derived class to align the stored data with some data source.

Update implementation should do one of the following:

A. If the update succeeded and has changes...

  1. call CachingComponentBase::Set to update the stored value and send a notification to subscribers
  2. call UpdateStatisticsScope::Finish
  3. return normally (an exception is allowed in edge cases) B. If the update succeeded and verified that there are no changes...
  1. DON'T call CachingComponentBase::Set
  2. call UpdateStatisticsScope::FinishNoChanges
  3. return normally (an exception is allowed in edge cases) C. If the update failed...
  1. DON'T call CachingComponentBase::Set
  2. call UpdateStatisticsScope::FinishWithError, or...
  3. throw an exception, which will be logged nicely
Parameters
typetype of the update
last_updatetime of the last update (value of now from previous invocation of Update or default constructed value if this is the first Update).
nowcurrent time point
Exceptions
std::exceptionon update failure
See also
Basics of Caches

Implements cache::CacheUpdateTrait.


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