# cluster-tier-config

[Tier Management SOP](https://pingcap.feishu.cn/wiki/wikcnAwm9IRS7etkvfrP4m7NPGc)

---

## Release changes to production

1. Open a pull request, when it is merged, CICD will automatically update the change to production.
2. Update price table on official website with marketing team：
  * EN: https://en.pingcap.com/tidb-cloud-pricing/
  * JP: https://pingcap.co.jp/tidb-cloud/

## Cluster tier unit management 

We split the tier units of cluster into multiple files according to the following rules.

* X86-based dedicated cluster: tier_unit-dedicated-*.yaml
* Serverless(also known as devtier): tier_unit-shared.yaml
* Special case for old customers: tier_unit-special.yaml
* ARM-based dedicated cluster: tier_unit-arm.yaml

## Cluster tier management

All tiers are put into a single file named "tiers.yaml" and are ordered according to the
following hierarchy.

- dedicated
  - pd
    - 2C(if exists)
    - 4C
    - any other tier in ascending order
  - tidb
  - tikv
  - tiflash
- serverless
  - pd
  - tidb
  - tikv
  - tiflash

## SKU management
> Note: in the future, all sku yaml files will be removed from this repository and managed by billing system.

All skus can be classified into cluster related and non-cluster related. The cluster related skus consist of
node skus and storage skus. The non-cluster related skus consist of any non-cluster scope sku, like import, cdc etc.

All skus are grouped by the following rules:

- Skus for backup: sku-backup.yaml
- Skus for DM: sku-dm.yaml
- Skus for cdc: sku-extra.yaml 
- Skus for cluster: sku-node.yaml.
  - all skus in this file are generated by program, don't manually change this file.

### sku-node.yaml management

If you add new computes or storages, Please modify [script/genNodeSku/price.go](./script/genNodeSku/price.go) to add
the cost of these computes or storages.
**Don't** modify the `markup` if you don't know what you are doing.


### Pricing

- Node Compute price = node cost * instanceMarkup
- Node Storage price = storage cost * storageMarkup
- Others = case by case

To get the cost of compute or storage, see the following links:

* For AWS node price, see https://aws.amazon.com/ec2/pricing/on-demand/
* For GCP ndoe price, see https://cloud.google.com/compute/vm-instance-pricing
* For custom instance type, search for "N2 custom vCPUs and memory"

* For AWS disk price, see https://aws.amazon.com/ebs/pricing/
* For GCP disk price, see https://cloud.google.com/compute/disks-image-pricing#disk The price.go uses GB per Month, which is directly the list pricing for AWS/GCP


## Tools

### Node sku generator

You can run this tool to automatically generate skus for compute and storage related skus for cluster.
By the way, the `price_table.csv` file is also generated together.

```shell
make  ENVIRONMENT=[nightly|staging|prod] gen-node-sku
```

### Storage throughput checker
> We should use the EC2 instance throughput baseline as the throughput for tier unit storage. 
> Give more throughput than the baseline is not recommended, because the throughput beyond the baseline
> is only can be used for 30 minutes at least once every 24 hours.
> See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-optimized.html to get more information.

Run the following command to check the throughput used by tier units on AWS.

```shell
make  ENVIRONMENT=[nightly|staging|prod] check-storage-throughput
```

If you want to ignore check for some tier units, you can add key of these tier unit into `./script/checker/storage_throughput_checker.go:whitelistTierUnitKeys`.

### Tier integrity check

You can run this tool to check integrity of tiers, that enable you can confidently change tier. 

```shell
make  ENVIRONMENT=[nightly|staging|prod] check-tier-integrity
```

### Using deprecated tier unit checker

You can run this tool to check whether using deprecated tier units in tiers. 

```shell
make  ENVIRONMENT=[nightly|staging|prod] check-using-deprecated-tier-unit
```
