Repository navigation
Expand file tree
/
Copy pathrds_size.go
More file actions
59 lines (54 loc) · 2.35 KB
/
Copy pathrds_size.go
File metadata and controls
59 lines (54 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package common //nolint:revive // pkg/common is the module's core domain package, imported by name (common.X) throughout this repo and by consumer-mcp
import "strings"
// rdsInstanceNU maps an RDS instance size suffix to the normalized units AWS
// uses for size-flexible RDS reservations within an instance family (Single-AZ):
// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithReservedDBInstances.html#USER_WorkingWithReservedDBInstances.SizeFlexible
// The doc table runs micro to 32xlarge and has no 48xlarge or nano row; nano is kept
// from the earlier family-NU table.
var rdsInstanceNU = map[string]float64{
"nano": 0.25,
"micro": 0.5,
"small": 1,
"medium": 2,
"large": 4,
"xlarge": 8,
"2xlarge": 16,
"4xlarge": 32,
"6xlarge": 48,
"8xlarge": 64,
"10xlarge": 80,
"12xlarge": 96,
"16xlarge": 128,
"24xlarge": 192,
"32xlarge": 256,
}
// RDSInstanceNU returns the normalized units of an RDS instance type such as
// "db.r7g.2xlarge" (16). It returns 0 when the size is not recognized.
func RDSInstanceNU(instanceType string) float64 {
parts := strings.Split(instanceType, ".")
if len(parts) < 3 {
return 0
}
return rdsInstanceNU[parts[len(parts)-1]]
}
// RDSFamily returns the family prefix of an RDS instance type, e.g.
// "db.r7g.2xlarge" gives "db.r7g". It returns "" when the type has no size suffix.
func RDSFamily(instanceType string) string {
parts := strings.Split(instanceType, ".")
if len(parts) < 3 {
return ""
}
return strings.Join(parts[:len(parts)-1], ".")
}
// RDSSizeFlexibleEngine reports whether reservations of an engine are size-flexible. It is
// an allowlist: MySQL, MariaDB, PostgreSQL and Aurora. Oracle is exact-class: BYOL is
// flexible but License Included is not, and recommendations normalize Oracle without the
// license, so a flexible key for a commitment would never match its recommendation and
// would let a duplicate through. Oracle stays exact until both paths carry the license
// model (#342). SQL Server, Db2 (the AWS doc lists it both as flexible and as not) and
// unknown engines are exact-class too, so a reservation is never credited to a size it
// may not cover.
func RDSSizeFlexibleEngine(engine string) bool {
e := strings.ToLower(strings.TrimSpace(engine))
return e == "mysql" || e == "mariadb" || e == "postgres" || e == "postgresql" || strings.HasPrefix(e, "aurora")
}