Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3534: Tag compute resources according to the tool's metadata #3544

Merged
merged 20 commits into from
May 30, 2024

Conversation

ekazachkova
Copy link
Contributor

@ekazachkova ekazachkova commented May 28, 2024

The current PR provides implementation for issue #3534

The following changes were added:

  • a new preferences cluster.instances.tags. This preference supports tool/run_id/owner keys only.
{
  "owner": "CP_OWNER",
  "run_id": "CP_RUN_ID",
  "tool": "CP_TOOL"
}
  • a new preference cluster.instances.allowed.tags. This preferences allows to specify comma-separated list of string values. If tool's metadata key exactly matches the value from this list the corresponding metadata (a key-value pair) shall be added to compute resources tags. Name value is not allowed.
  • stop run behaviour modification: tags shall be removed from compute resources if run status changed to final.
  • attach disks: tags shall be added to a new disks.
  • nodeup and reassign_node scripts support new --tags option. This option accepts a list of <tag_name>=<tag_value> string values. If this list provided the corresponding tags shall be added to instances and ebs volumes.
  • if CP_CAP_SHARE_FS_TYPE=lustre corresponding tags shall be added to created FS.

NOTE: all changes implemented for AWS provider only.

… remove instance tags during pipeline stop
@ekazachkova ekazachkova requested review from mzueva and tcibinan and removed request for mzueva May 28, 2024 15:34
Comment on lines 374 to 378
client.deleteTags(new DeleteTagsRequest()
.withResources(resourcesIds)
.withTags(tags.stream()
.map(Tag::new)
.collect(Collectors.toList())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract deleteTags method similarly to how createTags is extracted.

Comment on lines 240 to 244
final Optional<PipelineRun> run = optionalRun.isPresent() ? optionalRun : pipelineRunManager.findRun(runId);
if (!run.isPresent()) {
return Collections.emptyMap();
}
return metadataManager.prepareCustomInstanceTags(run.get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use more optional-friendly implementation here.

Suggested change
final Optional<PipelineRun> run = optionalRun.isPresent() ? optionalRun : pipelineRunManager.findRun(runId);
if (!run.isPresent()) {
return Collections.emptyMap();
}
return metadataManager.prepareCustomInstanceTags(run.get());
return optionalRun.map(Optional::of)
.orElseGet(() -> pipelineRunManager.findRun(runId))
.map(metadataManager::prepareCustomInstanceTags)
.orElseGet(Collections::emptyMap);

Comment on lines 434 to 438
final Set<String> instanceTagsKeys = new HashSet<>(Arrays.asList(preferenceManager.findPreference(
SystemPreferences.CLUSTER_INSTANCE_ALLOWED_CUSTOM_TAGS)
.filter(StringUtils::isNotBlank)
.map(value -> value.split(","))
.orElse(Strings.EMPTY_ARRAY)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use Stream API here.

Suggested change
final Set<String> instanceTagsKeys = new HashSet<>(Arrays.asList(preferenceManager.findPreference(
SystemPreferences.CLUSTER_INSTANCE_ALLOWED_CUSTOM_TAGS)
.filter(StringUtils::isNotBlank)
.map(value -> value.split(","))
.orElse(Strings.EMPTY_ARRAY)));
final Set<String> instanceTagsKeys = preferenceManager.findPreference(
SystemPreferences.CLUSTER_INSTANCE_ALLOWED_CUSTOM_TAGS)
.filter(StringUtils::isNotBlank)
.map(value -> value.split(","))
.map(Arrays::stream)
.orElseGet(Stream::empty)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toSet());

Comment on lines 446 to 448
final Map<String, PipeConfValue> metadataData = MapUtils.emptyIfNull(Objects.isNull(toolMetadata)
? null
: toolMetadata.getData());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionals are perfect for such a situation.

Suggested change
final Map<String, PipeConfValue> metadataData = MapUtils.emptyIfNull(Objects.isNull(toolMetadata)
? null
: toolMetadata.getData());
final Map<String, PipeConfValue> metadataData = Optional.ofNullable(toolMetadata)
.map(MetadataEntry::getData)
.orElseGet(Collections::emptyMap);

Comment on lines 364 to 365
final Map<String, String> customTags = resolveCommonCustomInstanceTags(run);
return resolveInstanceTagsFromMetadata(run.getDockerImage(), customTags);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using a simpler approach for collecting tags from various sources.

Suggested change
final Map<String, String> customTags = resolveCommonCustomInstanceTags(run);
return resolveInstanceTagsFromMetadata(run.getDockerImage(), customTags);
final Map<String, String> implicitTags = resolveCommonCustomInstanceTags(run);
final Map<String, String> explicitTags = resolveInstanceTagsFromMetadata(run);
return CommonUtils.mergeMaps(implicitTags, explicitTags);

* - run_id - Integer ID of a run
* - owner - Username of a run owner
*/
public enum CommonCustomInstanceTagsTypes {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name of the class is too confusing. It's both common and custom. Can we just call it CommonInstanceTagType? I think that for the most part of the code in this pull request there is no actual need in having custom in name.

@ekazachkova ekazachkova merged commit cb8c9fd into develop May 30, 2024
4 checks passed
ekazachkova added a commit that referenced this pull request May 31, 2024
sidoruka pushed a commit that referenced this pull request Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants