Skip to content

Fix inflated dashboard host count for Constructed Inventories (Issue #1459)#16359

Open
TheDevCodingKen wants to merge 3 commits intoansible:develfrom
TheDevCodingKen:fix/issue-1459-dashboard-host-count
Open

Fix inflated dashboard host count for Constructed Inventories (Issue #1459)#16359
TheDevCodingKen wants to merge 3 commits intoansible:develfrom
TheDevCodingKen:fix/issue-1459-dashboard-host-count

Conversation

@TheDevCodingKen
Copy link

@TheDevCodingKen TheDevCodingKen commented Mar 17, 2026

Summary

Fixes ansible/awx-operator#1459

The dashboard previously counted duplicate host records generated by Constructed Inventories, artificially inflating the 'Total' and 'Failed' host metrics.

This PR updates the DashboardView API queryset to leverage .values('name').distinct().count(). This ensures the underlying SQL query filters out duplicate database rows and accurately reflects the true number of unique managed nodes.

Summary by CodeRabbit

  • Bug Fixes

    • Dashboard host statistics now exclude virtual/constructed inventory hosts when computing total hosts and failure counts, providing more accurate metrics; failure-detail links remain unchanged.
  • Tests

    • Added a functional test ensuring dashboard host counts ignore duplicate hosts from constructed inventories.

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 55a2ba03-1665-4622-817d-53094985d1a9

📥 Commits

Reviewing files that changed from the base of the PR and between 2592ff8 and 12d00a2.

📒 Files selected for processing (2)
  • awx/api/views/__init__.py
  • awx/main/tests/functional/api/test_dashboard.py

📝 Walkthrough

Walkthrough

Dashboard host-count logic now excludes hosts coming from virtual inventories (inventories with kind smart or constructed) when computing the dashboard hosts.total and hosts.failed counts.

Changes

Cohort / File(s) Summary
Dashboard Host Count Logic
awx/api/views/__init__.py
Introduce base_user_hosts by excluding inventories with kind in ['smart', 'constructed']; use base_user_hosts.count() for hosts.total and filter failures from base_user_hosts.
Tests (new)
awx/main/tests/functional/api/test_dashboard.py
Add test_dashboard_host_count_ignores_constructed_inventories to verify dashboard host total ignores duplicate hosts from a constructed inventory.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main fix: addressing inflated dashboard host counts caused by constructed inventories, with a reference to the issue number.
Linked Issues check ✅ Passed The pull request addresses the core requirement from issue #1459 by excluding virtual inventory hosts (constructed and smart) from dashboard host count calculations, ensuring unique managed nodes are counted.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the dashboard host count issue: modifying DashboardView to filter virtual inventories and adding a test to verify the fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@awx/api/views/__init__.py`:
- Around line 211-212: The host counts use values('name').distinct().count(),
which undercounts hosts that share a name across inventories because Host.name
is only unique per-inventory; change the deduplication to use instance_id (or
inventory-scoped filtering) instead: update the two usages of
user_hosts.values('name').distinct().count() and
user_hosts_failed.values('name').distinct().count() to count distinct non-empty
instance_id (e.g., exclude empty instance_id and use
values('instance_id').distinct().count()) or apply inventory-aware filtering
depending on the calling context so Host instance uniqueness is correctly
measured.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6a73207a-27b7-48ff-bbc6-d7631da0a06c

📥 Commits

Reviewing files that changed from the base of the PR and between 1646694 and b277e76.

📒 Files selected for processing (1)
  • awx/api/views/__init__.py

@TheDevCodingKen TheDevCodingKen force-pushed the fix/issue-1459-dashboard-host-count branch 3 times, most recently from cd9ce19 to 2592ff8 Compare March 17, 2026 21:08
@TheDevCodingKen
Copy link
Author

@coderabbitai resume

@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

✅ Actions performed

Reviews resumed.

Signed-off-by: TheDevCodingKen <93670654+TheDevCodingKen@users.noreply.github.com>
Signed-off-by: TheDevCodingKen <93670654+TheDevCodingKen@users.noreply.github.com>
…ed inventories

Signed-off-by: TheDevCodingKen <93670654+TheDevCodingKen@users.noreply.github.com>
@TheDevCodingKen TheDevCodingKen force-pushed the fix/issue-1459-dashboard-host-count branch from 2592ff8 to 12d00a2 Compare March 19, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inflated Total Host Count on Dashboard when Using Constructed Inventory with Existing Inventories

1 participant