Skip to content

lapi: make decisions stream page size configurable - #4733

Merged
blotus merged 4 commits into
crowdsecurity:masterfrom
tommy-ng0:lapi-stream-page-size
Oct 7, 2026
Merged

blotus merged 4 commits into
crowdsecurity:masterfrom
tommy-ng0:lapi-stream-page-size

Conversation

@tommy-ng0

@tommy-ng0 tommy-ng0 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Adds a new config key: api.server.decisions_stream.page_size.

What and why

Each in-flight /v1/decisions/stream request holds one page of decisions in memory, and the page size was hardcoded to 30000 (// FIXME : make it configurable). With ~1.2k bouncers pulling a large delta at once, that's what put our LAPI into an OOM loop.

This makes the page size configurable, as suggested in #4711:

api:
  server:
    decisions_stream:
      page_size: 10000

It lives in its own decisions_stream section so other stream settings (like a concurrent requests limit) can join it. csconfig sets the default (30000) when the section or page_size is unset. The controller falls back to the default with a warning for a value of 0 or less, because ent drops LIMIT for 0 and SQLite ignores a negative one, so a non-positive value must never reach the query.

Lower values cap memory per request, at the cost of more DB round trips (the dedup subquery runs once per page). Bouncers see no difference: a pull is still one response with every decision in it.

Part of #4711

How it was tested

TestStreamDecisionPageSize runs the stream with page sizes of 1, 2 and 5 against 5 active and 3 expired decisions, so the startup resync and the delta both cross id_gt page boundaries. It also checks that an unset section, 0 and -1 fall back to 30000. TestLoadDecisionsStream covers the csconfig default.

$ go test ./pkg/apiserver/ -run TestStreamDecisionPageSize -count=1 -v
    --- PASS: TestStreamDecisionPageSize/section_unset (0.02s)
    --- PASS: TestStreamDecisionPageSize/zero_falls_back_to_default (0.02s)
    --- PASS: TestStreamDecisionPageSize/negative_falls_back_to_default (0.02s)
    --- PASS: TestStreamDecisionPageSize/one_per_page (0.02s)
    --- PASS: TestStreamDecisionPageSize/partial_last_page (0.01s)
    --- PASS: TestStreamDecisionPageSize/exact_multiple (0.01s)
ok  	github.com/crowdsecurity/crowdsec/pkg/apiserver	0.109s

$ go test ./pkg/csconfig/ -run 'TestLoadDecisionsStream|TestLoadAPIServer' -count=1 -v
--- PASS: TestLoadAPIServer (0.00s)
--- PASS: TestLoadDecisionsStream (0.00s)
ok  	github.com/crowdsecurity/crowdsec/pkg/csconfig	0.007s

$ TEST_LOCAL_ONLY=1 go test ./pkg/apiserver/... ./pkg/csconfig/... -count=1
ok  	github.com/crowdsecurity/crowdsec/pkg/apiserver	12.940s
ok  	github.com/crowdsecurity/crowdsec/pkg/apiserver/controllers/v1	0.008s
ok  	github.com/crowdsecurity/crowdsec/pkg/csconfig	0.010s

To check the tests aren't tautological, I broke the paging loop end condition, the config wiring, the non-positive fallback, and the csconfig default, one at a time. A test failed each time.

golangci-lint 2.13.2, run like make lint for linux, windows and freebsd: no issues in the changed files. All three report the same 22 issues that master reports with this version.

Not yet done: a local run against a real instance.

Checklist

  • One concern only.
  • No break to LAPI/CAPI payloads, database schema, config keys, or cscli -o json|raw output.
  • A human has reviewed this diff line by line.
  • A human has tested this change, not only an agent.

AI assistance used: mostly

/kind enhancement
/area local-api
/area configuration

Adds api.server.decisions_stream_page_size (default 30000, the previous
hardcoded value). Each in-flight /v1/decisions/stream request holds one
page in memory, so lowering it caps per-request memory at the cost of
more DB round trips.

Refs crowdsecurity#4711
Validating in LoadAPIServer pushed it over the revive cyclomatic limit.
Handle it where the value is used instead: 0 or negative falls back to
30000, and a negative value logs a warning. This also covers callers that
skip LoadAPIServer, which could previously pass a negative limit.
@tommy-ng0
tommy-ng0 marked this pull request as ready for review October 4, 2026 21:44
Comment thread pkg/csconfig/api.go Resolved
tommy-ng0 and others added 2 commits October 6, 2026 11:00
Review feedback: the key becomes decisions_stream.page_size so other
stream settings can join it, and the default is set in csconfig when the
config is loaded. The controller keeps a single <= 0 check that warns and
falls back to the default.
@tommy-ng0
tommy-ng0 requested a review from blotus October 5, 2026 22:04
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.16%. Comparing base (307f3d3) to head (d876505).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4733      +/-   ##
==========================================
- Coverage   71.16%   71.16%   -0.01%     
==========================================
  Files         538      538              
  Lines       36392    36405      +13     
==========================================
+ Hits        25900    25909       +9     
- Misses      10491    10495       +4     
  Partials        1        1              
Flag Coverage Δ
bats 45.78% <87.50%> (+0.01%) ⬆️
unit-linux 46.91% <100.00%> (+0.01%) ⬆️
unit-windows 34.59% <37.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blotus
blotus merged commit 93f9c05 into crowdsecurity:master Oct 7, 2026
17 checks passed
blotus added a commit to crowdsecurity/crowdsec-docs that referenced this pull request Oct 27, 2026
Document api.server.decisions_stream: page_size
(crowdsecurity/crowdsec#4733), max_concurrent_requests and max_queue_wait
(crowdsecurity/crowdsec#4747). Based on the work in #1179 and #1180.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
gabrielcosi pushed a commit to gabrielcosi/home-ops that referenced this pull request Oct 29, 2026
… ➔ v1.8.2) (#1487)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker.io/crowdsecurity/crowdsec](https://github.com/crowdsecurity/crowdsec) | patch | `v1.8.1` → `v1.8.2` |
| [docker.io/crowdsecurity/crowdsec](https://github.com/crowdsecurity/crowdsec) | patch | `v1.8.1-debian` → `v1.8.2-debian` |

---

### Release Notes

<details>
<summary>crowdsecurity/crowdsec (docker.io/crowdsecurity/crowdsec)</summary>

### [`v1.8.2`](https://github.com/crowdsecurity/crowdsec/releases/tag/v1.8.2)

[Compare Source](crowdsecurity/crowdsec@v1.8.1...v1.8.2)

##### Version 1.8.2

- Brings [custom JS fingerprinting capabilities](https://docs.crowdsec.net/docs/next/appsec/bot_detection/custom_js/) to the bot detection feature, allowing both users and us to distribute detection rules directly via the hub.
- Brings [rate limiting feature](https://docs.crowdsec.net/docs/next/appsec/rate_limiting/) to the WAF.
- Brings performance improvements to the Security Engine, optimizing both memory copy behaviors and relying on static analysis to avoid processing unnecessary regular expressions.
- Brings performance improvements to the WAF, optimizing out-of-band rules processing.
- Brings performance improvements to the Bot Detection, optimizing memory usage.

##### New Features & Major improvements

- \[WAF] Add RateLimiting feature ([#&#8203;4721](crowdsecurity/crowdsec#4721)) [@&#8203;blotus](https://github.com/blotus)
- \[bot-detection] Add custom JS fingerprinting capabilities ([#&#8203;4657](crowdsecurity/crowdsec#4657)) [@&#8203;buixor](https://github.com/buixor)
- \[bot-detection] Add cscli bot subcommand ([#&#8203;4666](crowdsecurity/crowdsec#4666)) [@&#8203;blotus](https://github.com/blotus)
- \[WAF] Improve out-of-band rules performances ([#&#8203;4722](crowdsecurity/crowdsec#4722)) [@&#8203;blotus](https://github.com/blotus)
- \[Security Engine] Run postoverflows in a separate goroutine to avoid blocking on slow enrichments ([#&#8203;4672](crowdsecurity/crowdsec#4672)) [@&#8203;blotus](https://github.com/blotus)
- \[bot-detection] Improve memory usage ([#&#8203;4674](crowdsecurity/crowdsec#4674)) [@&#8203;blotus](https://github.com/blotus)
- \[Security Engine] Various performance improvements to regular expression processing ([#&#8203;4736](crowdsecurity/crowdsec#4736)) ([#&#8203;4731](crowdsecurity/crowdsec#4731)) ([#&#8203;4729](crowdsecurity/crowdsec#4729)) [@&#8203;blotus](https://github.com/blotus) [@&#8203;buixor](https://github.com/buixor)

##### Improvements

- Add `cs_features` metric ([#&#8203;4770](crowdsecurity/crowdsec#4770)) [@&#8203;blotus](https://github.com/blotus)
- bot detection: add an option to set SameSite=None + Partitioned flag on cookie ([#&#8203;4764](crowdsecurity/crowdsec#4764)) [@&#8203;blotus](https://github.com/blotus)
- exprhelpers: add GetDecisionsSinceCountByScenario ([#&#8203;4756](crowdsecurity/crowdsec#4756)) [@&#8203;tommy-ng0](https://github.com/tommy-ng0)
- lapi: optionally limit concurrent decision stream requests ([#&#8203;4747](crowdsecurity/crowdsec#4747)) [@&#8203;tommy-ng0](https://github.com/tommy-ng0)
- exprhelpers: LookupHost goes through the DNS cache ([#&#8203;4741](crowdsecurity/crowdsec#4741)) [@&#8203;twiesing](https://github.com/twiesing)
- metrics: add CAPI last pull timestamp and error counter ([#&#8203;4749](crowdsecurity/crowdsec#4749)) [@&#8203;NazarkinRoman](https://github.com/NazarkinRoman)
- prometheus: add kind label to cs_alerts ([#&#8203;4742](crowdsecurity/crowdsec#4742)) [@&#8203;blotus](https://github.com/blotus)
- lapi: make decisions stream page size configurable ([#&#8203;4733](crowdsecurity/crowdsec#4733)) [@&#8203;tommy-ng0](https://github.com/tommy-ng0)
- Fix ValidateChallengeResponse ([#&#8203;4737](crowdsecurity/crowdsec#4737)) [@&#8203;buixor](https://github.com/buixor)
- bot-detection: add new FlagSubmission() helper ([#&#8203;4727](crowdsecurity/crowdsec#4727)) [@&#8203;blotus](https://github.com/blotus)
- appsec: add an optional category to the request score ([#&#8203;4715](crowdsecurity/crowdsec#4715)) [@&#8203;buixor](https://github.com/buixor)
- apiserver: reload the TLS server certificate when its files change ([#&#8203;4709](crowdsecurity/crowdsec#4709)) [@&#8203;ohartwig](https://github.com/ohartwig)
- fix image link ([#&#8203;4702](crowdsecurity/crowdsec#4702)) [@&#8203;buixor](https://github.com/buixor)
- waf: add SkipProcessing() helper ([#&#8203;4667](crowdsecurity/crowdsec#4667)) [@&#8203;blotus](https://github.com/blotus)
- \[bot-detection] drop the URI from the cookie ([#&#8203;4656](crowdsecurity/crowdsec#4656)) [@&#8203;buixor](https://github.com/buixor)

##### Bug Fixes

- acquisition/file: don't send half-written lines, or skip the lines after them ([#&#8203;4678](crowdsecurity/crowdsec#4678)) [@&#8203;n1koo](https://github.com/n1koo), [@&#8203;blotus](https://github.com/blotus), [@&#8203;claude](https://github.com/claude)
- fix(cscli): display human-readable timestamps in local time ([#&#8203;4759](crowdsecurity/crowdsec#4759)) [@&#8203;sep2](https://github.com/sep2)
- remove runtime Fatalf calls ([#&#8203;4760](crowdsecurity/crowdsec#4760)) [@&#8203;blotus](https://github.com/blotus)
- waf: fix log spam when usin unix socket on freebsd ([#&#8203;4745](crowdsecurity/crowdsec#4745)) [@&#8203;blotus](https://github.com/blotus)
- docker: read from now if container restarts ([#&#8203;4605](crowdsecurity/crowdsec#4605)) [@&#8203;blotus](https://github.com/blotus)
- splunk-notification: add an option to configure InsecureSkipVerify ([#&#8203;4720](crowdsecurity/crowdsec#4720)) [@&#8203;blotus](https://github.com/blotus)
- victorialogs: move the datasource to RestartableStreamer interface ([#&#8203;4738](crowdsecurity/crowdsec#4738)) [@&#8203;blotus](https://github.com/blotus)
- metrics: remove series of deleted machines and bouncers ([#&#8203;4712](crowdsecurity/crowdsec#4712)) [@&#8203;somaz94](https://github.com/somaz94)
- buckets: make a copy of all event maps before pouring the event to a bucket ([#&#8203;4481](crowdsecurity/crowdsec#4481)) [@&#8203;blotus](https://github.com/blotus)
- fix(database): keep simulated decisions from suppressing real bans ([#&#8203;4679](crowdsecurity/crowdsec#4679)) [@&#8203;4erdenko](https://github.com/4erdenko), [@&#8203;blotus](https://github.com/blotus)
- fix a nasty bug in transfrom where the effective uuid for a datasource ([#&#8203;4697](crowdsecurity/crowdsec#4697)) [@&#8203;sabban](https://github.com/sabban)
- hubtest: add a tiebreaker based on the alert date to have a consistent order ([#&#8203;4699](crowdsecurity/crowdsec#4699)) [@&#8203;blotus](https://github.com/blotus)
- syslog: copy buffer before handing it to the datasource ([#&#8203;4690](crowdsecurity/crowdsec#4690)) [@&#8203;blotus](https://github.com/blotus)
- Expand env vars in online_api_credentials.yaml ([#&#8203;4677](crowdsecurity/crowdsec#4677)) [@&#8203;kushiemoon-dev](https://github.com/kushiemoon-dev)

##### Chore / Deps

- build(deps): bump the gomod group with 5 updates ([#&#8203;4778](crowdsecurity/crowdsec#4778)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump the github-actions group with 2 updates ([#&#8203;4777](crowdsecurity/crowdsec#4777)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump certifi from 2026.1.4 to 2026.10.19 in /build/docker/test ([#&#8203;4780](crowdsecurity/crowdsec#4780)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump the github-actions group across 1 directory with 8 updates ([#&#8203;4766](crowdsecurity/crowdsec#4766)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump the gomod group with 16 updates ([#&#8203;4767](crowdsecurity/crowdsec#4767)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump the gomod group with 8 updates ([#&#8203;4753](crowdsecurity/crowdsec#4753)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- fpscanner: use fork ([#&#8203;4761](crowdsecurity/crowdsec#4761)) [@&#8203;blotus](https://github.com/blotus)
- waf: update to coraza 3.8.0 ([#&#8203;4724](crowdsecurity/crowdsec#4724)) [@&#8203;blotus](https://github.com/blotus), [@&#8203;buixor](https://github.com/buixor)
- build(deps): bump the gomod group across 1 directory with 19 updates ([#&#8203;4730](crowdsecurity/crowdsec#4730)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- CI: skip more docker tests on windows ([#&#8203;4728](crowdsecurity/crowdsec#4728)) [@&#8203;blotus](https://github.com/blotus)
- grok: embed grok library instead of having it as a dep ([#&#8203;4725](crowdsecurity/crowdsec#4725)) [@&#8203;blotus](https://github.com/blotus)
- docker datasource: skip tests on windows ([#&#8203;4719](crowdsecurity/crowdsec#4719)) [@&#8203;blotus](https://github.com/blotus)
- agents.md: keep comments to a reasonable level ([#&#8203;4716](crowdsecurity/crowdsec#4716)) [@&#8203;blotus](https://github.com/blotus)
- build(deps): bump the github-actions group with 7 updates ([#&#8203;4693](crowdsecurity/crowdsec#4693)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump the gomod group with 11 updates ([#&#8203;4694](crowdsecurity/crowdsec#4694)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump github.com/go-openapi/validate from 0.26.5 to 1.0.0 ([#&#8203;4682](crowdsecurity/crowdsec#4682)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump the gomod group with 19 updates ([#&#8203;4681](crowdsecurity/crowdsec#4681)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump cryptography from 48.0.1 to 50.0.0 in /build/docker/test ([#&#8203;4591](crowdsecurity/crowdsec#4591)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- bump to go 1.27 ([#&#8203;4675](crowdsecurity/crowdsec#4675)) [@&#8203;blotus](https://github.com/blotus)
- build(deps): bump the github-actions group across 1 directory with 3 updates ([#&#8203;4658](crowdsecurity/crowdsec#4658)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- build(deps): bump the gomod group across 1 directory with 21 updates ([#&#8203;4659](crowdsecurity/crowdsec#4659)) [@&#8203;dependabot\[bot\]](https://github.com/apps/dependabot)
- AGENTS.md: clearer guidance on tests ([#&#8203;4713](crowdsecurity/crowdsec#4713)) [@&#8203;blotus](https://github.com/blotus)
- pimp readme ([#&#8203;4701](crowdsecurity/crowdsec#4701)) [@&#8203;buixor](https://github.com/buixor)

##### Geolite2 notice

This product includes GeoLite2 data created by MaxMind, available from <a href="https://www.maxmind.com"><https://www.maxmind.com></a>.

##### Installation

Take a look at the [installation instructions](https://doc.crowdsec.net/docs/getting_started/install_crowdsec).

</details>

---

### Configuration

📅 **Schedule**: (in timezone Europe/Berlin)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xODEuMSIsInVwZGF0ZWRJblZlciI6IjQ0LjE4MS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.xcd.dev/gabrielcosi/home-ops/pulls/1487
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants