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

Better error handling for flavor detection #6804

Merged
merged 7 commits into from
Feb 14, 2025

Conversation

michalpristas
Copy link
Contributor

@michalpristas michalpristas commented Feb 11, 2025

This PR adds better error handling for flavor detection when manifest file is not found during extracting tar/zip packages.
Backward upgrade tests now working, un-skipping them

Related issues

Closes #6731
Closes #6729
Closes #6732

@michalpristas michalpristas added bug Something isn't working Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches labels Feb 11, 2025
@michalpristas michalpristas self-assigned this Feb 11, 2025
@michalpristas michalpristas marked this pull request as ready for review February 12, 2025 10:15
@michalpristas michalpristas requested a review from a team as a code owner February 12, 2025 10:15
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@michalpristas michalpristas requested a review from pchila February 12, 2025 10:15
Comment on lines +237 to +240
// no flavor loaded
if flavor.Name == "" {
return acceptAllFn, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this actually happen? Is there a flavor in the registry with an empty name? Intuitively, it makes more sense to me to try to prevent this occurrence in the first place instead of handling it downstream like this.

Copy link
Contributor Author

@michalpristas michalpristas Feb 12, 2025

Choose a reason for hiding this comment

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

actually this path specifically does not happen now. we always return error when this is default. i'm leaving it here as safety net. i can remove it as well if you prefer but i rather have it here

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment if you want to keep it? Right now, it suggests this can actually happen.

@michalpristas michalpristas changed the title Fix/flavors backwards Better error handling for flavor detection Feb 12, 2025
@@ -55,11 +55,15 @@ func Flavor(detectedFlavor string, registryPath string, flavorsRegistry map[stri
if flavorsRegistry == nil {
f, err := os.Open(registryPath)
if err != nil {
return FlavorDefinition{}, err
if os.IsNotExist(err) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a case where the registryPath is not an empty string?
The manifest is already parsed at the call locations of install.Flavor, what is the usecase where we need to open the manifest again here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously it was used by other code path where registry was not opened before. yes this can be cleaned up now

Copy link
Contributor Author

@michalpristas michalpristas Feb 13, 2025

Choose a reason for hiding this comment

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

but as this does not address the bugs and alters a behavior i will address it separately to avoid introducing side effects

Copy link

Quality Gate failed Quality Gate failed

Failed conditions
34.8% Coverage on New Code (required ≥ 40%)

See analysis details on SonarQube

@michalpristas michalpristas merged commit 086a9a6 into elastic:main Feb 14, 2025
13 of 14 checks passed
mergify bot pushed a commit that referenced this pull request Feb 14, 2025
* Revert "Skip flaky tests on windows while root cause is being investigated (#6734)"

This reverts commit 09c9abc.

* handle registry not present

* 6733 has another root cause

* some more error context

(cherry picked from commit 086a9a6)
michalpristas added a commit that referenced this pull request Feb 14, 2025
* Revert "Skip flaky tests on windows while root cause is being investigated (#6734)"

This reverts commit 09c9abc.

* handle registry not present

* 6733 has another root cause

* some more error context

(cherry picked from commit 086a9a6)

Co-authored-by: Michal Pristas <michal.pristas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment