Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Conversation

@bennaaym
Copy link
Contributor

Description

This PR is an improvement of the existing Labgraph Monitor application

The PR adds the following :

  • Migrate the old application from Javascript to Typescript( static/strong typing support)
  • Use a much simpler serialized representation of the computational graph (old representation was complex, hard to process, and contained redundant data)
  • Add input/output messages (name, fields & datatypes)
  • Add REALTIME / MOCK features

(!) this PR is complementary to the following PR Bennaaym/yaml support #58

Fixes #45

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Feature/Issue validation/testing

Tested the different components of the application using react-testing-library & jest

Checklist:

  • Have you added tests that prove your fix is effective or that this feature works?
  • New and existing unit tests pass locally with these changes?
  • Has code been commented, particularly in hard-to-understand areas?
  • Have you made corresponding changes to the documentation?

bennaaym and others added 25 commits February 10, 2022 15:59
…vious graph structure is different than the new one
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 18, 2022
@dtemir
Copy link
Contributor

dtemir commented Mar 1, 2022

hey @bennaaym. again, awesome work! i just wanted to let you know that there are two sub-directories under labgraph_monitor/src/pages: Home and home. Having both of them threw me an error, so I deleted the home one and everything worked.

Screenshot from 2022-03-01 14-18-02

@bennaaym
Copy link
Contributor Author

bennaaym commented Mar 2, 2022

@dtemir thank you for reporting that, "/home" wasn't supposed to be committed. I removed it.

@fzchriha
Copy link
Contributor

fzchriha commented Mar 5, 2022

Hi @bennaaym, I reviewed the changes I believe it is enough to fix #45 , could you please tell me what are the features your current solution doesn't have? Great job!

@@ -0,0 +1,8 @@
#!/bin/sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Is .husky file a compulsory file for this commit?

Copy link
Contributor Author

@bennaaym bennaaym Mar 8, 2022

Choose a reason for hiding this comment

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

Currently I'm using prettier, eslint, husky to automate formatting, identifying patterns which keeps the code consistent and production-ready.
I believe that aligns with the approach that LabGraph is using with python by using flake8. The point of using husky is to automate the process through git-hooks, my current code will run a check whenever a contributor tries to add a new commit(pre-commit git-hook) that will prevent bad commits from being committed if there are any (e.g: unwanted console.log(), unused packages, unformatted code ...).
The husky script will run only if there is a change in the extensions/prototypes/labgraph_monitor directory.

@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this robots.txt used for?

Copy link
Contributor Author

@bennaaym bennaaym Mar 8, 2022

Choose a reason for hiding this comment

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

robots.txt file tells search engine crawlers which URLs the crawler can access on the site (Robots Exclusion Protocol). This is used mainly to avoid overloading the site with requests. It is mainly useful in case Labgraph Monitor will be deployed. It can be deleted in case of localhost usage.

@@ -0,0 +1,9601 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to have this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yarn unlike npm provides a deterministic approach to set up node_modules using Lockfiles that ensures that every install results in the exact same file structure in node_modules across all machines. Deleting yarn.lock may create errors when trying to set up the dependencies. ref: https://engineering.fb.com/2016/10/11/web/yarn-a-new-package-manager-for-javascript/

Copy link
Contributor

@jfResearchEng jfResearchEng left a comment

Choose a reason for hiding this comment

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

Thank you for contributing this PR! This looks good and please have a quick review of my comments.

@jfResearchEng jfResearchEng mentioned this pull request Mar 7, 2022
6 tasks
@bennaaym
Copy link
Contributor Author

bennaaym commented Mar 8, 2022

Hi, @fzchriha thanks for helping review this PR. The current application makes use of all the data provided by the WebSocket API, adding new features to the frontend should always be associated with updates in the backend.

