Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
316da705
Unverified
Commit
316da705
authored
4 years ago
by
Mark Sagi-Kazar
Browse files
Options
Downloads
Patches
Plain Diff
refactor: use new health checker
Signed-off-by:
Mark Sagi-Kazar
<
mark.sagikazar@gmail.com
>
parent
d77147f7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/dex/serve.go
+3
-1
3 additions, 1 deletion
cmd/dex/serve.go
server/handlers_test.go
+14
-9
14 additions, 9 deletions
server/handlers_test.go
server/server.go
+10
-1
10 additions, 1 deletion
server/server.go
server/server_test.go
+2
-0
2 additions, 0 deletions
server/server_test.go
with
29 additions
and
11 deletions
cmd/dex/serve.go
+
3
−
1
View file @
316da705
...
@@ -275,6 +275,8 @@ func runServe(options serveOptions) error {
...
@@ -275,6 +275,8 @@ func runServe(options serveOptions) error {
// explicitly convert to UTC.
// explicitly convert to UTC.
now
:=
func
()
time
.
Time
{
return
time
.
Now
()
.
UTC
()
}
now
:=
func
()
time
.
Time
{
return
time
.
Now
()
.
UTC
()
}
healthChecker
:=
gosundheit
.
New
()
serverConfig
:=
server
.
Config
{
serverConfig
:=
server
.
Config
{
SupportedResponseTypes
:
c
.
OAuth2
.
ResponseTypes
,
SupportedResponseTypes
:
c
.
OAuth2
.
ResponseTypes
,
SkipApprovalScreen
:
c
.
OAuth2
.
SkipApprovalScreen
,
SkipApprovalScreen
:
c
.
OAuth2
.
SkipApprovalScreen
,
...
@@ -287,6 +289,7 @@ func runServe(options serveOptions) error {
...
@@ -287,6 +289,7 @@ func runServe(options serveOptions) error {
Logger
:
logger
,
Logger
:
logger
,
Now
:
now
,
Now
:
now
,
PrometheusRegistry
:
prometheusRegistry
,
PrometheusRegistry
:
prometheusRegistry
,
HealthChecker
:
healthChecker
,
}
}
if
c
.
Expiry
.
SigningKeys
!=
""
{
if
c
.
Expiry
.
SigningKeys
!=
""
{
signingKeys
,
err
:=
time
.
ParseDuration
(
c
.
Expiry
.
SigningKeys
)
signingKeys
,
err
:=
time
.
ParseDuration
(
c
.
Expiry
.
SigningKeys
)
...
@@ -329,7 +332,6 @@ func runServe(options serveOptions) error {
...
@@ -329,7 +332,6 @@ func runServe(options serveOptions) error {
telemetryRouter
.
Handle
(
"/metrics"
,
promhttp
.
HandlerFor
(
prometheusRegistry
,
promhttp
.
HandlerOpts
{}))
telemetryRouter
.
Handle
(
"/metrics"
,
promhttp
.
HandlerFor
(
prometheusRegistry
,
promhttp
.
HandlerOpts
{}))
// Configure health checker
// Configure health checker
healthChecker
:=
gosundheit
.
New
()
{
{
handler
:=
gosundheithttp
.
HandleHealthJSON
(
healthChecker
)
handler
:=
gosundheithttp
.
HandleHealthJSON
(
healthChecker
)
telemetryRouter
.
Handle
(
"/healthz"
,
handler
)
telemetryRouter
.
Handle
(
"/healthz"
,
handler
)
...
...
This diff is collapsed.
Click to expand it.
server/handlers_test.go
+
14
−
9
View file @
316da705
...
@@ -10,6 +10,8 @@ import (
...
@@ -10,6 +10,8 @@ import (
"testing"
"testing"
"time"
"time"
gosundheit
"github.com/AppsFlyer/go-sundheit"
"github.com/AppsFlyer/go-sundheit/checks"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/gorilla/mux"
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
...
@@ -33,20 +35,23 @@ func TestHandleHealth(t *testing.T) {
...
@@ -33,20 +35,23 @@ func TestHandleHealth(t *testing.T) {
}
}
}
}
type
badStorage
struct
{
storage
.
Storage
}
func
(
b
*
badStorage
)
CreateAuthRequest
(
r
storage
.
AuthRequest
)
error
{
return
errors
.
New
(
"storage unavailable"
)
}
func
TestHandleHealthFailure
(
t
*
testing
.
T
)
{
func
TestHandleHealthFailure
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
httpServer
,
server
:=
newTestServer
(
ctx
,
t
,
func
(
c
*
Config
)
{
httpServer
,
server
:=
newTestServer
(
ctx
,
t
,
func
(
c
*
Config
)
{
c
.
Storage
=
&
badStorage
{
c
.
Storage
}
c
.
HealthChecker
=
gosundheit
.
New
()
c
.
HealthChecker
.
RegisterCheck
(
&
gosundheit
.
Config
{
Check
:
&
checks
.
CustomCheck
{
CheckName
:
"fail"
,
CheckFunc
:
func
()
(
details
interface
{},
err
error
)
{
return
nil
,
errors
.
New
(
"error"
)
},
},
InitiallyPassing
:
false
,
ExecutionPeriod
:
1
*
time
.
Second
,
})
})
})
defer
httpServer
.
Close
()
defer
httpServer
.
Close
()
...
...
This diff is collapsed.
Click to expand it.
server/server.go
+
10
−
1
View file @
316da705
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"sync/atomic"
"sync/atomic"
"time"
"time"
gosundheit
"github.com/AppsFlyer/go-sundheit"
"github.com/felixge/httpsnoop"
"github.com/felixge/httpsnoop"
"github.com/gorilla/handlers"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/gorilla/mux"
...
@@ -93,6 +94,8 @@ type Config struct {
...
@@ -93,6 +94,8 @@ type Config struct {
Logger
log
.
Logger
Logger
log
.
Logger
PrometheusRegistry
*
prometheus
.
Registry
PrometheusRegistry
*
prometheus
.
Registry
HealthChecker
gosundheit
.
Health
}
}
// WebConfig holds the server's frontend templates and asset configuration.
// WebConfig holds the server's frontend templates and asset configuration.
...
@@ -333,7 +336,13 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
...
@@ -333,7 +336,13 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
// "authproxy" connector.
// "authproxy" connector.
handleFunc
(
"/callback/{connector}"
,
s
.
handleConnectorCallback
)
handleFunc
(
"/callback/{connector}"
,
s
.
handleConnectorCallback
)
handleFunc
(
"/approval"
,
s
.
handleApproval
)
handleFunc
(
"/approval"
,
s
.
handleApproval
)
handle
(
"/healthz"
,
s
.
newHealthChecker
(
ctx
))
handle
(
"/healthz"
,
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
!
c
.
HealthChecker
.
IsHealthy
()
{
s
.
renderError
(
r
,
w
,
http
.
StatusInternalServerError
,
"Health check failed."
)
return
}
fmt
.
Fprintf
(
w
,
"Health check passed"
)
}))
handlePrefix
(
"/static"
,
static
)
handlePrefix
(
"/static"
,
static
)
handlePrefix
(
"/theme"
,
theme
)
handlePrefix
(
"/theme"
,
theme
)
s
.
mux
=
r
s
.
mux
=
r
...
...
This diff is collapsed.
Click to expand it.
server/server_test.go
+
2
−
0
View file @
316da705
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"testing"
"testing"
"time"
"time"
gosundheit
"github.com/AppsFlyer/go-sundheit"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/kylelemons/godebug/pretty"
"github.com/kylelemons/godebug/pretty"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus"
...
@@ -96,6 +97,7 @@ func newTestServer(ctx context.Context, t *testing.T, updateConfig func(c *Confi
...
@@ -96,6 +97,7 @@ func newTestServer(ctx context.Context, t *testing.T, updateConfig func(c *Confi
},
},
Logger
:
logger
,
Logger
:
logger
,
PrometheusRegistry
:
prometheus
.
NewRegistry
(),
PrometheusRegistry
:
prometheus
.
NewRegistry
(),
HealthChecker
:
gosundheit
.
New
(),
}
}
if
updateConfig
!=
nil
{
if
updateConfig
!=
nil
{
updateConfig
(
&
config
)
updateConfig
(
&
config
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment