# Autoscaling Rules

{% hint style="info" %}
Autoscaling rules are supported from AutoScaler version `1.31.0`
{% endhint %}

Once Autoscaler is [installed](/set-up-and-installation/datafy-installation.md) and you've selected which volumes to optimize, the next step is to activate autoscaling: you can do this manually for each volume via the [Fleet Manager](https://app.datafy.io/fleet-manager/all-volumes), or set up an [autoscaling rule](https://app.datafy.io/fleet-manager/autoscale-rules).

Autoscaling rules are templates that identify volumes matching specific conditions and automatically enable autoscaling for them. Once activated, a rule applies to all existing and future matching volumes. This is particularly beneficial for initial autoscaling setup in large environments and continuous management in dynamic environments, such as EKS clusters, where volumes are frequently created and destroyed.

## Create a New Autoscaling Rule

Autoscaling rules can be created simply and easily through the [Datafy app](https://app.datafy.io/fleet-manager/autoscale-rules).

To get started, open the rule creation wizard, by selecting the "Create new rule" button:

<figure><img src="/files/bm81UbLCihGI85g3nlNg" alt="" width="178"><figcaption></figcaption></figure>

{% hint style="success" %}
You can automate rule creation and management across multiple accounts using the `datafy` Terraform provider. For details see the [autoscaling\_rule resource](https://registry.terraform.io/providers/datafy-io/datafy/latest/docs/resources/autoscaling_rule) in the Terraform registry.

Intereseted but don't use Terraform? Let us know!
{% endhint %}

{% stepper %}
{% step %}

#### Define Rule Conditions

Each autoscaling rule is built from **conditions** that define which volumes it applies to. A volume will match a rule if it meets all of the conditions in the rule (logical AND).

Each condition contains a volume attribute, a logical operator and at least one value.

<details>

<summary>Volume Attribute</summary>

Select one of the following volume attributes for the condition to check:

* Cluster - cluster name, use to apply autoscaling to all volumes in a cluster
* Node group - node group name, use to apply autoscaling to certain node groups within a cluster
* Instance ID - use to apply to or exclude volumes attached to specific instance. This is not recommended for dynamic environments where volumes may move between EC2 instances.
* Volume Tags - array of volume tags, with each tag formatted as a single string `"key:value"`\ <br>

<figure><img src="/files/qYRKkekjwfGUuzZAdxPx" alt="" width="188"><figcaption></figcaption></figure>

</details>

<details>

<summary>Logical Operator</summary>

Define which operator will be used to check the selected attribute:

* **Is** – the value must match exactly
* **Is not** – the value must not match
* **Contains** – the value must include the specified text
* **Does not contain** – the value must not include the specified text

<figure><img src="/files/GwqX8TyyZntROIVIWWSW" alt="" width="188"><figcaption></figcaption></figure>

{% hint style="info" %}
For the volume tags array, the *is* and *contains* conditions check that at least one tag matches the defined values, and the *is not* and *does not contain* conditions checks that none of the tags match the defined values
{% endhint %}

</details>

<details>

<summary>Values</summary>

Use the search to find values of the existing attributes in your account. For conditions with exact match operators (*is* or *is not*) an exact value must be selected from the list, for conditions with *contains* or *does not contain* any value can be used.

If you add multiple values to a condition, a volume will match it if the attribute has any one of the defined values (logical OR).

<figure><img src="/files/Ms5mjHGxnMOBr9RCj8Jz" alt=""><figcaption><p>Representation of "<em>Cluster name contains <code>dev</code></em> <em><strong>or</strong></em> <em><code>prod</code>"</em></p></figcaption></figure>

</details>

You can add additional conditions to your rule with the "+And" and "+Add type" buttons.

<figure><img src="/files/FadxYPkt2b40kljOYUsU" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Check Matching Volumes

Once your conditions are defined, select the "Next" button to see which volumes match the rule.

The matching volumes are presented in three categories:

1. Matching volumes - volumes that matched the rule and can start autoscaling right away.
2. Potential volumes - volumes that matched the rule but don't have AutoScaler installed. These will start autoscaling once AutoScaler is installed on their instance.
3. Excluded - volumes that match the rule but are [excluded from autoscaling rules](#exceptions-from-rules).

{% hint style="info" %}
Volumes that match the rule but do not support autoscaling (for example, unattached volumes) will not appear.
{% endhint %}

<figure><img src="/files/y7Ls1fSpxHCEP0p1RH9Q" alt=""><figcaption></figcaption></figure>

If you find volumes you didn't intend to include, go back and continue editing your rule until you reach the desired result.
{% endstep %}

{% step %}

#### Create Rule

Once you're satisfied with the rule conditions and the volumes it will apply to, create the rule:

* "Create" button - your rule will be created in an inactive state. The rule will not activate autoscaling until it is turned on.
* "Create and Apply" - your rule will be created and start activating autoscaling for the matching volumes immediately.
  {% endstep %}
  {% endstepper %}

## Monitor and Manage Rules

### Activation Progress

After you create and apply a rule, autoscaling is activated for all matching volumes. To view these volumes and their status, select the rule in the [AutoScale Rules](https://app.datafy.io/fleet-manager/autoscale-rules) table and visit the "Matching Volumes" tab. You can monitor the live progress of each autoscaling activation event in the Optimization Actions on the [Reports](https://app.datafy.io/reports) page and track actual storage savings in the Usage and Utilization charts on the same page.

{% hint style="success" %}
When autoscaling is activated, volumes attached to the same instance migrate sequentially to avoid impacting your applications. Migration occurs locally on the relevant instance, allowing unlimited volume migrations in your account simultaneously.
{% endhint %}

### Editing Rules

All rules in your account appear in the [AutoScale Rules](https://app.datafy.io/fleet-manager/autoscale-rules) table, summarizing the number and capacity of volumes matching each rule. By selecting a rule, you can view its full conditions and list of matching volumes, divided into matching, potential, and [exceptions](#exceptions-from-rules).

From here you can:

* Edit a rule's conditions
* Disable or enable a rule
* Delete a rule

{% hint style="warning" %}
Changes to a rule (including disabling or deleting) do not reverse previously executed autoscaling activations - those volumes will continue to autoscale until [directly deactivated](/volume-lifecycle/managing-autoscaling-volumes.md#deactivating-autoscaling).
{% endhint %}

### Exceptions from Rules

Some volumes are defined as exceptions from the autoscaling rules - even if they match, rules will not be applied to them.

Volumes that have an exception are identified in the All Volumes table, and are listed as exceptions to the specific rules that apply to them.

<figure><img src="/files/5VHFmxYRtmLN05XULvJv" alt="" width="124"><figcaption></figcaption></figure>

{% hint style="info" %}
Exceptions are from all autoscaling rules, not from any specific rule
{% endhint %}

#### Creating an Exception

Volumes are defined as exceptions in one of two ways:

1. When [autoscaling is deactivated](/volume-lifecycle/managing-autoscaling-volumes.md#deactivating-autoscaling) for a volume, it is automatically made an exception to the rules. This prevents any rule from re-activating the autoscaling.
2. When viewing the details of an existing rule, select any matching volume and create an exception for it. This can be done for active and inactive rules, and matching or potential volumes.

<figure><img src="/files/cQLrbnYFigWKFX80fXoo" alt="" width="375"><figcaption></figcaption></figure>

{% hint style="warning" %}
Direct exceptions of specific volumes should be used to handle special cases. To prevent undesired autoscaling activation of a category or group of volumes, make sure to add exclusive conditions to rules when they are created.
{% endhint %}

#### Clearing Exceptions

If you want to clear an exception from a volume, find it in the exceptions list of a rule that applies to it, and select the "Remove Exception" button. If the relevant rule is active and the volume is attached to an instance with AutoScaler installed, autoscaling will be automatically activated for the volume.

<figure><img src="/files/jIKW9f6fJvD62upO1JNw" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="success" %}
You don't need to clear exceptions to activate autoscaling for a specific volume, you can [activate](/volume-lifecycle/managing-autoscaling-volumes.md#activating-autoscaling) it directly from the [All Volumes](https://app.datafy.io/fleet-manager/all-volumes) table.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datafy.io/volume-lifecycle/autoscaling-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
