userver: userver/dynamic_config/client/client.hpp Source File
Loading...
Searching...
No Matches
client.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <chrono>
7#include <optional>
8#include <string>
9#include <unordered_map>
10#include <vector>
11
14
15USERVER_NAMESPACE_BEGIN
16
17namespace clients::http {
18class Client;
19} // namespace clients::http
20
21namespace dynamic_config {
22
24 std::string service_name;
27 std::chrono::milliseconds timeout{0};
28 int retries{1};
29 std::string config_url;
31 std::vector<std::string> fallback_config_urls;
32 bool append_path_to_url{true};
33 std::string stage_name;
34 bool is_prestable{false};
35 std::string circuit;
37 std::vector<std::string> service_overrides;
39 std::unordered_map<std::string, formats::json::Value> additional_request_params{};
40};
41
49class Client final {
50public:
51 Client(clients::http::Client& http_client, const ClientConfig&);
52
53 ~Client();
54
55 using Timestamp = std::string;
56
57 struct Reply {
58 USERVER_NAMESPACE::dynamic_config::DocsMap docs_map;
59 std::vector<std::string> kill_switches_disabled;
60 std::vector<std::string> removed;
61 Timestamp timestamp;
62
63 bool IsEmpty() const { return docs_map.Size() == 0 && removed.empty(); }
64 };
65
66 struct JsonReply {
68 std::vector<std::string> kill_switches_disabled;
69 Timestamp timestamp;
70 };
71
72 Reply DownloadFullDocsMap();
73
74 Reply FetchDocsMap(const std::optional<Timestamp>& last_update, const std::vector<std::string>& fields_to_load);
75
76 JsonReply FetchJson(const std::optional<Timestamp>& last_update, const std::vector<std::string>& fields_to_load);
77
78private:
79 formats::json::Value FetchConfigs(
80 const std::optional<Timestamp>& last_update,
81 const std::vector<std::string>& fields_to_load
82 );
83
84 std::string FetchConfigsValues(std::string_view body);
85
86 std::string FetchConfigsValuesFrom(const std::string& url, std::string_view body);
87
88 const ClientConfig config_;
89 const std::vector<std::string> urls_;
90 clients::http::Client& http_client_;
91};
92
93} // namespace dynamic_config
94
95USERVER_NAMESPACE_END