Skip to content
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,287 changes: 1,258 additions & 29 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ anyhow = "1.0.100"
thiserror = "2.0.17"
tempfile = "3.23.0"
jsonschema = "0.36.0"
sentry = "0.46"
chrono = "0.4"
2 changes: 1 addition & 1 deletion clients/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Options {
let values_dir = base_dir.join("values");

let registry = Arc::new(SchemaRegistry::from_directory(&schemas_dir)?);
let loaded_values = registry.load_values_json(&values_dir)?;
let (loaded_values, _) = registry.load_values_json(&values_dir)?;
let values = Arc::new(RwLock::new(loaded_values));

let watcher_registry = Arc::clone(&registry);
Expand Down
4 changes: 2 additions & 2 deletions examples/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.13-slim AS builder

# Install build dependencies
RUN apt-get update && apt-get install -y curl build-essential && \
RUN apt-get update && apt-get install -y curl build-essential pkg-config libssl-dev && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

Expand All @@ -15,7 +15,7 @@ COPY clients ./clients
COPY examples/rust ./examples/rust

# Build Python wheel
RUN pip install maturin && \
RUN pip install maturin[patchelf] && \
cd clients/python && \
maturin build --release

Expand Down
2 changes: 1 addition & 1 deletion examples/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sentry_options::{init, options};
/// ^C to exit
fn main() -> anyhow::Result<()> {
init()?;
let sentry_options = options("testing");
let sentry_options = options("sentry-options-testing");

loop {
sleep(Duration::from_secs(3));
Expand Down
3 changes: 2 additions & 1 deletion examples/values/sentry-options-testing/values.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"options": {
"example-option": "this is my string value"
}
},
"generated_at": "2026-01-21T17:00:00+00:00"
}
12 changes: 6 additions & 6 deletions sentry-options-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,14 @@ fn cli_write(args: WriteArgs, quiet: bool) -> Result<()> {
let grouped = load_and_validate(&args.root, &schema_registry)?;
ensure_no_duplicate_keys(&grouped)?;

let generated_at = chrono::Utc::now().to_rfc3339();

match args.output_format {
OutputFormat::Json => {
let out_path = args.out.ok_or_else(|| {
AppError::Validation("--out is required for json output format".to_string())
})?;
let json_outputs = generate_json(grouped)?;
let json_outputs = generate_json(grouped, &generated_at)?;
let num_files = json_outputs.len();
write_json(PathBuf::from(&out_path), json_outputs)?;

Expand All @@ -243,8 +245,6 @@ fn cli_write(args: WriteArgs, quiet: bool) -> Result<()> {
let target = args.target.ok_or_else(|| {
AppError::Validation("--target is required for configmap output format".into())
})?;

let generated_at = chrono::Utc::now().to_rfc3339();
let configmap = generate_configmap(
&grouped,
&namespace,
Expand Down Expand Up @@ -690,7 +690,7 @@ mod tests {
);

let grouped = f.load().unwrap();
let json_outputs = generate_json(grouped).unwrap();
let json_outputs = generate_json(grouped, "2026-01-21T00:00:00Z").unwrap();

// Find the s4s output
let s4s_output = json_outputs
Expand Down Expand Up @@ -724,7 +724,7 @@ mod tests {
);

let grouped = f.load().unwrap();
let json_outputs = generate_json(grouped).unwrap();
let json_outputs = generate_json(grouped, "2026-01-21T00:00:00Z").unwrap();
let json_str = &json_outputs[0].1;

// Parse and check that keys are in alphabetical order
Expand Down Expand Up @@ -758,7 +758,7 @@ mod tests {
assert!(result.is_ok());

let grouped = result.unwrap();
let json_outputs = generate_json(grouped).unwrap();
let json_outputs = generate_json(grouped, "2026-01-21T00:00:00Z").unwrap();
let json: serde_json::Value = serde_json::from_str(&json_outputs[0].1).unwrap();

assert_eq!(json["options"]["string_val"], "hello");
Expand Down
23 changes: 18 additions & 5 deletions sentry-options-cli/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,29 @@ fn merge_all_options(maps: NamespaceMap) -> Result<Vec<MergedOptions>> {
Ok(results)
}

pub fn generate_json(maps: NamespaceMap) -> Result<Vec<(String, String)>> {
/// Generate JSON output files for all namespace/target combinations.
///
/// # Arguments
/// * `generated_at` - RFC3339 formatted timestamp (e.g., "2026-01-14T00:00:00Z")
pub fn generate_json(maps: NamespaceMap, generated_at: &str) -> Result<Vec<(String, String)>> {
merge_all_options(maps)?
.into_iter()
.map(|m| {
let wrapper = BTreeMap::from([("options", m.options)]);
Ok((
format!("sentry-options-{}-{}.json", m.namespace, m.target),
serde_json::to_string(&wrapper)?,
serde_json::to_string(&serde_json::json!({
"options": m.options,
"generated_at": generated_at,
}))?,
))
})
.collect()
}

/// Generate a Kubernetes ConfigMap for a specific namespace/target.
///
/// # Arguments
/// * `generated_at` - RFC3339 formatted timestamp (e.g., "2026-01-14T00:00:00Z")
pub fn generate_configmap(
maps: &NamespaceMap,
namespace: &str,
Expand All @@ -121,8 +131,10 @@ pub fn generate_configmap(
let name = format!("sentry-options-{}-{}", namespace, target);

let options = merge_options_for_target(maps, namespace, target)?;
let wrapper = BTreeMap::from([("options", &options)]);
let values_json = serde_json::to_string(&wrapper)?;
let values_json = serde_json::to_string(&serde_json::json!({
"options": options,
"generated_at": generated_at,
}))?;

let mut annotations = BTreeMap::from([("generated_at".to_string(), generated_at.to_string())]);
if let Some(sha) = commit_sha {
Expand Down Expand Up @@ -248,6 +260,7 @@ mod tests {
let parsed: serde_json::Value = serde_json::from_str(values_json).unwrap();
assert_eq!(parsed["options"]["string_val"], "hello");
assert_eq!(parsed["options"]["int_val"], 42);
assert_eq!(parsed["generated_at"], "2026-01-14T00:00:00Z");
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions sentry-options-validation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ anyhow.workspace = true
thiserror.workspace = true
jsonschema.workspace = true
tempfile.workspace = true
sentry.workspace = true
chrono.workspace = true

[dev-dependencies]
tempfile.workspace = true
Expand Down
Loading
Loading