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
0c4974a3
Commit
0c4974a3
authored
Oct 09, 2016
by
yuexiao-wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some logs and commend informations for healthz
Signed-off-by:
yuexiao-wang
<
wang.yuexiao@zte.com.cn
>
parent
853ee4c9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
healthz.go
pkg/healthz/healthz.go
+4
-4
healthz_test.go
pkg/healthz/healthz_test.go
+4
-4
No files found.
pkg/healthz/healthz.go
View file @
0c4974a3
...
@@ -23,7 +23,7 @@ import (
...
@@ -23,7 +23,7 @@ import (
"sync"
"sync"
)
)
// HealthzChecker is a named healthz check.
// HealthzChecker is a named healthz check
er
.
type
HealthzChecker
interface
{
type
HealthzChecker
interface
{
Name
()
string
Name
()
string
Check
(
req
*
http
.
Request
)
error
Check
(
req
*
http
.
Request
)
error
...
@@ -41,7 +41,7 @@ func DefaultHealthz(checks ...HealthzChecker) {
...
@@ -41,7 +41,7 @@ func DefaultHealthz(checks ...HealthzChecker) {
// PingHealthz returns true automatically when checked
// PingHealthz returns true automatically when checked
var
PingHealthz
HealthzChecker
=
ping
{}
var
PingHealthz
HealthzChecker
=
ping
{}
// ping implements the simplest possible health checker.
// ping implements the simplest possible health
z
checker.
type
ping
struct
{}
type
ping
struct
{}
func
(
ping
)
Name
()
string
{
func
(
ping
)
Name
()
string
{
...
@@ -53,7 +53,7 @@ func (ping) Check(_ *http.Request) error {
...
@@ -53,7 +53,7 @@ func (ping) Check(_ *http.Request) error {
return
nil
return
nil
}
}
// NamedCheck returns a health checker for the given name and function.
// NamedCheck returns a health
z
checker for the given name and function.
func
NamedCheck
(
name
string
,
check
func
(
r
*
http
.
Request
)
error
)
HealthzChecker
{
func
NamedCheck
(
name
string
,
check
func
(
r
*
http
.
Request
)
error
)
HealthzChecker
{
return
&
healthzCheck
{
name
,
check
}
return
&
healthzCheck
{
name
,
check
}
}
}
...
@@ -125,7 +125,7 @@ func adaptCheckToHandler(c func(r *http.Request) error) http.HandlerFunc {
...
@@ -125,7 +125,7 @@ func adaptCheckToHandler(c func(r *http.Request) error) http.HandlerFunc {
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
err
:=
c
(
r
)
err
:=
c
(
r
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"
I
nternal server error: %v"
,
err
),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
fmt
.
Sprintf
(
"
i
nternal server error: %v"
,
err
),
http
.
StatusInternalServerError
)
}
else
{
}
else
{
fmt
.
Fprint
(
w
,
"ok"
)
fmt
.
Fprint
(
w
,
"ok"
)
}
}
...
...
pkg/healthz/healthz_test.go
View file @
0c4974a3
...
@@ -29,15 +29,15 @@ func TestInstallHandler(t *testing.T) {
...
@@ -29,15 +29,15 @@ func TestInstallHandler(t *testing.T) {
InstallHandler
(
mux
)
InstallHandler
(
mux
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"http://example.com/healthz"
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"http://example.com/healthz"
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"
U
nexpected error: %v"
,
err
)
t
.
Fatalf
(
"
u
nexpected error: %v"
,
err
)
}
}
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
mux
.
ServeHTTP
(
w
,
req
)
mux
.
ServeHTTP
(
w
,
req
)
if
w
.
Code
!=
http
.
StatusOK
{
if
w
.
Code
!=
http
.
StatusOK
{
t
.
Errorf
(
"
E
xpected %v, got %v"
,
http
.
StatusOK
,
w
.
Code
)
t
.
Errorf
(
"
e
xpected %v, got %v"
,
http
.
StatusOK
,
w
.
Code
)
}
}
if
w
.
Body
.
String
()
!=
"ok"
{
if
w
.
Body
.
String
()
!=
"ok"
{
t
.
Errorf
(
"
E
xpected %v, got %v"
,
"ok"
,
w
.
Body
.
String
())
t
.
Errorf
(
"
e
xpected %v, got %v"
,
"ok"
,
w
.
Body
.
String
())
}
}
}
}
...
@@ -53,7 +53,7 @@ func TestMulitipleChecks(t *testing.T) {
...
@@ -53,7 +53,7 @@ func TestMulitipleChecks(t *testing.T) {
{
"/healthz"
,
"ok"
,
http
.
StatusOK
,
false
},
{
"/healthz"
,
"ok"
,
http
.
StatusOK
,
false
},
{
"/healthz?verbose"
,
"[+]ping ok
\n
[-]bad failed: this will fail
\n
healthz check failed
\n
"
,
http
.
StatusInternalServerError
,
true
},
{
"/healthz?verbose"
,
"[+]ping ok
\n
[-]bad failed: this will fail
\n
healthz check failed
\n
"
,
http
.
StatusInternalServerError
,
true
},
{
"/healthz/ping"
,
"ok"
,
http
.
StatusOK
,
true
},
{
"/healthz/ping"
,
"ok"
,
http
.
StatusOK
,
true
},
{
"/healthz/bad"
,
"
I
nternal server error: this will fail
\n
"
,
http
.
StatusInternalServerError
,
true
},
{
"/healthz/bad"
,
"
i
nternal server error: this will fail
\n
"
,
http
.
StatusInternalServerError
,
true
},
{
"/healthz"
,
"[+]ping ok
\n
[-]bad failed: this will fail
\n
healthz check failed
\n
"
,
http
.
StatusInternalServerError
,
true
},
{
"/healthz"
,
"[+]ping ok
\n
[-]bad failed: this will fail
\n
healthz check failed
\n
"
,
http
.
StatusInternalServerError
,
true
},
}
}
...
...
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