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

Why do we need sha1 when consuming the API? #92

Open
oytuntez opened this issue Aug 5, 2021 · 8 comments
Open

Why do we need sha1 when consuming the API? #92

oytuntez opened this issue Aug 5, 2021 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@oytuntez
Copy link

oytuntez commented Aug 5, 2021

Hi there,

Thank you for your work in this very practical library. I've been enjoying the documentation and actually just finalized generating a large test content now.

I have one question: sha1 hashes. Why do we need to expose them to the outside? It makes the client experience so much harder. Basically, one needs to re-deploy the client that uses RosaeNLG if a template is updated to call the API with the proper sha1 hash.

At first, I thought the API was keeping versions, so sha1 allowed clients to use multiple versions of a template, but that is not the case. What do you think of adding another render endpoint, only with the template name, without requiring clients to know about its sha1?

Oytun

@oytuntez oytuntez added the enhancement New feature or request label Aug 5, 2021
@oytuntez
Copy link
Author

oytuntez commented Aug 5, 2021

Or it just forces clients to make a couple more API calls to first get the sha1 of the template, and then another call to render with that sha1.

@ludans
Copy link
Contributor

ludans commented Aug 5, 2021

Thanks!

Yes, sha1 hashes make experience harder. They were not here at the beginning, I hesitated a lot to add them, but I added for one reason.

Let's have an architecture with a load balancer and multiple RosaeNLG instances behind it. Each instance must be able to render any template. They are loaded automatically and cached at first render call.

The problem is the following: when a template gets updated, only once instance (the one that receives the new template) is aware and can update its cache. The others instances would keep serving outdated templates.

When sending a new sha1 to instances with an outdated cache, these instances are able to see it that they don't have the proper version and smoothly reload the template and update their cache.

There are probably other ways to do it but which would probably imply instance to instance communication, which I would like to avoid.

In practice, there are ways to cope with sha1 transparently in the code:

  • make a first GET call to get information about the template (including the sha1)
  • even better, make a render call with a random sha1 (e.g. 'aaa'): you will get a 308 with the proper sha1, that you can keep afterwards (this is what I do)

Also, another option is to not use the API to deploy new versions of the templates, but to bundle docker images that contain RosaeNLG and its templates, using CI/CD, as (somewhat) described here: https://rosaenlg.org/rosaenlg/3.0.1/dev_experience.html#_deploy_to_use_as_an_api

@oytuntez
Copy link
Author

oytuntez commented Aug 5, 2021 via email

@oytuntez
Copy link
Author

oytuntez commented Aug 5, 2021 via email

@ludans
Copy link
Contributor

ludans commented Aug 5, 2021

Render without sha1 would:

  • load the template if it is not in the cache yet
  • or render whatever it has in its cache (considering its cache is always good)

I would be happy to have a PR with it. Please

  • add test cases :)
  • add documentation :)

For your target, you say:
We will probably upload the templates to the server (single node, no cluster) and reload its cache.
I would rather use the API endpoint that does all the job: The template is validated, loaded, autotested (if configured so), and saved on disk or S3 if persistent storage is set.

@oytuntez
Copy link
Author

oytuntez commented Aug 5, 2021 via email

@reinoldus
Copy link

For people trying to get docker deployment done in one CI step:

If you used the "yo" template as given in the docs, you should be able to use this Dockerfile to get pre-compiled templates working in your docker container:

FROM rosaenlg/server:3.2.0
COPY package.json /
COPY package-lock.json /
RUN npm i
COPY ./ /
RUN npx gulp package

FROM rosaenlg/server:3.2.0
ENV ROSAENLG_HOMEDIR=/templates
RUN mkdir /templates
COPY --from=0 /dist/ ./templates/
RUN cd /templates && for i in *.json; do mv $i "DEFAULT_USER#$i";done && cd -

It uses a multi stage docker build. First stage, we copy the local "yo" project and run the steps as described in the docs via gulp package.

Second step: Copy the files from the first stage into the final stage in the "/templates" directory.
The server then should start with the compile messages.

All templates then can be accessed using a "random" sha1 hash.

@ludans ludans mentioned this issue Mar 15, 2022
10 tasks
@ludans
Copy link
Contributor

ludans commented Mar 15, 2022

Thanks @reinoldus for this docker recipe. I have added this in the documentation, PR is #118 .
It will be included in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants