Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(config): Make config schema output ordered #17694

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/vector-config-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ license = "MPL-2.0"
[dependencies]
convert_case = { version = "0.6", default-features = false }
darling = { version = "0.13", default-features = false, features = ["suggestions"] }
indexmap = { version = "1.9", default-features = false, features = ["serde"] }
once_cell = { version = "1", default-features = false, features = ["std"] }
proc-macro2 = { version = "1.0", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive"] }
Expand Down
4 changes: 3 additions & 1 deletion lib/vector-config-common/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ pub mod visit;

pub(crate) const DEFINITIONS_PREFIX: &str = "#/definitions/";

pub type Map<K, V> = indexmap::IndexMap<K, V>;
// We have chosen the `BTree*` types here instead of hash tables to provide for a consistent
// ordering of the output elements between runs and changes to the configuration.
pub type Map<K, V> = std::collections::BTreeMap<K, V>;
pub type Set<V> = std::collections::BTreeSet<V>;

pub use self::gen::{SchemaGenerator, SchemaSettings};
Expand Down
12 changes: 2 additions & 10 deletions lib/vector-config/src/schema/visitors/inline_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,11 @@ impl Visitor for InlineSingleUseReferencesVisitor {
occurrence_visitor.visit_root_schema(root);
let occurrence_map = occurrence_visitor.into_occurrences();

let eligible_to_inline = occurrence_map
self.eligible_to_inline = occurrence_map
.into_iter()
// Filter out any schemas which have more than one occurrence, as naturally, we're
// trying to inline single-use schema references. :)
.filter_map(|(def_name, occurrences)| {
if occurrences == 1 {
Some(def_name)
} else {
None
}
})
.filter_map(|(def_name, occurrences)| (occurrences == 1).then_some(def_name))
// However, we'll also filter out some specific schema definitions which are only
// referenced once, specifically: component base types and component types themselves.
//
Expand All @@ -72,8 +66,6 @@ impl Visitor for InlineSingleUseReferencesVisitor {
.map(|s| s.as_ref().to_string())
.collect::<HashSet<_>>();

self.eligible_to_inline = eligible_to_inline;

// Now run our own visitor logic, which will use the inline eligibility to determine if a
// schema reference in a being-visited schema should be replaced inline with the original
// referenced schema, in turn removing the schema definition.
Expand Down
4 changes: 2 additions & 2 deletions lib/vector-config/src/schema/visitors/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Mergeable for serde_json::Map<String, Value> {

impl<K, V> Mergeable for Map<K, V>
where
K: std::hash::Hash + Eq + Clone,
K: Clone + Eq + Ord,
V: Clone + Mergeable,
{
fn merge(&mut self, other: &Self) {
Expand Down Expand Up @@ -261,7 +261,7 @@ where

fn merge_map<K, V>(destination: &mut Map<K, V>, source: &Map<K, V>)
where
K: std::hash::Hash + Eq + Clone,
K: Clone + Eq + Ord,
V: Clone + Mergeable,
{
destination.merge(source);
Expand Down
4 changes: 2 additions & 2 deletions lib/vector-config/src/schema/visitors/unevaluated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ fn is_markable_schema(definitions: &Map<String, Schema>, schema: &SchemaObject)
.as_ref()
.and_then(|reference| {
let reference = get_cleaned_schema_reference(reference);
definitions.get_full(reference)
definitions.get_key_value(reference)
})
.and_then(|(_, name, schema)| schema.as_object().map(|schema| (name, schema)))
.and_then(|(name, schema)| schema.as_object().map(|schema| (name, schema)))
.map_or(false, |(name, schema)| {
debug!(
"Following schema reference '{}' for subschema markability.",
Expand Down