Skip to main content

datadog_agent_config_testing/config_registry/
mod.rs

1/// Datadog Agent configuration annotations, generated from `schema_overlay.yaml`.
2///
3/// Type definitions live here (hand-written); generated annotation constants and statics
4/// live in `annotations_index.rs` (generated in-tree by `build.rs`).
5pub use datadog_agent_config::classifier::{structs, Pipeline, PipelineAffinity, Severity};
6
7/// Support level for a configuration key, as recorded in the testing annotation layer.
8///
9/// Unlike the prod [`datadog_agent_config::classifier::SupportLevel`], this enum includes
10/// [`Full`][SupportLevel::Full] so that generated annotation constants can express keys that work
11/// identically to the core agent. The prod classifier omits `Full` because fully supported keys
12/// require no diagnostic action.
13#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14pub enum SupportLevel {
15    /// Fully supported with identical behavior to the core agent.
16    Full,
17    /// Supported but with behavioral or default-value differences.
18    Partial,
19    /// Explicitly incompatible; ADP does not support this key.
20    Incompatible(Severity),
21    /// Intentionally ignored.
22    #[allow(unused)]
23    Ignored,
24    /// Unrecognized by ADP.
25    #[allow(unused)]
26    Unrecognized,
27}
28
29/// Declares a set of [`SalukiAnnotation`] constants and generates a companion `ALL` slice.
30///
31/// Each entry declares one named `pub const` annotation. The macro also emits:
32///
33/// ```ignore
34/// pub const ALL: &[&SalukiAnnotation] = &[&NAME1, &NAME2, ...];
35/// ```
36///
37/// so that `annotations_index.rs` can aggregate submodules with a single
38/// `v.extend_from_slice(my_module::ALL)` line rather than listing every constant by name.
39#[macro_export]
40macro_rules! declare_annotations {
41    ( $( $(#[$attr:meta])* $name:ident = $val:expr ;)+ ) => {
42        $(
43            $(#[$attr])*
44            pub const $name: $crate::config_registry::SalukiAnnotation = $val;
45        )+
46
47        /// All annotations declared in this module, in declaration order.
48        pub const ALL: &[$crate::config_registry::SalukiAnnotationRef] = &[
49            $( &$name, )+
50        ];
51    };
52}
53
54/// The shape of a configuration value.
55#[derive(Clone, Copy, Debug, PartialEq, Eq)]
56pub enum ValueType {
57    /// A boolean (`true` / `false`).
58    Bool,
59    /// A UTF-8 string.
60    String,
61    /// An unsigned integer.
62    Integer,
63    /// A floating-point number.
64    Float,
65    /// A list of strings (YAML sequence or space-separated env var string).
66    StringList,
67}
68
69/// Which schema source of truth defined the `SchemaEntry`
70#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
71#[repr(u8)]
72pub(crate) enum Schema {
73    /// Saluki defined the `SchemaEntry`.
74    Saluki,
75    /// The vendored Datadog config schema defines the `SchemaEntry`.
76    Datadog,
77}
78
79/// Schema-derived metadata for a single configuration key.
80#[derive(Debug)]
81pub struct SchemaEntry {
82    /// The source of truth from which this entry was derived.
83    #[allow(dead_code)]
84    pub(crate) schema: Schema,
85
86    /// Canonical dot-separated YAML path for this key (for example, `"proxy.http"`).
87    pub yaml_path: &'static str,
88
89    /// Environment variables that deliver this value, as declared in the schema.
90    pub env_vars: &'static [&'static str],
91
92    /// Shape of the value.
93    pub value_type: ValueType,
94
95    /// JSON-encoded default value from the Agent schema, if present.
96    pub default: Option<&'static str>,
97}
98
99/// Saluki-specific annotation for a single configuration key.
100#[derive(Debug)]
101pub struct SalukiAnnotation {
102    /// The schema entry this annotation enriches.
103    pub schema: &'static SchemaEntry,
104
105    /// How well saluki supports this key.
106    pub support_level: SupportLevel,
107
108    /// Additional YAML paths beyond the canonical one in the schema (aliases).
109    pub additional_yaml_paths: &'static [&'static str],
110
111    /// Overrides the schema's `env_vars` list entirely when `Some`.
112    pub env_var_override: Option<&'static [&'static str]>,
113
114    /// Config structs that incorporate this key, as [`structs`] constants.
115    pub used_by: &'static [&'static str],
116
117    /// Overrides the schema's `value_type` when `Some`.
118    pub value_type_override: Option<ValueType>,
119
120    /// Overrides the smoke-test injected value entirely when `Some`.
121    pub test_json: Option<&'static str>,
122
123    /// Which pipelines this key affects.
124    pub pipeline_affinity: PipelineAffinity,
125}
126
127/// A reference to a [`SalukiAnnotation`], used as the element type of `ALL` slices generated by
128/// [`declare_annotations!`].
129pub type SalukiAnnotationRef = &'static SalukiAnnotation;
130
131impl SalukiAnnotation {
132    /// The canonical YAML path for this key (from the schema).
133    pub fn yaml_path(&self) -> &'static str {
134        self.schema.yaml_path
135    }
136
137    /// All YAML paths for this key: canonical first, then any aliases.
138    pub fn all_yaml_paths(&self) -> impl Iterator<Item = &'static str> {
139        std::iter::once(self.schema.yaml_path).chain(self.additional_yaml_paths.iter().copied())
140    }
141
142    /// Effective env vars: the override list if set, otherwise the schema's list.
143    pub fn effective_env_vars(&self) -> &'static [&'static str] {
144        self.env_var_override.unwrap_or(self.schema.env_vars)
145    }
146
147    /// Shape of the value: override if set, otherwise from the schema.
148    pub fn value_type(&self) -> ValueType {
149        self.value_type_override.unwrap_or(self.schema.value_type)
150    }
151}
152
153/// A fully resolved configuration key.
154#[derive(Debug)]
155pub struct ConfigKey {
156    /// All dot-separated YAML paths that deliver this value.
157    pub yaml_paths: Vec<&'static str>,
158
159    /// All environment variables that deliver this value.
160    pub env_vars: Vec<&'static str>,
161
162    /// Shape of the value.
163    pub value_type: ValueType,
164
165    /// Config structs that incorporate this key, as [`structs`] constants.
166    pub used_by: &'static [&'static str],
167}
168
169impl From<&SalukiAnnotation> for ConfigKey {
170    fn from(a: &SalukiAnnotation) -> Self {
171        ConfigKey {
172            yaml_paths: a.all_yaml_paths().collect(),
173            env_vars: a.effective_env_vars().to_vec(),
174            value_type: a.value_type(),
175            used_by: a.used_by,
176        }
177    }
178}
179
180// Generated module containing all annotation constants and the aggregation statics.
181include!("annotations_index.rs");