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

Make API nginx log once per request #3163

Merged
merged 1 commit into from
Oct 18, 2023
Merged

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Oct 7, 2023

Fixes

Fixes #3126 by @obulat

Description

While reviewing #3108, I found a way to make Nginx log only once, using the json style described in the nginx.conf.template, to the frontend nginx container.
This PR adds the same changes to the API nginx container.

Testing Instructions

Rebuild the api and nginx containers (use just recreate, or delete the openverse-nginx image using a GUI and run just up), and access the API through the nginx proxy: http://0.0.0.0:50270/v1/images/?q=cat

Check the nginx container (image name is openverse-nginx) logs: there should only be one json formatted log per request, and not two logs per request as described in the issue.
Here's the logs I saw after opening the api home page and then searching for "cat" images:

{"time_local":"11/Oct/2023:15:53:14 +0000","remote_addr":"192.168.247.1","remote_user":"","request":"GET /v1/ HTTP/1.1","status": "200","host_header": "0.0.0.0","body_bytes_sent":576,"request_time":"0.016","http_referrer":"","http_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36","upstream_response_time":0.016,"http_x_forwarded_for":""}
{"time_local":"11/Oct/2023:15:53:14 +0000","remote_addr":"192.168.247.1","remote_user":"","request":"GET /v1/schema/ HTTP/1.1","status": "200","host_header": "0.0.0.0","body_bytes_sent":84591,"request_time":"0.112","http_referrer":"http://0.0.0.0:50270/v1/","http_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36","upstream_response_time":0.112,"http_x_forwarded_for":""}
{"time_local":"11/Oct/2023:15:53:18 +0000","remote_addr":"192.168.247.1","remote_user":"","request":"GET /v1/images/?q=cat HTTP/1.1","status": "200","host_header": "0.0.0.0","body_bytes_sent":8561,"request_time":"0.486","http_referrer":"","http_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36","upstream_response_time":0.486,"http_x_forwarded_for":""}

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@obulat obulat requested a review from a team as a code owner October 7, 2023 11:29
@github-actions github-actions bot added the 🧱 stack: api Related to the Django API label Oct 7, 2023
@obulat obulat self-assigned this Oct 7, 2023
@obulat obulat added 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository labels Oct 7, 2023
@obulat obulat changed the title Make access_log log once per request Make API nginx log once per request Oct 7, 2023
@obulat obulat added the 🟨 priority: medium Not blocking but should be addressed soon label Oct 7, 2023
Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

Cool!

Copy link
Member

@krysal krysal left a comment

Choose a reason for hiding this comment

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

Perhaps I'm missing some steps, are those the full instructions? I remember some slightly different steps to test nginx locally but I can't find them exactly.

Also, I notice now there are two Nginx services under the api profile, proxy and nginx, are both serving the same/similar goals? Can't they be combined?

I'm requesting changes for clarification on how to test this and responses. The questions go to @sarayourfriend and @dhruvkb too in case you know, given you have worked more closely with these services.

api/nginx.conf.template Show resolved Hide resolved
@obulat obulat force-pushed the remove_duplicate_api_logging branch from 8fab39d to 5f0d683 Compare October 11, 2023 15:59
@sarayourfriend
Copy link
Collaborator

The "proxy" container is leftover for SSL testing locally. Its presence continues to be confusing to lots of people, and @dhruvkb and I have talked about getting rid of it: I don't know if there's an issue though. @dhruvkb do you remember/can you create an issue with whatever we decided, if you remember that?

@obulat obulat requested a review from krysal October 13, 2023 04:27
@obulat obulat force-pushed the remove_duplicate_api_logging branch from 5f0d683 to 7c9a2d0 Compare October 13, 2023 04:27
@openverse-bot
Copy link
Collaborator

Based on the medium urgency of this PR, the following reviewers are being gently reminded to review this PR:

@krysal
@dhruvkb
This reminder is being automatically generated due to the urgency configuration.

Excluding weekend1 days, this PR was ready for review 7 day(s) ago. PRs labelled with medium urgency are expected to be reviewed within 4 weekday(s)2.

@obulat, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings.

Footnotes

  1. Specifically, Saturday and Sunday.

  2. For the purpose of these reminders we treat Monday - Friday as weekdays. Please note that the operation that generates these reminders runs at midnight UTC on Monday - Friday. This means that depending on your timezone, you may be pinged outside of the expected range.

@obulat obulat force-pushed the remove_duplicate_api_logging branch from 7c9a2d0 to 0a8ea69 Compare October 18, 2023 07:25
api/nginx.conf.template Show resolved Hide resolved
@obulat obulat merged commit 4d9676e into main Oct 18, 2023
44 checks passed
@obulat obulat deleted the remove_duplicate_api_logging branch October 18, 2023 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: api Related to the Django API
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Duplicated API access logs
4 participants