These are some features that I think are useful and align with LabGraph Monitor vision:

  • Currently when an edge is clicked, "message_name", "message_fields" and "fields_datatypes" are displayed, it will be useful to add the "fields_values" (The changes can be made on the Mocks then transferred to be real-time when the backend is updated)

  • After adding "fiedls_values", keeping track of the values may be hard since the values will be changing every 200ms(depends on the sampling rate, currently it's 5 samples/s), So I think adding visualisation to the data might be useful (something like Chart.js can be used for that ).

  • Storing snapshots of the data might be useful for future analysis. (something like Redis can be used for that)

  • Another feature is to change the flow of messages in realtime, setting up the UI for that is relatively simple(updatable-edge), but it will require a lot of work in terms of backend and the serialized graph representation

@bennaaym bennaaym requested a review from jfResearchEng March 8, 2022 09:35
@jfResearchEng
Copy link
Contributor

Thanks, bennaaym, for replying to the comments and recommendations on additional features! I've asked an additional reviewer to help review this PR by end of this week.

Copy link

@navn-r navn-r left a comment

Choose a reason for hiding this comment

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

Overall, this PR is ready for @dtemir and @fzchriha to use as a base. However please still consider my comments.

Awesome Job! 🌮 💯

@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 4,
Copy link

Choose a reason for hiding this comment

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

Quick Question, is this tab width also consistent with the formatting on the Python side?

Copy link
Contributor Author

@bennaaym bennaaym Mar 12, 2022

Choose a reason for hiding this comment

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

currently, flake8 show a warning if the tab size isn't a multiple of 4 however the code can be always committed (that might need to be automated more). For typescript Airbnb guidelines suggest using 2 as tab size however I changed it to 4 to keep it consistent with Python.

ref: 949ffc9

Copy link

Choose a reason for hiding this comment

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

Personally, I'm used to the Airbnb spec with 2, and probably most Front End contributors would be as well. However, if the repo wants to be consistent for both React and Python then yea I guess thats okay.


Once Node is installed, you can verify that node/npm was installed successfully by running the following:
- [Node.js](https://nodejs.org/en/)
- [Yarn](https://classic.yarnpkg.com/lang/en/docs/install) (**RECOMMENDED**)
Copy link

Choose a reason for hiding this comment

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

I wouldn't put this as recommended, rather it should be compulsery. What we don't want is a contributor thinking its okay to just use npm and the repo would end up with two lockfiles.

Copy link
Contributor Author

@bennaaym bennaaym Mar 12, 2022

Choose a reason for hiding this comment

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

Done. however, I don't think there is a way to prevent the user from using npm. I added package-lock.json to .gitignore to prevent it from being committed

Copy link

Choose a reason for hiding this comment

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

Yea I think that works. My suggestion was really to tell a contributor

"hey don't use npm, just stick with yarn"

**Set up the application**

The above should display the version of node/npm that were installed. For example:
(!) The following tutorial utilizes **yarn** (recommended) however **npm** can be utilized as well.
Copy link

Choose a reason for hiding this comment

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

See above statement about yarn and npm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 19 to 20
labgraph> cd extensions/prototypes/labgraph_monitor
labgraph\extensions\prototypes\labgraph_monitor>
Copy link

Choose a reason for hiding this comment

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

nitpick, since everyone has different prompts for their terminals, It would be better to have just

Suggested change
labgraph> cd extensions/prototypes/labgraph_monitor
labgraph\extensions\prototypes\labgraph_monitor>
cd extensions/prototypes/labgraph_monitor

as the step, so contributors could just copy paste the code snippet as they go through.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Note: npx is a package that comes with npm 5.2+
```
npx create-react-app labgraph_monitor_extension
labgraph\extensions\prototypes\labgraph_monitor> yarn
Copy link

Choose a reason for hiding this comment

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

[Nitpick] Same applies here, at this step, its assumed that the user is already at the given directory, so we could just have

Suggested change
labgraph\extensions\prototypes\labgraph_monitor> yarn
yarn

Again this is just a nitpick, but if proceeding with my suggestion, make sure to do it to the other code snippets as well.

🤠

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

dispatch(setConnection(WS_STATE.IS_CONNECTING));
};

const handleDiconnect = (event: React.FormEvent<HTMLFormElement>) => {
Copy link

@navn-r navn-r Mar 11, 2022

Choose a reason for hiding this comment

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

Suggested change
const handleDiconnect = (event: React.FormEvent<HTMLFormElement>) => {
const handleDisconnect = (event: React.FormEvent<HTMLFormElement>) => {

be sure to change the other places in which this function is called :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

const [mock, setMock] = useState<string>('');
const dispatch = useDispatch();

const handleChange = (_: React.SyntheticEvent, newValue: string) => {
Copy link

Choose a reason for hiding this comment

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

This seems a bit redundant, we could just have (_, newValue) => setValue(newValue) inside the onChange, rather than having a brand new function. Either remove it, or rename it to something less generic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 24 to 29
{selectedNode.id && <Typography>{selectedNode.id}</Typography>}
{!selectedNode.id && (
<Typography style={{ fontSize: '.8rem', fontWeight: 400 }}>
Click on a node to see its information
</Typography>
)}
Copy link

Choose a reason for hiding this comment

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

Suggested change
{selectedNode.id && <Typography>{selectedNode.id}</Typography>}
{!selectedNode.id && (
<Typography style={{ fontSize: '.8rem', fontWeight: 400 }}>
Click on a node to see its information
</Typography>
)}
{selectedNode?.id ? (<Typography>{selectedNode.id}</Typography>) : (
<Typography style={{ fontSize: '.8rem', fontWeight: 400 }}>
Click on a node to see its information
</Typography>
)}

Better to switch to ternary in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

const WSContextProvider: React.FC<ReactNode> = ({ children }): JSX.Element => {
const { connection, graph } = useSelector((state: RootState) => state.ws);

const clientRef = useRef<any>(null);
Copy link

Choose a reason for hiding this comment

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

nitpick, not helpful to have any, could we replace that with its actual type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

*/
import INode from './INode';

interface IGraph {
Copy link

Choose a reason for hiding this comment

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

It seems like this interface is present in multiple files. Any way we could just have one central source for the IGraph, INode interfaces, rahter than multiple IGraph.ts 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.

Done

@jfResearchEng jfResearchEng merged commit adf27ac into facebookresearch:main Apr 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LabGraph Monitor Improvement - Add input/output message information in LabGraph Monitor UI

6 participants