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

lens: migrates from react-scripts to vite #3506

Merged
merged 8 commits into from
Feb 11, 2024
Merged

lens: migrates from react-scripts to vite #3506

merged 8 commits into from
Feb 11, 2024

Conversation

SamTV12345
Copy link
Contributor

@SamTV12345 SamTV12345 commented Feb 4, 2023

This pr introduces vite a very fast bundling tool for react and other languages. It contains a modern API, live reloading, env variables and many more features.

Once this pr is merged I will add some of these features like dynamic imports.

@jcchavezs
Copy link
Contributor

jcchavezs commented Feb 4, 2023 via email

@SamTV12345
Copy link
Contributor Author

Sure. Vite is the intended way to run a modern react application. React scripts from Facebook is very bloated and contains more than 1000 packages in the standard configuration. It doesn't support lazy loading resources and takes forever to start in dev mode. Vite solves this issue with a modern API and a nearly instant start.

I just finished implementing language changing. You can start the project by starting the jar which runs at port 9411 and then start the dev mode of the frontend with npm run dev. The values are currently hard coded. I will change this next to be better configurable.

@SamTV12345 SamTV12345 marked this pull request as ready for review February 5, 2023 10:55
@SamTV12345
Copy link
Contributor Author

I am nearly done. The only failing test is UIConfig.test.jsx. What should the base url of the UIConfig.test.js file be?

@SamTV12345
Copy link
Contributor Author

Feel free to review this pr.

@SamTV12345
Copy link
Contributor Author

Could somebody please approve running workflows? I'd like to check if the pipeline is working. @jcchavezs @tacigar

@SamTV12345
Copy link
Contributor Author

Hopefully this is the last round of workflows. Could you please trigger them again? @jcchavezs @tacigar

@SamTV12345
Copy link
Contributor Author

SamTV12345 commented Feb 11, 2023

The relevant checks are working. I have no clue why the mysql build should fail when I only change the UI or why the IT test takes so long @jcchavezs @tacigar ?

@SamTV12345
Copy link
Contributor Author

Any chance to get this merged with higher priority @jcchavezs @tacigar ?

@jcchavezs
Copy link
Contributor

Please rebase

@SamTV12345
Copy link
Contributor Author

Done.

@SamTV12345
Copy link
Contributor Author

Is the pull request so far okay or are there changes necessary?

@jcchavezs jcchavezs requested a review from tacigar May 23, 2023 08:03
@@ -0,0 +1,2 @@
VITE_UI_URL=/zipkin
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is a good idea to check in env specific files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually sets the ui url for the frontend. I'm not sure what you mean with "check in env specific files".

@jcchavezs
Copy link
Contributor

Do you mind checking @tacigar ? Pinging @wu-sheng as @skywalking also uses lens.

@SamTV12345
Copy link
Contributor Author

Any update @jcchavezs ?

@codefromthecrypt
Copy link
Member

@SamTV12345 would this sort out the dead react-scripts problem? It seems like it would. If so, would you be inclined to rebase? #3713

@SamTV12345
Copy link
Contributor Author

@codefromthecrypt I rebased the master branch.

@SamTV12345
Copy link
Contributor Author

Seems like eslint is not configured yet correctly.

@codefromthecrypt
Copy link
Member

Thanks @SamTV12345, can you run ./mvnw com.mycila:license-maven-plugin:format and add a commit or force-push a new one to pass the license check? until then, we can't reach the part that actually runs the UI tests. If you can't and granted edits, I can do it for you also.

@SamTV12345
Copy link
Contributor Author

Thanks @SamTV12345, can you run ./mvnw com.mycila:license-maven-plugin:format and add a commit or force-push a new one to pass the license check? until then, we can't reach the part that actually runs the UI tests. If you can't and granted edits, I can do it for you also.

I ran the command.

@SamTV12345
Copy link
Contributor Author

Thanks @SamTV12345, can you run ./mvnw com.mycila:license-maven-plugin:format and add a commit or force-push a new one to pass the license check? until then, we can't reach the part that actually runs the UI tests. If you can't and granted edits, I can do it for you also.

If you'd like to you can start testing and reviewing the commit.

Copy link
Member

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

Thanks for the progress! I made some notes as I think we want to keep variable names the same, so that there is less change to developers. Also I think you may need to run npm run lint to fix that, possibly you'll have to run the ./mvnw com.mycila:license-maven-plugin:format after

