Skip to content

Conversation

@srnagar
Copy link
Member

@srnagar srnagar commented Dec 18, 2025

What does this PR do?

[Provide a clear, concise description of the changes]

This pull request refactors the metrics querying implementation in the monitoring tool to use the newer Azure Resource Manager (ARM) Monitor SDK instead of the deprecated Azure.Monitor.Query SDK. The main changes involve updating service registrations, removing the legacy metrics client service, and rewriting metric-related logic to use the new ARM Monitor APIs. This improves maintainability and aligns the codebase with current Azure SDK recommendations.

Migration to Azure Resource Manager Monitor SDK

  • Replaced all usage of Azure.Monitor.Query and related models with Azure.ResourceManager.Monitor and its models throughout MonitorMetricsService, including metric querying, definitions, and namespaces logic. [1] [2] [3] [4] [5] [6] [7]

Service and Dependency Updates

  • Removed the IMetricsQueryClientService interface and its implementation (MetricsQueryClientService); updated DI registration and all service usages to rely on ARM Monitor SDK instead. [1] [2] [3]

Project and Package Reference Changes

  • Removed Azure.Monitor.Query NuGet package reference and added Azure.ResourceManager.Monitor to both the solution-wide packages and the monitoring tool project file. [1] [2] [3]

Testing and Code Clean-up

  • Updated test project imports to remove references to the old metrics query SDK and models.

These changes modernize the metrics querying subsystem and ensure future compatibility with Azure SDKs.

GitHub issue number?

#1272

Pre-merge Checklist

  • Required for All PRs
    • [c] Read contribution guidelines
    • [c] PR title clearly describes the change
    • [c] Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes using script at eng/scripts/Process-PackageReadMe.ps1. See Package README
    • Updated command list in /servers/Azure.Mcp.Server/docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • Run .\eng\scripts\Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

@srnagar srnagar changed the title Azure Monitor: Use Azure.ResourceManager.Monitor package to query met… Azure Monitor: Use Azure.ResourceManager.Monitor package to query metrics Dec 22, 2025
Copy link
Member

@jairmyree jairmyree left a comment

Choose a reason for hiding this comment

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

Besides the one comment it looks good to me

@jairmyree jairmyree self-requested a review January 6, 2026 19:59
@github-project-automation github-project-automation bot moved this from Untriaged to In Progress in Azure MCP Server Jan 6, 2026
@srnagar srnagar marked this pull request as ready for review January 6, 2026 22:58
@srnagar srnagar requested review from a team and qianwens as code owners January 6, 2026 22:58
Copilot AI review requested due to automatic review settings January 6, 2026 22:58
@srnagar srnagar requested review from a team and jongio as code owners January 6, 2026 22:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request migrates the Azure Monitor metrics querying implementation from the deprecated Azure.Monitor.Query SDK to the newer Azure.ResourceManager.Monitor SDK. The refactoring modernizes the metrics subsystem to align with current Azure SDK recommendations and improves long-term maintainability.

Key Changes:

  • Replaced Azure.Monitor.Query package with Azure.ResourceManager.Monitor (version 1.4.0-beta.3)
  • Removed IMetricsQueryClientService interface and its implementation, migrating to ARM client pattern via BaseAzureService.CreateArmClientAsync
  • Updated metric querying, definitions, and namespaces logic to use ARM Monitor SDK APIs with pageable async enumerables instead of the previous SDK's response patterns

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
Directory.Packages.props Removed Azure.Monitor.Query package reference and added Azure.ResourceManager.Monitor beta package
tools/Azure.Mcp.Tools.Quota/src/Azure.Mcp.Tools.Quota.csproj Removed Azure.Monitor.Query package reference (cleanup)
tools/Azure.Mcp.Tools.Monitor/src/Azure.Mcp.Tools.Monitor.csproj Removed Azure.Monitor.Query and added Azure.ResourceManager.Monitor package references
tools/Azure.Mcp.Tools.Monitor/src/MonitorSetup.cs Removed IMetricsQueryClientService from service registration
tools/Azure.Mcp.Tools.Monitor/src/Services/IMetricsQueryClientService.cs Deleted interface (no longer needed with ARM client pattern)
tools/Azure.Mcp.Tools.Monitor/src/Services/MetricsQueryClientService.cs Deleted service implementation (replaced by ARM client from base class)
tools/Azure.Mcp.Tools.Monitor/src/Services/MonitorMetricsService.cs Refactored all three methods to use ARM Monitor SDK, updated constructor to remove metrics client dependency, added ISO string helper method
tools/Azure.Mcp.Tools.Monitor/tests/Azure.Mcp.Tools.Monitor.UnitTests/Metrics/MonitorMetricsServiceTests.cs Updated tests to remove metrics client mocks, marked several tests to skip (require actual ARM client)
servers/Azure.Mcp.Server/CHANGELOG.md Documented breaking change and migration to new SDK
core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Minor whitespace change
Comments suppressed due to low confidence (1)

tools/Azure.Mcp.Tools.Monitor/src/Services/MonitorMetricsService.cs:206

            foreach (var timeSeries in metric.Timeseries)
            {
                if (timeSeries.Data.Count == 0)
                    continue;

                var compactTimeSeries = new MetricTimeSeries
                {
                    Metadata = new Dictionary<string, string>(),
                    Start = timeSeries.Data.First().TimeStamp.UtcDateTime,
                    End = timeSeries.Data.Last().TimeStamp.UtcDateTime,
                    Interval = interval ?? "PT1M"
                };

                // Add metadata/dimensions
                if (timeSeries.Metadatavalues != null)
                {
                    foreach (var metadata in timeSeries.Metadatavalues)
                    {
                        if (metadata.Name?.Value != null && metadata.Value != null)
                        {
                            compactTimeSeries.Metadata[metadata.Name.Value] = metadata.Value;
                        }
                    }
                }

                // Extract values into arrays, only including non-null arrays
                var avgValues = timeSeries.Data
                    .Where(v => v.Average.HasValue)
                    .Select(v => v.Average!.Value)
                    .ToArray();
                if (avgValues.Length > 0)
                    compactTimeSeries.AvgBuckets = avgValues;

                var minValues = timeSeries.Data
                    .Where(v => v.Minimum.HasValue)
                    .Select(v => v.Minimum!.Value)
                    .ToArray();
                if (minValues.Length > 0)
                    compactTimeSeries.MinBuckets = minValues;

                var maxValues = timeSeries.Data
                    .Where(v => v.Maximum.HasValue)
                    .Select(v => v.Maximum!.Value)
                    .ToArray();
                if (maxValues.Length > 0)
                    compactTimeSeries.MaxBuckets = maxValues;

                var totalValues = timeSeries.Data
                    .Where(v => v.Total.HasValue)
                    .Select(v => v.Total!.Value)
                    .ToArray();
                if (totalValues.Length > 0)
                    compactTimeSeries.TotalBuckets = totalValues;

                var countValues = timeSeries.Data
                    .Where(v => v.Count.HasValue)
                    .Select(v => v.Count!.Value)
                    .ToArray();
                if (countValues.Length > 0)
                    compactTimeSeries.CountBuckets = countValues;

                compactResult.TimeSeries.Add(compactTimeSeries);
            }

@srnagar srnagar enabled auto-merge (squash) January 8, 2026 19:50
@srnagar srnagar merged commit 30810f7 into microsoft:main Jan 9, 2026
28 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Azure MCP Server Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants