这是indexloc提供的服务,不要输入任何密码
Skip to content

skip system and unsample-able collections in introspection #160

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

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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ This changelog documents the changes between release versions.

### Fixed

- Database introspection no longer fails if any individual collection cannot be sampled ([#160](https://github.com/hasura/ndc-mongodb/pull/160))

## [1.7.1] - 2025-03-12

### Added

- Add watch command while initializing metadata (#157)
- Add watch command while initializing metadata ([#157](https://github.com/hasura/ndc-mongodb/pull/157))

### Changed

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ anyhow = "1.0.80"
clap = { version = "4.5.1", features = ["derive", "env"] }
enum-iterator = "^2.0.0"
futures-util = "0.3.28"
indent = "^0.1.1"
indexmap = { workspace = true }
itertools = { workspace = true }
json-structural-diff = "^0.2.0"
Expand Down
25 changes: 22 additions & 3 deletions crates/cli/src/introspection/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ pub async fn sample_schema_from_db(
while let Some(collection_spec) = collections_cursor.try_next().await? {
let collection_name = collection_spec.name;

// The `system.*` namespace is reserved for internal use. In some deployments, such as
// MongoDB v6 running on Atlas, aggregate permissions are denied for `system.views` which
// causes introspection to fail. So we skip those collections.
if collection_name.starts_with("system.") {
log_warning!("collection {collection_name} is under the system namespace which is reserved for internal use - skipping");
continue;
}

let previously_defined_collection =
previously_defined_collections.remove(collection_name.as_str());

Expand All @@ -96,15 +104,26 @@ pub async fn sample_schema_from_db(
.map(|c| c.collection.r#type.clone())
.unwrap_or_else(|| collection_name.clone().into());

let Some(collection_schema) = sample_schema_from_collection(
let sample_result = match sample_schema_from_collection(
&collection_name,
collection_type_name.clone(),
sample_size,
all_schema_nullable,
db,
)
.await?
else {
.await
{
Ok(schema) => schema,
Err(err) => {
let indented_error = indent::indent_all_by(2, err.to_string());
log_warning!(
"an error occurred attempting to sample collection, {collection_name} - skipping\n{indented_error}"
);
continue;
}
};

let Some(collection_schema) = sample_result else {
log_warning!("could not find any documents to sample from collection, {collection_name} - skipping");
continue;
};
Expand Down
Loading