In general, to know what the PR will pass or fail, run ./mvnw clean install -pl ./zipkin/zipkin-lens.. this may save you time from testing with github

@@ -0,0 +1,2 @@
VITE_UI_URL=http://localhost:51204/zipkin
Copy link
Member

Choose a reason for hiding this comment

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

So, in our README, we have instructions to set API_BASE env when building, and this is used for npm start to use a different base path for the target. I wonder if this is what you are doing here? If so, maybe rename the variable to API_BASE? If this can take from the env variable, then maybe we don't need these files, and things work the same?

"react-redux": "^7.1.0",
"react-router-dom": "^5.0.1",
"react-scripts": "5.0.1",
Copy link
Member

Choose a reason for hiding this comment

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

glad this is gone ;)

@@ -116,7 +116,7 @@
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
<arguments>install --legacy-peer-deps</arguments>
Copy link
Member

Choose a reason for hiding this comment

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

need a comment above why

@@ -262,7 +262,7 @@
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
<argument>install --legacy-peer-deps</argument>
Copy link
Member

Choose a reason for hiding this comment

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

same 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.

npm introduced this in Version 7 to restore compability with the program. To cite stackoverflow:

Due to the large number of modules that haven't specifically added React v17 (or more recently, React 18) as a peerDependency, it's now commonplace to encounter the unable to resolve dependency tree error when running npm installs within a v17 React application.

So it is pretty much required to use this flag. It does not break installations. It just makes sure that installation goes as smooth as possible. We could switch to pnpm which is more modern than npm. But I wouldn't introduce this in this pr.

Copy link
Member

Choose a reason for hiding this comment

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

so maybe make an XML comment similarly? I'm not contesting it, just why should stay in the source tree.

e.g.

<!-- A large number of modules haven't specifically added React as a peerDependency.
       This flag is a norm and keeps the installation smooth.
        See https://the/so/link -->


render(
<LookbackMenu close={close} onChange={onChange} lookback={lookback} />,
);

// Click outside of the component.
fireEvent.click(document);

// TODO: Should comment out this line.
Copy link
Member

Choose a reason for hiding this comment

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

I'm ok removing this note as it doesn't explain why it should be uncommented.. and possibly it isn't valid anymore anyway. confusing comments are worse than none

@@ -11,5 +11,4 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

@import '~vizceral-react/dist/vizceral.css';
/*@import '~vizceral-react/dist/vizceral.css';*/
Copy link
Member

Choose a reason for hiding this comment

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

why is this commented out?

* the License.
*/

import { getLocale, setLocale } from './locale';
Copy link
Member

Choose a reason for hiding this comment

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

should we make something like this for i18s.test.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be beneficial to do.


/* eslint-disable global-require */

describe('BASE_PATH', () => {
Copy link
Member

Choose a reason for hiding this comment

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

so we used to have instructions for setting BASE_PATH.. I think it is now VITE_API_URL? Is it possible to restore BASE_PATH as this feature was requested by users and better to keep name and instructions the same if possible

<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
Copy link
Member

Choose a reason for hiding this comment

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

I guess you are removing this because there is nothing in vite like PUBLIC_URL in react-scripts?

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 exactly. The base path for vite needs to be set in the vite config ts. Then all paths are prepended with the correct url.

component={DependenciesPage}
/>
)}
<BrowserRouter basename={import.meta.env.VITE_UI_URL}>
Copy link
Member

Choose a reason for hiding this comment

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

lets keep the variable names the same, as it is less for people to understand, unless literally VITE_UI_URL is the required name.

Suggested change
<BrowserRouter basename={import.meta.env.VITE_UI_URL}>
<BrowserRouter basename={import.meta.env.BASE_PATH}>

@codefromthecrypt
Copy link
Member

@SamTV12345 because you raised this PR from the branch named master, I won't be able to rebase it without closing this PR. Let us know if you have time to complete this, or if someone else should create a new PR

@SamTV12345
Copy link
Contributor Author

Hi @codefromthecrypt , sorry for the silence. I'm studying CS for masters degree. I have time from today till end of march. So it should be pretty likely to get this pull request merged till then. I'll continue working on it this evening.

@codefromthecrypt
Copy link
Member

@SamTV12345 epic! thanks for the context and your help!

@SamTV12345
Copy link
Contributor Author

