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

gRPC implementation #2

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

gRPC implementation #2

wants to merge 37 commits into from

Conversation

luca-schlecker
Copy link
Collaborator

This pr implements the gRPC api specified in snowballr-api. Some functions are implemented as dummies. Authentication is handled using plain-text, be warned!

Copy link

@Merseleo Merseleo 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 all this work. I'm looking forward to finally use a completely working mock backend, especially as we can finally implement e2e tests now.

Still there are some things (especially code style and documentation) that are not at level I want to accept without changes or discussion.
However, it seems to work perfectly, at least as far as I tested it for now.

A general advice: please make the PRs a little bit smaller.

.gitmodules Outdated
[submodule "api"]
path = api
url = [email protected]:SE-UUlm/snowballr-api.git
branch = feat/initial-api
Copy link

Choose a reason for hiding this comment

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

I think you forgot to change this branch. feat/initiali-api doesn't exist anymore and we should also use main and no feature branch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did miss this, yes.

RUN npm install
RUN npm run compile:proto
RUN npm run build
CMD ["npm", "run", "start"]
Copy link

Choose a reason for hiding this comment

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

Only a question of interest: why do you use this format to run a command not RUN npm run start?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

RUN npm run start would execute that command during build time. The server should be started when running the docker container, thus CMD is used instead of RUN. If you however meant why I put the command in brackets, I don't know. It's valid either way.

@@ -0,0 +1,47 @@
# SnowballR Mock Backend

Copy link

Choose a reason for hiding this comment

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

Great that you added a README.md file, I like it a lot! However, imo it would be even better to have one or two introductory sentences explaining what the mock backend is, what it is not and why we need it. Because we know its purpose etc., but somebody else not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a few introductory sentences. 👍

Comment on lines +24 to +27

```sh
npm run start
```
Copy link

Choose a reason for hiding this comment

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

So do i understand correctly, that this would not work directly, but I have to start the envoy proxy separately. If so, please mention this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed out the proxy and thus updated the README. Should be clearer now.

README.md Outdated
Comment on lines 36 to 47
## Tooling

Both [grpcurl](https://github.com/fullstorydev/grpcurl) and
[grpcui](https://github.com/fullstorydev/grpcui) can be very helpful when
getting to know the api or debugging. Install the ones you like and use them
like this (replacing the address if needed):

```sh
grpcui -plaintext 127.0.0.1:8080
grpcurl -plaintext 127.0.0.1:8080 snowballr.SnowballR.IsAuthenticated
```

Copy link

Choose a reason for hiding this comment

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

Very useful section, thank you!

But the default ist 8081, isn't it? (at least it was on my machine)

Copy link

Choose a reason for hiding this comment

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

One minor request: I think it would be nice to add a hint, that you to register first, because no default user exist for now and use this access token to add a Authorization field in the request. Because this was not totally clear to me at the beginning.

src/service.ts Outdated
): void {
const { id } = call.request;
if (project_papers.has(id)) {
callback(null, project_papers.get(id)!);
Copy link

Choose a reason for hiding this comment

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

I do not really understand what this method is supposed to do? What is this id, a paper id? And then a get a paper from any project, even if I am not part of? If so, what's the difference to the getPaperById method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is the id of the association of a paper with a project.

src/service.ts Outdated
): void {
const { projectId, paperId, stage } = call.request;
if (project_papers.has(projectId)) {
const id = project_papers.size.toString();
Copy link

Choose a reason for hiding this comment

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

I don't think this Id is unique this way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. Fixed it.

src/service.ts Outdated
selectedCriteriaIds: selectedCriteriaIds,
});

paper_reviews.get(projectPaperId)!.push(id);
Copy link

Choose a reason for hiding this comment

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

I thought the reviews are stored in the project paper?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are associated with them using an extra map.

src/service.ts Outdated
Comment on lines 1003 to 1007
for (const [projectPaperId, reviews] of paper_reviews) {
paper_reviews.set(
projectPaperId,
reviews.filter((c) => c != id),
);
Copy link

Choose a reason for hiding this comment

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

Maybe it is too late, but I don't understand this delete method. Why don't you delete the review from the reviews list and from the paper_reviews? And again, I thought the IDs are also stored in the project paper?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no need to delete the review. Helps when determining a unique id.

src/service.ts Outdated
Comment on lines 1078 to 1093
getForwardReferencedPapers: function (
_: ServerUnaryCall<Id, Paper_List>,
callback: sendUnaryData<Paper_List>,
): void {
callback(null, {
papers: Array.from(papers.values()),
});
},
getBackwardReferencedPapers: function (
_: ServerUnaryCall<Id, Paper_List>,
callback: sendUnaryData<Paper_List>,
): void {
callback(null, {
papers: Array.from(papers.values()),
});
},
Copy link

Choose a reason for hiding this comment

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

Why don't you use the Id here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just reply with arbitrary papers. Just to get something displayed.

@Slartibartfass2
Copy link

Hi, not sure if this was already mentioned. The README should contain the information that there's a submodule which needs to be set up.

@Slartibartfass2
Copy link

Also, there should be a .dockerignore file so that unwanted files aren't copied to the image.
I recommend using docker init. It detects npm and automatically creates all necessary files while using best practices.

@Merseleo
Copy link

Merseleo commented Feb 6, 2025

Hi, not sure if this was already mentioned. The README should contain the information that there's a submodule which needs to be set up.

Actually that is mentioned in the snowballr-api repo or do you mean how to initialize a git submodule?

@Slartibartfass2
Copy link

Hi, not sure if this was already mentioned. The README should contain the information that there's a submodule which needs to be set up.

Actually that is mentioned in the snowballr-api repo or do you mean how to initialize a git submodule?

In my opinion, we should provide a step-by-step instruction of how a new developer can start the mock server without having to figure it out themselves. I.e.:

  1. (cloning the repo)
  2. initializing the submodule using git submodule update --init
  3. either starting the docker container or running it directly

This should all go in a "How to get started" section where no questions are left open.

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