Skip to content

Conversation

@santihernandezc
Copy link

@santihernandezc santihernandezc commented Dec 4, 2025

Fixes #746


Note

Archives and deduplicates counters/histograms/summaries from soft-deleted tenant registries and includes them in aggregations; adds tests and a benchmark.

  • Metrics (TenantRegistries):
    • Add archived MetricFamilyMap to store metrics from soft-deleted registries (excludes gauges).
    • Replace soft-delete flow: AddTenantRegistry and RemoveTenantRegistry now call archiveTenantRegistry and remove the registry; keep old RemoveTenantRegistry_Old for reference.
    • Implement archival with label-based dedup and value aggregation via deduplicateMetrics, getMetricLabelSignature, and mergeMetricValues (counters/summaries/histograms only).
    • BuildMetricFamiliesPerTenant: include archived metrics as an empty-tenant entry; copy archived under lock to avoid concurrent access.
  • Tests/Benchmarks:
    • Add TestSoftRemoveTenantRegistryDeduplication ensuring deduplication and accumulation; gauges not archived.
    • Add BenchmarkSoftRemoveMemoryLeak to verify bounded memory on tenant churn.

Written by Cursor Bugbot for commit 350206f. This will update automatically on new commits. Configure here.

@santihernandezc santihernandezc marked this pull request as draft December 4, 2025 14:19
newFamily := &dto.MetricFamily{
Name: v.Name,
Help: v.Help,
Type: v.Type,
Copy link

Choose a reason for hiding this comment

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

Bug: Inconsistent metric type used for deduplication vs storage

The deduplicateMetrics function is called with m.GetType() (the new metric's type), but the resulting MetricFamily is created with v.Type (the existing metric's type). If types somehow differ, the merged metrics would be processed using one type but the family would be labeled with a different type, causing inconsistent metric data. The type used for merging and for the family should be consistent.

Fix in Cursor Fix in Web

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.

Memory leak when repeatedly creating and soft-removing tenant registries

1 participant