userver: userver/storages/clickhouse/component.hpp Source File
⚠️ 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
component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/clickhouse/component.hpp
4/// @brief @copybrief components::ClickHouse
5
6#include <userver/components/loggable_component_base.hpp>
7
8#include <userver/utils/statistics/storage.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace clients::dns {
13class Component;
14}
15
16namespace storages::clickhouse {
17class Cluster;
18}
19
20namespace components {
21
22// clang-format off
23
24/// @ingroup userver_components
25///
26/// @brief ClickHouse client component
27///
28/// Provides access to a ClickHouse cluster.
29///
30/// ## Static configuration example:
31///
32/// @snippet samples/clickhouse_service/static_config.yaml Clickhouse service sample - static config
33///
34/// If the component is configured with an secdist_alias, it will lookup
35/// connection data in secdist.json via secdist_alias value, otherwise via
36/// components name.
37///
38/// ## Secdist format
39///
40/// A ClickHouse alias in secdist is described as a JSON object
41/// `clickhouse_settings`, containing descriptions of databases.
42///
43/// @snippet samples/clickhouse_service/tests/conftest.py Clickhouse service sample - secdist
44///
45/// ## Static options:
46/// Name | Description | Default value
47/// --------------------- | ------------------------------------------------ | ---------------
48/// secdist_alias | name of the key in secdist config | components name
49/// initial_pool_size | number of connections created initially | 5
50/// max_pool_size | maximum number of created connections | 10
51/// queue_timeout | client waiting for a free connection time limit | 1s
52/// use_secure_connection | whether to use TLS for connections | true
53/// compression | compression method to use (none / lz4) | none
54
55// clang-format on
56
58 public:
59 /// Component constructor
60 ClickHouse(const ComponentConfig&, const ComponentContext&);
61 /// Component destructor
62 ~ClickHouse() override;
63
64 /// Cluster accessor
65 std::shared_ptr<storages::clickhouse::Cluster> GetCluster() const;
66
67 static yaml_config::Schema GetStaticConfigSchema();
68
69 private:
70 clients::dns::Component& dns_;
71
72 std::shared_ptr<storages::clickhouse::Cluster> cluster_;
73 utils::statistics::Entry statistics_holder_;
74};
75
76template <>
77inline constexpr bool kHasValidate<ClickHouse> = true;
78
79} // namespace components
80
81USERVER_NAMESPACE_END