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

add stats summary endpoint #2123

Merged
merged 16 commits into from
Feb 12, 2024
Merged

Conversation

0oM4R
Copy link
Contributor

@0oM4R 0oM4R commented Feb 5, 2024

Description

Using nginx javascript we can run a script whenever the user hit the target endpoint, the mentioned endpoint is /api/stats-summary, this will reduce code replication and make data consistent over different websites; threefold.io, dashboard
also we are caching the data for one day, if any errors happen while updating it, we are returning the outdated data with flag outdated if there is no cached data too or if any error happen while reading it, we return a dummy data,

Changes

  • DockerFile:
    • update the nginx version: njs require the latest nginx image
    • copy nginx files to the image
  • Nginx :
    • in nginx.conf I just loaded the needed js module and set the resolver:
      the actual changes on the default nginx.conf is :
      load_module modules/ngx_http_js_module.so;
      js_path "/etc/nginx/njs/";
      
      resolver 8.8.8.8;
      js_import main from stats.js;
      
    • add /summary endpoint to server in `default.conf
    • add njs script

Related Issues

Checklist

  • Tests included
  • Build pass
  • Documentation
  • Code format and docstrings
  • Screenshots/Video attached (needed for UI changes)

0oM4R added 2 commits February 4, 2024 18:47
- add njs scritp and its realted configurations
- update docker file
@0oM4R
Copy link
Contributor Author

0oM4R commented Feb 5, 2024

the verify option is disabled here as we don't have ssl cert for the image;
Screenshot from 2024-02-05 12-41-06

fetchPromises.push(ngx.fetch(urls[i], { method: "GET", verify: false }));

@MohamedElmdary
Copy link
Member

Do we need to implement retries 3 times and/or return back default values if it failed? @AhmedHanafy725

@MohamedElmdary
Copy link
Member

  1. Let's invest if this script is used as server or just fire whenever we call route ... in case it works as server we can implement a very simple in-memory cache (last for 1 day)

  2. Add 3 reties for request (better to call the failed urls only if possible)

@0oM4R 0oM4R marked this pull request as draft February 6, 2024 09:10
@0oM4R 0oM4R marked this pull request as ready for review February 7, 2024 14:48
@@ -8,5 +8,6 @@ COPY . /app/
RUN yarn install
RUN yarn lerna run build --no-private && yarn workspace @threefold/newstats build

FROM nginx:1.16.0-alpine
FROM nginx:alpine
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to have a certain version, so it does not get crashed because a new Alpine image is released.

@0oM4R 0oM4R requested a review from AhmedHanafy725 February 11, 2024 10:51
@AhmedHanafy725 AhmedHanafy725 merged commit 4259b69 into development Feb 12, 2024
3 checks passed
@AhmedHanafy725 AhmedHanafy725 deleted the development_statsSummary branch February 12, 2024 09:13
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