Skip to main content

datadog_agent_config/classifier/
mod.rs

1//! Configuration key classifier.
2//!
3//! A programmatic registry of all recognized configuration keys. Each entry describes the key
4//! purely from the configuration system's perspective: its canonical YAML path, the environment
5//! variables that map to it, the shape of its value, and which internal config structs consume it.
6//!
7//! This registry is intentionally free of Rust field names and struct internals—it models the
8//! configuration surface as an operator would see it, and can be used at runtime to detect
9//! unknown or unsupported keys in a loaded configuration file.
10//!
11//! ## User Guide
12//!
13//! The registry is generated at build time from `schema_overlay.yaml`, which partitions every
14//! key in `core_schema.yaml` into exactly one of: supported, unsupported, or ignored. Data
15//! integrity (uniqueness, full coverage, sorted sections) is enforced by `SchemaOverlay::load()`
16//! during the build.
17//!
18//! ### Adding a Configuration Key
19//!
20//! Add a `supported` entry in `lib/datadog-agent/config/schema/schema_overlay.yaml` with
21//! `support_level`, `pipelines`, `used_by`, `description`, and `config_registry_filename`.
22//! The build generates the annotation constants automatically.
23//!
24//! ### Updating the Vendored Schema
25//!
26//! After updating `core_schema.yaml`, the build will fail if any new keys are not covered
27//! by the overlay. For each new key, add it to the appropriate section of
28//! `schema_overlay.yaml`.
29
30#[allow(clippy::module_inception)]
31mod classifier;
32
33pub use classifier::{Classification, ConfigClassifier};
34
35/// Identifiers for known configuration structs.
36///
37/// Used as values in annotation `used_by` fields to declare which structs consume a given key.
38/// Adding a new struct here is the first step when registering its configuration keys.
39pub mod structs {
40    /// Identifier for `ProxyConfiguration`.
41    pub const PROXY_CONFIGURATION: &str = "ProxyConfiguration";
42    /// Identifier for `ForwarderConfiguration`.
43    pub const FORWARDER_CONFIGURATION: &str = "ForwarderConfiguration";
44    /// Identifier for `DogStatsDConfiguration`.
45    pub const DOGSTATSD_CONFIGURATION: &str = "DogStatsDConfiguration";
46    /// Identifier for `ContainerdConfiguration`.
47    pub const CONTAINERD_CONFIGURATION: &str = "ContainerdConfiguration";
48    /// Identifier for `OtlpConfiguration`.
49    pub const OTLP_CONFIGURATION: &str = "OtlpConfiguration";
50    /// Identifier for `AggregateConfiguration`.
51    pub const AGGREGATE_CONFIGURATION: &str = "AggregateConfiguration";
52    /// Identifier for `DogStatsDMapperConfiguration`.
53    pub const DOGSTATSD_MAPPER_CONFIGURATION: &str = "DogStatsDMapperConfiguration";
54    /// Identifier for `DogStatsDDebugLogConfiguration`.
55    pub const DOGSTATSD_DEBUG_LOG_CONFIGURATION: &str = "DogStatsDDebugLogConfiguration";
56    /// Identifier for `DogStatsDPrefixFilterConfiguration`.
57    pub const DOGSTATSD_PREFIX_FILTER_CONFIGURATION: &str = "DogStatsDPrefixFilterConfiguration";
58    /// Identifier for `DatadogMetricsConfiguration`.
59    pub const DATADOG_METRICS_CONFIGURATION: &str = "DatadogMetricsConfiguration";
60    /// Identifier for `DatadogTraceConfiguration`.
61    pub const DATADOG_TRACE_CONFIGURATION: &str = "DatadogTraceConfiguration";
62    /// Identifier for `DatadogLogsConfiguration`.
63    pub const DATADOG_LOGS_CONFIGURATION: &str = "DatadogLogsConfiguration";
64    /// Identifier for `DatadogEventsConfiguration`.
65    pub const DATADOG_EVENTS_CONFIGURATION: &str = "DatadogEventsConfiguration";
66    /// Identifier for `DatadogServiceChecksConfiguration`.
67    pub const DATADOG_SERVICE_CHECKS_CONFIGURATION: &str = "DatadogServiceChecksConfiguration";
68    /// Identifier for `DatadogApmStatsEncoderConfiguration`.
69    pub const DATADOG_APM_STATS_ENCODER_CONFIGURATION: &str = "DatadogApmStatsEncoderConfiguration";
70    /// Identifier for `MrfConfiguration`.
71    pub const MRF_CONFIGURATION: &str = "MrfConfiguration";
72    /// Identifier for `OtlpDecoderConfiguration`.
73    pub const OTLP_DECODER_CONFIGURATION: &str = "OtlpDecoderConfiguration";
74    /// Identifier for `OtlpRelayConfiguration`.
75    pub const OTLP_RELAY_CONFIGURATION: &str = "OtlpRelayConfiguration";
76    /// Identifier for `TraceObfuscationConfiguration`.
77    pub const TRACE_OBFUSCATION_CONFIGURATION: &str = "TraceObfuscationConfiguration";
78    /// Identifier for `RemoteAgentClientConfiguration`.
79    pub const REMOTE_AGENT_CLIENT_CONFIGURATION: &str = "RemoteAgentClientConfiguration";
80    /// Identifier for `TagFilterlistConfiguration`.
81    pub const TAG_FILTERLIST_CONFIGURATION: &str = "TagFilterlistConfiguration";
82    /// Keys read via `get_typed` / `try_get_typed` rather than struct deserialization.
83    pub const GET_TYPED: &str = "get_typed";
84}
85
86/// The ADP pipeline a config key affects.
87#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
88pub enum Pipeline {
89    /// DogStatsD metrics pipeline.
90    DogStatsD,
91    /// Agent checks pipeline.
92    Checks,
93    /// OTLP ingestion frontend.
94    Otlp,
95    /// Internal trace processing. Active when OTLP is enabled and proxy/relay mode (which uses the
96    /// core Agent for transport) is off.
97    Traces,
98}
99
100/// Which pipelines a config key affects.
101#[derive(Clone, Copy, Debug, PartialEq, Eq)]
102pub enum PipelineAffinity {
103    /// The list of pipelines affected by the key.
104    ///
105    /// This list must be non-empty, enforced by test.
106    Pipelines(&'static [Pipeline]),
107    /// The key affects all pipelines or ADP behavior as a whole.
108    CrossCutting,
109}
110
111/// The `Severity` level of a config key that Saluki doesn't support.
112#[derive(Clone, Copy, Debug, PartialEq, Eq)]
113pub enum Severity {
114    /// Saluki's incompatibility with the key is considered minor.
115    Low,
116
117    /// Saluki's incompatibility with the key is considered potentially impactful.
118    Medium,
119
120    /// Saluki's incompatibility with the key is considered problematic.
121    High,
122}
123
124/// The support level for a given configuration key.
125///
126/// Full support is omitted from the enum and those keys are not classified since there is nothing
127/// to be done about them downstream.
128#[derive(Clone, Copy, Debug, PartialEq, Eq)]
129pub enum SupportLevel {
130    /// Partially supported.
131    Partial,
132    /// Explicitly incompatible.
133    Incompatible(Severity),
134    /// Intentionally ignored.
135    #[allow(unused)]
136    Ignored,
137    /// Unrecognized.
138    #[allow(unused)]
139    Unrecognized,
140}
141
142/// Slim per-key data generated at build time for the classifier.
143///
144/// Carries only what the classifier needs: enough to look up a key, determine its support level,
145/// check whether a value is the default, and report which pipelines are affected.
146pub struct ClassifierEntry {
147    /// Canonical dot-separated YAML path.
148    pub yaml_path: &'static str,
149    /// Additional YAML paths (aliases) that resolve to this key.
150    pub aliases: &'static [&'static str],
151    /// How well saluki supports this key.
152    pub support_level: SupportLevel,
153    /// Which pipelines this key affects.
154    pub pipeline_affinity: PipelineAffinity,
155    /// JSON-encoded default value from the Agent schema, if present.
156    pub default: Option<&'static str>,
157}
158
159mod classifier_data;
160use classifier_data::CLASSIFIER_ENTRIES;