Skip to content

Commit a472327

Browse files
npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67dTyler Longwell
andcommitted
Merge origin/main into eva/replica-heartbeat-fence
* origin/main: Publish symbol-bearing debug relay images (#3250) feat(tracing): add datastore tracing plumbing (#2760) Signed-off-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@buzz.block.builderlab.xyz> Co-authored-by: Tyler Longwell <[email protected]> Signed-off-by: Tyler Longwell <[email protected]>
2 parents 221245a + 3a4bf51 commit a472327

8 files changed

Lines changed: 239 additions & 35 deletions

File tree

‎.env.example‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ RELAY_URL=ws://localhost:3000
105105
# -----------------------------------------------------------------------------
106106
# Logging / Tracing
107107
# -----------------------------------------------------------------------------
108-
RUST_LOG=buzz_relay=debug,buzz_db=debug,buzz_auth=debug,buzz_pubsub=debug,tower_http=debug
108+
RUST_LOG=buzz_relay=debug,buzz_datastore=info,buzz_db=debug,buzz_auth=debug,buzz_pubsub=debug,tower_http=debug
109+
# Optional OpenTelemetry-only target filter. This is deliberately independent
110+
# from RUST_LOG so log verbosity changes cannot break trace parentage.
111+
# BUZZ_OTEL_FILTER=buzz_relay=info,buzz_datastore=info
109112

110113
# OTLP tracing endpoint (optional — leave unset to disable)
111114
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317

‎.github/workflows/docker.yml‎

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Docker image
22

3-
# Builds and publishes the public Buzz relay image as ghcr.io/block/buzz.
3+
# Builds and publishes the public Buzz relay images as ghcr.io/block/buzz.
4+
# Normal tags contain stripped binaries; matching debug-* tags contain the same
5+
# optimized binaries with line-table debug information for native profilers.
46
#
57
# Strategy: each architecture builds on its native runner (ubuntu-24.04 for
68
# amd64, ubuntu-24.04-arm for arm64), pushes to GHCR by digest, then a final
@@ -15,8 +17,10 @@ name: Docker image
1517
#
1618
# Triggers:
1719
# - push to main → :main + :sha-<7>
20+
# + :debug-main + :debug-sha-<7>
1821
# - push tags relay-v*.*.* → :{version} + :{major}.{minor} + :{major}
19-
# (+ :latest for stable, NOT for prereleases)
22+
# + matching :debug-* tags
23+
# (+ :latest/:debug-latest for stable releases)
2024
# - pull_request → build only (no push), cache stays warm
2125
# - workflow_dispatch → manual relay-tag rescue at the tag itself
2226
#
@@ -95,10 +99,6 @@ jobs:
9599
runner: ubuntu-24.04-arm
96100
arch: arm64
97101

98-
outputs:
99-
# Used downstream by `merge` to stitch the manifest.
100-
version: ${{ steps.meta.outputs.version }}
101-
102102
steps:
103103
- name: Checkout
104104
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
@@ -163,12 +163,13 @@ jobs:
163163
org.opencontainers.image.description=WebSocket relay server for the Buzz communications platform
164164
org.opencontainers.image.licenses=Apache-2.0
165165
166-
- name: Build and push by digest
167-
id: build
166+
- name: Build and push release image by digest
167+
id: build-release
168168
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
169169
with:
170170
context: .
171171
file: ./Dockerfile
172+
target: runtime
172173
platforms: ${{ matrix.platform }}
173174
labels: ${{ steps.meta.outputs.labels }}
174175
# Push by digest, not by tag — the merge job assembles the tags
@@ -180,25 +181,49 @@ jobs:
180181
cache-to: |
181182
${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && format('type=registry,ref={0}-buildcache:{1},mode=max,compression=zstd', env.IMAGE_NAME, matrix.arch) || '' }}
182183
183-
- name: Export digest
184+
- name: Build and push debug image by digest
185+
id: build-debug
186+
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
187+
with:
188+
context: .
189+
file: ./Dockerfile
190+
target: runtime-debug
191+
platforms: ${{ matrix.platform }}
192+
labels: ${{ steps.meta.outputs.labels }}
193+
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
194+
cache-from: |
195+
type=registry,ref=${{ env.IMAGE_NAME }}-buildcache:${{ matrix.arch }}
196+
197+
- name: Export release and debug digests
184198
if: github.event_name != 'pull_request'
185199
env:
186-
DIGEST: ${{ steps.build.outputs.digest }}
200+
RELEASE_DIGEST: ${{ steps.build-release.outputs.digest }}
201+
DEBUG_DIGEST: ${{ steps.build-debug.outputs.digest }}
187202
run: |
188-
mkdir -p /tmp/digests
189-
touch "/tmp/digests/${DIGEST#sha256:}"
203+
mkdir -p /tmp/digests-release /tmp/digests-debug
204+
touch "/tmp/digests-release/${RELEASE_DIGEST#sha256:}"
205+
touch "/tmp/digests-debug/${DEBUG_DIGEST#sha256:}"
190206
191-
- name: Upload digest
207+
- name: Upload release digest
192208
if: github.event_name != 'pull_request'
193209
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
194210
with:
195-
name: digests-${{ matrix.arch }}
196-
path: /tmp/digests/*
211+
name: digests-release-${{ matrix.arch }}
212+
path: /tmp/digests-release/*
213+
if-no-files-found: error
214+
retention-days: 1
215+
216+
- name: Upload debug digest
217+
if: github.event_name != 'pull_request'
218+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
219+
with:
220+
name: digests-debug-${{ matrix.arch }}
221+
path: /tmp/digests-debug/*
197222
if-no-files-found: error
198223
retention-days: 1
199224

200225
merge:
201-
name: Merge multi-arch manifest
226+
name: Merge ${{ matrix.variant }} multi-arch manifest
202227
if: github.event_name != 'pull_request'
203228
runs-on: ubuntu-24.04
204229
needs: build
@@ -208,13 +233,21 @@ jobs:
208233
packages: write # push the merged manifest
209234
id-token: write # OIDC for provenance attestation on the manifest
210235
attestations: write
236+
strategy:
237+
fail-fast: false
238+
matrix:
239+
include:
240+
- variant: release
241+
tag_prefix: ""
242+
- variant: debug
243+
tag_prefix: debug-
211244

212245
steps:
213246
- name: Download all per-arch digests
214247
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
215248
with:
216249
path: /tmp/digests
217-
pattern: digests-*
250+
pattern: digests-${{ matrix.variant }}-*
218251
merge-multiple: true
219252

220253
- name: Set up Docker Buildx
@@ -237,9 +270,12 @@ jobs:
237270
# the build job's `meta` step for why match=^relay-v(.*)$, why
238271
# value=${{ inputs.version }} carries the rescue-dispatch version,
239272
# and why :latest is left to flavor.latest=auto.
273+
flavor: |
274+
latest=auto
275+
prefix=${{ matrix.tag_prefix }},onlatest=true
240276
tags: |
241277
type=ref,event=branch,enable=${{ github.event_name != 'workflow_dispatch' || inputs.version == '' }}
242-
type=sha,prefix=sha-,format=short,enable=${{ github.event_name != 'workflow_dispatch' || inputs.version == '' }}
278+
type=sha,prefix=${{ matrix.tag_prefix }}sha-,format=short,enable=${{ github.event_name != 'workflow_dispatch' || inputs.version == '' }}
243279
type=semver,pattern={{version}},match=^relay-v(.*)$,value=${{ inputs.version }}
244280
type=semver,pattern={{major}}.{{minor}},match=^relay-v(.*)$,value=${{ inputs.version }}
245281
type=semver,pattern={{major}},match=^relay-v(.*)$,value=${{ inputs.version }}
@@ -284,11 +320,12 @@ jobs:
284320
- name: Summary
285321
env:
286322
IMAGE_NAME: ${{ env.IMAGE_NAME }}
323+
VARIANT: ${{ matrix.variant }}
287324
MERGED_DIGEST: ${{ steps.manifest.outputs.digest }}
288325
META_TAGS: ${{ steps.meta.outputs.tags }}
289326
run: |
290327
{
291-
echo "### Published \`${IMAGE_NAME}\`"
328+
echo "### Published \`${IMAGE_NAME}\` (${VARIANT})"
292329
echo
293330
echo "**Digest:** \`${MERGED_DIGEST}\`"
294331
echo

‎Dockerfile‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,22 @@ RUN apt-get update \
5959
ca-certificates \
6060
git \
6161
&& rm -rf /var/lib/apt/lists/*
62+
# Keep enough DWARF for native profilers to resolve optimized code to source
63+
# locations. The normal runtime strips it below; runtime-debug retains it.
64+
ENV CARGO_PROFILE_RELEASE_DEBUG=line-tables-only
6265
COPY --from=planner /build/recipe.json recipe.json
6366
# Cook the full workspace recipe — relay deps include workspace siblings, so
6467
# scoping to -p buzz-relay misses transitive deps and re-builds them later.
6568
RUN cargo chef cook --release --recipe-path recipe.json
6669
COPY . .
6770
RUN cargo build --release --locked -p buzz-relay --bin buzz-relay \
6871
-p buzz-admin --bin buzz-admin \
69-
-p buzz-pair-relay --bin buzz-pair-relay \
70-
&& strip target/release/buzz-relay \
72+
-p buzz-pair-relay --bin buzz-pair-relay
73+
74+
# Derive the normal release binaries from the same optimized ELF files as the
75+
# debug image so the two variants cannot drift at code-generation time.
76+
FROM builder AS stripped-binaries
77+
RUN strip target/release/buzz-relay \
7178
&& strip target/release/buzz-admin \
7279
&& strip target/release/buzz-pair-relay
7380

@@ -111,8 +118,8 @@ COPY web/ web/
111118
COPY admin-web/ admin-web/
112119
RUN pnpm -C web build && pnpm -C admin-web build
113120

114-
# ─── Stage 5: runtime ───────────────────────────────────────────────────────
115-
FROM debian:${DEBIAN_VERSION}-slim AS runtime
121+
# ─── Stage 5: shared runtime ────────────────────────────────────────────────
122+
FROM debian:${DEBIAN_VERSION}-slim AS runtime-base
116123

117124
# OCI annotations: required for GHCR to auto-link the image to this repo and
118125
# inherit its visibility. org.opencontainers.image.source is the load-bearing
@@ -135,9 +142,6 @@ RUN apt-get update \
135142
&& useradd --system --uid 1000 --gid 1000 --home-dir /var/lib/buzz \
136143
--create-home --shell /usr/sbin/nologin buzz
137144

138-
COPY --from=builder /build/target/release/buzz-relay /usr/local/bin/buzz-relay
139-
COPY --from=builder /build/target/release/buzz-admin /usr/local/bin/buzz-admin
140-
COPY --from=builder /build/target/release/buzz-pair-relay /usr/local/bin/buzz-pair-relay
141145
COPY --from=web-builder /build/web/dist /srv/buzz/web
142146
COPY --from=web-builder /build/admin-web/dist /srv/buzz/admin-web
143147

@@ -157,3 +161,18 @@ USER buzz:buzz
157161
WORKDIR /var/lib/buzz
158162

159163
ENTRYPOINT ["/usr/local/bin/buzz-relay"]
164+
165+
# Optimized binaries with line-table debug information for native profiling.
166+
# Published under debug-* tags; runtime behavior otherwise matches the normal
167+
# image exactly.
168+
FROM runtime-base AS runtime-debug
169+
COPY --from=builder /build/target/release/buzz-relay /usr/local/bin/buzz-relay
170+
COPY --from=builder /build/target/release/buzz-admin /usr/local/bin/buzz-admin
171+
COPY --from=builder /build/target/release/buzz-pair-relay /usr/local/bin/buzz-pair-relay
172+
173+
# Keep the stripped runtime as the final/default Dockerfile target so existing
174+
# `docker build .` callers and release tags retain their current behavior.
175+
FROM runtime-base AS runtime
176+
COPY --from=stripped-binaries /build/target/release/buzz-relay /usr/local/bin/buzz-relay
177+
COPY --from=stripped-binaries /build/target/release/buzz-admin /usr/local/bin/buzz-admin
178+
COPY --from=stripped-binaries /build/target/release/buzz-pair-relay /usr/local/bin/buzz-pair-relay

‎RELEASING.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ or mobile GitHub Release.
5757
2. **Merge the PR.** `auto-tag-on-release-pr-merge` pushes
5858
`relay-v<version>`.
5959
3. **The tag triggers `docker.yml`.** Stable releases update the version
60-
aliases and `latest`; prereleases do not.
60+
aliases and `latest`; prereleases do not. Each release also publishes an
61+
optimized, symbol-bearing image under matching `debug-` tags (for example,
62+
`debug-0.3.0` and `debug-latest`) for native profiling. The ordinary tags
63+
remain stripped and are the default for deployments that do not need it.
6164

6265
Every push to `main` continues to publish the rolling relay `:main` and
63-
`:sha-<7>` tags.
66+
`:sha-<7>` tags, plus matching `:debug-main` and `:debug-sha-<7>` variants.
6467

6568
### Mobile
6669

‎crates/buzz-relay/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ reqwest = { workspace = true }
9292
tokio-tungstenite = { workspace = true }
9393
futures = "0.3"
9494
flate2 = "1.1.9"
95+
opentelemetry_sdk = { workspace = true, features = ["testing"] }

‎crates/buzz-relay/src/main.rs‎

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use std::sync::Arc;
44

55
use tracing::{error, info, warn};
66
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
7+
8+
fn log_env_filter(rust_log: Option<&str>) -> EnvFilter {
9+
EnvFilter::new(rust_log.unwrap_or("buzz_relay=info"))
10+
}
711
use uuid::Uuid;
812

913
use buzz_audit::AuditService;
@@ -107,9 +111,17 @@ async fn main() -> anyhow::Result<()> {
107111
};
108112

109113
tracing_subscriber::registry()
110-
.with(fmt::layer().json().flatten_event(true))
111-
.with(EnvFilter::from_default_env().add_directive("buzz_relay=info".parse()?))
112-
.with(otel_layer)
114+
.with(
115+
fmt::layer()
116+
.json()
117+
.flatten_event(true)
118+
.with_filter(log_env_filter(std::env::var("RUST_LOG").ok().as_deref())),
119+
)
120+
.with(otel_layer.map(|layer| {
121+
layer.with_filter(telemetry::otel_env_filter(
122+
std::env::var("BUZZ_OTEL_FILTER").ok().as_deref(),
123+
))
124+
}))
113125
.init();
114126

115127
// Log any exporter-build failure now that the subscriber is installed.
@@ -1067,6 +1079,52 @@ async fn main() -> anyhow::Result<()> {
10671079
Ok(())
10681080
}
10691081

1082+
#[cfg(test)]
1083+
mod env_filter_tests {
1084+
use super::log_env_filter;
1085+
use buzz_relay::telemetry::otel_env_filter;
1086+
use tracing_subscriber::prelude::*;
1087+
1088+
#[test]
1089+
fn unset_enables_datastore_only_for_otel_filter() {
1090+
let logs = tracing_subscriber::registry().with(log_env_filter(None));
1091+
tracing::subscriber::with_default(logs, || {
1092+
assert!(!tracing::enabled!(target: "buzz_datastore", tracing::Level::INFO));
1093+
assert!(tracing::enabled!(target: "buzz_relay", tracing::Level::INFO));
1094+
});
1095+
1096+
let otel = tracing_subscriber::registry().with(otel_env_filter(None));
1097+
tracing::subscriber::with_default(otel, || {
1098+
assert!(tracing::enabled!(target: "buzz_datastore", tracing::Level::INFO));
1099+
});
1100+
}
1101+
1102+
#[test]
1103+
fn explicit_datastore_off_is_preserved_alone() {
1104+
assert_eq!(
1105+
otel_env_filter(Some("buzz_datastore=off")).to_string(),
1106+
"buzz_datastore=off"
1107+
);
1108+
}
1109+
1110+
#[test]
1111+
fn explicit_datastore_debug_is_preserved_alone() {
1112+
assert_eq!(
1113+
otel_env_filter(Some("buzz_datastore=debug")).to_string(),
1114+
"buzz_datastore=debug"
1115+
);
1116+
}
1117+
1118+
#[test]
1119+
fn log_and_otel_filters_are_configured_independently() {
1120+
assert_eq!(log_env_filter(Some("warn")).to_string(), "warn");
1121+
assert_eq!(
1122+
otel_env_filter(Some("buzz_relay=debug")).to_string(),
1123+
"buzz_relay=debug"
1124+
);
1125+
}
1126+
}
1127+
10701128
async fn run_community_revalidator(
10711129
state: Arc<AppState>,
10721130
period: std::time::Duration,

0 commit comments

Comments
 (0)