Skip to content

fix: bound sessions_data memory usage - #78

Open
tensorsdynamics wants to merge 1 commit into
LazarenkoA:masterfrom
tensorsdynamics:fix/sessions-data-bounds-gauge
Open

fix: bound sessions_data memory usage#78
tensorsdynamics wants to merge 1 commit into
LazarenkoA:masterfrom
tensorsdynamics:fix/sessions-data-bounds-gauge

Conversation

@tensorsdynamics

Copy link
Copy Markdown

Summary

  • make sessions_data_gauge the safe default while preserving explicit Summary compatibility;
  • cap the in-memory session buffer at 10,000 entries and expire samples after 2 minutes independently of Prometheus scrapes;
  • avoid starting the background RAC sampler when sessions_data is disabled;
  • reject concurrent /metrics_rac scrapes with HTTP 503 instead of queueing expensive RAC calls;
  • document the PromQL migration and add regression tests for buffer bounds, TTL, high cardinality, disabled configuration, compatibility fallback, and scrape concurrency.

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_rac responses very large.

Compatibility

  • Existing Summary series remain available with:
MetricKinds:
  SessionsData: ["Summary"]
  • Unsupported explicit kinds fall back to Summary instead of silently exporting no metric.
  • Exporter names are normalized consistently with the existing Metrics.Contains behavior.

Verification

  • go test -v ./... -gcflags=all=-l -race using golang:1.24 — passed;
  • Windows amd64 cross-build using golang:1.24 — passed;
  • gofmt -d — clean;
  • git diff --check — clean.

go vet ./... still reports the existing context.WithTimeout cancel warning in unchanged app.go:91; this PR does not alter that code path.

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.
Comment thread README.md

### SessionsData: безопасный режим и миграция

Начиная с этой версии `MetricKinds.SessionsData` по умолчанию использует

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

напиши с версии v1.5.3

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() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай этот блок кода вынесем в метод конструктор (фабрику), который в зависимости от настроек инициализирует тот или иной объект

}
}
if exp.summary == nil && exp.gauge == nil {
newSummary()

@LazarenkoA LazarenkoA Sep 2, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

точно? вроде ПР меняем по умолчанию на gauge


select {
case <-time.After(delay):
case <-ticker.C:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

какой в этом смысл?

exp.mx.Unlock()
}
exp.mx.Lock()
exp.pruneSessionsDataBufferLocked(now)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как будто бы изобретение кеша, возьми готовую либу
https://github.com/hashicorp/golang-lru
или другую (поищи подходящую для твоей задумки )

@LazarenkoA

Copy link
Copy Markdown
Owner

за тесты отдельное спасибо

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants