Skip to content

Commit e200bef

Browse files
committed
roachprod: unify AWS-specifics tags with other providers
The roachprod clusters created with the AWS provider were created with capitalized tags (via remapping) instead of the lowercase tags defined in the `vm` package which is in use by all other providers. This was leading to missing labels in observability and a mismatch in the AWS cost analysis dashboards. This patch removes the remapping of labels during VM creation, but keeps a remapping as a fallback mechanism in listing for retro-compatibility with outdated roachprod binaries and gc-ing of older releases. The retro-compatibility is to be removed when all tested releases use the (lowercase) unified tags. Epic: none Release note: None
1 parent d2acf29 commit e200bef

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

pkg/roachprod/vm/aws/aws.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ var configJson []byte
4141
//go:embed old.json
4242
var oldJson []byte
4343

44+
var (
45+
// TODO(golgeek, 2025-03-25): remove this in one year or so when all
46+
// resources are created with the unified tags.
47+
legacyTagsRemapping = map[string]string{
48+
"Cluster": vm.TagCluster,
49+
"Created": vm.TagCreated,
50+
"Lifetime": vm.TagLifetime,
51+
"Roachprod": vm.TagRoachprod,
52+
"Spot": vm.TagSpotInstance,
53+
}
54+
)
55+
4456
// Init initializes the AWS provider and registers it into vm.Providers.
4557
//
4658
// If the aws tool is not available on the local path, the provider is a stub.
@@ -446,7 +458,17 @@ type Tags []Tag
446458
func (t Tags) MakeMap() map[string]string {
447459
tagMap := make(map[string]string, len(t))
448460
for _, entry := range t {
449-
tagMap[entry.Key] = entry.Value
461+
462+
// If the resource was created with the legacy tags, we remap
463+
// to the unified ones.
464+
// TODO(golgeek, 2025-03-25): remove this in one year or so when all
465+
// resources are created with the unified tags.
466+
if tag, ok := legacyTagsRemapping[entry.Key]; ok {
467+
tagMap[tag] = entry.Value
468+
} else {
469+
tagMap[entry.Key] = entry.Value
470+
}
471+
450472
}
451473
return tagMap
452474
}
@@ -831,7 +853,7 @@ func (p *Provider) Reset(l *logger.Logger, vms vm.List) error {
831853
// This will update the Lifetime tag on the instances.
832854
func (p *Provider) Extend(l *logger.Logger, vms vm.List, lifetime time.Duration) error {
833855
return p.AddLabels(l, vms, map[string]string{
834-
"Lifetime": lifetime.String(),
856+
vm.TagLifetime: lifetime.String(),
835857
})
836858
}
837859

@@ -1104,7 +1126,7 @@ func (in *DescribeInstancesOutputInstance) toVM(
11041126
}
11051127

11061128
var lifetime time.Duration
1107-
if lifeText, ok := tagMap["Lifetime"]; ok {
1129+
if lifeText, ok := tagMap[vm.TagLifetime]; ok {
11081130
lifetime, err = time.ParseDuration(lifeText)
11091131
if err != nil {
11101132
errs = append(errs, err)
@@ -1220,7 +1242,7 @@ func (p *Provider) describeInstances(
12201242
tagMap := in.Tags.MakeMap()
12211243

12221244
// Ignore any instances that we didn't create
1223-
if tagMap["Roachprod"] != "true" {
1245+
if tagMap[vm.TagRoachprod] != "true" {
12241246
continue in
12251247
}
12261248

@@ -1277,18 +1299,16 @@ func (p *Provider) runInstance(
12771299
m[vm.TagCreated] = timeutil.Now().Format(time.RFC3339)
12781300
m["Name"] = name
12791301

1302+
// TODO(golgeek, 2025-03-25): In an effort to unify tags in lowercase across
1303+
// all providers, AWS cost analysis dashboard will break as they look for a
1304+
// capitalized `Cluster` tag. We duplicate the tag for now and will remove it
1305+
// once all resources are created with the unified tags in a year or so.
1306+
m["Cluster"] = m[vm.TagCluster]
1307+
12801308
if providerOpts.UseSpot {
12811309
m[vm.TagSpotInstance] = "true"
12821310
}
12831311

1284-
var awsLabelsNameMap = map[string]string{
1285-
vm.TagCluster: "Cluster",
1286-
vm.TagCreated: "Created",
1287-
vm.TagLifetime: "Lifetime",
1288-
vm.TagRoachprod: "Roachprod",
1289-
vm.TagSpotInstance: "Spot",
1290-
}
1291-
12921312
var labelPairs []string
12931313
addLabel := func(key, value string) {
12941314
// N.B. AWS does not allow empty values.
@@ -1305,9 +1325,6 @@ func (p *Provider) runInstance(
13051325
addLabel(key, value)
13061326
}
13071327
for key, value := range m {
1308-
if n, ok := awsLabelsNameMap[key]; ok {
1309-
key = n
1310-
}
13111328
addLabel(key, value)
13121329
}
13131330
labels := strings.Join(labelPairs, ",")

0 commit comments

Comments
 (0)