Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
5d998940
Commit
5d998940
authored
Oct 08, 2016
by
Matt Holt
Committed by
GitHub
Oct 08, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1165 from aishraj/master
Have milliseconds as the latency log time unit
parents
20a54d0e
733f622f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
caddyhttp/httpserver/replacer.go
caddyhttp/httpserver/replacer.go
+11
-0
caddyhttp/httpserver/replacer_test.go
caddyhttp/httpserver/replacer_test.go
+18
-0
No files found.
caddyhttp/httpserver/replacer.go
View file @
5d998940
...
@@ -286,11 +286,22 @@ func (r *replacer) getSubstitution(key string) string {
...
@@ -286,11 +286,22 @@ func (r *replacer) getSubstitution(key string) string {
return
r
.
emptyValue
return
r
.
emptyValue
}
}
return
roundDuration
(
time
.
Since
(
r
.
responseRecorder
.
start
))
.
String
()
return
roundDuration
(
time
.
Since
(
r
.
responseRecorder
.
start
))
.
String
()
case
"{latency_ms}"
:
if
r
.
responseRecorder
==
nil
{
return
r
.
emptyValue
}
elapsedDuration
:=
time
.
Since
(
r
.
responseRecorder
.
start
)
return
strconv
.
FormatInt
(
convertToMilliseconds
(
elapsedDuration
),
10
)
}
}
return
r
.
emptyValue
return
r
.
emptyValue
}
}
//convertToMilliseconds returns the number of milliseconds in the given duration
func
convertToMilliseconds
(
d
time
.
Duration
)
int64
{
return
d
.
Nanoseconds
()
/
1e6
}
// Set sets key to value in the r.customReplacements map.
// Set sets key to value in the r.customReplacements map.
func
(
r
*
replacer
)
Set
(
key
,
value
string
)
{
func
(
r
*
replacer
)
Set
(
key
,
value
string
)
{
r
.
customReplacements
[
"{"
+
key
+
"}"
]
=
value
r
.
customReplacements
[
"{"
+
key
+
"}"
]
=
value
...
...
caddyhttp/httpserver/replacer_test.go
View file @
5d998940
...
@@ -150,3 +150,21 @@ func TestRound(t *testing.T) {
...
@@ -150,3 +150,21 @@ func TestRound(t *testing.T) {
}
}
}
}
}
}
func
TestMillisecondConverstion
(
t
*
testing
.
T
)
{
var
testCases
=
map
[
time
.
Duration
]
int64
{
2
*
time
.
Second
:
2000
,
9039492
*
time
.
Nanosecond
:
9
,
1000
*
time
.
Microsecond
:
1
,
127
*
time
.
Nanosecond
:
0
,
0
*
time
.
Millisecond
:
0
,
255
*
time
.
Millisecond
:
255
,
}
for
dur
,
expected
:=
range
testCases
{
numMillisecond
:=
convertToMilliseconds
(
dur
)
if
numMillisecond
!=
expected
{
t
.
Errorf
(
"Expected %v. Got %v"
,
expected
,
numMillisecond
)
}
}
}
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