Skip to content

Conversation

efd6
Copy link
Contributor

@efd6 efd6 commented Sep 16, 2025

For #2868

Please take a look.

@efd6 efd6 self-assigned this Sep 16, 2025
@efd6 efd6 requested a review from a team September 16, 2025 04:28
@efd6 efd6 force-pushed the export_profile_loading branch from 0e30fc2 to be5209a Compare September 16, 2025 21:06
)

const currentVersion = 1
const CurrentVersion = 1
Copy link
Member

Choose a reason for hiding this comment

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

Is this going to be used out of the package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Member

Choose a reason for hiding this comment

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

Could you give more deatils about how this is going to be used out of the package?

)

func (p *Profile) migrate(version uint) error {
func (p *Profile) Migrate(version uint) error {
Copy link
Member

@jsoriano jsoriano Sep 17, 2025

Choose a reason for hiding this comment

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

At the moment migration is part of the profile loading process, it shouldn't be needed out of the package. Do you have a use case for this?

If this is intended to load from a directory with the migrations included, maybe we could keep loadProfile private, and create a method LoadProfileFrom, that does the same as LoadProfile, including the migrations. So callers don't need to care about migrations.

Something like this:

func LoadProfile(profileName string) (*Profile, error) {
	loc, err := locations.NewLocationManager()
	if err != nil {
		return nil, fmt.Errorf("error finding stack dir location: %w", err)
	}

	return LoadProfileFrom(profileName, loc.ProfileDir())
}

func LoadProfileFrom(profileName, profilesDir string) (*Profile, error) {
	profile, err := loadProfile(profilesDir, profileName)
	if err != nil {
		return nil, err
	}

	err = profile.migrate(currentVersion)
	if err != nil {
		return nil, fmt.Errorf("error migrating profile to version %v: %w", currentVersion, err)
	}

	return profile, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given the choice of reduced code duplication/increased code complixity, and reduced exported functions in an internal package, I chose the latter.

Copy link
Member

@jsoriano jsoriano Sep 17, 2025

Choose a reason for hiding this comment

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

It is not so much about functions exported or code duplication, but about responsibilities.
As the package is defined now the responsibility of migrating profiles clearly belongs to the profile package.
If we expose different methods for load and migration of profiles, this responsibility is diluted.
Also, exposing two different "LoadProfile" methods that do different things is prone to errors (LoadProfile would run migrations, but LoadProfileFrom wouldn't).

@efd6
Copy link
Contributor Author

efd6 commented Sep 17, 2025

The changes that are in this are the minimal set that I need to be able to implement a testscript hook for bringing up/taking down a stack.

@jsoriano
Copy link
Member

The changes that are in this are the minimal set that I need to be able to implement a testscript hook for bringing up/taking down a stack.

I understand how loading specific profiles may be needed, but running migrations from different places looks error-prone. Why is this needed?

@efd6
Copy link
Contributor Author

efd6 commented Sep 17, 2025

I don't specifically need the migration method, but this is the minimal change to get the behaviour that is needed given the way that testing is done here. Ideally, I'd not do it, but the proposal above it more complicated for IMO limited benefit.

@jsoriano
Copy link
Member

I don't specifically need the migration method, but this is the minimal change to get the behaviour that is needed given the way that testing is done here. Ideally, I'd not do it, but the proposal above it more complicated for IMO limited benefit.

I think I am missing what is the needed behavior. Other packages can already load profiles with LoadProfile. They only cannot choose the directory where profiles are stored. If this is needed, in my opinion just adding a LoadProfileFrom method as proposed in #2916 (comment) introduces much less complexity than having to use the migration functionality out of the profile package.

@efd6
Copy link
Contributor Author

efd6 commented Sep 17, 2025

If this is needed, in my opinion just adding a LoadProfileFrom method as proposed in #2916 (comment) introduces much less complexity than having to use the migration functionality out of the profile package.

I this is insisted, I will do this, but I disagree.

Specifically, "having to use the migration functionality out of the profile package" is not part of the required behaviour, though I can see test situations where it may be, and in that case, it would then have to be exported. I do not see the benefit from hiding functionality in a package that is internal, and I am seeing significant composability friction because of the level of non-exported labels in these packages.

@jsoriano
Copy link
Member

I this is insisted, I will do this, but I disagree.

I am sorry for the disagreement, but I would greatly prefer to avoid exposing migration functionality if not needed, yes. Also, if we expose two methods for loading profiles, I would prefer both to be consistent regarding migrations (or any other thing that they do).

I can see test situations where it may be, and in that case, it would then have to be exported.

One of the advantages of keeping separated responsibilities is that other packages shouldn't need to care about this functionality, including its testing.

If we happen to find a situation where we would benefit from exposing this functionality out of this package I would be happy to do it. Till then I would prefer to keep it separated.

@efd6 efd6 force-pushed the export_profile_loading branch from 3e0a6e5 to 6325ab8 Compare September 17, 2025 22:58
@elasticmachine
Copy link
Collaborator

elasticmachine commented Sep 17, 2025

⏳ Build in-progress, with failures

Failed CI Steps

History

cc @efd6

@efd6 efd6 force-pushed the export_profile_loading branch from 6325ab8 to d45bb61 Compare September 17, 2025 23:02
@efd6 efd6 requested a review from jsoriano September 17, 2025 23:52
@efd6 efd6 changed the title internal/profile: export profile loading and migration functions internal/profile: export profile loading function Sep 17, 2025
Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

LGTM!

@efd6 efd6 merged commit b3c1be3 into elastic:main Sep 18, 2025
3 checks passed
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.

4 participants