@codefromthecrypt The pipelines are passing. There is a regression in the tests but doesn't seem to be introduced by me:
image

@SamTV12345
Copy link
Contributor Author

A rebase solved that issue too. So all pipelines are green. If you need more help or other code changes just ask. I've got now a lot of time till the next semester starts.

Copy link
Member

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

great progress and I think we are very close!

@@ -0,0 +1 @@
BASE_PATH=/zipkin
Copy link
Member

Choose a reason for hiding this comment

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

So, I think there are two concepts going on

  1. what is the base path of the UI (to override in case it isn't "/zipkin"
  2. how do you get to the API server (formerly API_BASE which is a URI)

Can you separate these out, and then try to match up the README with whatever the outcome is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I separated the two variables API_BASE and BASE_PATH. You are definetely right. It is best to separate the two.

Copy link
Member

Choose a reason for hiding this comment

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

So, the README says this:

By default, API requests are proxied to http://localhost:9411. You can change this target using
the API_BASE environment variable, e.g., API_BASE=http://tracing.company.com npm start.

So being user-empathetic, best to check the README works or change the readme. I think API_BASE should be defaulted to http://localhost:9411 and BASE_PATH should be a path (like /zipkin), not a URI like BASE_PATH in the .env.test file.

Can you think through this, and converge with the README or change it and update? If BASE_PATH must be a URI not a path, then, we need to note that in the release notes and change the variable to BASE_URI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The BASE_PATH variable can be anything. I changed it to correctly reflect the values described in the README.

@codefromthecrypt
Copy link
Member

Loving that green build! fyi @tacigar I will merge sam's work when he finishes unless you scream!

@codefromthecrypt
Copy link
Member

@SamTV12345 In case you are interested in a varied experience our JS/TS tracing library is in dire need of help. If no one helps get it back into shape, we'll have to kill the project. If you have some time to polish it up, I'm sure you'll make a lot of friends openzipkin/zipkin-js#536

@SamTV12345
Copy link
Contributor Author

@SamTV12345 In case you are interested in a varied experience our JS/TS tracing library is in dire need of help. If no one helps get it back into shape, we'll have to kill the project. If you have some time to polish it up, I'm sure you'll make a lot of friends openzipkin/zipkin-js#536

Thanks for the invite. Sure I'll take a look at the JavaScript repository. Maybe I can polish this up. I've been maintaining Etherpad for 1 1/2 years so shouldn't be a problem to find my way through the code :).

@SamTV12345
Copy link
Contributor Author

@codefromthecrypt Should I just fork the js repository, make the changes and create a pull request?

@codefromthecrypt
Copy link
Member

@codefromthecrypt Should I just fork the js repository, make the changes and create a pull request?

for starters, yep! and please make one not off the "master" branch, rather a change-specific one as that makes it easier for us to contribute to the PR if needed. Cheers!

Copy link
Member

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

Last comment I think. If there's nothing left in the README that is out-of-date, once addressed, let's merge!

@@ -0,0 +1,2 @@
BASE_PATH=/zipkin
API_BASE=http://localhost:51204/zipkin
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 .env.test file used anywhere? if not, maybe we can delete it to remove questions about it or possible port conflicts. if this actually used in tests, I guess there's no way to have it use a random port e.g. by specifying port zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used during the tests so the test Browserrouter knows where to find the routes etc. I don't really know what happens if I skip the API_BASE variable. If you ever start with E2E tests you can then simply start Zipkin on port 51204.

Copy link
Member

Choose a reason for hiding this comment

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

good enough for me!

@SamTV12345
Copy link
Contributor Author

@codefromthecrypt Should I just fork the js repository, make the changes and create a pull request?

for starters, yep! and please make one not off the "master" branch, rather a change-specific one as that makes it easier for us to contribute to the PR if needed. Cheers!

Thanks. I'll take a look at it and see what can be improved.

@codefromthecrypt codefromthecrypt merged commit 2ada407 into openzipkin:master Feb 11, 2024
12 checks passed
@codefromthecrypt
Copy link
Member

Thanks for all the work and patience @SamTV12345!

@SamTV12345
Copy link
Contributor Author

You're welcome @codefromthecrypt . It's been great working with you on this pull request :).

@codefromthecrypt codefromthecrypt changed the title Added vite. lens: migrates from react-scripts to vite Feb 12, 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.

3 participants