CompositionalIT / farmer

Repeatable Azure deployments with ARM templates - made easy!
https://compositionalit.github.io/farmer
MIT License
522 stars 156 forks source link

App Insights - Alerts #778

Open MarcoGix opened 2 years ago

MarcoGix commented 2 years ago

Hi,

I tried to add alerts (thanks for this feature, we were waiting for it!) but I have 2 main issue:

  1. MetricsName.PercentageCPU is translated to arm script to "Percentage CPU" but seems azure accepts only "CpuPercentage" .
  2. I'm not able to put the proper ResourceId for a Database: there is no ResourceId property and I cannot create the desided one "Microsoft.Sql/servers/databases"

Thanks in advice. Marco

Thorium commented 2 years ago

Hi,

  1. There are both "Percentage CPU" and "CPU Percentage" defined in https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported so I recommend to PR adding more constants but not removing the previous ones. Or maybe Isaac does a web-page parser here. ;-)

  2. Check the unit-tests:

    let sql = 
    sqlServer {
        name "my37server"; admin_username "isaac"
        add_databases [ sqlDb { name "mydb23"; sku Farmer.Sql.DtuSku.S0 } ]
    }
    let db = sql.Databases.Head
    let resId = Farmer.Arm.Sql.databases.resourceId (sql.Name.ResourceName, db.Name) |> Managed

    So DB resourceId takes 2 parameters, the server and the database. That should do. Or you could also do:

    let primaryDatabaseFullId =
    ArmExpression.create(
        $"concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Sql/servers/', '{databaseServerName.ResourceName.Value}', '/databases/','{database.Name.Value}')"
    ).Eval()
MarcoGix commented 2 years ago

Thanks for the answer!

Regarding (1) I saw that is already customizable doing for example. MetricName = MetricsName "CpuPercentage"

I have a new question, I saw taht now alert are automatically set to criterionType = "StaticThresholdCriterion".

There will be a future support for Dynamic too? with the Thresold Sensitivity parameters too.

Thorium commented 2 years ago

The initial implementation was just an accepted PR what I wanted to have in my system. So I guess they'll accept PRs for adding supports for other parameters too.