Azure Service Bus autoscaling in bicep template - azure

On our project we are using Service Bus, for the Infrastructure as Code we are using bicep template in order to deploy this Service Bus. Lately we came to the conclusion that we should enable scaling for our service bus as we were having some serious issues with the capacity of just 1 single Message Unit.
Does anyone know if there is anyway to add the autoscaling in the bicep template for a service bus Azure Resource ? I cannot really find something in the MS official documentation.
Google didn't helped ...

If you have a look at the documentation, there is an ARM template that show how to configure autoscaling:
Automatically update messaging units of an Azure Service Bus namespace.
The equivalent bicep (using az bicep decompile) looks like this:
#description('Name of the Service Bus namespace')
param serviceBusNamespaceName string
#description('Name of the Queue')
param serviceBusQueueName string
#description('Name of the auto scale setting.')
param autoScaleSettingName string
#description('Location for all resources.')
param location string = resourceGroup().location
resource serviceBusNamespaceName_resource 'Microsoft.ServiceBus/namespaces#2021-11-01' = {
name: serviceBusNamespaceName
location: location
sku: {
name: 'Premium'
}
properties: {
}
}
resource serviceBusNamespaceName_serviceBusQueueName 'Microsoft.ServiceBus/namespaces/queues#2021-11-01' = {
parent: serviceBusNamespaceName_resource
name: '${serviceBusQueueName}'
properties: {
lockDuration: 'PT5M'
maxSizeInMegabytes: 1024
requiresDuplicateDetection: false
requiresSession: false
defaultMessageTimeToLive: 'P10675199DT2H48M5.4775807S'
deadLetteringOnMessageExpiration: false
duplicateDetectionHistoryTimeWindow: 'PT10M'
maxDeliveryCount: 10
autoDeleteOnIdle: 'P10675199DT2H48M5.4775807S'
enablePartitioning: false
enableExpress: false
}
}
resource autoScaleSettingName_resource 'Microsoft.Insights/autoscaleSettings#2021-05-01-preview' = {
name: autoScaleSettingName
location: 'East US'
tags: {
}
properties: {
name: autoScaleSettingName
enabled: true
predictiveAutoscalePolicy: {
scaleMode: 'Disabled'
scaleLookAheadTime: null
}
targetResourceUri: serviceBusNamespaceName_resource.id
profiles: [
{
name: 'Increase messaging units to 2 on weekends'
capacity: {
minimum: '2'
maximum: '2'
default: '2'
}
rules: []
recurrence: {
frequency: 'Week'
schedule: {
timeZone: 'Eastern Standard Time'
days: [
'Saturday'
'Sunday'
]
hours: [
6
]
minutes: [
0
]
}
}
}
{
name: '{"name":"Scale Out at 75% CPU and Scale In at 25% CPU","for":"Increase messaging units to 4 on weekends"}'
capacity: {
minimum: '1'
maximum: '8'
default: '2'
}
rules: [
{
scaleAction: {
direction: 'Increase'
type: 'ServiceAllowedNextValue'
value: '1'
cooldown: 'PT5M'
}
metricTrigger: {
metricName: 'NamespaceCpuUsage'
metricNamespace: 'microsoft.servicebus/namespaces'
metricResourceUri: serviceBusNamespaceName_resource.id
operator: 'GreaterThan'
statistic: 'Average'
threshold: 75
timeAggregation: 'Average'
timeGrain: 'PT1M'
timeWindow: 'PT10M'
dimensions: []
dividePerInstance: false
}
}
{
scaleAction: {
direction: 'Decrease'
type: 'ServiceAllowedNextValue'
value: '1'
cooldown: 'PT5M'
}
metricTrigger: {
metricName: 'NamespaceCpuUsage'
metricNamespace: 'microsoft.servicebus/namespaces'
metricResourceUri: serviceBusNamespaceName_resource.id
operator: 'LessThan'
statistic: 'Average'
threshold: 25
timeAggregation: 'Average'
timeGrain: 'PT1M'
timeWindow: 'PT10M'
dimensions: []
dividePerInstance: false
}
}
]
recurrence: {
frequency: 'Week'
schedule: {
timeZone: 'Eastern Standard Time'
days: [
'Saturday'
'Sunday'
]
hours: [
18
]
minutes: [
0
]
}
}
}
]
notifications: []
targetResourceLocation: 'East US'
}
}

Related

Update budget amount on existing budget by bicep file

I have already budgets created by the bicep and work perfectly. But I want to change the amount on an existing budget by bicep file. Is it possible to do that? I'm receiving errors with the date, or is the budget already exist, .... finally I cannot change it. Below my bicep files:
targetScope = 'subscription'
#description('Name of the Budget. It should be unique within a resource group.')
param budgetName string = 'ConsumptionBudget'
#description('The total amount of cost or usage to track with the budget')
param budgetAmount int
#description('Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0.01 and 1000.')
param firstPercentageThreshold int = 75
#description('First action group name')
param firstActionGroup string
#description('Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0.01 and 1000.')
param secondPercentageThreshold int = 100
#description('Second action group name')
param secondActionGroup string
#description('Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0.01 and 1000.')
param thirdPercentageThreshold int = 110
#description('First action group name')
param thirdActionGroup string
#description('The list of email addresses to send the budget notification to when the threshold is exceeded.')
param contactEmails array = []
param contactRoles array = [
'Owner'
]
#description('The start date must be first of the month in YYYY-MM-DD format. Future start date should not be more than three months. Past start date should be selected within the timegrain preiod.')
param startDate string = '${utcNow('yyyy-MM')}-01'
#description('The time covered by a budget. Tracking of the amount will be reset based on the time grain.')
#allowed([
'Monthly'
'Quarterly'
'Annually'
])
param timeGrain string = 'Monthly'
#description('Subscription id on which budget will be created')
param subscriptionId string
#description('Resource group name in which action groups are located - Action groups passed in firstActionGroup, secondActionGroup, thirdActionGroup')
param resourceGroupName string
var category = 'Cost'
var operator = 'GreaterThan'
resource budgetExists 'Microsoft.Consumption/budgets#2021-10-01' existing = {
name: budgetName
}
resource budget 'Microsoft.Consumption/budgets#2021-10-01' = if(budgetExists.id==null){
name: budgetName
properties: {
timePeriod: {
startDate: startDate
}
timeGrain: timeGrain
category: category
amount: budgetAmount
notifications: {
NotificationForExceededBudget1: {
enabled: true
contactEmails: contactEmails
threshold: firstPercentageThreshold
operator: operator
contactRoles: contactRoles
contactGroups: [
'/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/microsoft.insights/actionGroups/${firstActionGroup}'
]
}
NotificationForExceededBudget2: {
enabled: true
contactEmails: contactEmails
threshold: secondPercentageThreshold
operator: operator
contactRoles: contactRoles
contactGroups: [
'/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/microsoft.insights/actionGroups/${secondActionGroup}'
]
}
NotificationForExceededBudget3: {
enabled: true
contactEmails: contactEmails
threshold: thirdPercentageThreshold
operator: operator
contactRoles: contactRoles
contactGroups: [
'/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/microsoft.insights/actionGroups/${thirdActionGroup}'
]
}
}
}
}
resource budgetUpdate 'Microsoft.Consumption/budgets#2021-10-01' = if(budgetExists.id != null) {
name: budgetName
eTag: budgetExists.eTag
properties: {
timePeriod: {
startDate: budgetExists.properties.timePeriod.startDate
endDate: budgetExists.properties.timePeriod.endDate
}
timeGrain: budgetExists.properties.timeGrain
category: budgetExists.properties.category
amount: budgetAmount
filter: {}
notifications: {
NotificationForExceededBudget1: {
enabled: true
contactEmails: contactEmails
threshold: firstPercentageThreshold
operator: operator
contactRoles: contactRoles
contactGroups: [
'/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/microsoft.insights/actionGroups/${firstActionGroup}'
]
}
NotificationForExceededBudget2: {
enabled: true
contactEmails: contactEmails
threshold: secondPercentageThreshold
operator: operator
contactRoles: contactRoles
contactGroups: [
'/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/microsoft.insights/actionGroups/${secondActionGroup}'
]
}
NotificationForExceededBudget3: {
enabled: true
contactEmails: contactEmails
threshold: thirdPercentageThreshold
operator: operator
contactRoles: contactRoles
contactGroups: [
'/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/microsoft.insights/actionGroups/${thirdActionGroup}'
]
}
}
}
}
Below exceptions from pipelines:
nner Errors:
2023-01-31T08:08:56.4475545Z {"code": "InvalidTemplate", "target": "/subscriptions/d955395e-9c5f-4fa0-ad91-c46ea57d4646/providers/Microsoft.Resources/deployments/budget_20230131080855", "message": "Deployment template validation failed: 'The resource 'Microsoft.Consumption/budgets/ConsumptionBudget' at line '1' and column '3675' is defined multiple times in a template. Please see https://aka.ms/arm-syntax-resources for usage details.'.", "additionalInfo": [{"type": "TemplateViolation", "info": {"lineNumber": 1, "linePosition": 3675, "path": "properties.template.resources[0]"}}]}
This is because you cannot define same resource in a deployment twice :) Looking at your bicep Microsoft.Consumption/budgets/ is indeed defined twice, just with a different condition. Having condition doesn't count, it is still a duplicate :|
What is more, the way you check for existence won't work, as 'existing' keyword in bicep is simply translated to subscriptionResourceId('Microsoft.Consumption/budgets', parameters('budgetName') while compiling to ARM, and this will never be NULL as it is just a helper method to calculate full resource ID, not checking its existence.

