Skip to content
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

feat(monorepo): Merge rust services into Posthog as a subtree #22845

Merged
merged 270 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
270 commits
Select commit Hold shift + click to select a range
938b3a1
Fix docker build (#18)
Sep 6, 2023
fca44ad
Correct debian version (#19)
Sep 8, 2023
d3f5de6
Only build ARM images, as we only run ARM (#20)
Sep 8, 2023
a9cc8a2
Allow setting bind address (#21)
Sep 11, 2023
eea90a5
Use a big ARM builder for docker (#22)
Sep 11, 2023
565d096
Capture several fields to the ProcessedEvent output (#15)
xvello Sep 13, 2023
8eb6a2a
Initial workspace setup (#25)
Sep 14, 2023
3390610
Add Prometheus metrics exporting (#23)
Sep 14, 2023
76905ec
implement error handling with a CaptureError enum (#24)
xvello Sep 14, 2023
1474f99
Fix docker build (#26)
Sep 14, 2023
af529b1
Add graceful shutdown handler (#27)
Sep 14, 2023
6ed0609
get django_compat test closer to green (#28)
xvello Sep 15, 2023
9ad1d64
drop the unused site_url field (#30)
xvello Sep 15, 2023
7e74df8
fill the data field in analytics events (#31)
xvello Oct 9, 2023
c03638b
Add billing limiter (#33)
Oct 19, 2023
30b4994
align envvars with plugin-server (#34)
xvello Oct 23, 2023
9ceabe7
add more metrics (#35)
xvello Oct 26, 2023
c9e835e
add envconfig to parse envvars (#36)
xvello Oct 26, 2023
7cd2d61
Create LICENSE (#38)
Oct 27, 2023
e6ea52f
Fix the redis billing update (#39)
Oct 27, 2023
fb6fa7c
kafka: check reachability + collect metrics (#37)
xvello Oct 27, 2023
53017d7
kafka: add ssl support (#40)
xvello Oct 27, 2023
9cf0959
metrics: consolidate into a labelled capture_events_dropped_total metric
xvello Oct 30, 2023
a841ac4
metrics: report capture_event_batch_size in kafka sink too (#42)
xvello Oct 31, 2023
4b3634b
add cors support (#43)
xvello Oct 31, 2023
4f85f1a
cors: enable allow_credentials (#44)
xvello Nov 3, 2023
bcc4549
add end2end testing harness to capture-server crate (#45)
xvello Nov 6, 2023
8f60032
kafka sink: expose more rdkafka settings (#46)
xvello Nov 6, 2023
780f390
implement liveness checks based on rdkafka health (#41)
xvello Nov 7, 2023
e56e1f1
Add tracing setup (#47)
Nov 13, 2023
014456d
feat: add partition limiter + overflow (#48)
Nov 13, 2023
0b1b0a2
tracing: add batch_size and token to root span (#49)
xvello Nov 14, 2023
3e70e71
route GETs to the legacy endpoint too (#53)
xvello Nov 20, 2023
b68bd7e
fix: increment over_quota by batch size instead of 1 (#56)
xvello Nov 21, 2023
f9fe9f1
add more span attributes (#55)
Nov 21, 2023
6cee0a5
fix new span setup (#57)
Nov 21, 2023
f8a07fb
account for process_events errors in capture_events_dropped_total and…
xvello Nov 21, 2023
7228307
properly process Kafka produce ACKs to propagate errors (#59)
xvello Nov 27, 2023
7056e80
feat(overflow): add overflow_forced_keys envvar (#54)
xvello Nov 27, 2023
03e47f4
Initial commit
ellie Nov 27, 2023
80f5270
Structure
ellie Nov 27, 2023
2ca64c0
Add rust workflow
ellie Nov 27, 2023
cd4d639
tracing: add ack_wait spans (#60)
xvello Nov 28, 2023
cc43e21
feat: trim distinct_id to 200 chars (#61)
xvello Nov 28, 2023
681fcaf
chore: add dispatch trigger (#62)
Nov 28, 2023
132ceee
feat: Initial PgQueue implementation
tomasfarias Nov 29, 2023
388b544
feat: Support for attempted_by
tomasfarias Nov 30, 2023
bfeab36
fix: Wait for Postgres to be up in CI
tomasfarias Nov 30, 2023
8b2325b
fix: Formatting
tomasfarias Nov 30, 2023
ec6ba09
fix: README recommends --waiting for docker compose to be up
tomasfarias Nov 30, 2023
c6ab642
chore: Add comment on SKIP LOCKED clause
tomasfarias Nov 30, 2023
da952a6
fix: Use the type alias I defined
tomasfarias Nov 30, 2023
5d0838f
feat: Support for retrying
tomasfarias Dec 1, 2023
67c28b0
chore: Add docstrings
tomasfarias Dec 1, 2023
8c5c7ec
chore: Add basic requirements
tomasfarias Dec 1, 2023
d05f6eb
feat: Implement PgTransactionJob to hold a transaction open for the job
tomasfarias Dec 1, 2023
4bf6516
refactor: Move queries to state handling methods in Job
tomasfarias Dec 1, 2023
401336a
refactor: Return from match and close connection as recommended
tomasfarias Dec 1, 2023
2ab6250
fix: Update docstring
tomasfarias Dec 4, 2023
521fb51
fix: More docstring updates.
tomasfarias Dec 4, 2023
746120b
fix: Typo
tomasfarias Dec 4, 2023
d5f345d
fix: Update documentation and names
tomasfarias Dec 4, 2023
123a3fa
Merge pull request #1 from PostHog/feat/pgqueue
tomasfarias Dec 4, 2023
e455464
add deps
ellie Nov 27, 2023
749dd17
feat: auto-detect gzip compression on input payloads (#63)
xvello Dec 4, 2023
efe67f8
boot http server
ellie Nov 27, 2023
9fb81ef
Formatting, move shared deps into workspace
ellie Dec 4, 2023
731ae14
add metrics
ellie Dec 4, 2023
3524d26
refactor:typo (#64)
Neon-20 Dec 5, 2023
7ff5b80
feat: accept other JSON types as distinct_id, stringify them (#65)
xvello Dec 5, 2023
a0072d1
Merge pull request #2 from PostHog/ellie/setup-producer-api
ellie Dec 7, 2023
fa43c0a
fix MessageSizeTooLarge handling (#66)
xvello Dec 7, 2023
a63a00c
feat: Include migrations and echo-server in docker-compose stack
tomasfarias Dec 6, 2023
690888a
refactor: Support in pgqueue for consumer
tomasfarias Dec 6, 2023
7824d69
feat: First consumer implementation
tomasfarias Dec 6, 2023
d91c90a
chore: Cargo lock update
tomasfarias Dec 6, 2023
3bdd1c0
chore: Remove install of sqlx from CI
tomasfarias Dec 6, 2023
c25ac6f
fix: Use depends_on instead of requires
tomasfarias Dec 6, 2023
8c7cb79
fix: Address clippy linting issues
tomasfarias Dec 6, 2023
2d99f77
fix: Split up docker compose start up in CI
tomasfarias Dec 6, 2023
71d5929
fix: Typo
tomasfarias Dec 7, 2023
09acfef
fix: Delete Cargo.lock
tomasfarias Dec 8, 2023
6d3080d
fix: Re-add Cargo.lock
tomasfarias Dec 8, 2023
f76915e
chore: Add comment referencing connection limit
tomasfarias Dec 8, 2023
e461d06
Merge pull request #3 from PostHog/feat/worker
tomasfarias Dec 8, 2023
1047179
refactor: Re-use client in consumer
tomasfarias Dec 8, 2023
0525d7b
fix: Limit number of concurrent HTTP requests with Semaphore
tomasfarias Dec 8, 2023
3582537
chore: Use workspace dependencies
tomasfarias Dec 8, 2023
e1e45f6
Merge pull request #6 from PostHog/chore/use-workspace-dependencies
tomasfarias Dec 8, 2023
31b1e7a
refactor: Rename to max_concurrent_jobs
tomasfarias Dec 8, 2023
5cdff6a
chore: Remove deprecated comment
tomasfarias Dec 8, 2023
1358e3b
refactor: Return result from processing task
tomasfarias Dec 8, 2023
7ddeb89
Merge pull request #5 from PostHog/refactor/re-use-client-in-consumer
bretthoerner Dec 11, 2023
332c3d5
release: ship debug symbols in image for continuous profiling (#67)
xvello Dec 11, 2023
fb078fc
report partition_limits_key_count metric (#69)
xvello Dec 12, 2023
f714f32
revert rdkafka to 0.34 to evaluate impact (#68)
xvello Dec 12, 2023
3c7479a
chore(ci): add short sha to docker ci image (#71)
Dec 12, 2023
eae1cb1
Add basic webhook produce endpoint
bretthoerner Dec 7, 2023
454b96d
feat: clean up partition limiter state on schedule (#72)
Dec 13, 2023
1a7e87a
carve out the limiters and sinks sub-modules (#70)
xvello Dec 13, 2023
56dfe44
return rdkafka to 0.36 (#73)
xvello Dec 13, 2023
98b9c4a
Merge pull request #4 from PostHog/brett/produce
bretthoerner Dec 14, 2023
74c5207
Add indexes, drop redundant column
bretthoerner Dec 12, 2023
2b03197
Merge pull request #7 from PostHog/brett/indexes
bretthoerner Dec 14, 2023
c00bc04
Append final errors to error array and treat request errors as retryable
bretthoerner Dec 15, 2023
9084c6e
Remove Result from WebhookConsumer::new
bretthoerner Dec 15, 2023
988a1b0
Merge pull request #11 from PostHog/brett/err
bretthoerner Dec 15, 2023
71bf553
Add hook-janitor skeleton
bretthoerner Dec 13, 2023
d2d929d
Add Kafka message types for app_metrics and plugin_log_entries
bretthoerner Dec 14, 2023
a938a10
Squelch clippy complaints
bretthoerner Dec 18, 2023
5a5c3be
Remove pointless Result
bretthoerner Dec 18, 2023
2b36b2e
Merge pull request #14 from PostHog/brett/janitor2
bretthoerner Dec 18, 2023
769c8f2
refactor: Add a metadata field to job queue
tomasfarias Dec 18, 2023
cf986b2
fix: Update webhook.rs docs
tomasfarias Dec 18, 2023
491c269
feat: Use new WebhookJobError struct for error reporting
tomasfarias Dec 18, 2023
c64c3d0
fix: Return response from send_webhook
tomasfarias Dec 19, 2023
d80644b
refactor: Re-use underlying error when failing after retry
tomasfarias Dec 19, 2023
b2ec0c5
Merge pull request #12 from PostHog/refactor/add-metadata-field
tomasfarias Dec 19, 2023
e4ee369
chore: Update docs
tomasfarias Dec 19, 2023
f480307
refactor: Have Connection Error catch all reqwest errors
tomasfarias Dec 19, 2023
44cdad7
Merge pull request #13 from PostHog/feat/webhook-error
tomasfarias Dec 19, 2023
f9b32ae
Implement Webhook cleanup
bretthoerner Dec 19, 2023
72aa509
Drop unnecessary asyncs
bretthoerner Dec 19, 2023
4fe1087
Make WebhookJobMetadata fields required
bretthoerner Dec 19, 2023
9ad59d2
Switch to sqlx::test for per-test DBs and fixtures
bretthoerner Dec 19, 2023
9359e7c
Add tests, fix some bugs found by said tests
bretthoerner Dec 19, 2023
cc206a5
feat: Give non-transactional consumer a chance
tomasfarias Dec 8, 2023
bd4dc4b
refactor: Two clients one for each mode
tomasfarias Dec 14, 2023
3747c34
Handle some feedback
bretthoerner Dec 20, 2023
d28dfef
refactor: Support both modes in single client with WebhookJob trait
tomasfarias Dec 20, 2023
b747d4c
fix: Elide lifetimes
tomasfarias Dec 20, 2023
059fc99
Add SerializableTxn for a little safety
bretthoerner Dec 20, 2023
8aeaad7
Cleanup AppMetric creation and serialization
bretthoerner Dec 20, 2023
a94ee2f
Clean up row counts
bretthoerner Dec 20, 2023
66ea834
Tweak ErrorType, add some notes about stability of serialized types
bretthoerner Dec 20, 2023
dd8faee
Finish up tests
bretthoerner Dec 20, 2023
d603510
refactor: Only one run method
tomasfarias Dec 21, 2023
934a0e0
Merge pull request #9 from PostHog/feat/support-for-non-transactional…
tomasfarias Dec 21, 2023
fe972c7
feat: Give non-transactional consumer a chance
tomasfarias Dec 8, 2023
dc97d8c
refactor: Two clients one for each mode
tomasfarias Dec 14, 2023
acd0d13
refactor: PgQueue no longer takes a RetryPolicy
tomasfarias Dec 14, 2023
0f61af3
fix: Rebase on changes and fix all conflicts
tomasfarias Dec 21, 2023
74624d3
Merge pull request #10 from PostHog/refactor/separate-retry-policy-fr…
tomasfarias Dec 21, 2023
c3997f1
Merge remote-tracking branch 'origin/main' into fix/webhook-cleanup-c…
tomasfarias Dec 21, 2023
9b7ab99
feat: Provide a function to start serving metrics
tomasfarias Dec 21, 2023
ec37286
feat: Serve basic count metrics on consumer
tomasfarias Dec 21, 2023
0a014cb
refactor: Use tokio::time::interval instead of async_std::task::sleep
tomasfarias Dec 21, 2023
f3e1252
feat: Track webhook job processing
tomasfarias Dec 21, 2023
0e54cea
fix: Remove unused imports
tomasfarias Dec 21, 2023
1f8088b
Update hook-common/src/kafka_messages/app_metrics.rs
bretthoerner Dec 21, 2023
2220b6b
Update hook-common/src/kafka_messages/app_metrics.rs
bretthoerner Dec 21, 2023
5088429
Update hook-common/src/kafka_messages/app_metrics.rs
bretthoerner Dec 21, 2023
980765d
Merge pull request #15 from PostHog/brett/webhook-cleanup
bretthoerner Dec 21, 2023
db076bf
refactor: Split-up router creation from metrics serving to allow call…
tomasfarias Dec 22, 2023
232c540
refactor: Only track duration seconds on success
tomasfarias Dec 22, 2023
f57f031
Merge pull request #18 from PostHog/feat/consumer-metrics
tomasfarias Dec 22, 2023
83426b8
feat: Implement support for retrying jobs to different queue (#19)
tomasfarias Jan 3, 2024
76476ef
fix: Add org name to image path (#22)
tomasfarias Jan 3, 2024
a277c45
refactor: Deploy the migration container too (#24)
tomasfarias Jan 5, 2024
3b5229d
Change dequeue ORDER BY and rename finished_at (#23)
bretthoerner Jan 5, 2024
7d519ab
refactor: Remove table name config and hardcode table name (#25)
tomasfarias Jan 8, 2024
ead1bf2
Minor query syntax/ordering cleanup (#26)
bretthoerner Jan 9, 2024
892d30b
Add metrics, fix metrics endpoint, bump deps (#27)
bretthoerner Jan 9, 2024
35d7e33
Get total row counts in janitor for metrics and consistency checking …
bretthoerner Jan 9, 2024
b00ef38
Login to DockerHub in CI (#74)
bretthoerner Jan 9, 2024
86e6a26
refactor: Rename producer and consumer images (#29)
tomasfarias Jan 9, 2024
29c2415
Login to DockerHub in CI (#30)
bretthoerner Jan 9, 2024
2499ea6
Login to Docker before QEMU (#32)
bretthoerner Jan 9, 2024
9cd1132
Login to DockerHub (#75)
bretthoerner Jan 10, 2024
46f9f93
refactor: Rename producer for api and consumer for worker (#31)
tomasfarias Jan 10, 2024
d6cc49f
Sync default ports with charts (#33)
bretthoerner Jan 10, 2024
878f112
Log errors in worker (#34)
bretthoerner Jan 10, 2024
b096678
Log PgJobError String (#35)
bretthoerner Jan 10, 2024
35877d3
Install ca-certificates (#37)
bretthoerner Jan 10, 2024
5011f18
fix: Syntax error in fail method (#38)
tomasfarias Jan 10, 2024
9b7d313
Log productive janitor runs at info level (#40)
bretthoerner Jan 11, 2024
677a094
Drop target from Prom labels (#41)
bretthoerner Jan 11, 2024
2437bd5
Add user-agent (#42)
bretthoerner Jan 11, 2024
d5dd35d
feat: Set idle tx timeout in migration (#39)
tomasfarias Jan 11, 2024
1982b0d
Fix app_metrics topic, don't encode null error_uuid (#43)
bretthoerner Jan 11, 2024
51a5c5f
Remove idle_in_transaction_session_timeout migration (#44)
bretthoerner Jan 12, 2024
8900f50
Use signed integers for plugin_id/plugin_config_id (#45)
bretthoerner Jan 12, 2024
58d573a
feat: make sure metrics cover all axum endpoints (#46)
xvello Jan 15, 2024
9fa90fd
improve janitor metrics (#48)
xvello Jan 16, 2024
b5029a9
feat: add readiness and liveness endpoints to all roles (#47)
xvello Jan 16, 2024
c181c50
Add queue depth gauges (#49)
bretthoerner Jan 16, 2024
1422683
feat: add webhook_worker_saturation_percent metric for autoscaling (#50)
xvello Jan 17, 2024
23ef5e2
fix:fix janitor get_queue_depth when queue is empty (#54)
xvello Jan 17, 2024
9c9ebd5
Remove queue filters from janitor (#52)
bretthoerner Jan 17, 2024
099053e
Make retry_queue_name truly optional from env to main (#53)
bretthoerner Jan 17, 2024
58474c0
refactor: Use new NonEmptyString config type for queue names (#55)
tomasfarias Jan 17, 2024
499f143
Log error rather than exiting process on dequeue error (#51)
bretthoerner Jan 18, 2024
a4b9943
add webhook_cleanup_last_success_timestamp metric for alerting (#59)
xvello Jan 19, 2024
e2b5dcb
Change created_at to scheduled_at for metrics (#58)
bretthoerner Jan 19, 2024
6729401
Add very basic version of job unstuck-ing for non-txn jobs that hang …
bretthoerner Jan 30, 2024
da6250b
fix: Use a good index for dequeue (#61)
tomasfarias Feb 2, 2024
8559b12
declare a PG application name visible in PG stats (#62)
xvello Feb 5, 2024
615c61d
Add proper e2e histrogram based on metadata created_at (#64)
bretthoerner Feb 5, 2024
304852c
Revert "Add proper e2e histrogram based on metadata created_at (#64)"…
bretthoerner Feb 5, 2024
54bf761
Dequeue multiple items at a time (#60)
bretthoerner Feb 6, 2024
26672ae
Remove non-transactional mode (#65)
bretthoerner Feb 6, 2024
74ff834
Merge rusty-hook repo into capture repo.
bretthoerner Feb 6, 2024
bf7cccf
Sync workflow style/naming
bretthoerner Feb 6, 2024
5c64ef0
fix: Bump failure counter on job error (#36)
tomasfarias Feb 6, 2024
fca80b0
Use a single image type, namespace images under hog-rs
bretthoerner Feb 6, 2024
58d777f
Use Depot for build-push-action (#6)
bretthoerner Feb 7, 2024
017ae03
Fix depot build-push-action version and drop invalid builder argument…
bretthoerner Feb 7, 2024
49fa92b
Configure Actions permissions for build runs (#8)
bretthoerner Feb 7, 2024
a42a056
Actions docker build: change build-args to a newline delimited string…
bretthoerner Feb 7, 2024
6770bed
Temporarily switch to a single build-args argument (#10)
bretthoerner Feb 7, 2024
cb635eb
Fix Docker entrypoint (#11)
bretthoerner Feb 7, 2024
f9626e9
Add ENV for BIN (#12)
bretthoerner Feb 7, 2024
c856730
Add histogram for insertion time to completion time (#5)
bretthoerner Feb 8, 2024
4214362
Fix clippy complaint (#13)
bretthoerner Feb 8, 2024
3bcbb23
Drop debug symbols from release (#15)
bretthoerner Feb 9, 2024
e3047a6
replace vestigial unwraps with proper error reporting (#14)
xvello Feb 12, 2024
1ac549d
Replace DOCKERHUB_USERNAME secret with plaintext (#18)
frankh Feb 21, 2024
92018ab
Use Depot runners (#16)
bretthoerner Feb 23, 2024
56d4615
cleanup and upgrade deps (#20)
xvello Apr 15, 2024
591d765
capture: make otel service name configurable, will use deploy name (#22)
xvello Apr 22, 2024
4db3670
capture: add support for the /batch request shape (#21)
xvello Apr 22, 2024
0d48419
common: refactor health into its own lib crate (#23)
xvello Apr 24, 2024
55292bd
capture: don't allow events submitted with an empty distinct_id (#25)
xvello Apr 24, 2024
60debad
chore: improve linting (#26)
xvello Apr 24, 2024
26a67e9
capture: set kafka partitioner to murmur2_random (#27)
xvello Apr 25, 2024
9f5b72d
capture: don't serialize sent_at if empty (#28)
xvello Apr 30, 2024
bca9f84
feat(capture): send historical_migration batches to separate topic (#30)
xvello Apr 30, 2024
db332e5
fix capture CI (#32)
xvello May 2, 2024
c6d5c67
ci: move cargo check to linting job (#33)
xvello May 2, 2024
f7e02cc
feat: Track response in error details (#29)
tomasfarias May 3, 2024
e2ce466
CI: upgrade to Rust 1.77.2 and Debian bookworm (#34)
xvello May 3, 2024
cf9b82d
Bump webhook max size to 5MB (#38)
bretthoerner May 3, 2024
ee769d9
Make max_body_size configurable via env, drop custom check, use 413 (…
bretthoerner May 3, 2024
7715f46
chore: merge capture & capture-server crates (#36)
xvello May 6, 2024
e8343d9
ci: refactor docker build workflows for all rust crates (#37)
xvello May 6, 2024
281af61
hook-worker: deny traffic to internal IPs and IPv6 (#35)
xvello May 6, 2024
ae707cb
chore: cleanup unnecessary clippy allows (#40)
xvello May 6, 2024
871441b
feat(flags): Basic flags service (#31)
neilkakkar May 7, 2024
ebaf596
capture: add overflow_enabled option (#43)
xvello May 27, 2024
f71dc08
feat(flags): Do token validation and extract distinct id (#41)
neilkakkar May 29, 2024
ff0780c
capture: add broker rtt latency and timeout metrics (#44)
xvello May 29, 2024
8d69910
capture: fix produce_rtt_latency metric unit (#46)
xvello May 30, 2024
63db2a6
feat(flags): Extract flag definitions from redis (#42)
neilkakkar May 30, 2024
cf30272
capture: subdivide process_events_error cause (#48)
xvello Jun 6, 2024
f28466a
feat(flags): Match flags on rollout percentage (#45)
neilkakkar Jun 10, 2024
f6569a7
feat(flags): Add basic property matching (#47)
neilkakkar Jun 10, 2024
b43108d
merge history
neilkakkar Jun 10, 2024
ee6cd6d
chore: adjust ci for rust services, merge master
neilkakkar Jun 11, 2024
b5341ad
chore: merge master
neilkakkar Jun 12, 2024
6a7173b
Merge branch 'master' of github.com:PostHog/posthog into merge-repos-…
neilkakkar Jun 12, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/build-and-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
push:
branches:
- master
paths-ignore:
- 'rust/**'

jobs:
slack:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-hog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
# If this run wasn't initiated by the bot (meaning: snapshot update) and we've determined
# there are backend changes, cancel previous runs
- uses: n1hility/cancel-previous-runs@v3
if: github.actor != 'posthog-bot' && needs.changes.outputs.backend == 'true'
if: github.actor != 'posthog-bot' && needs.changes.outputs.hog == 'true'
with:
token: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/container-images-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ on:
push:
branches:
- master
paths-ignore:
- 'rust/**'
workflow_dispatch:

jobs:
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/rust-docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Build container images

on:
workflow_dispatch:
push:
paths:
- 'rust/**'
branches:
- 'master'

jobs:
build:
name: Build and publish container image
strategy:
matrix:
image:
- capture
- hook-api
- hook-janitor
- hook-worker
runs-on: depot-ubuntu-22.04-4
permissions:
id-token: write # allow issuing OIDC tokens for this workflow run
contents: read # allow reading the repo contents
packages: write # allow push to ghcr.io

defaults:
run:
working-directory: rust

steps:
- name: Check Out Repo
# Checkout project code
# Use sparse checkout to only select files in rust directory
# Turning off cone mode ensures that files in the project root are not included during checkout
uses: actions/checkout@v3
with:
sparse-checkout: 'rust/'
sparse-checkout-cone-mode: false

- name: Set up Depot CLI
uses: depot/setup-action@v1

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: posthog
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: false

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/posthog/posthog/${{ matrix.image }}
tags: |
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Build and push image
id: docker_build
uses: depot/build-push-action@v1
with:
context: ./rust/
file: ./rust/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: BIN=${{ matrix.image }}

- name: Container image digest
run: echo ${{ steps.docker_build.outputs.digest }}
86 changes: 86 additions & 0 deletions .github/workflows/rust-hook-migrator-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Build hook-migrator docker image

on:
workflow_dispatch:
push:
paths:
- 'rust/**'
branches:
- 'master'

permissions:
packages: write

jobs:
build:
name: build and publish hook-migrator image
runs-on: depot-ubuntu-22.04-4
permissions:
id-token: write # allow issuing OIDC tokens for this workflow run
contents: read # allow reading the repo contents
packages: write # allow push to ghcr.io

defaults:
run:
working-directory: rust

steps:
- name: Check Out Repo
# Checkout project code
# Use sparse checkout to only select files in rust directory
# Turning off cone mode ensures that files in the project root are not included during checkout
uses: actions/checkout@v3
with:
sparse-checkout: 'rust/'
sparse-checkout-cone-mode: false

- name: Set up Depot CLI
uses: depot/setup-action@v1

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: posthog
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/posthog/hog-rs/hook-migrator
tags: |
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Build and push migrator
id: docker_build_hook_migrator
uses: depot/build-push-action@v1
with:
context: ./rust/
file: ./rust/Dockerfile.migrate
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Hook-migrator image digest
run: echo ${{ steps.docker_build_hook_migrator.outputs.digest }}
192 changes: 192 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
name: Rust

on:
workflow_dispatch:
push:
branches: [master, main]
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
# Job to decide if we should run rust ci
# See https://github.com/dorny/paths-filter#conditional-execution for more details
changes:
runs-on: ubuntu-latest
timeout-minutes: 5
if: github.repository == 'PostHog/posthog'
name: Determine need to run rust checks
# Set job outputs to values from filter step
outputs:
rust: ${{ steps.filter.outputs.rust }}
steps:
# For pull requests it's not necessary to checkout the code, but we
# also want this to run on master so we need to checkout
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
rust:
# Avoid running rust tests for irrelevant changes
- 'rust/**'

build:
needs: changes
runs-on: depot-ubuntu-22.04-4

defaults:
run:
working-directory: rust

steps:
# Checkout project code
# Use sparse checkout to only select files in rust directory
# Turning off cone mode ensures that files in the project root are not included during checkout
- uses: actions/checkout@v3
if: needs.changes.outputs.rust == 'true'
with:
sparse-checkout: 'rust/'
sparse-checkout-cone-mode: false

- name: Install rust
if: needs.changes.outputs.rust == 'true'
uses: dtolnay/[email protected]

- uses: actions/cache@v3
if: needs.changes.outputs.rust == 'true'
with:
path: |
~/.cargo/registry
~/.cargo/git
rust/target
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}

- name: Run cargo build
if: needs.changes.outputs.rust == 'true'
run: cargo build --all --locked --release && find target/release/ -maxdepth 1 -executable -type f | xargs strip

test:
needs: changes
runs-on: depot-ubuntu-22.04-4
timeout-minutes: 10

defaults:
run:
working-directory: rust

steps:
# Checkout project code
# Use sparse checkout to only select files in rust directory
# Turning off cone mode ensures that files in the project root are not included during checkout
- uses: actions/checkout@v3
if: needs.changes.outputs.rust == 'true'
with:
sparse-checkout: 'rust/'
sparse-checkout-cone-mode: false

- name: Login to DockerHub
if: needs.changes.outputs.rust == 'true'
uses: docker/login-action@v2
with:
username: posthog
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Setup dependencies
if: needs.changes.outputs.rust == 'true'
run: |
docker compose up kafka redis db echo_server -d --wait
docker compose up setup_test_db
echo "127.0.0.1 kafka" | sudo tee -a /etc/hosts

- name: Install rust
if: needs.changes.outputs.rust == 'true'
uses: dtolnay/[email protected]

- uses: actions/cache@v3
if: needs.changes.outputs.rust == 'true'
with:
path: |
~/.cargo/registry
~/.cargo/git
rust/target
key: ${ runner.os }-cargo-debug-${{ hashFiles('**/Cargo.lock') }}

- name: Run cargo test
if: needs.changes.outputs.rust == 'true'
run: cargo test --all-features

linting:
needs: changes
runs-on: depot-ubuntu-22.04-4

defaults:
run:
working-directory: rust

steps:
# Checkout project code
# Use sparse checkout to only select files in rust directory
# Turning off cone mode ensures that files in the project root are not included during checkout
- uses: actions/checkout@v3
if: needs.changes.outputs.rust == 'true'
with:
sparse-checkout: 'rust/'
sparse-checkout-cone-mode: false

- name: Install rust
if: needs.changes.outputs.rust == 'true'
uses: dtolnay/[email protected]
with:
components: clippy,rustfmt

- uses: actions/cache@v3
if: needs.changes.outputs.rust == 'true'
with:
path: |
~/.cargo/registry
~/.cargo/git
rust/target
key: ${{ runner.os }}-cargo-debug-${{ hashFiles('**/Cargo.lock') }}

- name: Check format
if: needs.changes.outputs.rust == 'true'
run: cargo fmt -- --check

- name: Run clippy
if: needs.changes.outputs.rust == 'true'
run: cargo clippy -- -D warnings

- name: Run cargo check
if: needs.changes.outputs.rust == 'true'
run: cargo check --all-features

shear:
needs: changes
runs-on: depot-ubuntu-22.04-4

defaults:
run:
working-directory: rust

steps:
# Checkout project code
# Use sparse checkout to only select files in rust directory
# Turning off cone mode ensures that files in the project root are not included during checkout
- uses: actions/checkout@v3
if: needs.changes.outputs.rust == 'true'
with:
sparse-checkout: 'rust/'
sparse-checkout-cone-mode: false

- name: Install cargo-binstall
if: needs.changes.outputs.rust == 'true'
uses: cargo-bins/cargo-binstall@main

- name: Install cargo-shear
if: needs.changes.outputs.rust == 'true'
run: cargo binstall --no-confirm cargo-shear

- run: cargo shear
if: needs.changes.outputs.rust == 'true'
Loading
Loading