|
1 | 1 | #pragma once |
2 | 2 |
|
3 | | -// TODO: Document |
| 3 | +// Remote Configuration is a Datadog capability that allows a user to remotely |
| 4 | +// configure and change the behaviour of the tracing library. |
| 5 | +// The current implementation is restricted to Application Performance |
| 6 | +// Monitoring features. |
| 7 | +// |
| 8 | +// The `RemoteConfigurationManager` class implement the protocol to query, |
| 9 | +// process and verify configuration from a remote source. It is also |
| 10 | +// responsible for handling configuration updates received from a remote source |
| 11 | +// and maintains the state of applied configuration. |
| 12 | +// It interacts with the `ConfigManager` to seamlessly apply or revert |
| 13 | +// configurations based on responses received from the remote source. |
4 | 14 |
|
5 | 15 | #include <string> |
6 | 16 |
|
|
10 | 20 | #include "runtime_id.h" |
11 | 21 | #include "string_view.h" |
12 | 22 | #include "trace_sampler_config.h" |
13 | | -#include "tracer_id.h" |
| 23 | +#include "tracer_signature.h" |
14 | 24 |
|
15 | 25 | namespace datadog { |
16 | 26 | namespace tracing { |
17 | 27 |
|
18 | 28 | class RemoteConfigurationManager { |
| 29 | + // Represents the *current* state of the RemoteConfigurationManager. |
| 30 | + // It is also used to report errors to the remote source. |
19 | 31 | struct State { |
20 | 32 | uint64_t targets_version = 1; |
21 | 33 | std::string opaque_backend_state; |
22 | 34 | Optional<std::string> error_message; |
23 | 35 | }; |
24 | 36 |
|
| 37 | + // Holds information about a specific configuration update, |
| 38 | + // including its identifier, hash value, version number and the content. |
25 | 39 | struct Configuration { |
26 | 40 | std::string id; |
27 | 41 | std::string hash; |
28 | 42 | std::size_t version; |
29 | 43 | ConfigUpdate content; |
30 | 44 | }; |
31 | 45 |
|
32 | | - TracerID tracer_id_; |
| 46 | + TracerSignature tracer_signature_; |
33 | 47 | ConfigManager& config_manager_; |
34 | | - std::string client_id_; |
| 48 | + std::string client_id_; ///< Identifier a `RemoteConfigurationManager` |
35 | 49 |
|
36 | 50 | State state_; |
37 | 51 | std::unordered_map<std::string, Configuration> applied_config_; |
38 | 52 |
|
39 | 53 | public: |
40 | | - RemoteConfigurationManager(const TracerID& tracer_id, |
| 54 | + RemoteConfigurationManager(const TracerSignature& tracer_signature, |
41 | 55 | ConfigManager& config_manager); |
42 | 56 |
|
| 57 | + // Construct a JSON object representing the payload to be sent in a remote |
| 58 | + // configuration request. |
43 | 59 | nlohmann::json make_request_payload(); |
44 | 60 |
|
| 61 | + // Handles the response received from a remote source and udates the internal |
| 62 | + // state accordingly. |
45 | 63 | void process_response(const nlohmann::json& json); |
46 | 64 |
|
47 | 65 | private: |
| 66 | + // Tell if a `config_path` is a new configuration update. |
48 | 67 | bool is_new_config(StringView config_path, const nlohmann::json& config_meta); |
49 | 68 |
|
| 69 | + // Apply a remote configuration. |
50 | 70 | void apply_config(Configuration config); |
| 71 | + |
| 72 | + // Revert a remote configuration. |
51 | 73 | void revert_config(Configuration config); |
52 | 74 | }; |
53 | 75 |
|
|
0 commit comments