-
Notifications
You must be signed in to change notification settings - Fork 0
ops: ship docker logs to Better Stack via Vector sidecar #23
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
+114
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Vector config — scrapes every docker container on the VPS and ships | ||
| # structured logs to Better Stack. One agent for the whole host so both | ||
| # the free-tier stack (this compose file) and the paid-backend stack | ||
| # (separate compose at /opt/paid-backend) are covered by mounting the | ||
| # host's docker socket read-only. | ||
| # | ||
| # Bearer token is sourced from the BETTERSTACK_SOURCE_TOKEN environment | ||
| # variable that docker compose injects from the VPS .env file. Token | ||
| # never appears in this file or git. | ||
| # | ||
| # KNOWN LIMITATION (docker.sock attack surface): | ||
| # Mounting /var/run/docker.sock into this container — even with :ro — gives | ||
| # Vector full Docker API access (the :ro flag restricts the socket FILE, | ||
| # not the API operations the daemon will perform on its behalf). A Vector | ||
| # container compromise would let an attacker enumerate, exec into, or | ||
| # replace any container on the host. Mitigated for now by: | ||
| # (1) pinning the Vector image to an exact tag (no :latest), | ||
| # (2) reviewing image releases before bumping the tag, | ||
| # (3) the VPS being single-tenant. | ||
| # Upgrade path: front the socket with `tecnativa/docker-socket-proxy` | ||
| # limiting the daemon API to GET /containers + GET /events + log streams | ||
| # only. Adds one container, ~5 MB RAM. Defer until traffic justifies the | ||
| # extra moving piece. | ||
|
|
||
| # ── Source: every container's stdout/stderr ────────────────────────────────── | ||
| [sources.docker] | ||
| type = "docker_logs" | ||
| # Skip Vector's own logs so we don't bill ourselves for our own chatter. | ||
| # Docker Compose prefixes container names with the project + index | ||
| # (e.g. `github-store-backend-vector-1`), so an exact-match exclusion of | ||
| # `"vector"` doesn't fire. exclude_containers accepts substring prefix | ||
| # matching — every entry below is "does the container_name start with this | ||
| # prefix". The bare project-name variants cover bring-up before this branch | ||
| # lands; the prefixed variants cover the Compose-managed names. | ||
| exclude_containers = [ | ||
| "vector", | ||
| "github-store-backend-vector", | ||
| "github-store-backend_vector", | ||
| "paid-backend-vector", | ||
| "paid-backend_vector", | ||
| ] | ||
|
|
||
| # ── Transform: tag each event with backend identity ────────────────────────── | ||
| # Adds a `service` field derived from the container name so Better Stack | ||
| # filters can distinguish free-tier (app, postgres, meilisearch, caddy) | ||
| # from paid-backend (paid-app, paid-postgres, …). | ||
| [transforms.tagged] | ||
| type = "remap" | ||
| inputs = ["docker"] | ||
| source = ''' | ||
| .service = .container_name | ||
| .host = "komi-vps" | ||
| ''' | ||
|
|
||
| # ── Sink: Better Stack HTTP ingest ─────────────────────────────────────────── | ||
| # NDJSON over HTTPS. Their docs: | ||
| # https://betterstack.com/docs/logs/http-rest-api/ | ||
| [sinks.betterstack] | ||
| type = "http" | ||
| inputs = ["tagged"] | ||
| uri = "https://${BETTERSTACK_INGEST_HOST}/" | ||
| method = "post" | ||
| encoding.codec = "json" | ||
| framing.method = "newline_delimited" | ||
| compression = "gzip" | ||
|
|
||
| [sinks.betterstack.auth] | ||
| strategy = "bearer" | ||
| token = "${BETTERSTACK_SOURCE_TOKEN}" | ||
|
|
||
| [sinks.betterstack.request.headers] | ||
| Content-Type = "application/json" | ||
|
|
||
| # Buffer + retry so a brief Better Stack outage doesn't drop events. | ||
| [sinks.betterstack.buffer] | ||
| type = "memory" | ||
| max_events = 5000 | ||
| when_full = "drop_newest" | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
|
|
||
| [sinks.betterstack.request] | ||
| retry_attempts = 5 | ||
| retry_max_duration_secs = 30 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.