Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
e873a31b
Commit
e873a31b
authored
Oct 04, 2016
by
Eric Chiang
Committed by
Eric Chiang
Oct 05, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
server: add health check endpoint
parent
3681a57a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
handlers.go
server/handlers.go
+30
-0
server.go
server/server.go
+1
-0
No files found.
server/handlers.go
View file @
e873a31b
...
...
@@ -20,6 +20,36 @@ import (
"github.com/coreos/dex/storage"
)
func
(
s
*
Server
)
handleHealth
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
start
:=
s
.
now
()
err
:=
func
()
error
{
// Instead of trying to introspect health, just try to use the underlying storage.
a
:=
storage
.
AuthRequest
{
ID
:
storage
.
NewID
(),
ClientID
:
storage
.
NewID
(),
// Set a short expiry so if the delete fails this will be cleaned up quickly by garbage collection.
Expiry
:
s
.
now
()
.
Add
(
time
.
Minute
),
}
if
err
:=
s
.
storage
.
CreateAuthRequest
(
a
);
err
!=
nil
{
return
fmt
.
Errorf
(
"create auth request: %v"
,
err
)
}
if
err
:=
s
.
storage
.
DeleteAuthRequest
(
a
.
ID
);
err
!=
nil
{
return
fmt
.
Errorf
(
"delete auth request: %v"
,
err
)
}
return
nil
}()
t
:=
s
.
now
()
.
Sub
(
start
)
if
err
!=
nil
{
log
.
Printf
(
"Storage health check failed: %v"
,
err
)
http
.
Error
(
w
,
"Health check failed"
,
http
.
StatusInternalServerError
)
return
}
fmt
.
Fprintf
(
w
,
"Health check passed in %s"
,
t
)
}
func
(
s
*
Server
)
handlePublicKeys
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
// TODO(ericchiang): Cache this.
keys
,
err
:=
s
.
storage
.
GetKeys
()
...
...
server/server.go
View file @
e873a31b
...
...
@@ -159,6 +159,7 @@ func newServer(c Config, rotationStrategy rotationStrategy) (*Server, error) {
handleFunc
(
"/auth/{connector}"
,
s
.
handleConnectorLogin
)
handleFunc
(
"/callback/{connector}"
,
s
.
handleConnectorCallback
)
handleFunc
(
"/approval"
,
s
.
handleApproval
)
handleFunc
(
"/healthz"
,
s
.
handleHealth
)
s
.
mux
=
r
return
s
,
nil
...
...
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