Bicep - Unable to Create VM Snapshot Backup Policy for Azure Recovery Services Vault

I am trying to deploy a Recovery Services Vault as part of an infrastructure release using Bicep. I am having trouble deploying one backup policy in particular, a VM Snapshot backup policy (AzureIaaSVM).
I have followed the Bicep reference page for creating the template but it fails validation when trying to deploy.
I am using VSCode to develop and when I build an ARM template from the Bicep file, it fails validation with the following message:
If I have understood the documentation correctly, there should be more than just 'AzureStorage' being allowed here.
My question is, is this a tooling/API problem or have I misunderstood the documentation? If so, what would I have to alter to get this working?
The template:
resource vmSnapshotBackupPolicy 'Microsoft.RecoveryServices/vaults/backupPolicies#2022-03-01' = {
name: 'vm-snapshot-policy'
location: resourceLocation
parent: recoveryServicesVault
properties: {
protectedItemsCount: 0
backupManagementType: 'AzureIaasVM'
instantRPDetails: {
azureBackupRGNamePrefix: 'vmsnapshot'
}
instantRpRetentionRangeInDays: 2
policyType: 'V1'
retentionPolicy: {
retentionPolicyType: 'LongTermRetentionPolicy'
dailySchedule: {
retentionDuration: {
count: 7
durationType: 'Days'
}
retentionTimes: [
'2022-10-21T02:00:00Z'
]
}
monthlySchedule: {
retentionDuration: {
count: 6
durationType: 'Months'
}
retentionScheduleDaily: {
daysOfTheMonth: [
{
date: 1
isLast: false
}
]
}
retentionScheduleFormatType: 'Daily'
retentionTimes: [
'2022-10-21T02:00:00Z'
]
}
weeklySchedule: {
daysOfTheWeek: [
'Sunday'
]
retentionDuration: {
count: 4
durationType: 'Weeks'
}
retentionTimes: [
'2022-10-21T02:00:00Z'
]
}
yearlySchedule: {
monthsOfYear: [
'July'
]
retentionDuration: {
count: 2
durationType: 'Years'
}
retentionScheduleDaily: {
daysOfTheMonth: [
{
date: 1
isLast: false
}
]
}
retentionScheduleFormatType: 'Daily'
retentionTimes: [
'2022-10-21T02:00:00Z'
]
}
}
schedulePolicy: {
schedulePolicyType: 'SimpleSchedulePolicy'
scheduleRunFrequency: 'Daily'
scheduleRunTimes: [
'2022-10-21T02:00:00Z'
]
scheduleWeeklyFrequency: 0
}
timeZone: 'UTC'
}
}
It's a tooling problem, see: https://github.com/Azure/azure-quickstart-templates/blob/master/quickstarts/microsoft.recoveryservices/recovery-services-backup-vms/main.bicep for another example.
You can also add a comment here: https://github.com/Azure/bicep/issues/784 for the tooling issue.

mutation syntax error : grapgql update string

here is my mutation . that was working fine . from yesterday it throw error on condition key
condition: "{\"data\":{\"a\":{\"source\":\"ENTITY_STATE\",\"id\":\"4b026027-7458-4ba4-9079-f3dd4f16b65b\"}},\"rules\":{\"==\":[{\"var\":\"a.on\"},false]}}"
here is my full mutation :
mutation {
rule {
create(
input: {
name: "After every minute ?"
description: "Will turn on device after every minute"
triggers: [
{
name: "TimeTrigger"
options: {
cron: "* * * * 1"
# time: "after 10 seconds"
}
}
]
condition: "{\"data\":{\"a\":{\"source\":\"ENTITY_STATE\",\"id\":\"4b026027-7458-4ba4-9079-f3dd4f16b65b\"}},\"rules\":{\"==\":[{\"var\":\"a.on\"},false]}}"
actions: [
{
name: "EntitySetStateAction"
options: {
entityId: "4b026027-7458-4ba4-9079-f3dd4f16b65b"
state: "{\"on\": true,\"thermostat.mode\": \"cool\",\"thermostat.setpoint\": 20,\"fanSpeed.mode\": \"high\"}"
# state: {on: true}
}
}
]
}
) {
id
embedded
name
description
active
actions {
options
} # triggers
# condition {rulenes data}
# triggers
}
}
}

