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

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

Detailed Description

Component that does a periodic update of runtime configs.

Note that the service with dynamic config update component and without configs cache requires successful update to start. See dynamic_config_fallback for details and explanation.

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 true
load-only-my-values request from the client only the values used by this service true
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
# options from components::CachingComponentBase
update-types: full-and-incremental
update-interval: 5s
update-jitter: 2s
full-update-interval: 5m
first-update-fail-ok: true
config-settings: false
additional-cleanup-interval: 5m

Definition at line 75 of file component.hpp.

+ Inheritance diagram for components::DynamicConfigClientUpdater:

Public Types

using DataType
 

Public Member Functions

 DynamicConfigClientUpdater (const ComponentConfig &, const ComponentContext &)
 
dynamic_config::AdditionalKeysToken SetAdditionalKeys (std::vector< std::string > keys)
 
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 ()
 
ComponentHealth GetComponentHealth () const override
 
void OnLoadingCancelled () override
 
void OnAllComponentsAreStopping () override
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 

Static Public Attributes

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

Protected Types

using LoggableComponentBase = ComponentBase
 Legacy alias, use ComponentBase instead.
 
enum class  Flag {
  kNone = 0 ,
  kNoFirstUpdate = 1 << 0
}
 Periodic update flags. More...
 

Protected Member Functions

void Set (std::unique_ptr< const dynamic_config::DocsMap > value_ptr)
 
void Set (dynamic_config::DocsMap &&value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void Emplace (Args &&... args)
 
void Clear ()
 Clears the content of the cache by string a default constructed T.
 
virtual bool MayReturnNull () const
 Whether Get is expected to return nullptr.
 
virtual void PreAssignCheck (const dynamic_config::DocsMap *old_value_ptr, const dynamic_config::DocsMap *new_value_ptr) const
 If the option has-pre-assign-check is set true in static config, this function is called before assigning the new value to the cache.
 
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
 
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 ()
 
virtual void WriteContents (dump::Writer &writer, const dynamic_config::DocsMap &contents) const
 
virtual std::unique_ptr< const dynamic_config::DocsMapReadContents (dump::Reader &reader) const
 

Member Typedef Documentation

◆ DataType

Definition at line 161 of file caching_component_base.hpp.

◆ LoggableComponentBase

Legacy alias, use ComponentBase instead.

Definition at line 69 of file component_base.hpp.

Member Enumeration Documentation

◆ Flag

enum class cache::CacheUpdateTrait::Flag
strongprotectedinherited

Periodic update flags.

Enumerator
kNoFirstUpdate 

Disable initial update on start.

Definition at line 62 of file cache_update_trait.hpp.

Member Function Documentation

◆ Clear()

void components::CachingComponentBase< dynamic_config::DocsMap >::Clear ( )
protectedinherited

Clears the content of the cache by string a default constructed T.

Definition at line 200 of file caching_component_base.hpp.

◆ Emplace()

void components::CachingComponentBase< dynamic_config::DocsMap >::Emplace ( Args &&... args)
protectedinherited

Definition at line 197 of file caching_component_base.hpp.

◆ Get()

Returns
cache contents. May be nullptr if and only if MayReturnNull returns true.
Exceptions
cache::EmptyCacheErrorif the contents are nullptr, and MayReturnNull returns false (which is the default behavior).

Definition at line 167 of file caching_component_base.hpp.

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

◆ GetEventChannel()

concurrent::AsyncEventChannel< const std::shared_ptr< const dynamic_config::DocsMap > & > & components::CachingComponentBase< dynamic_config::DocsMap >::GetEventChannel ( )
inherited

Definition at line 180 of file caching_component_base.hpp.

◆ GetUnsafe()

Returns
cache contents. May be nullptr regardless of MayReturnNull().

Definition at line 170 of file caching_component_base.hpp.

◆ InvalidateAsync()

void cache::CacheUpdateTrait::InvalidateAsync ( UpdateType update_type)
inherited

Non-blocking forced cache update of specified type.

See also
PeriodicTask::ForceStepAsync for behavior details

◆ MayReturnNull()

bool components::CachingComponentBase< dynamic_config::DocsMap >::MayReturnNull ( ) const
protectedvirtualinherited

Whether Get is expected to return nullptr.

Definition at line 203 of file caching_component_base.hpp.

◆ Name()

const std::string & cache::CacheUpdateTrait::Name ( ) const
inherited
Returns
name of the component

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

◆ OnCacheModified()

void cache::CacheUpdateTrait::OnCacheModified ( )
protectedinherited

Called in CachingComponentBase::Set during update to indicate that the cached data has been modified

◆ OnLoadingCancelled()

void components::ComponentBase::OnLoadingCancelled ( )
inlineoverridevirtualinherited

Called once if the creation of any other component failed. If the current component expects some other component to take any action with the current component, this call is a signal that such action may never happen due to components loading was cancelled. Application components might not want to override it.

Reimplemented from components::RawComponentBase.

Definition at line 44 of file component_base.hpp.

◆ PreAssignCheck()

void components::CachingComponentBase< dynamic_config::DocsMap >::PreAssignCheck ( const dynamic_config::DocsMap * old_value_ptr,
const dynamic_config::DocsMap * new_value_ptr ) const
protectedvirtualinherited

If the option has-pre-assign-check is set true in static config, this function is called before assigning the new value to the cache.

Note
old_value_ptr and new_value_ptr can be nullptr.

Definition at line 215 of file caching_component_base.hpp.

◆ ReadContents()

std::unique_ptr< const dynamic_config::DocsMap > components::CachingComponentBase< dynamic_config::DocsMap >::ReadContents ( dump::Reader & reader) const
protectedvirtualinherited

Definition at line 209 of file caching_component_base.hpp.

◆ Set() [1/2]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 193 of file caching_component_base.hpp.

◆ Set() [2/2]

void components::CachingComponentBase< dynamic_config::DocsMap >::Set ( std::unique_ptr< const dynamic_config::DocsMap > value_ptr)
protectedinherited

Sets the new value of cache. As a result the Get() member function starts returning the value passed into this function after the Update() finishes.

Warning
Do not forget to update cache::UpdateStatisticsScope, otherwise the behavior is undefined.

Definition at line 190 of file caching_component_base.hpp.

◆ StopPeriodicUpdates()

void cache::CacheUpdateTrait::StopPeriodicUpdates ( )
protectedinherited

Stops periodic updates.

Warning
Should be called in destructor of derived class.

◆ UpdateAndListen()

concurrent::AsyncEventSubscriberScope components::CachingComponentBase< dynamic_config::DocsMap >::UpdateAndListen ( Class * obj,
std::string name,
void(Class::*)(const std::shared_ptr< const dynamic_config::DocsMap > &) func )
inherited

Subscribes to cache updates using a member function. Also immediately invokes the function with the current cache contents.

Definition at line 175 of file caching_component_base.hpp.

◆ UpdateSyncDebug()

void cache::CacheUpdateTrait::UpdateSyncDebug ( UpdateType update_type)
inherited

Forces a cache update of specified type.

Exceptions
IfUpdate throws

◆ WriteContents()

void components::CachingComponentBase< dynamic_config::DocsMap >::WriteContents ( dump::Writer & writer,
const dynamic_config::DocsMap & contents ) const
protectedvirtualinherited

Override to use custom serialization for cache dumps

Definition at line 207 of file caching_component_base.hpp.


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