Skip to content

Conversation

@inthirakumaaran
Copy link
Contributor

@inthirakumaaran inthirakumaaran commented Dec 23, 2025

Purpose

Related IS 6.1.0 and below versions
Remove the counter logic related b2b org count

Summary by CodeRabbit

  • Refactor
    • Simplified identity usage data collection by removing B2B organization metrics from reports. The system now exclusively tracks total user count and root organization statistics, eliminating multi-organization hierarchy traversal logic.
    • Eliminated dependency on the organization management service, reducing overall system complexity and external service requirements for data collection operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

Walkthrough

The pull request removes B2B organization counting functionality from the identity usage data collector component. Changes include deleting the OrganizationCounter class, refactoring UserCounter to operate independently of OrganizationManager, removing the organizationManager dependency throughout the stack, and eliminating B2B organization-related fields from data models.

Changes

Cohort / File(s) Summary
Dependency Management
collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml
Removed identity organization management dependency and import-package entry; removed related version properties; updated identity.framework.version.range from [7.0.0,8.0.0) to [5.0.0,8.0.0)
Core Collection Logic
collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java
Removed OrganizationManager and OrganizationCounter dependencies; eliminated B2B organization accumulation logic in collectSystemStatistics and processTenant; removed TOTAL_B2B_ORGS metric publishing
Counter Components
collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/OrganizationCounter.java
File deleted; removed public method countB2BOrganizations and constructor
collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/UserCounter.java
Service Infrastructure
collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorDataHolder.java
Removed organizationManager field, getter, and setter
collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorServiceComponent.java
Data Models
collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/SystemUsage.java
Removed totalB2BOrganizations field, getter, setter, and toString reference
collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/TenantUsage.java

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 B2B orgs bundled away with care,
Simpler stats now fill the air,
UserCounter stands alone so bright,
Metrics lean but tracking right! 📊

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete. It provides only a brief Purpose section but omits all other required template sections including Goals, Approach, User stories, Release notes, Documentation, Testing, Security, and other critical details. Complete the PR description by filling out the remaining required template sections. At minimum, provide Goals, Approach, Release notes, and Documentation impact. Include test coverage details and confirm security checks.
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title '[IS]Remove b2b org count.' accurately reflects the main change: removal of B2B organization counting logic throughout the codebase.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f2398b and 6dae24d.

📒 Files selected for processing (8)
  • collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/OrganizationCounter.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/UserCounter.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorDataHolder.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorServiceComponent.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/SystemUsage.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/TenantUsage.java
💤 Files with no reviewable changes (5)
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorDataHolder.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorServiceComponent.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/SystemUsage.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/OrganizationCounter.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/TenantUsage.java
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-12-07T18:41:22.612Z
Learnt from: ashanhr
Repo: wso2/usage-data-collector PR: 8
File: collectors/org.wso2.carbon.usage.data.collector.common/src/main/java/org/wso2/carbon/usage/data/collector/common/internal/UsageDataCollectorServiceComponent.java:93-108
Timestamp: 2025-12-07T18:41:22.612Z
Learning: In the wso2/usage-data-collector repository, for the common collector module (org.wso2.carbon.usage.data.collector.common), errors in UsageDataCollectorServiceComponent should be silenced (gated behind debug flags) to avoid exposing internal issues in customer-facing scenarios, particularly for non-fatal errors like meta information publishing failures at startup.

Applied to files:

  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml
📚 Learning: 2025-11-21T04:35:45.575Z
Learnt from: inthirakumaaran
Repo: wso2/usage-data-collector PR: 4
File: collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/UserCounter.java:170-227
Timestamp: 2025-11-21T04:35:45.575Z
Learning: In the WSO2 usage data collector (collectors/org.wso2.carbon.usage.data.collector.identity), errors should not be logged at ERROR level in production for customer-facing scenarios. Error logging should be gated behind debug flags to avoid exposing internal issues to customers unless debug logging is explicitly enabled.

Applied to files:

  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java
📚 Learning: 2025-12-19T11:41:50.935Z
Learnt from: inthirakumaaran
Repo: wso2/usage-data-collector PR: 12
File: collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollectorScheduler.java:43-43
Timestamp: 2025-12-19T11:41:50.935Z
Learning: In the wso2/usage-data-collector repository, for the identity collector module (org.wso2.carbon.usage.data.collector.identity), the default scheduled day for UsageDataCollectorScheduler is WEDNESDAY (DayOfWeek.WEDNESDAY), not SUNDAY, as per the latest decision.

Applied to files:

  • collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml
📚 Learning: 2025-12-03T03:41:25.406Z
Learnt from: inthirakumaaran
Repo: wso2/usage-data-collector PR: 9
File: collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml:74-93
Timestamp: 2025-12-03T03:41:25.406Z
Learning: In WSO2 Carbon projects, dependency versions (such as httpclient5, httpcore5, securevault) are often constrained by what's available in the Carbon platform. Since libraries are imported as OSGi packages with version ranges, components will automatically use updated/secure versions when the Carbon platform is upgraded, without requiring changes to the component's pom.xml.

Applied to files:

  • collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml
🔇 Additional comments (6)
collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml (2)

32-234: Dependency removal for B2B organization counting is complete and verified.

The removal of the org.wso2.carbon.identity.organization.management.service dependency, along with related imports and properties, is correctly implemented. No lingering references to organization management APIs remain in the codebase, confirming the changes enable backward compatibility with WSO2 IS 6.1.0 and below as intended.


220-220: No backward compatibility issues detected with Identity Framework version range.

The version range has been widened from [7.0.0,8.0.0) to [5.0.0,8.0.0) to support older Identity Framework versions. Verification confirms the collector only uses stable core utilities (IdentityDatabaseUtil, IdentityUtil) from org.wso2.carbon.identity.core, which are fundamental components available across all supported versions. The organization management dependency and all its references have been completely removed, eliminating any version-specific API concerns. The change is safe and aligns with the PR objective to support IS 6.1.0 and below.

collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java (2)

54-59: LGTM!

The constructor change correctly aligns with the simplified UserCounter that now only requires RealmService.


129-136: LGTM!

The tenant processing is cleanly simplified. The user count is now retrieved directly via countUsersInOrganization, which aligns with the removal of B2B organization counting.

collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/UserCounter.java (2)

52-55: LGTM!

Constructor correctly simplified to accept only RealmService after removing OrganizationManager dependency.


60-81: LGTM!

The refactored method:

  • Correctly resolves tenant ID from domain
  • Properly manages the privileged tenant flow with cleanup in finally
  • Error handling appropriately gates logging behind debug flag, consistent with project conventions

Based on learnings, error logging gated behind debug flags is the expected pattern for this module.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@inthirakumaaran
Copy link
Contributor Author

DO NOT MERGE we need to create different branch for this

@inthirakumaaran inthirakumaaran marked this pull request as draft December 23, 2025 09:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java (1)

47-47: Unused constant TOTAL_B2B_ORGS should be removed.

This constant is no longer referenced after removing B2B org metric publishing from publishUsageMetrics. It should be removed as part of this cleanup.

🔎 Proposed fix
     public static final String SUPER_TENANT = "carbon.super";
     public static final String TOTAL_USERS = "TOTAL_USERS";
-    public static final String TOTAL_B2B_ORGS = "TOTAL_B2B_ORGS";
     public static final String TOTAL_ROOT_ORGS = "TOTAL_ROOT_ORGS";
collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/UserCounter.java (2)

44-48: Remove unused constants.

LDAP_PAGE_SIZE and MAX_LDAP_ITERATIONS are not used anywhere after LDAP counting logic was removed. The remaining constants (SLEEP_BETWEEN_REQUESTS_MS, SLEEP_AFTER_MAX_REQUESTS_MS, MAX_REQUESTS_PER_MINUTE) are only used by applyRateLimiting, which itself appears to be dead code (see below).

🔎 Proposed fix
 public class UserCounter {

     private static final Log LOG = LogFactory.getLog(UserCounter.class);

-    // Configuration
-    private static final int LDAP_PAGE_SIZE = 100;
-    private static final int MAX_LDAP_ITERATIONS = 1000;
-    private static final long SLEEP_BETWEEN_REQUESTS_MS = 100; // 100ms
-    private static final long SLEEP_AFTER_MAX_REQUESTS_MS = 5_000; // 5 seconds
-    private static final int MAX_REQUESTS_PER_MINUTE = 2;
-
     private final RealmService realmService;

162-185: Remove unused applyRateLimiting method and associated constants.

The applyRateLimiting method is never invoked anywhere in the codebase. Additionally, the constants SLEEP_BETWEEN_REQUESTS_MS, SLEEP_AFTER_MAX_REQUESTS_MS, and MAX_REQUESTS_PER_MINUTE are only referenced within this dead method and should be removed along with it.

🔎 Proposed fix
     private boolean isJDBCUserStore(UserStoreManager userStoreManager, String domain) {

         try {
             AbstractUserStoreManager abstractUSM =
                     (AbstractUserStoreManager) userStoreManager.getSecondaryUserStoreManager(domain);
             return abstractUSM instanceof JDBCUserStoreManager;
         } catch (Exception e) {
             return false;
         }
     }
-
-    /**
-     * Apply rate limiting to protect database
-     * - Sleeps 100ms between every request
-     * - Sleeps 6 seconds after every 10 requests
-     */
-    private void applyRateLimiting(int iteration) throws InterruptedException {
-
-        // Always sleep a bit between requests
-        Thread.sleep(SLEEP_BETWEEN_REQUESTS_MS);
-
-        // After take a longer break after certain request count.
-        if (iteration % MAX_REQUESTS_PER_MINUTE == 0) {
-            LOG.debug(String.format("Rate limit checkpoint reached (%d requests). Sleeping for %dms",
-                    iteration, SLEEP_AFTER_MAX_REQUESTS_MS));
-            Thread.sleep(SLEEP_AFTER_MAX_REQUESTS_MS);
-            LOG.debug("Resumed after rate limit sleep");
-        }
-
-        // After 5000 users enforce another sleep.
-        if (iteration % 50 == 0) {
-            Thread.sleep(SLEEP_AFTER_MAX_REQUESTS_MS);
-            LOG.debug(String.format("Progress: %d iterations completed", iteration));
-        }
-    }
 }

Also remove the unused constants at lines 46-48:

-    private static final long SLEEP_BETWEEN_REQUESTS_MS = 100; // 100ms
-    private static final long SLEEP_AFTER_MAX_REQUESTS_MS = 5_000; // 5 seconds
-    private static final int MAX_REQUESTS_PER_MINUTE = 2;
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f2398b and 6dae24d.

📒 Files selected for processing (8)
  • collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/OrganizationCounter.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/UserCounter.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorDataHolder.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorServiceComponent.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/SystemUsage.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/TenantUsage.java
💤 Files with no reviewable changes (5)
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorDataHolder.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/internal/UsageDataCollectorServiceComponent.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/SystemUsage.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/OrganizationCounter.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/model/TenantUsage.java
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-12-07T18:41:22.612Z
Learnt from: ashanhr
Repo: wso2/usage-data-collector PR: 8
File: collectors/org.wso2.carbon.usage.data.collector.common/src/main/java/org/wso2/carbon/usage/data/collector/common/internal/UsageDataCollectorServiceComponent.java:93-108
Timestamp: 2025-12-07T18:41:22.612Z
Learning: In the wso2/usage-data-collector repository, for the common collector module (org.wso2.carbon.usage.data.collector.common), errors in UsageDataCollectorServiceComponent should be silenced (gated behind debug flags) to avoid exposing internal issues in customer-facing scenarios, particularly for non-fatal errors like meta information publishing failures at startup.

Applied to files:

  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java
  • collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml
📚 Learning: 2025-11-21T04:35:45.575Z
Learnt from: inthirakumaaran
Repo: wso2/usage-data-collector PR: 4
File: collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/UserCounter.java:170-227
Timestamp: 2025-11-21T04:35:45.575Z
Learning: In the WSO2 usage data collector (collectors/org.wso2.carbon.usage.data.collector.identity), errors should not be logged at ERROR level in production for customer-facing scenarios. Error logging should be gated behind debug flags to avoid exposing internal issues to customers unless debug logging is explicitly enabled.

Applied to files:

  • collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java
📚 Learning: 2025-12-19T11:41:50.935Z
Learnt from: inthirakumaaran
Repo: wso2/usage-data-collector PR: 12
File: collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollectorScheduler.java:43-43
Timestamp: 2025-12-19T11:41:50.935Z
Learning: In the wso2/usage-data-collector repository, for the identity collector module (org.wso2.carbon.usage.data.collector.identity), the default scheduled day for UsageDataCollectorScheduler is WEDNESDAY (DayOfWeek.WEDNESDAY), not SUNDAY, as per the latest decision.

Applied to files:

  • collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml
📚 Learning: 2025-12-03T03:41:25.406Z
Learnt from: inthirakumaaran
Repo: wso2/usage-data-collector PR: 9
File: collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml:74-93
Timestamp: 2025-12-03T03:41:25.406Z
Learning: In WSO2 Carbon projects, dependency versions (such as httpclient5, httpcore5, securevault) are often constrained by what's available in the Carbon platform. Since libraries are imported as OSGi packages with version ranges, components will automatically use updated/secure versions when the Carbon platform is upgraded, without requiring changes to the component's pom.xml.

Applied to files:

  • collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml
🔇 Additional comments (6)
collectors/org.wso2.carbon.usage.data.collector.identity/pom.xml (2)

32-234: Dependency removal for B2B organization counting is complete and verified.

The removal of the org.wso2.carbon.identity.organization.management.service dependency, along with related imports and properties, is correctly implemented. No lingering references to organization management APIs remain in the codebase, confirming the changes enable backward compatibility with WSO2 IS 6.1.0 and below as intended.


220-220: No backward compatibility issues detected with Identity Framework version range.

The version range has been widened from [7.0.0,8.0.0) to [5.0.0,8.0.0) to support older Identity Framework versions. Verification confirms the collector only uses stable core utilities (IdentityDatabaseUtil, IdentityUtil) from org.wso2.carbon.identity.core, which are fundamental components available across all supported versions. The organization management dependency and all its references have been completely removed, eliminating any version-specific API concerns. The change is safe and aligns with the PR objective to support IS 6.1.0 and below.

collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/UsageDataCollector.java (2)

54-59: LGTM!

The constructor change correctly aligns with the simplified UserCounter that now only requires RealmService.


129-136: LGTM!

The tenant processing is cleanly simplified. The user count is now retrieved directly via countUsersInOrganization, which aligns with the removal of B2B organization counting.

collectors/org.wso2.carbon.usage.data.collector.identity/src/main/java/org/wso2/carbon/usage/data/collector/identity/counter/UserCounter.java (2)

52-55: LGTM!

Constructor correctly simplified to accept only RealmService after removing OrganizationManager dependency.


60-81: LGTM!

The refactored method:

  • Correctly resolves tenant ID from domain
  • Properly manages the privileged tenant flow with cleanup in finally
  • Error handling appropriately gates logging behind debug flag, consistent with project conventions

Based on learnings, error logging gated behind debug flags is the expected pattern for this module.

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.

1 participant