fix: bound sessions_data memory usage - #78
Open
tensorsdynamics wants to merge 1 commit into
Open
Conversation
Default per-session metrics to Gauge, cap and expire the sampling buffer, avoid background collection when disabled, and reject concurrent RAC scrapes. Preserve explicit Summary compatibility and add regression tests.
LazarenkoA
reviewed
Sep 2, 2026
|
|
||
| ### SessionsData: безопасный режим и миграция | ||
|
|
||
| Начиная с этой версии `MetricKinds.SessionsData` по умолчанию использует |
LazarenkoA
reviewed
Sep 2, 2026
| exp.ExporterCheckSheduleJob.settings = s | ||
| // SessionsData has its own metric-kind setting. Summary remains available | ||
| // for compatibility, while Gauge is the safe default (see README). | ||
| newSummary := func() { |
Owner
There was a problem hiding this comment.
давай этот блок кода вынесем в метод конструктор (фабрику), который в зависимости от настроек инициализирует тот или иной объект
LazarenkoA
reviewed
Sep 2, 2026
| } | ||
| } | ||
| if exp.summary == nil && exp.gauge == nil { | ||
| newSummary() |
Owner
There was a problem hiding this comment.
точно? вроде ПР меняем по умолчанию на gauge
LazarenkoA
reviewed
Sep 2, 2026
|
|
||
| select { | ||
| case <-time.After(delay): | ||
| case <-ticker.C: |
LazarenkoA
reviewed
Sep 2, 2026
| exp.mx.Unlock() | ||
| } | ||
| exp.mx.Lock() | ||
| exp.pruneSessionsDataBufferLocked(now) |
Owner
There was a problem hiding this comment.
как будто бы изобретение кеша, возьми готовую либу
https://github.com/hashicorp/golang-lru
или другую (поищи подходящую для твоей задумки )
Owner
|
за тесты отдельное спасибо |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
sessions_data_gaugethe safe default while preserving explicit Summary compatibility;sessions_datais disabled;/metrics_racscrapes with HTTP 503 instead of queueing expensive RAC calls;Why
The previous per-session Summary mode kept quantile state for a high-cardinality label set and the sampling buffer depended on successful scrapes. On a busy 1C server this could grow memory usage into tens of GiB and make
/metrics_racresponses very large.Compatibility
Metrics.Containsbehavior.Verification
go test -v ./... -gcflags=all=-l -raceusinggolang:1.24— passed;golang:1.24— passed;gofmt -d— clean;git diff --check— clean.go vet ./...still reports the existingcontext.WithTimeoutcancel warning in unchangedapp.go:91; this PR does not alter that code path.