Skip to content

fix(graph): refactor query method to accept subscriptions directly and add QueryOptions for management group scope#883

Merged
cmendible merged 1 commit into
mainfrom
issue-882
Jun 9, 2026
Merged

fix(graph): refactor query method to accept subscriptions directly and add QueryOptions for management group scope#883
cmendible merged 1 commit into
mainfrom
issue-882

Conversation

@cmendible

Copy link
Copy Markdown
Member

Description

This pull request refactors how subscription data is passed to Resource Graph queries across the codebase, improving type safety and simplifying the API. It introduces a new QueryOptions struct for optional query features, updates all scanner modules to use a map[string]string for subscriptions instead of slices of pointers, and removes redundant code for preparing subscription lists. Additionally, it enables management group scope for policy queries via the new options struct.

API and Query Handling Improvements:

  • Updated GraphQueryClient.Query to accept subscriptions as a map[string]string (from []*string), improving clarity and type safety. All call sites in scanner modules are updated accordingly. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]
  • Introduced QueryOptions struct to control optional query features (e.g., ManagementGroupScope), and refactored query batching and pagination logic for clarity and maintainability. [1] [2]
  • Enabled management group scope for Azure Policy queries by passing QueryOptions{ManagementGroupScope: true} where needed.

Code Simplification and Cleanup:

  • Removed repetitive code that converted subscription maps to pointer slices throughout scanner modules, reducing boilerplate and potential for errors. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]
  • Removed unnecessary deduplication logic in the Advisor scanner, relying on the query itself for uniqueness. [1] [2]

Scanner Module Adjustments:

  • Updated all scanners (Advisor, ArcSQL, Azure Policy, Defender, OpenAI Throttling, and ResourceDiscovery) to use the new query API and pass subscription maps, and to utilize the subscription name mapping directly for result enrichment. [1] [2]

These changes collectively streamline Resource Graph querying, reduce duplicated code, and provide a more flexible and robust interface for future enhancements.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #882

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Unit tests passing

@cmendible cmendible left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@codecov-commenter

codecov-commenter commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.13%. Comparing base (14b206c) to head (e4f1ae4).

Files with missing lines Patch % Lines
internal/scanners/advisor.go 0.00% 22 Missing ⚠️
internal/graph/graph.go 0.00% 15 Missing ⚠️
internal/scanners/resources.go 0.00% 3 Missing ⚠️
internal/scanners/defender.go 0.00% 2 Missing ⚠️
internal/graph/graph_scanner.go 0.00% 1 Missing ⚠️
internal/scanners/arc_sql.go 0.00% 1 Missing ⚠️
internal/scanners/azure_policy.go 0.00% 1 Missing ⚠️
internal/scanners/plugins/openai/throttling.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #883      +/-   ##
==========================================
+ Coverage   22.96%   23.13%   +0.16%     
==========================================
  Files          95       95              
  Lines        5860     5818      -42     
==========================================
  Hits         1346     1346              
+ Misses       4406     4364      -42     
  Partials      108      108              
Flag Coverage Δ
unittests 23.13% <0.00%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…d add QueryOptions for management group scope #882
@cmendible cmendible merged commit 2c7d6b7 into main Jun 9, 2026
12 checks passed
@cmendible cmendible deleted the issue-882 branch June 9, 2026 18:05
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.

perf: improve Resource Graph query performance

2 participants