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

Return an HTTP 429 when we're over capacity #232

Merged
merged 6 commits into from
Nov 30, 2022
Merged

Return an HTTP 429 when we're over capacity #232

merged 6 commits into from
Nov 30, 2022

Conversation

thomshutt
Copy link
Contributor

Currently very crude, but protects us from being DOSed.

Future iterations will probably be

  1. Include job size and current completion % in the calculation
  2. Include machine resource availability (CPU, memory, network) in the calculation

@codecov
Copy link

codecov bot commented Nov 30, 2022

Codecov Report

Merging #232 (f1528e2) into main (c42c128) will increase coverage by 0.21792%.
The diff coverage is 64.70588%.

❗ Current head f1528e2 differs from pull request most recent head f65f399. Consider uploading reports for the commit f65f399 to get more accurate results

Impacted file tree graph

@@                 Coverage Diff                 @@
##                main        #232         +/-   ##
===================================================
+ Coverage   51.85364%   52.07156%   +0.21792%     
===================================================
  Files             32          33          +1     
  Lines           2077        2124         +47     
===================================================
+ Hits            1077        1106         +29     
- Misses           894         912         +18     
  Partials         106         106                 
Impacted Files Coverage Δ
pipeline/coordinator.go 72.34043% <0.00000%> (-5.52217%) ⬇️
cache/cache.go 67.74194% <20.00000%> (-23.56241%) ⬇️
api/http.go 67.21311% <100.00000%> (+18.49516%) ⬆️
middleware/capacity.go 100.00000% <100.00000%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c42c128...f65f399. Read the comment docs.

Impacted Files Coverage Δ
pipeline/coordinator.go 72.34043% <0.00000%> (-5.52217%) ⬇️
cache/cache.go 67.74194% <20.00000%> (-23.56241%) ⬇️
api/http.go 67.21311% <100.00000%> (+18.49516%) ⬆️
middleware/capacity.go 100.00000% <100.00000%> (ø)

Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

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

LGTM

middleware/capacity.go Outdated Show resolved Hide resolved
middleware/capacity.go Outdated Show resolved Hide resolved
pipeline/coordinator.go Outdated Show resolved Hide resolved
Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

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

Nice!

Comment on lines +43 to +49
coordinator.StartUploadJob(pipeline.UploadJobPayload{
RequestID: fmt.Sprintf("request-%d", x),
})
}

// Set up the HTTP handler
handler := HasCapacity(coordinator, next)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm I wonder how racy this is since the jobs run in background and the stub handlers return immediately. Does it pass consistently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I think because the stub handlers never trigger the Mist callbacks right? So the jobs stay in flight

Copy link
Member

Choose a reason for hiding this comment

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

Not sure actually. I think they may return an error which finishes the job and sends a callback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's the real handlers with mock clients instead

@thomshutt thomshutt merged commit f97f50f into main Nov 30, 2022
@thomshutt thomshutt deleted the capacity branch November 30, 2022 12:39
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.

2 participants