Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
6ba41732
Commit
6ba41732
authored
Mar 01, 2021
by
Robert Czechowski
Browse files
Set different request duration thresholds to get better messages for long-taking requests
parent
d4c98bcb
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/webfw_iron.rs
View file @
6ba41732
...
...
@@ -137,6 +137,14 @@ impl AroundMiddleware for RequestTimeLogger {
use
std
::
time
::{
Duration
,
Instant
};
Box
::
new
(
move
|
req
:
&
mut
Request
|
->
IronResult
<
Response
>
{
// Set thresholds
let
(
threshold
,
threshold_critical
)
=
match
req
.url
.path
()
.iter
()
.next
()
{
Some
(
&
"save"
)
=>
(
Duration
::
from_millis
(
80
),
Duration
::
from_millis
(
120
)),
Some
(
&
"contest"
)
=>
(
Duration
::
from_millis
(
80
),
Duration
::
from_millis
(
120
)),
Some
(
&
"oauth"
)
=>
(
Duration
::
from_millis
(
800
),
Duration
::
from_millis
(
3200
)),
_
=>
(
Duration
::
from_millis
(
20
),
Duration
::
from_millis
(
80
)),
};
// Begin measurement
let
start
=
Instant
::
now
();
...
...
@@ -146,8 +154,9 @@ impl AroundMiddleware for RequestTimeLogger {
// End measurement
let
duration
=
start
.elapsed
();
let
threshold
=
Duration
::
from_millis
(
50
);
if
duration
>
threshold
{
if
duration
>
threshold_critical
{
println!
(
"Request took MUCH too long ({:?}) {}: {}"
,
duration
,
req
.method
,
req
.url
);
}
else
if
duration
>
threshold
{
println!
(
"Request took too long ({:?}) {}: {}"
,
duration
,
req
.method
,
req
.url
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment