-
Notifications
You must be signed in to change notification settings - Fork 2.2k
chore(config): begin laying out primitives for programmatically querying schema #17130
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
Changes from 6 commits
04e6a00
ccbe0a5
57167f9
e70a41d
6c58d71
eecf625
03262ef
e51cee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this crate intended for use in anything other than
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that I can foresee, and I did have the thought that it might make more sense just to move it entirely into |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [package] | ||
| name = "docs-renderer" | ||
| version = "0.1.0" | ||
| authors = ["Vector Contributors <vector@datadoghq.com>"] | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| anyhow = { version = "1.0.66", default-features = false, features = ["std"] } | ||
| serde = { version = "1.0", default-features = false } | ||
| serde_json = { version = "1.0", default-features = false, features = ["std"] } | ||
| snafu = { version = "0.7.4", default-features = false } | ||
| tracing = { version = "0.1.34", default-features = false } | ||
| tracing-subscriber = { version = "0.3.16", default-features = false, features = ["ansi", "env-filter", "fmt", "json", "registry", "tracing-log"] } | ||
| vector-config = { path = "../vector-config" } | ||
| vector-config-common = { path = "../vector-config-common" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| mod renderer; | ||
|
|
||
| use std::collections::HashMap; | ||
|
|
||
| use crate::renderer::SchemaRenderer; | ||
| use anyhow::{Context, Result}; | ||
| use tracing::debug; | ||
| use vector_config::schema::parser::{component::ComponentSchema, query::SchemaQuerier}; | ||
| use vector_config_common::constants::{self, ComponentType}; | ||
|
|
||
| fn main() -> Result<()> { | ||
| let querier = SchemaQuerier::from_schema("/tmp/vector-config-schema.json") | ||
| .context("Failed to create querier from given schema file path.")?; | ||
|
|
||
| let base_component_types = &[ | ||
| ComponentType::Source, | ||
| ComponentType::Transform, | ||
| ComponentType::Sink, | ||
| ]; | ||
| for base_component_type in base_component_types { | ||
| // Find the base component schema for the component type itself, which is analogous to | ||
| // `SourceOuter`, `SinkOuter`, etc. We render the schema for that separately as it's meant | ||
| // to be common across components of the same type, etc. | ||
| let base_component_schema = querier | ||
| .query() | ||
| .with_custom_attribute_kv( | ||
| constants::DOCS_META_COMPONENT_BASE_TYPE, | ||
| base_component_type, | ||
| ) | ||
| .run_single()?; | ||
|
|
||
| debug!( | ||
| "Got base component schema for component type '{}'.", | ||
| base_component_type.as_str() | ||
| ); | ||
|
|
||
| // Find all component schemas of the same component type. | ||
| let maybe_component_schemas = querier | ||
| .query() | ||
| .with_custom_attribute_kv(constants::DOCS_META_COMPONENT_TYPE, base_component_type) | ||
| .run() | ||
| .into_iter() | ||
| .map(ComponentSchema::try_from) | ||
| .collect::<Result<Vec<_>, _>>()?; | ||
|
|
||
| debug!( | ||
| "Found {} component schema(s) for component type '{}'.", | ||
| maybe_component_schemas.len(), | ||
| base_component_type.as_str() | ||
| ); | ||
|
|
||
| let mut rendered_component_schemas = HashMap::new(); | ||
|
|
||
| // Render the base component schema. | ||
| let base_component_schema_renderer = SchemaRenderer::new(&querier, base_component_schema); | ||
| let rendered_base_component_schema = | ||
| base_component_schema_renderer.render().context(format!( | ||
| "Failed to render the base component schema for component type '{}'.", | ||
| base_component_type.as_str() | ||
| ))?; | ||
| rendered_component_schemas.insert( | ||
| format!("base/{}", base_component_type.as_str()), | ||
| rendered_base_component_schema, | ||
| ); | ||
|
|
||
| // Render each of the component schemas for this component type. | ||
| for component_schema in maybe_component_schemas { | ||
| let component_name = component_schema.component_name().to_string(); | ||
| let component_schema_renderer = SchemaRenderer::new(&querier, component_schema); | ||
| let rendered_component_schema = component_schema_renderer.render().context(format!( | ||
| "Failed to render the '{}' component schema.", | ||
| component_name | ||
| ))?; | ||
| rendered_component_schemas.insert( | ||
| format!("{}s/base/{}", base_component_type.as_str(), component_name), | ||
| rendered_component_schema, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.