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

ref(spans): Add spans buffer v2 #85856

Merged
merged 65 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
b229e4e
ref(process-spans): Add spans buffer v2
untitaker Feb 25, 2025
1f4d0dd
wip on making the spans buffer fit for redis cluster
untitaker Feb 25, 2025
c4048bd
revert
untitaker Feb 25, 2025
cb1b88a
fix sunionstore
untitaker Feb 25, 2025
ec2e6a6
add todo
untitaker Feb 25, 2025
e45fa59
add code comment
untitaker Feb 25, 2025
a7fead9
add done_flush_segments
untitaker Feb 27, 2025
18d0cf7
fix mypy
untitaker Feb 27, 2025
2896294
add todo
untitaker Feb 27, 2025
4be2e59
fix fix fix
untitaker Feb 27, 2025
03085db
handle post-order correctly, add some docs
untitaker Mar 3, 2025
b39c1d0
fix bug with root timeout
untitaker Mar 4, 2025
84094ee
fix byteswarnings
untitaker Mar 4, 2025
fabfcbb
lol
untitaker Mar 4, 2025
616f719
Merge branch 'master' into spans-buffer-consumer-v2
jan-auer Mar 5, 2025
bd3b5a0
add metrics
untitaker Mar 5, 2025
6201190
fix: Filter empty segments and output correct segment ids
jan-auer Mar 5, 2025
9c348a9
fix typing
untitaker Mar 6, 2025
6be4be8
Merge branch 'master' into spans-buffer-consumer-v2
jan-auer Mar 6, 2025
f25279e
move flusher out of subthread, filter out empty segments, add more me…
untitaker Mar 6, 2025
68fe488
Merge branch 'master' into spans-buffer-consumer-v2
jan-auer Mar 6, 2025
d390312
enforce max_segments via redis, do not skip empty segments from deletion
untitaker Mar 6, 2025
41ce2da
debounce flush_segments
untitaker Mar 7, 2025
3990a3f
move flushing to bg thread
untitaker Mar 7, 2025
c46b255
fix backpressure being constantly disabled
untitaker Mar 7, 2025
4d98576
max-flush-segments cli
untitaker Mar 7, 2025
0978065
fix up
untitaker Mar 7, 2025
2262729
remove old buffer impl, make sharding configurable
untitaker Mar 10, 2025
8028e0d
remove old span buffer impl
untitaker Mar 10, 2025
a44f14d
fix dangling queue keys
untitaker Mar 10, 2025
1c6393e
add max-inflight-segments
untitaker Mar 10, 2025
b0089a5
Merge remote-tracking branch 'origin/master' into spans-buffer-consum…
untitaker Mar 10, 2025
3b0213d
Merge remote-tracking branch 'origin/master' into spans-buffer-consum…
untitaker Mar 10, 2025
6a4edf2
Merge remote-tracking branch 'origin/master' into spans-buffer-consum…
untitaker Mar 11, 2025
0d3810f
tweak shard assignment, wip
untitaker Mar 11, 2025
f5b95ae
fix tests
untitaker Mar 11, 2025
024ebef
more logs, better watermarking
untitaker Mar 11, 2025
c784d09
fix log line
untitaker Mar 11, 2025
d8f26bf
fix backpressure
untitaker Mar 11, 2025
22b33d4
remove dead test
untitaker Mar 12, 2025
78e6422
use hashsets
untitaker Mar 12, 2025
0449ac7
Revert "remove dead test"
untitaker Mar 12, 2025
d373662
remove dead test, attempt 2
untitaker Mar 12, 2025
336f143
fix is_segment_span preliminarily
untitaker Mar 12, 2025
6b3b11e
Merge remote-tracking branch 'origin/master' into spans-buffer-consum…
untitaker Mar 12, 2025
e4cbfaf
fix typing
untitaker Mar 12, 2025
494808e
Merge branch 'master' into spans-buffer-consumer-v2
jan-auer Mar 13, 2025
5371d81
fix: Put back the produce step into process-segments
jan-auer Mar 13, 2025
c2f38b1
fix test
untitaker Mar 13, 2025
92b2dd3
align shard count with partition count
untitaker Mar 13, 2025
6ad30b6
fix bytes warnings and tests again
untitaker Mar 13, 2025
43a507f
fix arbitrary span tree depths
untitaker Mar 13, 2025
5e33357
revert dockerifle
untitaker Mar 13, 2025
5a5c616
remove excessive logging
untitaker Mar 13, 2025
41f683c
Merge branch 'master' into spans-buffer-consumer-v2
untitaker Mar 13, 2025
7210543
inflight segments metric
untitaker Mar 13, 2025
224fc5c
apply review feedback
untitaker Mar 14, 2025
7e91b3e
rename file, fix tests, add one more docstring
untitaker Mar 14, 2025
1fdb6c5
fix a few bugs, remove backpressure
untitaker Mar 14, 2025
3603b02
fix nested root_spans case
untitaker Mar 14, 2025
ed8a075
fix typing
untitaker Mar 14, 2025
dfe0e72
remove more dead code
untitaker Mar 14, 2025
5a3ba1b
apply review feedback
untitaker Mar 14, 2025
ab9be2e
fix some more bugs and add e2e test
untitaker Mar 14, 2025
5da6916
fix mypy
untitaker Mar 14, 2025
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
16 changes: 15 additions & 1 deletion src/sentry/consumers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,21 @@ def ingest_transactions_options() -> list[click.Option]:
"process-spans": {
"topic": Topic.INGEST_SPANS,
"strategy_factory": "sentry.spans.consumers.process.factory.ProcessSpansStrategyFactory",
"click_options": multiprocessing_options(default_max_batch_size=100),
"click_options": [
click.Option(
["--max-flush-segments", "max_flush_segments"],
type=int,
default=100,
help="The number of segments to download from redis at once. Defaults to 100.",
),
click.Option(
["--max-inflight-segments", "max_inflight_segments"],
type=int,
default=10000,
help="The number of segments that can exist in Redis before the consumer applies backpressure. 0 is unlimited. Defaults to 10000.",
),
*multiprocessing_options(default_max_batch_size=100),
],
},
"process-segments": {
"topic": Topic.BUFFERED_SEGMENTS,
Expand Down
56 changes: 56 additions & 0 deletions src/sentry/scripts/spans/add-buffer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--[[

Add a span to the span buffer.

KEYS:
- "project_id:trace_id" -- just for redis-cluster routing, all keys that the script uses are sharded like this/have this hashtag.

ARGS:
- payload -- str
- is_root_span -- bool
- span_id -- str
- parent_span_id -- str
- set_timeout -- int

]]--

local project_and_trace = KEYS[1]

local payload = ARGV[1]
local is_root_span = ARGV[2] == "true"
local span_id = ARGV[3]
local parent_span_id = ARGV[4]
local set_timeout = tonumber(ARGV[5])

local span_key = string.format("span-buf:s:{%s}:%s", project_and_trace, span_id)

local main_redirect_key = string.format("span-buf:sr:{%s}", project_and_trace)
local set_span_id = parent_span_id
for i = 0, 10000 do -- theoretically this limit means that segment trees of depth 10k may not be joined together correctly, if there is e.g. a hole of size 10k.
local new_set_span = redis.call("hget", main_redirect_key, set_span_id)
if not new_set_span or new_set_span == set_span_id then
break
end

set_span_id = new_set_span
end

redis.call("hset", main_redirect_key, span_id, set_span_id)
local set_key = string.format("span-buf:s:{%s}:%s", project_and_trace, set_span_id)

if not is_root_span then
redis.call("sunionstore", set_key, set_key, span_key)
redis.call("del", span_key)
end
redis.call("sadd", set_key, payload)
redis.call("expire", set_key, set_timeout)

redis.call("expire", main_redirect_key, set_timeout)

local has_root_span_key = string.format("span-buf:hrs:%s", set_key)
local has_root_span = redis.call("get", has_root_span_key) == "1"
if has_root_span or is_root_span then
redis.call("setex", has_root_span_key, set_timeout, "1")
end

return {span_key, set_key, has_root_span or is_root_span}
159 changes: 0 additions & 159 deletions src/sentry/spans/buffer/redis.py

This file was deleted.

Loading
Loading