Skip to content

Commit 843c6e4

Browse files
committed
fix(otlp): composed schema shared by all build consumers
1 parent 95e873b commit 843c6e4

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

lib/datadog-agent/config-overlay-model/src/schema_gen.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ pub struct FieldInfo {
9494
pub fn load_schema(datadog_schema: &Path, otel_schema_dir: &Path) -> IndexMap<String, FieldInfo> {
9595
let doc = crate::load_composed_schema(datadog_schema, otel_schema_dir)
9696
.unwrap_or_else(|e| panic!("failed to load composed schema: {e}"));
97+
load_schema_from_value(&doc)
98+
}
99+
100+
/// Builds the flat `yaml_path → FieldInfo` map from a pre-loaded composed schema.
101+
///
102+
/// Callers that already hold the composed schema should use this instead of [`load_schema`] to
103+
/// avoid a redundant disk read and guarantee every consumer sees the same document.
104+
pub fn load_schema_from_value(doc: &serde_yaml::Value) -> IndexMap<String, FieldInfo> {
97105
let properties = doc
98106
.get("properties")
99107
.and_then(|v| v.as_mapping())

lib/datadog-agent/config/build.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::PathBuf;
22

3-
use datadog_agent_config_overlay_model::{schema_gen, Files, SchemaOverlay};
3+
use datadog_agent_config_overlay_model::{load_composed_schema, schema_gen, Files, SchemaOverlay};
44

55
#[path = "build/classifier_gen.rs"]
66
mod classifier_gen;
@@ -28,12 +28,14 @@ fn main() {
2828
println!("cargo:rerun-if-changed=build/env_reader_gen.rs");
2929
println!("cargo:rerun-if-changed=build/witness_gen.rs");
3030

31-
let schema_path = files.datadog_schema.clone();
32-
let schema_map = schema_gen::load_schema(&files.datadog_schema, &files.otel_schema_dir);
31+
// Load the composed schema once and pass the in-memory value to every consumer.
32+
let composed_schema = load_composed_schema(&files.datadog_schema, &files.otel_schema_dir)
33+
.unwrap_or_else(|e| panic!("failed to load composed schema: {e}"));
34+
let schema_map = schema_gen::load_schema_from_value(&composed_schema);
3335
let overlay = SchemaOverlay::load(files).unwrap_or_else(|e| panic!("{e}"));
3436

3537
classifier_gen::generate(&overlay, &schema_map, &manifest_dir);
36-
datadog_config_gen::generate(&overlay, &schema_path, &schema_map, &manifest_dir);
38+
datadog_config_gen::generate(&overlay, &composed_schema, &schema_map, &manifest_dir);
3739
env_reader_gen::generate(&overlay, &schema_map, &manifest_dir);
3840
// Must run after datadog_config_gen: it parses the freshly-written datadog_configuration.rs.
3941
witness_gen::generate(&overlay, &manifest_dir);

lib/datadog-agent/config/build/datadog_config_gen.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
2424
use std::path::Path;
2525

2626
use datadog_agent_config_overlay_model::schema_gen::{FieldInfo, FieldType};
27-
use datadog_agent_config_overlay_model::{load_resolved_schema, InputShape, KnownEntry, SchemaOverlay};
27+
use datadog_agent_config_overlay_model::{InputShape, KnownEntry, SchemaOverlay};
2828
use indexmap::IndexMap;
2929
use serde_json::{Map, Value};
3030
use syn::visit_mut::{self, VisitMut};
@@ -43,16 +43,13 @@ const LEAF_KEYWORDS: &[&str] = &[
4343
];
4444

4545
pub fn generate(
46-
overlay: &SchemaOverlay, schema_path: &Path, schema_map: &IndexMap<String, FieldInfo>, manifest_dir: &Path,
46+
overlay: &SchemaOverlay, composed_schema: &serde_yaml::Value, schema_map: &IndexMap<String, FieldInfo>,
47+
manifest_dir: &Path,
4748
) {
4849
let supported = supported_keys(overlay);
4950

50-
// Load the schema with all `$ref` files inlined (apm_config, multi_region_failover, ...).
51-
// Without $ref resolution those subsystem keys are silently absent and the witness driver
52-
// cannot cover them. Delegate to overlay-model's resolver rather than duplicating it.
53-
let schema_yaml = load_resolved_schema(schema_path).unwrap_or_else(|e| panic!("failed to load schema: {e}"));
5451
let schema: Value =
55-
serde_json::to_value(schema_yaml).unwrap_or_else(|e| panic!("failed to convert schema to JSON: {e}"));
52+
serde_json::to_value(composed_schema).unwrap_or_else(|e| panic!("failed to convert schema to JSON: {e}"));
5653
let properties = schema
5754
.get("properties")
5855
.and_then(Value::as_object)

0 commit comments

Comments
 (0)