Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b61a8fbb
Commit
b61a8fbb
authored
Nov 12, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16271 from jayunit100/hammer-backoff-metrics-part1
Auto commit by PR queue bot
parents
3080e7b3
072980af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
8 deletions
+36
-8
metrics.go
pkg/client/metrics/metrics.go
+10
-0
request.go
pkg/client/unversioned/request.go
+26
-8
No files found.
pkg/client/metrics/metrics.go
View file @
b61a8fbb
...
@@ -38,6 +38,15 @@ var (
...
@@ -38,6 +38,15 @@ var (
},
},
[]
string
{
"verb"
,
"url"
},
[]
string
{
"verb"
,
"url"
},
)
)
RequestResult
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Subsystem
:
restClientSubsystem
,
Name
:
"request_status_codes"
,
Help
:
"Number of http requests, partitioned by metadata"
,
},
[]
string
{
"code"
,
"method"
,
"host"
},
)
)
)
var
registerMetrics
sync
.
Once
var
registerMetrics
sync
.
Once
...
@@ -48,6 +57,7 @@ func Register() {
...
@@ -48,6 +57,7 @@ func Register() {
// Register the metrics.
// Register the metrics.
registerMetrics
.
Do
(
func
()
{
registerMetrics
.
Do
(
func
()
{
prometheus
.
MustRegister
(
RequestLatency
)
prometheus
.
MustRegister
(
RequestLatency
)
prometheus
.
MustRegister
(
RequestResult
)
})
})
}
}
...
...
pkg/client/unversioned/request.go
View file @
b61a8fbb
...
@@ -586,6 +586,7 @@ func (r *Request) Watch() (watch.Interface, error) {
...
@@ -586,6 +586,7 @@ func (r *Request) Watch() (watch.Interface, error) {
client
=
http
.
DefaultClient
client
=
http
.
DefaultClient
}
}
resp
,
err
:=
client
.
Do
(
req
)
resp
,
err
:=
client
.
Do
(
req
)
updateURLMetrics
(
r
,
resp
,
err
)
if
err
!=
nil
{
if
err
!=
nil
{
// The watch stream mechanism handles many common partial data errors, so closed
// The watch stream mechanism handles many common partial data errors, so closed
// connections can be retried in many cases.
// connections can be retried in many cases.
...
@@ -603,6 +604,23 @@ func (r *Request) Watch() (watch.Interface, error) {
...
@@ -603,6 +604,23 @@ func (r *Request) Watch() (watch.Interface, error) {
return
watch
.
NewStreamWatcher
(
watchjson
.
NewDecoder
(
resp
.
Body
,
r
.
codec
)),
nil
return
watch
.
NewStreamWatcher
(
watchjson
.
NewDecoder
(
resp
.
Body
,
r
.
codec
)),
nil
}
}
// updateURLMetrics is a convenience function for pushing metrics.
// It also handles corner cases for incomplete/invalid request data.
func
updateURLMetrics
(
req
*
Request
,
resp
*
http
.
Response
,
err
error
)
{
url
:=
"none"
if
req
.
baseURL
!=
nil
{
url
=
req
.
baseURL
.
Host
}
// If we have an error (i.e. apiserver down) we report that as a metric label.
if
err
!=
nil
{
metrics
.
RequestResult
.
WithLabelValues
(
err
.
Error
(),
req
.
verb
,
url
)
.
Inc
()
}
else
{
//Metrics for failure codes
metrics
.
RequestResult
.
WithLabelValues
(
strconv
.
Itoa
(
resp
.
StatusCode
),
req
.
verb
,
url
)
.
Inc
()
}
}
// Stream formats and executes the request, and offers streaming of the response.
// Stream formats and executes the request, and offers streaming of the response.
// Returns io.ReadCloser which could be used for streaming of the response, or an error
// Returns io.ReadCloser which could be used for streaming of the response, or an error
// Any non-2xx http status code causes an error. If we get a non-2xx code, we try to convert the body into an APIStatus object.
// Any non-2xx http status code causes an error. If we get a non-2xx code, we try to convert the body into an APIStatus object.
...
@@ -621,6 +639,7 @@ func (r *Request) Stream() (io.ReadCloser, error) {
...
@@ -621,6 +639,7 @@ func (r *Request) Stream() (io.ReadCloser, error) {
client
=
http
.
DefaultClient
client
=
http
.
DefaultClient
}
}
resp
,
err
:=
client
.
Do
(
req
)
resp
,
err
:=
client
.
Do
(
req
)
updateURLMetrics
(
r
,
resp
,
err
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -657,6 +676,12 @@ func (r *Request) Stream() (io.ReadCloser, error) {
...
@@ -657,6 +676,12 @@ func (r *Request) Stream() (io.ReadCloser, error) {
// fn at most once. It will return an error if a problem occurred prior to connecting to the
// fn at most once. It will return an error if a problem occurred prior to connecting to the
// server - the provided function is responsible for handling server errors.
// server - the provided function is responsible for handling server errors.
func
(
r
*
Request
)
request
(
fn
func
(
*
http
.
Request
,
*
http
.
Response
))
error
{
func
(
r
*
Request
)
request
(
fn
func
(
*
http
.
Request
,
*
http
.
Response
))
error
{
//Metrics for total request latency
start
:=
time
.
Now
()
defer
func
()
{
metrics
.
RequestLatency
.
WithLabelValues
(
r
.
verb
,
r
.
finalURLTemplate
())
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
}()
if
r
.
err
!=
nil
{
if
r
.
err
!=
nil
{
return
r
.
err
return
r
.
err
}
}
...
@@ -687,6 +712,7 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
...
@@ -687,6 +712,7 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
req
.
Header
=
r
.
headers
req
.
Header
=
r
.
headers
resp
,
err
:=
client
.
Do
(
req
)
resp
,
err
:=
client
.
Do
(
req
)
updateURLMetrics
(
r
,
resp
,
err
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -720,10 +746,6 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
...
@@ -720,10 +746,6 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
// * If the server responds with a status: *errors.StatusError or *errors.UnexpectedObjectError
// * If the server responds with a status: *errors.StatusError or *errors.UnexpectedObjectError
// * http.Client.Do errors are returned directly.
// * http.Client.Do errors are returned directly.
func
(
r
*
Request
)
Do
()
Result
{
func
(
r
*
Request
)
Do
()
Result
{
start
:=
time
.
Now
()
defer
func
()
{
metrics
.
RequestLatency
.
WithLabelValues
(
r
.
verb
,
r
.
finalURLTemplate
())
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
}()
var
result
Result
var
result
Result
err
:=
r
.
request
(
func
(
req
*
http
.
Request
,
resp
*
http
.
Response
)
{
err
:=
r
.
request
(
func
(
req
*
http
.
Request
,
resp
*
http
.
Response
)
{
result
=
r
.
transformResponse
(
resp
,
req
)
result
=
r
.
transformResponse
(
resp
,
req
)
...
@@ -736,10 +758,6 @@ func (r *Request) Do() Result {
...
@@ -736,10 +758,6 @@ func (r *Request) Do() Result {
// DoRaw executes the request but does not process the response body.
// DoRaw executes the request but does not process the response body.
func
(
r
*
Request
)
DoRaw
()
([]
byte
,
error
)
{
func
(
r
*
Request
)
DoRaw
()
([]
byte
,
error
)
{
start
:=
time
.
Now
()
defer
func
()
{
metrics
.
RequestLatency
.
WithLabelValues
(
r
.
verb
,
r
.
finalURLTemplate
())
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
}()
var
result
Result
var
result
Result
err
:=
r
.
request
(
func
(
req
*
http
.
Request
,
resp
*
http
.
Response
)
{
err
:=
r
.
request
(
func
(
req
*
http
.
Request
,
resp
*
http
.
Response
)
{
result
.
body
,
result
.
err
=
ioutil
.
ReadAll
(
resp
.
Body
)
result
.
body
,
result
.
err
=
ioutil
.
ReadAll
(
resp
.
Body
)
...
...
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