CompositionalIT / farmer

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

Autoscale Settings: Adds support for defining autoscale settings #1085

Closed ninjarobot closed 6 months ago

ninjarobot commented 7 months ago

This PR closes #1072

The changes in this PR are as follows:

I have read the contributing guidelines and have completed the following:

If I haven't completed any of the tasks above, I include the reasons why here:

Below is a minimal example configuration that includes the new features, which can be used to deploy to Azure:

vmss {
    name "my-vmss"
    vm_profile (
        vm {
            vm_size Vm.Standard_B1s
            username "azureuser"
            operating_system Vm.UbuntuServer_2204LTS
            os_disk 30 Vm.Premium_LRS
            no_data_disk
            custom_script "apt update && apt install -y stress"
        }
    )
    autoscale (
        autoscaleSettings {
            name "my-vmss-autoscale"
            properties (
                autoscaleSettingsProperties {
                    profiles [
                        autoscaleProfile {
                            capacity (
                                autoscaleCapacity {
                                    maximum 10
                                }
                            )
                            rules [ // Two rules, one for scaling out and one for scaling in.
                                autoscaleRule { // Scale up with CPU > 60 across the scale set
                                    metric_trigger (
                                        autoscaleMetricTrigger {
                                            metric_name "Percentage CPU"
                                            divide_per_instance true
                                            operator MetricTriggerOperator.GreaterThan
                                            statistic MetricTriggerStatistic.Average
                                            threshold 60
                                            time_aggregation MetricTriggerTimeAggregation.Average
                                            time_grain (TimeSpan.FromMinutes 5)
                                            time_window (TimeSpan.FromMinutes 10)
                                        }
                                    )
                                    scale_action (
                                        scaleAction {
                                            cooldown (TimeSpan.FromMinutes 10)
                                            direction ScaleActionDirection.Increase
                                            action_type ScaleActionType.ChangeCount
                                            value 2
                                        }
                                    )
                                }
                                autoscaleRule { // Scale down with CPU < 20 across the scale set
                                    metric_trigger (
                                        autoscaleMetricTrigger { // Leaving most defaults
                                            metric_name "Percentage CPU"
                                            divide_per_instance true
                                            operator MetricTriggerOperator.LessThan
                                            threshold 20
                                        }
                                    )
                                    scale_action (
                                        scaleAction { // Leaving most defaults
                                            direction ScaleActionDirection.Decrease
                                        }
                                    )
                                }
                            ]
                        }
                    ]
                }
            )
        }
    )
}
ninjarobot commented 6 months ago

@isaacabraham I put in some links to ChatGPT conversations to show how I got it to generate the code, all starting with a copy-paste of the "schema" on the API reference page. Anyone can look at those so they could use see how it works to use the same technique. It took a little discussion to coerce it into the right code, and sometimes I just had to clean it up a little.

ninjarobot commented 6 months ago

@isaacabraham just checking again if you could please review this.