datadog_agent_config_corpus/lists.rs
1//! Allowed names in saved Agent configuration records, represented as Rust enums.
2//!
3//! The corpus reader uses these lists to reject unknown names instead of silently accepting a
4//! recording it cannot interpret. [`Source`] identifies where a setting came from, [`Getter`]
5//! names the Agent method called, [`Group`] describes a test case's coverage, and [`Level`]
6//! identifies a recorded warning's severity.
7//!
8//! Agent names were manually reviewed at [`REVIEWED_AT_AGENT_COMMIT`]; the recording format
9//! defines the case groups and permitted reads. When the schema pin changes, review the lists
10//! against their cited definitions before updating that constant.
11
12use std::fmt;
13
14/// The Agent commit these lists were last checked against.
15pub const REVIEWED_AT_AGENT_COMMIT: &str = "72cc7f34878cff03a4cc37be298d8902e0e492d1";
16
17/// Declares a string enum with its full list and its string forms.
18macro_rules! string_enum {
19 ($(#[$meta:meta])* $name:ident, $all:ident { $($(#[$vmeta:meta])* $variant:ident => $text:literal,)* }) => {
20 $(#[$meta])*
21 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
22 pub enum $name {
23 $($(#[$vmeta])* $variant,)*
24 }
25
26 impl $name {
27 /// Every variant, in declaration order.
28 pub const $all: &'static [$name] = &[$($name::$variant,)*];
29
30 /// The name as the corpus writes it.
31 pub fn as_str(self) -> &'static str {
32 match self {
33 $($name::$variant => $text,)*
34 }
35 }
36
37 /// Parses the name as the corpus writes it.
38 pub fn parse(s: &str) -> Option<Self> {
39 match s {
40 $($text => Some($name::$variant),)*
41 _ => None,
42 }
43 }
44 }
45
46 impl fmt::Display for $name {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 f.write_str(self.as_str())
49 }
50 }
51 };
52}
53
54string_enum! {
55 /// A `model.Source` string (`pkg/config/model/types.go:41-71` at the pin).
56 Source, ALL {
57 /// `schema`.
58 Schema => "schema",
59 /// `default`.
60 Default => "default",
61 /// `unknown`.
62 Unknown => "unknown",
63 /// `infra-mode`.
64 InfraMode => "infra-mode",
65 /// `file`.
66 File => "file",
67 /// `environment-variable`.
68 EnvironmentVariable => "environment-variable",
69 /// `config-post-init`.
70 ConfigPostInit => "config-post-init",
71 /// `secret`.
72 Secret => "secret",
73 /// `local-config-process`.
74 LocalConfigProcess => "local-config-process",
75 /// `agent-runtime`.
76 AgentRuntime => "agent-runtime",
77 /// `remote-config`.
78 RemoteConfig => "remote-config",
79 /// `fleet-policies`.
80 FleetPolicies => "fleet-policies",
81 /// `cli`.
82 Cli => "cli",
83 /// `provided`.
84 Provided => "provided",
85 /// The empty string: a streamed setting's `source` is written even when `""` (record.md §5.1).
86 /// Only legal there; a read source, an update source or an `unset_source` must never be `""`.
87 Empty => "",
88 }
89}
90
91impl Source {
92 /// The sources a case update may write or clear (case.md §5; `pkg/config/model/types.go:49-69`).
93 pub const UPDATE: &'static [Source] = &[
94 Source::InfraMode,
95 Source::File,
96 Source::EnvironmentVariable,
97 Source::FleetPolicies,
98 Source::ConfigPostInit,
99 Source::Secret,
100 Source::LocalConfigProcess,
101 Source::AgentRuntime,
102 Source::RemoteConfig,
103 Source::Cli,
104 ];
105}
106
107string_enum! {
108 /// An Agent getter a read may call (getter-map.md §2).
109 Getter, ALL {
110 /// `Get`, returning `interface{}`.
111 Get => "Get",
112 /// `GetString`, returning `string`.
113 GetString => "GetString",
114 /// `GetBool`, returning `bool`.
115 GetBool => "GetBool",
116 /// `GetInt`, returning `int`.
117 GetInt => "GetInt",
118 /// `GetInt32`, returning `int32`.
119 GetInt32 => "GetInt32",
120 /// `GetInt64`, returning `int64`.
121 GetInt64 => "GetInt64",
122 /// `GetFloat64`, returning `float64`.
123 GetFloat64 => "GetFloat64",
124 /// `GetFloat64Slice`, returning `[]float64`.
125 GetFloat64Slice => "GetFloat64Slice",
126 /// `GetDuration`, returning `time.Duration`.
127 GetDuration => "GetDuration",
128 /// `GetStringSlice`, returning `[]string`.
129 GetStringSlice => "GetStringSlice",
130 /// `GetStringMap`, returning `map[string]interface{}`.
131 GetStringMap => "GetStringMap",
132 /// `GetStringMapString`, returning `map[string]string`.
133 GetStringMapString => "GetStringMapString",
134 /// `GetStringMapStringSlice`, returning `map[string][]string`.
135 GetStringMapStringSlice => "GetStringMapStringSlice",
136 /// `GetSizeInBytes`, returning `uint`.
137 GetSizeInBytes => "GetSizeInBytes",
138 /// The Agent's OTLP section read, `configcheck.ReadConfigSection(cfg, key).ToStringMap()`, returning
139 /// `map[string]interface{}` (getter-map.md §2.1). It keeps only the section's configured leaves, plus
140 /// sections declared with a nil value, so schema defaults are absent. It is never a default getter.
141 ReadConfigSection => "ReadConfigSection",
142 /// `cfg.IsConfigured(key)` (`nodetreemodel/config.go:956`), returning `bool` (getter-map.md §2.1). It
143 /// reports whether the user set the key, not the key's value. It is never a default getter.
144 IsConfigured => "IsConfigured",
145 }
146}
147
148string_enum! {
149 /// A case's coverage group (case.md §3).
150 Group, ALL {
151 /// One case with no inputs, recording every modeled key.
152 Baseline => "baseline",
153 /// Every modeled key, set from each source.
154 Breadth => "breadth",
155 /// Representative modeled keys, with variants.
156 Depth => "depth",
157 /// Every unsupported schema key.
158 Unsupported => "unsupported",
159 /// Representatives of the excluded keys.
160 Excluded => "excluded",
161 /// Keys that are not in the schema.
162 Unknown => "unknown",
163 /// Hand-written cases, each naming behavior catalog entries in its `why` list.
164 Behavior => "behavior",
165 }
166}
167
168string_enum! {
169 /// A recorded warning's slog level (record.md §7).
170 Level, ALL {
171 /// `WARN`.
172 Warn => "WARN",
173 /// `ERROR`.
174 Error => "ERROR",
175 }
176}