Skip to content
Open
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
15 changes: 14 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"crates/sequins-live-query",
"crates/sequins-batch-chain",
"crates/sequins-hot-tier",
"crates/sequins-object-store",
"crates/sequins-cold-tier",
"crates/sequins-storage",
"crates/sequins-datafusion-backend",
Expand Down Expand Up @@ -53,6 +54,7 @@ sequins-companion-index = { path = "crates/sequins-companion-index" }
sequins-vortex-indexed-layout = { path = "crates/sequins-vortex-indexed-layout" }
sequins-attribute-codec = { path = "crates/sequins-attribute-codec" }
sequins-series-index = { path = "crates/sequins-series-index" }
sequins-object-store = { path = "crates/sequins-object-store" }
sequins-types = { path = "crates/sequins-types" }
sequins-otlp = { path = "crates/sequins-otlp" }
sequins-query = { path = "crates/sequins-query" }
Expand Down
2 changes: 1 addition & 1 deletion crates/sequins-cold-tier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sequins-arrow-schema = { workspace = true }
sequins-types = { workspace = true }
sequins-companion-index = { workspace = true }
sequins-series-index = { workspace = true }
sequins-object-store = { workspace = true }
sequins-vortex-indexed-layout = { workspace = true }

# Arrow / DataFusion
Expand Down Expand Up @@ -41,7 +42,6 @@ serde_json = { workspace = true }
# Utilities
chrono = { workspace = true }
uuid = { workspace = true }
url = { workspace = true }
hex = { workspace = true }
base64 = { workspace = true }
bytes = { workspace = true }
Expand Down
133 changes: 8 additions & 125 deletions crates/sequins-cold-tier/src/cold_tier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,132 +107,15 @@ impl ColdTier {

/// Create an object store from the cold-tier config.
///
/// Supports:
/// - Local filesystem: `file:///path` or `/path`
/// - AWS S3 (and S3-compatibles): `s3://bucket/path`
/// - Google Cloud Storage: `gs://bucket/path`
/// - Azure Blob Storage: `az://container/path` or `azure://container/path`
///
/// Connection settings for cloud stores (region, endpoint, HTTP, addressing,
/// optional static credentials) come from [`ColdTierConfig::object_store`].
/// Credentials default to the provider's standard chain — instance profile,
/// IRSA / workload identity — so a properly-configured pod needs no static
/// credentials in config.
/// Delegates to [`sequins_object_store::build`], which is shared with other
/// subsystems that need their own bucket or prefix. Connection settings come
/// from [`ColdTierConfig::object_store`]; credentials default to the
/// provider's standard chain.
fn create_store(config: &ColdTierConfig) -> Result<Arc<dyn ObjectStore>> {
use object_store::local::LocalFileSystem;

let uri = config.uri.as_str();
let os = &config.object_store;

// Local filesystem
if uri.starts_with("file://") || uri.starts_with('/') {
let path = uri.strip_prefix("file://").unwrap_or(uri);

// Create the directory if it doesn't exist
std::fs::create_dir_all(path).map_err(|e| {
Error::Storage(format!("Failed to create storage directory: {}", e))
})?;

// Use LocalFileSystem without prefix - we'll use full paths in queries
let store = LocalFileSystem::new();
return Ok(Arc::new(store));
}

// AWS S3
if uri.starts_with("s3://") {
use object_store::aws::AmazonS3Builder;

let url = url::Url::parse(uri)
.map_err(|e| Error::Config(format!("Invalid S3 URI '{}': {}", uri, e)))?;

let bucket = url
.host_str()
.ok_or_else(|| Error::Config(format!("S3 URI missing bucket name: {}", uri)))?;

// Base on `from_env` so the default AWS credential chain (instance
// profile, IRSA / web-identity, the credentials injected by the
// platform) is picked up with no configuration. Connection settings
// come from the cold-tier config, not the environment.
let mut builder = AmazonS3Builder::from_env().with_bucket_name(bucket);
if let Some(region) = &os.region {
builder = builder.with_region(region);
}
if let Some(endpoint) = &os.endpoint {
builder = builder.with_endpoint(endpoint);
}
if os.allow_http {
builder = builder.with_allow_http(true);
}
if let Some(vhost) = os.virtual_hosted_style {
builder = builder.with_virtual_hosted_style_request(vhost);
}
if let (Some(key), Some(secret)) = (&os.access_key_id, &os.secret_access_key) {
builder = builder
.with_access_key_id(key)
.with_secret_access_key(secret);
}

let store = builder
.build()
.map_err(|e| Error::Config(format!("Failed to create S3 store: {}", e)))?;

return Ok(Arc::new(store));
}

// Google Cloud Storage
if uri.starts_with("gs://") {
use object_store::gcp::GoogleCloudStorageBuilder;

let url = url::Url::parse(uri)
.map_err(|e| Error::Config(format!("Invalid GCS URI '{}': {}", uri, e)))?;

let bucket = url
.host_str()
.ok_or_else(|| Error::Config(format!("GCS URI missing bucket name: {}", uri)))?;

// `from_env` picks up GOOGLE_APPLICATION_CREDENTIALS and the default
// workload-identity credential chain; the bucket comes from the URI.
let store = GoogleCloudStorageBuilder::from_env()
.with_bucket_name(bucket)
.build()
.map_err(|e| Error::Config(format!("Failed to create GCS store: {}", e)))?;

return Ok(Arc::new(store));
}

// Azure Blob Storage
if uri.starts_with("az://") || uri.starts_with("azure://") {
use object_store::azure::MicrosoftAzureBuilder;

let stripped_uri = uri
.strip_prefix("az://")
.or_else(|| uri.strip_prefix("azure://"))
.unwrap();

let url = url::Url::parse(&format!("https://{}", stripped_uri))
.map_err(|e| Error::Config(format!("Invalid Azure URI '{}': {}", uri, e)))?;

let container = url.host_str().ok_or_else(|| {
Error::Config(format!("Azure URI missing container name: {}", uri))
})?;

// `from_env` picks up AZURE_STORAGE_* and the default credential chain
// (managed / workload identity); the container comes from the URI.
let mut builder = MicrosoftAzureBuilder::from_env().with_container_name(container);
if os.allow_http {
builder = builder.with_allow_http(true);
}
let store = builder
.build()
.map_err(|e| Error::Config(format!("Failed to create Azure store: {}", e)))?;

return Ok(Arc::new(store));
}

Err(Error::Config(format!(
"Unsupported object store URI: {}. Supported: file://, s3://, gs://, az://",
uri
)))
Ok(sequins_object_store::build(
&config.uri,
&config.object_store,
)?)
}

/// Dispatch a hot-tier flush to the appropriate per-signal write path.
Expand Down
34 changes: 6 additions & 28 deletions crates/sequins-cold-tier/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,12 @@ impl Default for ColdTierConfig {
}
}

/// Connection options for cloud object stores. All fields are optional; unset
/// values fall back to the object-store provider's defaults (including the
/// standard credential chain — instance profile, IRSA / workload identity).
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct ObjectStoreConfig {
/// Region (e.g. `us-east-1`). Unset uses the provider default.
pub region: Option<String>,

/// Custom endpoint URL for S3-compatible stores (MinIO, Ceph RGW, a gateway).
pub endpoint: Option<String>,

/// Allow plain-HTTP endpoints. Required for a local MinIO served over http
/// (object stores reject non-https endpoints otherwise).
#[serde(default)]
pub allow_http: bool,

/// Force path-style addressing (`endpoint/bucket`) instead of virtual-hosted
/// (`bucket.endpoint`). Most S3-compatibles (MinIO) need path-style.
pub virtual_hosted_style: Option<bool>,

/// Static access key id. Prefer the credential chain (IRSA / instance
/// profile) in production; set this only for local/dev (e.g. MinIO).
pub access_key_id: Option<String>,

/// Static secret access key (paired with `access_key_id`).
pub secret_access_key: Option<String>,
}
/// Connection options for cloud object stores.
///
/// Defined in [`sequins_object_store`] and re-exported here so it can be shared
/// with other subsystems that need their own bucket or prefix without depending
/// on the cold tier.
pub use sequins_object_store::ObjectStoreConfig;

/// Companion index configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
12 changes: 12 additions & 0 deletions crates/sequins-cold-tier/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ pub enum Error {
SeriesIndex(#[from] sequins_series_index::error::Error),
}

/// Flatten store-construction failures onto the existing variants so the
/// messages callers already match on are unchanged by the move to
/// `sequins-object-store`.
impl From<sequins_object_store::Error> for Error {
fn from(err: sequins_object_store::Error) -> Self {
match err {
sequins_object_store::Error::Config(msg) => Error::Config(msg),
io @ sequins_object_store::Error::Io(_) => Error::Storage(io.to_string()),
}
}
}

impl Error {
/// True if this batch can never be written to cold (a permanent schema
/// incompatibility), so it should be dropped rather than retried — otherwise it
Expand Down
21 changes: 21 additions & 0 deletions crates/sequins-object-store/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "sequins-object-store"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
authors.workspace = true
description = "Shared object-store construction for Sequins storage tiers"

[dependencies]
object_store = { workspace = true }

serde = { workspace = true, features = ["derive"] }
url = { workspace = true }

thiserror = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt"] }
bytes = { workspace = true }
Loading
Loading