Skip to content

Conversation

@YashodhanJoshi1
Copy link
Contributor

This fixes two issues for reporting triggers to own org :

  • sometimes triggers of different orgs would get reporting to different orgs, this fixes it by grouping triggers by org and then ingesting them
  • for cloud, previously it would cause issues for expired orgs and block alert manager, now this skips the expired orgs altogether. With a previous change of disabling trigger causing stuff (alerts, reports etc) for expired orgs completely, this change should fix the minor remaining problem as well.

Signed-off-by: Yashodhan Joshi <[email protected]>
@github-actions github-actions bot added the ☢️ Bug Something isn't working label Nov 27, 2025
@github-actions
Copy link
Contributor

Failed to generate code suggestions for PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 27, 2025

Greptile Overview

Greptile Summary

This PR fixes two critical issues with self-reporting trigger ingestion:

Key Changes:

  • Fixed cross-org data leakage: Triggers are now grouped by organization before ingestion, ensuring each org's triggers are ingested separately to the correct org's stream (queues.rs:303-334)
  • Fixed alert manager blocking on expired orgs: Added cloud-specific check to skip expired organizations during trigger ingestion, preventing the alert manager from being blocked by expired orgs (queues.rs:310-322)
  • Fixed variable reference bug: Corrected usage of local usage_reporting_mode variable instead of cfg.common.usage_reporting_mode in error handling (ingestion.rs:194)

Implementation Details:
The refactored logic moves the per-org trigger ingestion from the additional_reporting_orgs loop to a separate section. It builds a HashMap<String, Vec<json::Value>> to group triggers by org, validates each org's trial period status (cloud only), and ingests each org's triggers independently. This ensures triggers for org1 don't accidentally get ingested to org2's stream.

Confidence Score: 4/5

  • Safe to merge with minor considerations - fixes critical data leakage and blocking issues
  • The changes address critical production issues (cross-org data leakage and alert manager blocking). The logic is sound: grouping by org prevents data leakage, and skipping expired orgs prevents blocking. Score reduced from 5 to 4 due to the error handling in the cloud-specific check - continuing on error could still cause issues, though it's logged.
  • No files require special attention - changes are straightforward bug fixes

Important Files Changed

File Analysis

Filename Score Overview
src/service/self_reporting/ingestion.rs 5/5 Fixed variable reference bug - changed cfg.common.usage_reporting_mode to usage_reporting_mode on line 194
src/service/self_reporting/queues.rs 4/5 Refactored trigger ingestion to group by org and skip expired orgs (cloud feature), preventing cross-org data leakage and blocking issues

Sequence Diagram

sequenceDiagram
    participant Queue as ReportingQueue
    participant Ingest as ingest_buffered_data
    participant OrgCheck as organization::is_org_in_free_trial_period
    participant IngestionSvc as ingestion::ingest_reporting_data
    
    Note over Queue,Ingest: Buffered triggers arrive
    Queue->>Ingest: triggers (Vec<json::Value>)
    
    alt additional_reporting_orgs configured
        Note over Ingest: Send to configured orgs (META_ORG, etc.)
        loop for each additional_reporting_org
            Ingest->>IngestionSvc: ingest_reporting_data(triggers.clone(), trigger_stream)
        end
    end
    
    alt usage_report_to_own_org enabled && mode != "remote"
        Note over Ingest: Group triggers by org
        loop for each trigger in triggers
            Ingest->>Ingest: Parse TriggerData from JSON
            alt cloud feature enabled
                Ingest->>OrgCheck: is_org_in_free_trial_period(org_id)
                OrgCheck-->>Ingest: Ok(ongoing) or Err(e)
                alt !ongoing or error
                    Note over Ingest: Skip this trigger (expired org)
                end
            end
            Note over Ingest: Add trigger to per_org_map[org_id]
        end
        
        loop for each (org, values) in per_org_map
            Ingest->>IngestionSvc: ingest_reporting_data(values, trigger_stream)
            Note over Ingest: Each org's triggers ingested separately
        end
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@YashodhanJoshi1 YashodhanJoshi1 changed the title fix: self-org-trigger issues fix: self-org-trigger issues (main) Nov 27, 2025
YashodhanJoshi1 added a commit that referenced this pull request Nov 27, 2025
cherry-pick of #9348 for
release branch

---------

Signed-off-by: Yashodhan Joshi <[email protected]>
Co-authored-by: Yashodhan Joshi <[email protected]>
@YashodhanJoshi1 YashodhanJoshi1 merged commit b75aa57 into main Nov 27, 2025
37 of 40 checks passed
@YashodhanJoshi1 YashodhanJoshi1 deleted the fix/trigger_for_expired_orgs branch November 27, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants