Skip to content

Commit c555e65

Browse files
feat(server): Make storage-cogs opt-in and slim the cross build image (#730)
`objectstore-server` always enables `storage-cogs`, so every server build compiles librdkafka. Local builds, `test-python`, and the cross-build image all need cmake and libcurl headers for a feature they don't use. The cross image doesn't have cmake, so it currently fails to build. This PR adds a `storage-cogs` feature to `objectstore-server`. It is off by default and only enabled for release builds in `build.yml`. With the feature off, the `storage_cogs` config is compiled out and ignored. `Dockerfile.cross` and `test-python` drop the build deps that librdkafka needed. --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Jan Michael Auer <jan.auer@sentry.io>
1 parent acc28fd commit c555e65

7 files changed

Lines changed: 23 additions & 20 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ jobs:
3232
- name: Install dependencies
3333
run: |
3434
sudo apt-get update
35-
# libcurl4-openssl-dev: librdkafka is built from source and links against libcurl,
36-
# whose headers are not on the runner by default.
35+
# Workaround: rdkafka-sys requires always curl headers, fixed with librdkafka >=2.15.0.
3736
sudo apt-get install -y llvm libcurl4-openssl-dev
3837
3938
- name: Install sentry-cli
@@ -51,7 +50,7 @@ jobs:
5150

5251
- name: Build Binary
5352
run: |
54-
cargo build --release --locked --target=${{ matrix.target }} --bin objectstore --features profiling
53+
cargo build --release --locked --target=${{ matrix.target }} --bin objectstore --features profiling,storage-cogs
5554
cp target/${{ matrix.target }}/release/objectstore ./objectstore
5655
5756
- name: Split Debug Info

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424

2525
steps:
26-
# librdkafka is built from source and links against libcurl, whose headers are not
27-
# on the runner by default. Needed by anything that builds the `kafka` feature.
26+
# Workaround: rdkafka-sys requires always curl headers, fixed with librdkafka >=2.15.0.
2827
- name: Install libcurl-dev
2928
run: |
3029
sudo apt-get update
@@ -78,8 +77,7 @@ jobs:
7877
runs-on: ubuntu-latest
7978

8079
steps:
81-
# librdkafka is built from source and links against libcurl, whose headers are not
82-
# on the runner by default. Needed by anything that builds the `kafka` feature.
80+
# Workaround: rdkafka-sys requires always curl headers, fixed with librdkafka >=2.15.0.
8381
- name: Install libcurl-dev
8482
run: |
8583
sudo apt-get update
@@ -147,13 +145,6 @@ jobs:
147145
runs-on: ubuntu-latest
148146

149147
steps:
150-
# librdkafka is built from source and links against libcurl, whose headers are not
151-
# on the runner by default. Needed by anything that builds the `kafka` feature.
152-
- name: Install libcurl-dev
153-
run: |
154-
sudo apt-get update
155-
sudo apt-get install -y libcurl4-openssl-dev
156-
157148
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
158149

159150
- name: Install Rust Toolchain
@@ -190,8 +181,7 @@ jobs:
190181
id-token: write
191182

192183
steps:
193-
# librdkafka is built from source and links against libcurl, whose headers are not
194-
# on the runner by default. Needed by anything that builds the `kafka` feature.
184+
# Workaround: rdkafka-sys requires always curl headers, fixed with librdkafka >=2.15.0.
195185
- name: Install libcurl-dev
196186
run: |
197187
sudo apt-get update

‎Dockerfile.cross‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ FROM rust:slim-bookworm
44
RUN dpkg --add-architecture amd64 \
55
&& apt-get update -qq \
66
&& apt-get upgrade -y \
7-
&& apt-get install -y --no-install-recommends make pkg-config git libssl-dev:amd64 libcurl4-openssl-dev:amd64 gcc-x86-64-linux-gnu g++-x86-64-linux-gnu \
7+
&& apt-get install -y --no-install-recommends make git libssl-dev:amd64 gcc-x86-64-linux-gnu \
88
&& rm -rf /var/lib/apt/lists/*
99

1010
RUN rustup target add x86_64-unknown-linux-gnu
1111

1212
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc
1313
ENV CC=x86_64-linux-gnu-gcc
14-
ENV PKG_CONFIG_ALLOW_CROSS=1
1514
ENV OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu
1615
ENV OPENSSL_INCLUDE_DIR=/usr/include
1716

‎objectstore-server/Cargo.toml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ num_cpus = { workspace = true }
3333
objectstore-log = { workspace = true, features = ["init", "sentry"] }
3434
objectstore-metrics = { workspace = true }
3535
objectstore-options = { workspace = true }
36-
objectstore-service = { workspace = true, features = ["storage-cogs"] }
36+
objectstore-service = { workspace = true }
3737
objectstore-types = { workspace = true }
3838
papaya = { workspace = true }
3939
pin-project-lite = { workspace = true }
@@ -59,6 +59,9 @@ tikv-jemalloc-ctl = { workspace = true }
5959

6060
[features]
6161
profiling = ["dep:jemalloc_pprof", "tikv-jemallocator/profiling"]
62+
# Publishes the storage COGS change stream to Kafka. Off by default because it builds
63+
# librdkafka from source; release builds enable it.
64+
storage-cogs = ["objectstore-service/storage-cogs"]
6265

6366
[dev-dependencies]
6467
nix = { workspace = true, features = ["signal"] }

‎objectstore-server/docs/architecture.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ Key configuration sections:
128128
- `service` — storage service parameters (backend concurrency limit)
129129
- `killswitches` — traffic blocking rules
130130
- `storage_cogs` — where backends publish their cost-tracking change stream; corresponds
131-
to config on each backend. See [`change_stream`](objectstore_service::change_stream).
131+
to config on each backend. Requires the `storage-cogs` Cargo feature. See
132+
[`change_stream`](objectstore_service::change_stream).
132133
- `usecases` — per-use-case properties (expiration policy constraints)
133134
- `runtime` — worker threads, metrics interval
134135
- `sentry` / `metrics` / `logging` — observability

‎objectstore-server/src/config.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use anyhow::Result;
6565
use bytes::Bytes;
6666
use figment::providers::{Env, Format, Serialized, Yaml};
6767
use objectstore_service::backend::local_fs::FileSystemConfig;
68+
#[cfg(feature = "storage-cogs")]
6869
use objectstore_service::change_stream::CostTrackerConfig;
6970
use objectstore_service::encryption::Cipher;
7071
use objectstore_types::auth::Permission;
@@ -543,6 +544,9 @@ pub struct Config {
543544
/// - `OS__STORAGE_COGS__TOPIC=shared-resources-inventory`
544545
/// - `OS__STORAGE_COGS__BOOTSTRAP_SERVERS=kafka:9092`
545546
/// - `OS__STORAGE_COGS__OVERRIDE_PARAMS__<PROPERTY>=<value>`
547+
///
548+
/// Requires the `storage-cogs` Cargo feature.
549+
#[cfg(feature = "storage-cogs")]
546550
#[serde(default)]
547551
pub storage_cogs: Option<CostTrackerConfig>,
548552

@@ -852,6 +856,7 @@ impl Default for Config {
852856
cogs: None,
853857
}),
854858

859+
#[cfg(feature = "storage-cogs")]
855860
storage_cogs: None,
856861
runtime: Runtime::default(),
857862
logging: LoggingConfig::default(),
@@ -1166,6 +1171,7 @@ mod tests {
11661171
}
11671172

11681173
#[test]
1174+
#[cfg(feature = "storage-cogs")]
11691175
fn storage_cogs_via_env() {
11701176
figment::Jail::expect_with(|jail| {
11711177
jail.set_env("OS__STORAGE__TYPE", "bigtable");
@@ -1213,6 +1219,7 @@ mod tests {
12131219
};
12141220
let stream = storage.cogs.as_ref().expect("change stream");
12151221
assert_eq!(stream.sample_rate, 1.0, "reports everything by default");
1222+
#[cfg(feature = "storage-cogs")]
12161223
assert!(
12171224
config.storage_cogs.is_none(),
12181225
"no transport is configured by default"
@@ -1223,6 +1230,7 @@ mod tests {
12231230
}
12241231

12251232
#[test]
1233+
#[cfg(feature = "storage-cogs")]
12261234
fn serde_var_yaml_references() {
12271235
let secrets = tempfile::tempdir().unwrap();
12281236
let absolute_secret = secrets.path().join("kafka-password");

‎objectstore-server/src/state.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,14 @@ impl Services {
6464
tokio::spawn(track_allocator_metrics(config.runtime.metrics_interval));
6565

6666
// Absent config means no transport, and therefore no reporting.
67+
#[cfg(feature = "storage-cogs")]
6768
let streams = config
6869
.storage_cogs
6970
.as_ref()
7071
.map(ChangeStreamFactory::new)
7172
.unwrap_or_default();
73+
#[cfg(not(feature = "storage-cogs"))]
74+
let streams = ChangeStreamFactory::default();
7275
let cipher = match config.service.cipher()? {
7376
Some(cipher) => cipher,
7477
None => {

0 commit comments

Comments
 (0)