-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Discuss] Code alignment between master and 7.x branches #78923
Comments
I just wanted to highlight the Upgrade Assistant again as a plugin where the difference between master and 7.x is acute. Code that only exists on 7.x These all share the problem of not being discoverable from master, but I would say the last one, because it is nested inside of code that we reuse across versions, is the most troublesome. A mechanism like what you are describing can be very useful for making the core logic bits of UA easier to test and reason about! I'm not quite sure what the best approach might be for the components and routes - their potential for merge conflicts and regressions seems smaller if the code is well contained to a file/module - but the trick of remembering to test (for visual or logic regressions) is still there unless good, automated tests exist. Another piece I am foggy on, with having 7.x (and in future 8.x and 9.x) code alongside master, is how we handle going to the next major version. Do we simply delete the 7.x code from master when 7.x becomes 8.x? Or is there a way to leave the code in master and have the build assemble itself (again, tricky with points of overlap like the core logic bits in UA). I suppose the // but 👇🏻 branch might not be relevant to have around in future.
if (BRANCH === "7.x") {
} else if (BRANCH === "8.x") {
} else {} |
Thanks for starting this discussion @sebelga! I also want to add that the Snapshot & Restore plugin is another example of where we have a divergence between branches for some server routes and associated tests. This is due to breaking changes in ES snapshot APIs that only target 8.x. This PR highlights the differences: #39533. This at one point did lead to a regression when we were working on NP migration. |
I would be in favor of cleaning any code branch we don't support anymore. if (BRANCH === '7.x') {
// remove this if
} And when needed (where it is difficult to have a clear
So when we need to clean we only need to make 3 searches:
|
Update: I added an example for dynamic import in the PR description. |
I agree that this is a real problem that deserves a solution. With the 8.0 upgrade coming, it'd be great to start removing the deprecated functionality sooner rather than later without the risks that come with the This is largely a nit-pick, but it feels awkward to use the "branch" to make this determination, it feels more natural for this determination to be performed using the actual version number of the product itself. For example, the following feels more natural to me:
This was the approach that I played around with a rather long time ago and abandoned: kobelb@00724de#diff-ce2a4faae344e68d6a0ec1fb307a9b2738446bc89685c78c1ca9552688754342 However, I haven't seen the code diverge enough between |
You are right that we could use a major version number instead of the branch name. 👍 Not sure we need the granularity of minors and patches. As we get for free the dead code elimination with the js minimizer (all Having a |
In my opinion, this is the biggest trade-off. However, it allows us to continue to use the version number specified in the package.json as the source-of-truth. |
Not sure how/when the "package.json" version is bumped but it seems that Webpack should be able to also import the file and inject the version. But again, I miss knowledge here on the order of operations. |
Is my understanding correct that you're advocating that we use Webpack primarily for dead code elimination? Most of the situations where I've wanted to do code-branching based on version number wouldn't have benefitted significantly from dead code elimination. Do you have any examples where this would have a significant impact on bundle size? If dead code elimination isn't a deciding factor in the approach, we'll still have to decide between using a global-variable or having a "version service" which is provided by It should also be noted that Webpack is only used for building the client-side bundles, so it won't be a native solution for the server-side. |
You're making a good point about global vars and unit tests, although it shouldn't be too hard to define them before executing the tests. My main reason for Webpack was actually the simplicity and DX, before the benefit of dead code elimination. It seems that with the core services there are more moving parts and I don't see clearly why they are needed. If the only problem we need to solve is: is this branch X or Y (no need of the granularity of minor or patch version which the service could provide), then I was suggesting simplicity (both in implementation and consumption). Regarding dead code elimination, you are right that there isn't currently a need to optimize for it. I just thought: if we have if for free, why not? :) With that said, if you do want to avoid global vars and prefer the core service, I'm good with that, I let you decide. Just sharing some thoughts. |
@alisonelizabeth I'm on board! Thanks :elasticheart: |
Going to close this issue. I've opened #85969 to track the proposed implementation. |
In the ES UI team, we have several places (upgrade assistant, mappings and now the upcoming #78331) where the code between master and 7.x diverges.
Those differences are a problem for
7.x
and we got Saving not possible after editing index template #78384)We could try to remember all the little nuances between the branches, but we know we will forget them as we keep adding functionalities and plugins. We can try to keep a document up to date with the differences but I think it will get quickly obsolete and hard to parse to get a full picture of the differences.
The best place to indicate the difference IMO is in the code itself.
We can't get much clearer than that, and this can be backported without any problem.
In master, the above example will be evaluated to
Dynamic imports
When possible, the code that will be deprecated (e.g. a component rendering a deprecated mapping field), should be exported from a barrel file following the convention:
index_<branch>.ts
.As an example, the boost parameter is removed from the mappings in 8.x. We should remove its export from the current
index.ts
file and export it from aindex_7x.ts
file.Then its import can be conditional, according to the branch we are on
Tests
As a side benefit, when the code is self-explanatory, then there is little risk to forget to add a test for that code branch.
For now, I am only seeing the need of knowing the branch (the major version) the code will be run from. But this would leave the door open for feature flags in case there is a switch of priorities during a release cycle (which hasn't happened yet but we almost got into the situation in the last release).
The text was updated successfully, but these errors were encountered: