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

[Refactor] Refactor common code between all benchmark commands #1611

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ruflin
Copy link
Member

@ruflin ruflin commented Dec 21, 2023

There is quite a bit of duplicated code across all the benchmark commands. This is a first quick take on bringing it together.

Initially I wanted to only refactor 1-2 functions but one lead to the next things. I am pushing this now to get early review from others, this is not complete / not fully tested. Also potentially now that the refactoring is bigger, likeyl the best place of the common files has become a different place.

There is quite a bit of duplicated code across all the benchmark commands. This is a first quick take on bringing it together.

Initially I wanted to only refactor 1-2 functions but one lead to the next things. I am pushing this now to get early review from others, this is not complete / not fully tested. Also potentially now that the refactoring is bigger, likeyl the best place of the common files has become a different place.
@ruflin ruflin self-assigned this Dec 21, 2023
@aspacca
Copy link
Contributor

aspacca commented Dec 27, 2023

@ruflin so far all good for me

@@ -32,44 +34,23 @@ type scenario struct {
Corpora corpora `config:"corpora" json:"corpora"`
}

// TODO: Why is this slightly different from the common fields?
Copy link
Member Author

Choose a reason for hiding this comment

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

@aspacca You might know more here? And the one below?

Copy link
Contributor

Choose a reason for hiding this comment

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

the data required for both data_stream and corpora configuration is different between system benchmarks and rally/stream ones.

specifically: rally/stream does not require data_stream.vars and corpora.input_service

since I "duplicated" both structs used to unmarshal the yaml configuration in the rally/stream packages that I added, I removed the fields that were not required.

it is fine to have this two structs only in the common package as well, with all the fields currently defined in the system package (ie: the "version" we have in this file). the packages where the fields are not required will just not access them. there's no impact on the specs from the underlying structs that are used to unmarshal the yaml.

the only caveat is that what can happen is that someone could add data_stream.vars or corpora.input_service in a configuration where they are not required and provide a value that cannot be unmarshalled. in this case we cannot simply ignore/not access the not required fields, the user has to remove them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, I for now remove the 2 TODO mentions, we can always follow up on this.

@ruflin ruflin marked this pull request as ready for review January 17, 2024 07:58
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @ruflin

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the refactor! Added some nitpicking and waiting for Andrea's review.

// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package common
Copy link
Member

Choose a reason for hiding this comment

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

Nit. common seems too generic, could this go directly in the internal/benchrunner/runners package? Or to an internal/benchrunner/scenario package?

Copy link
Member Author

Choose a reason for hiding this comment

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

@aspacca Any thoughts?

return nil, fmt.Errorf("error loading scenario: %w", err)
}
scenarios[scenarioName] = scenario
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Nit. I think we can remove the else to have one less nesting level.

Suggested change
} else {
return scenarios
}

Copy link
Member Author

Choose a reason for hiding this comment

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

See my comment above, happy to follow up further code changes but now trying to focus on only moving things around, no logical changes.

return c, nil
}

func ReadScenarios(path, scenarioName, packageName, packageVersion string) (map[string]*Scenario, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Do we have any benefit on returning scenarios as a map? Returning a list would help controlling the order of execution and results. Scenario could have a field for the name.

Suggested change
func ReadScenarios(path, scenarioName, packageName, packageVersion string) (map[string]*Scenario, error) {
func ReadScenarios(path, scenarioName, packageName, packageVersion string) ([]*Scenario, error) {

Copy link
Member Author

Choose a reason for hiding this comment

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

@jsoriano I would prefer to delay code changes to a different PR. The reason is for this PR I only moved code around, not type / logic change to make sure the refactoring does not affect any of the logic.

@ruflin ruflin assigned lalit-satapathy and unassigned ruflin Apr 12, 2024
@ruflin
Copy link
Member Author

ruflin commented Apr 12, 2024

@lalit-satapathy This should have been a quick one around code cleanup. Unfortuantely I didn't manage to fully follow up so there are now conflicts. Hopefully nothing major to resolve.

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.

5 participants