`apiRevision` flag isn't working in Bicep template

I am using Bicep to deploy open api json into Azure API Management. The snippet looks like this.
resource fuseintegrationsapi 'Microsoft.ApiManagement/service/apis#2021-08-01' = {
name: '${apim.name}/integrations-api-${environment_name}'
properties: {
description: 'Contains integrations apis used to control the platform.'
type: 'http'
apiRevision: '1234'
isCurrent: true
subscriptionRequired: false
displayName: 'Integrations Api'
serviceUrl: '${api_backend_url}/api/test/v1/integrations'
path: '${environment_name}/api/test/v1/integrations'
protocols: [
protocol
]
value: api_link
format: 'openapi+json-link'
apiType: 'http'
}
dependsOn: [
api2
]
resource symbolicname 'policies' = {
name: 'policy'
properties: {
value: anonymous_operation_policy
format: 'rawxml'
}
}
}
Even though revision is hardcoded to 1234 it's always using default 1 and the API is not updating with latest open api specification.
I had the same problem and figured out that you have to put the revision in the name also.
name: '${apim.name}/integrations-api-${environment_name};rev=1234'

Marathon says 'Insufficient resources' for a task that needs less than what is available

I have a Mesos Master available through a public IP.
I have a Slave that offers some resources.
I try to deploy a small app, but Marathon respond
25646:[2016-12-13 15:26:57,440] INFO Offer [bd40f00f-ce24-4014-b1b1-82db64e68c10-O92]. Considering resources with roles {*} without resident reservation labels. Insufficient ports in offer for run spec [/nginx-test-n2] (mesosphere.marathon.tasks.PortsMatcher:marathon-akka.actor.default-dispatcher-1073)
25647:[2016-12-13 15:26:57,440] INFO Offer [bd40f00f-ce24-4014-b1b1-82db64e68c10-O92]. Insufficient resources for [/nginx-test-n2] (need cpus=0.2, mem=32.0, disk=0.0, gpus=0, ports=(), available in offer: [id { value: "bd40f00f-ce24-4014-b1b1-82db64e68c10-O92" } framework_id { value: "40aadcc7-8e0f-4634-af46-29d9c33bc03e-0000" } slave_id { value: "bd40f00f-ce24-4014-b1b1-82db64e68c10-S1" } hostname: "myproj-slave-vm-1" resources { name: "disk" type: SCALAR scalar { value: 3985.0 } role: "*" } resources { name: "cpus" type: SCALAR scalar { value: 0.6 } role: "*" } resources { name: "mem" type: SCALAR scalar { value: 6478.0 } role: "*" } url { scheme: "http" address { hostname: "myproj-slave-vm-1" ip: "10.1.10.20" port: 5051 } path: "/slave(1)" }] (mesosphere.mesos.TaskBuilder$:marathon-akka.actor.default-dispatcher-1073)
Which once unfolded is:
25628:[2016-12-13 15:26:52,425] INFO Offer [bd40f00f-ce24-4014-b1b1-82db64e68c10-O91].
Insufficient resources for [/nginx-test-n2] (need
cpus=0.2,
mem=32.0,
disk=0.0,
gpus=0,
ports=(),
available in offer:
[id {
value: "bd40f00f-ce24-4014-b1b1-82db64e68c10-O91"
}
framework_id {
value: "40aadcc7-8e0f-4634-af46-29d9c33bc03e-0000"
}
slave_id {
value: "bd40f00f-ce24-4014-b1b1-82db64e68c10-S1"
}
hostname: "myproj-slave-vm-1"
resources {
name: "disk"
type: SCALAR scalar {
value: 3985.0
}
role: "*"
}
resources {
name: "cpus"
type: SCALAR scalar {
value: 0.6
}
role: "*"
}
resources {
name: "mem"
type: SCALAR scalar {
value: 6478.0
}
role: "*"
}
url {
scheme: "http"
address {
hostname: "myproj-slave-vm-1"
ip: "10.1.10.20"
port: 5051
}
path: "/slave(1)"
}
]
I can't understand why Marathon says 'Insufficient resources', since it seems from the log that there is enough...
I solved it by adding resources=ports:[1-65000] to the agent execution command:
/usr/sbin/mesos-slave --master=10.2.0.56:5050 --work_dir=/var/lib/mesos/agent --containerizers=docker --executor_registration_timeout=3mins --log_dir=/var/log/mesos --resources=ports:[1-65000] --advertise_ip=10.1.10.20 --advertise_port=5051

Resources