Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] UnsupportedRequestContent error response when using Azure.ResourceManager.Monitor to create AutoscaleSettingResource #43948

Closed
bhanuprakash-1 opened this issue May 9, 2024 · 2 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. Mgmt This issue is related to a management-plane library. Monitor Monitor, Monitor Ingestion, Monitor Query needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@bhanuprakash-1
Copy link

bhanuprakash-1 commented May 9, 2024

Library name and version

Azure.ResourceManager.Monitor 1.3.1, Azure.ResourceManager 1.11.1, Azure.Identity 1.11.2

Describe the bug

I'm trying to create a AutoScaleSetting for my already existing App Service plan using the .NET SDKs Azure.ResourceManager.Monitor and Azure.ResourceManager. I was able to create other resources like App service, Web App etc in the same Resource group successfully. I'm using the DefaultAzureCredential() and my own identity(I'm logged into visual studio, where this code is running as a console app) and I'm also owner of the subscription and Resource group and App service plan, for which I'm trying to create the AutoScale setting.

But I'm getting exception and exception details are: the 400 error response is not clear on what exactly is the error.

Below is the error response:

Request content is not well formed or supported.
Status: 400 (Bad Request)
ErrorCode: UnsupportedRequestContent
 
Content:
{"code":"UnsupportedRequestContent","message":"Request content is not well formed or supported."}
 
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: <null>, Headers: {   Cache-Control: no-cache   Pragma: no-cache   Strict-Transport-Security: max-age=31536000; includeSubDomains   x-ms-request-id: 00000000-0000-0000-0000-000000000000   x-ms-ratelimit-remaining-subscription-writes: 1199   x-ms-correlation-request-id: 0498c1ee-52ff-4dc2-b304-7c22835f916e   x-ms-routing-request-id: CENTRALINDIA:20240508T182214Z:0498c1ee-52ff-4dc2-b304-7c22835f916e   X-Content-Type-Options: nosniff   X-Cache: CONFIG_NOCACHE   X-MSEdge-Ref: Ref A: C29CF5F458C94A8CB637104186C06A56 Ref B: MAA201060515019 Ref C: 2024-05-08T18:22:12Z   Date: Wed, 08 May 2024 18:22:13 GMT }}

My code which I'm using to configure Autoscale setting resource is:

// Create Autoscale setting
            ResourceIdentifier resourceIdentifierAppSvcPlan = appServicePlanLro.Value.Id;
            MonitorScaleCapacity scaleCapacity = new MonitorScaleCapacity(minimum: 3, maximum: 30, @default: 3);

            // cpu scale up logic
            MetricTrigger metricTriggerCpuScaleUp = new MetricTrigger(
                metricName: "CpuPercentage",
                metricResourceId: resourceIdentifierAppSvcPlan,
                timeGrain: TimeSpan.FromMinutes(1),
                statistic: MetricStatisticType.Average,
                timeWindow: TimeSpan.FromMinutes(1),
                timeAggregation: MetricTriggerTimeAggregationType.Average,
                @operator: MetricTriggerComparisonOperation.GreaterThan,
                threshold: 50);
            metricTriggerCpuScaleUp.MetricNamespace = "microsoft.web/serverfarms";
            metricTriggerCpuScaleUp.IsDividedPerInstance = false;

            MonitorScaleAction monitorScaleActionScaleUp = new MonitorScaleAction(
                MonitorScaleDirection.Increase,
                MonitorScaleType.PercentChangeCount,
                cooldown: TimeSpan.FromMinutes(1));
            monitorScaleActionScaleUp.Value = "100";

            // cpu scale down logic
            // scale down when cpu usage less than 20%
            MetricTrigger metricTriggerCpuScaleDown = new MetricTrigger(
                metricName: "CpuPercentage",
                metricResourceId: resourceIdentifierAppSvcPlan,
                timeGrain: TimeSpan.FromMinutes(1),
                statistic: MetricStatisticType.Average,
                timeWindow: TimeSpan.FromMinutes(5),
                timeAggregation: MetricTriggerTimeAggregationType.Average,
                @operator: MetricTriggerComparisonOperation.LessThan,
                threshold: 20);
            metricTriggerCpuScaleDown.MetricNamespace = "microsoft.web/serverfarms";
            metricTriggerCpuScaleDown.IsDividedPerInstance = false;

            MonitorScaleAction monitorScaleActionScaleDown = new MonitorScaleAction(
                MonitorScaleDirection.Decrease,
                MonitorScaleType.ChangeCount,
                cooldown: TimeSpan.FromMinutes(5));
            monitorScaleActionScaleDown.Value = "1";


            AutoscaleRule autoscaleRuleCpuScaleUp = new AutoscaleRule(metricTriggerCpuScaleUp, monitorScaleActionScaleUp);
            AutoscaleRule autoscaleRuleCpuScaleDown = new AutoscaleRule(metricTriggerCpuScaleDown, monitorScaleActionScaleDown);
            IEnumerable<AutoscaleRule> autoscaleRules = new List<AutoscaleRule> { autoscaleRuleCpuScaleUp, autoscaleRuleCpuScaleDown };

            AutoscaleProfile autoscaleProfile = new AutoscaleProfile("bhanu sdk app scale profile", scaleCapacity, autoscaleRules);
            IEnumerable<AutoscaleProfile> autoscaleProfiles = new List<AutoscaleProfile> { autoscaleProfile };
            AutoscaleSettingData autoscaleSettingData = new AutoscaleSettingData(AzureLocation.WestUS2, autoscaleProfiles);

            Console.WriteLine($"Autoscale setting before creation: {JsonConvert.SerializeObject(autoscaleSettingData)}\n");
            Console.ReadLine();

            ArmOperation<AutoscaleSettingResource> autoscaleSettingLro = await resourceGroup.GetAutoscaleSettings().CreateOrUpdateAsync(
                Azure.WaitUntil.Completed,
                "bhanu auto scale setting sdk",
                autoscaleSettingData).ConfigureAwait(false);

Expected behavior

400 error response should have a clear error message. Or the exception thrown by the .NET SDK should clear out what the user error is.

Actual behavior

Added exception message and x-ms-correlation id above.

Reproduction Steps

Have added code above. Use the code to repro.

Environment

OS Windows 11, Visual studio Enterprise 2022 (64-bit), version 17.9.6

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 9, 2024
@jsquire jsquire added Monitor Monitor, Monitor Ingestion, Monitor Query Mgmt This issue is related to a management-plane library. needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels May 9, 2024
@jsquire
Copy link
Member

jsquire commented May 9, 2024

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@melina5656
Copy link
Member

Hi @bhanuprakash-1, The reason for your issue is that a property named TargetResourceId was missing, which exists in AutoscaleSettingData.
You can refer to the following code snippet:

AutoscaleSettingData autoscaleSettingData = new AutoscaleSettingData(AzureLocation.WestUS2, autoscaleProfiles)
{
    TargetResourceId = appServicePlan.Data.Id,
};

Additionally, there are some minor issues in your code.

MonitorScaleCapacity scaleCapacity = new MonitorScaleCapacity(minimum: 3, maximum: 30, @default: 3);

The range of values for minimum and maximum is generally 1 to 10.

monitorScaleActionScaleUp.Value = "100";

This an invalid scale action value. You should provide a scale value less than or equal to the difference between the capacity maximum and the capacity minimum.

Thank you for your feedback.

@melina5656 melina5656 added the issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. Mgmt This issue is related to a management-plane library. Monitor Monitor, Monitor Ingestion, Monitor Query needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

4 participants