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

Debug api "502 Bad Gateway" issue #5184

Closed
5 tasks
fec-jli opened this issue Jun 30, 2022 · 8 comments
Closed
5 tasks

Debug api "502 Bad Gateway" issue #5184

fec-jli opened this issue Jun 30, 2022 · 8 comments

Comments

@fec-jli
Copy link
Contributor

fec-jli commented Jun 30, 2022

What we’re after

Recently, some api users report get the following error frequently :
"502 Bad Gateway: Registered endpoint failed to handle the request." when per_page > some number (like 100, 80.. on a couple of endpoints)

From user 1 's email:

Unsure as to what may be causing the error, but I continue to receive a 502 error when running the below request:
https://api.open.fec.gov/v1/committee/C00075820/reports/?sort_hide_null=false&per_page=100&api_key=DEMO_KEY&page=1&sort=-coverage_end_date&sort_null_only=false&sort_nulls_last=false
Result: 502 Bad Gateway: Registered endpoint failed to handle the request.

However, if I change the results per page to anything 50 and below, the request is successful.
 
https://api.open.fec.gov/v1/committee/C00075820/reports/?sort_hide_null=false&per_page=50&api_key=DEMO_KEY&page=1&sort=-coverage_end_date&sort_null_only=false&sort_nulls_last=false
 
This is the case for only this committee. I have run five other party committee reports and have been able to use 100 results per page. 

From user 2 's email:

here's a URL that gave the "502 Bad Gateway" issue while I was scraping Disbursement data for the 2002 election cycle.

https://api.open.fec.gov/v1/schedules/schedule_b/?sort_null_only=false&api_key=DEMO_KEY&sort_hide_null=false&two_year_transaction_period=2002&per_page=100&sort=-disbursement_date&last_index=3062020110010618030&last_disbursement_date=2001-02-27T00:00:00

There is no issue on local api env. (connect dev db)

Action item(s)

  • Identify the root cause of this issue
  • Fix the "502 Bad Gateway" issue

Completion criteria

  • We know what caused the 502s
    and
  • the queries in this ticket no longer throw a 502, or
  • we have created ticket(s) to fix it
@fec-jli
Copy link
Contributor Author

fec-jli commented Jun 30, 2022

@fec-jli fec-jli self-assigned this Jul 6, 2022
@pkfec
Copy link
Contributor

pkfec commented Jul 14, 2022

Quick summary of the things observed on Stage space:

  1. Tried increasing the API app instances to 4
  2. Tested committee/<committee_id>/reports and /schedules/schedule_b/ on Stage space by changing the per_page ranges from 80-100. The endpoints returned results until we EXCEEDED the DEMO_KEY rate limits.
  3. Will monitor and do more testing tomorrow
  4. We have to revisit the logic to scale the gevent workers.
  5. Or scale up the api app instances

@patphongs patphongs removed this from the Sprint 19.1 milestone Aug 10, 2022
@JonellaCulmer JonellaCulmer added this to the Sprint 19.1 milestone Aug 11, 2022
@fec-jli fec-jli modified the milestones: Sprint 19.2, Sprint 19.3 Sep 19, 2022
@patphongs patphongs modified the milestones: Sprint 19.3, Sprint 19.4 Sep 28, 2022
@fec-jli
Copy link
Contributor Author

fec-jli commented Oct 6, 2022

@fec-jli fec-jli removed their assignment Oct 18, 2022
@fec-jli fec-jli modified the milestones: Sprint 19.4, Sprint 19.5 Oct 18, 2022
@dzhang-fec
Copy link
Contributor

dzhang-fec commented Oct 20, 2022

Summary: The above 502 error issue are on multiple links. There were reported by multiple clients. We need to find a way for the coming elections. We can duplicate it
Root Reason Analysis: The browser has the limit of a web page which is around 250KB if it is not HTML content (similar on all of browsers). It is not a high loading issue, not a database query performance issue, not app python issue (unless we change the one line JSON data format code to display it with html. or multiple JSON lines)

workaround: to use curl or wget to get the large >250-350KB content. Actually, it is better for the client to automate it with a script/command line to parse the JSON format automatically. (Our API is not for users to view data from browser :) but use scripts)

Please review analysis details, workaround code and demo here; #5184 (comment)
Problem:
image
Analysis
I use curl/wget can get the result successfully and quickly
Here is the page_size
-rw-r--r--. 1 oracle oinstall 507559 Oct 20 11:28 100.txt (no way from the browser)
-rw-r--r--. 1 oracle oinstall 456644 Oct 20 11:29 90.txt (no way from the browser)
-rw-r--r--. 1 oracle oinstall 405903 Oct 20 11:30 80.txt (no way from the browser)
-rw-r--r--. 1 oracle oinstall 354925 Oct 20 11:30 70.txt (no way from the browser or sometimes)
-rw-r--r--. 1 oracle oinstall 304284 Oct 20 11:30 60.txt (no way from the browser or sometimes)
-rw-r--r--. 1 oracle oinstall 254006 Oct 20 11:30 50.txt ---browser ok
-rw-r--r--. 1 oracle oinstall 507559 Oct 20 11:36 100curl.txt (no way from the browser)

--the best is to use curl sample code
curl "https://api.open.fec.gov/v1/committee/C00075820/reports/?sort_hide_null=false&per_page=100&api_key=DEMO_KEY&page=1&sort=-coverage_end_date&sort_null_only=false&sort_nulls_last=false" >100curl.txt

or wget , sample code
wget "https://api.open.fec.gov/v1/committee/C00075820/reports/?sort_hide_null=false&per_page=100&api_key=DEMO_KEY&page=1&sort=-coverage_end_date&sort_null_only=false&sort_nulls_last=false" >100wget.txt

This works for Linux, MacOS or window users. samples
image
image
--one line result
image

Summary: use curl workaround.
(If we still want to use browser to do it, please consider to use html, zip, file download or multiple lines)

This was referenced Oct 26, 2022
@cnlucas
Copy link
Member

cnlucas commented Nov 1, 2022

Closing in favor of #5267

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants