userver: userver/clients/dns/component.hpp Source File
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/clients/dns/component.hpp
4/// @brief @copybrief clients::dns::Component
5
6#include <userver/clients/dns/resolver.hpp>
7#include <userver/components/component_base.hpp>
8#include <userver/utils/statistics/entry.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace clients::dns {
13
14// clang-format off
15
16/// @ingroup userver_components
17///
18/// @brief Caching DNS resolver component.
19///
20/// Returned references to clients::dns::Resolver live for a lifetime
21/// of the component and are safe for concurrent use.
22///
23/// ## Static options:
24/// Name | Description | Default value
25/// ---- | ----------- | -------------
26/// fs-task-processor | task processor for disk I/O operations | -
27/// hosts-file-path | path to the `hosts` file | /etc/hosts
28/// hosts-file-update-interval | `hosts` file cache reload interval | 5m
29/// network-timeout | timeout for network requests | 1s
30/// network-attempts | number of attempts for network requests | 1
31/// network-custom-servers | list of name servers to use | from `/etc/resolv.conf`
32/// cache-ways | number of ways for network cache | 16
33/// cache-size-per-way | size of each way of network cache | 256
34/// cache-max-reply-ttl | TTL limit for network replies caching | 5m
35/// cache-failure-ttl | TTL for network failures caching | 5s
36///
37/// ## Static configuration example:
38///
39/// @snippet components/common_component_list_test.cpp Sample dns client component config
40
41// clang-format on
42class Component final : public components::ComponentBase {
43public:
44 /// @ingroup userver_component_names
45 /// @brief The default name of clients::dns::Component component
46 static constexpr std::string_view kName = "dns-client";
47
48 Component(const components::ComponentConfig&, const components::ComponentContext&);
49
50 Resolver& GetResolver();
51
52 static yaml_config::Schema GetStaticConfigSchema();
53
54private:
55 void Write(utils::statistics::Writer& writer);
56
57 Resolver resolver_;
58 utils::statistics::Entry statistics_holder_;
59};
60
61} // namespace clients::dns
62
63template <>
64inline constexpr bool components::kHasValidate<clients::dns::Component> = true;
65
66USERVER_NAMESPACE_END