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
5f03479d
Unverified
Commit
5f03479d
authored
Dec 20, 2017
by
Frederic Branczyk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*: Add go runtime, process, HTTP and gRPC metrics
parent
b5baf6b1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
10 deletions
+81
-10
config.go
cmd/dex/config.go
+13
-7
serve.go
cmd/dex/serve.go
+38
-1
config-dev.yaml
examples/config-dev.yaml
+4
-0
server.go
server/server.go
+23
-1
server_test.go
server/server_test.go
+3
-1
No files found.
cmd/dex/config.go
View file @
5f03479d
...
...
@@ -19,13 +19,14 @@ import (
// Config is the config format for the main application.
type
Config
struct
{
Issuer
string
`json:"issuer"`
Storage
Storage
`json:"storage"`
Web
Web
`json:"web"`
OAuth2
OAuth2
`json:"oauth2"`
GRPC
GRPC
`json:"grpc"`
Expiry
Expiry
`json:"expiry"`
Logger
Logger
`json:"logger"`
Issuer
string
`json:"issuer"`
Storage
Storage
`json:"storage"`
Web
Web
`json:"web"`
Telemetry
Telemetry
`json:"telemetry"`
OAuth2
OAuth2
`json:"oauth2"`
GRPC
GRPC
`json:"grpc"`
Expiry
Expiry
`json:"expiry"`
Logger
Logger
`json:"logger"`
Frontend
server
.
WebConfig
`json:"frontend"`
...
...
@@ -104,6 +105,11 @@ type Web struct {
AllowedOrigins
[]
string
`json:"allowedOrigins"`
}
// Telemetry is the config format for telemetry including the HTTP server config.
type
Telemetry
struct
{
HTTP
string
`json:"http"`
}
// GRPC is the config for the gRPC API.
type
GRPC
struct
{
// The port to listen on.
...
...
cmd/dex/serve.go
View file @
5f03479d
...
...
@@ -14,6 +14,9 @@ import (
"time"
"github.com/ghodss/yaml"
grpcprometheus
"github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"google.golang.org/grpc"
...
...
@@ -93,7 +96,25 @@ func serve(cmd *cobra.Command, args []string) error {
logger
.
Infof
(
"config issuer: %s"
,
c
.
Issuer
)
prometheusRegistry
:=
prometheus
.
NewRegistry
()
err
=
prometheusRegistry
.
Register
(
prometheus
.
NewGoCollector
())
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to register Go runtime metrics: %v"
,
err
)
}
err
=
prometheusRegistry
.
Register
(
prometheus
.
NewProcessCollector
(
os
.
Getpid
(),
""
))
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to register process metrics: %v"
,
err
)
}
grpcMetrics
:=
grpcprometheus
.
NewServerMetrics
()
err
=
prometheusRegistry
.
Register
(
grpcMetrics
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to register gRPC server metrics: %v"
,
err
)
}
var
grpcOptions
[]
grpc
.
ServerOption
if
c
.
GRPC
.
TLSCert
!=
""
{
if
c
.
GRPC
.
TLSClientCA
!=
""
{
// Parse certificates from certificate file and key file for server.
...
...
@@ -117,7 +138,11 @@ func serve(cmd *cobra.Command, args []string) error {
ClientAuth
:
tls
.
RequireAndVerifyClientCert
,
ClientCAs
:
cPool
,
}
grpcOptions
=
append
(
grpcOptions
,
grpc
.
Creds
(
credentials
.
NewTLS
(
&
tlsConfig
)))
grpcOptions
=
append
(
grpcOptions
,
grpc
.
Creds
(
credentials
.
NewTLS
(
&
tlsConfig
)),
grpc
.
StreamInterceptor
(
grpcMetrics
.
StreamServerInterceptor
()),
grpc
.
UnaryInterceptor
(
grpcMetrics
.
UnaryServerInterceptor
()),
)
}
else
{
opt
,
err
:=
credentials
.
NewServerTLSFromFile
(
c
.
GRPC
.
TLSCert
,
c
.
GRPC
.
TLSKey
)
if
err
!=
nil
{
...
...
@@ -199,6 +224,7 @@ func serve(cmd *cobra.Command, args []string) error {
Web
:
c
.
Frontend
,
Logger
:
logger
,
Now
:
now
,
PrometheusRegistry
:
prometheusRegistry
,
}
if
c
.
Expiry
.
SigningKeys
!=
""
{
signingKeys
,
err
:=
time
.
ParseDuration
(
c
.
Expiry
.
SigningKeys
)
...
...
@@ -222,7 +248,17 @@ func serve(cmd *cobra.Command, args []string) error {
return
fmt
.
Errorf
(
"failed to initialize server: %v"
,
err
)
}
telemetryServ
:=
http
.
NewServeMux
()
telemetryServ
.
Handle
(
"/metrics"
,
promhttp
.
HandlerFor
(
prometheusRegistry
,
promhttp
.
HandlerOpts
{}))
errc
:=
make
(
chan
error
,
3
)
if
c
.
Telemetry
.
HTTP
!=
""
{
logger
.
Infof
(
"listening (http/telemetry) on %s"
,
c
.
Telemetry
.
HTTP
)
go
func
()
{
err
:=
http
.
ListenAndServe
(
c
.
Telemetry
.
HTTP
,
telemetryServ
)
errc
<-
fmt
.
Errorf
(
"listening on %s failed: %v"
,
c
.
Telemetry
.
HTTP
,
err
)
}()
}
if
c
.
Web
.
HTTP
!=
""
{
logger
.
Infof
(
"listening (http) on %s"
,
c
.
Web
.
HTTP
)
go
func
()
{
...
...
@@ -247,6 +283,7 @@ func serve(cmd *cobra.Command, args []string) error {
}
s
:=
grpc
.
NewServer
(
grpcOptions
...
)
api
.
RegisterDexServer
(
s
,
server
.
NewAPI
(
serverConfig
.
Storage
,
logger
))
grpcMetrics
.
InitializeMetrics
(
s
)
err
=
s
.
Serve
(
list
)
return
fmt
.
Errorf
(
"listening on %s failed: %v"
,
c
.
GRPC
.
Addr
,
err
)
}()
...
...
examples/config-dev.yaml
View file @
5f03479d
...
...
@@ -20,6 +20,10 @@ web:
# tlsCert: /etc/dex/tls.crt
# tlsKey: /etc/dex/tls.key
# Configuration for telemetry
telemetry
:
http
:
0.0.0.0:5558
# Uncomment this block to enable the gRPC API. This values MUST be different
# from the HTTP endpoints.
# grpc:
...
...
server/server.go
View file @
5f03479d
...
...
@@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"path"
"strconv"
"strings"
"sync"
"sync/atomic"
...
...
@@ -15,8 +16,10 @@ import (
"golang.org/x/crypto/bcrypt"
"github.com/felixge/httpsnoop"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"github.com/coreos/dex/connector"
...
...
@@ -75,6 +78,8 @@ type Config struct {
Web
WebConfig
Logger
logrus
.
FieldLogger
PrometheusRegistry
*
prometheus
.
Registry
}
// WebConfig holds the server's frontend templates and asset configuration.
...
...
@@ -214,9 +219,26 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
}
}
requestCounter
:=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"http_requests_total"
,
Help
:
"Count of all HTTP requests."
,
},
[]
string
{
"handler"
,
"code"
,
"method"
})
err
=
c
.
PrometheusRegistry
.
Register
(
requestCounter
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"server: Failed to register Prometheus HTTP metrics: %v"
,
err
)
}
instrumentHandlerCounter
:=
func
(
handlerName
string
,
handler
http
.
Handler
)
http
.
HandlerFunc
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
m
:=
httpsnoop
.
CaptureMetrics
(
handler
,
w
,
r
)
requestCounter
.
With
(
prometheus
.
Labels
{
"handler"
:
handlerName
,
"code"
:
strconv
.
Itoa
(
m
.
Code
),
"method"
:
r
.
Method
})
.
Inc
()
})
}
r
:=
mux
.
NewRouter
()
handleFunc
:=
func
(
p
string
,
h
http
.
HandlerFunc
)
{
r
.
HandleFunc
(
path
.
Join
(
issuerURL
.
Path
,
p
),
h
)
r
.
HandleFunc
(
path
.
Join
(
issuerURL
.
Path
,
p
),
instrumentHandlerCounter
(
p
,
h
)
)
}
handlePrefix
:=
func
(
p
string
,
h
http
.
Handler
)
{
prefix
:=
path
.
Join
(
issuerURL
.
Path
,
p
)
...
...
server/server_test.go
View file @
5f03479d
...
...
@@ -23,6 +23,7 @@ import (
oidc
"github.com/coreos/go-oidc"
"github.com/kylelemons/godebug/pretty"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/bcrypt"
"golang.org/x/oauth2"
...
...
@@ -92,7 +93,8 @@ func newTestServer(ctx context.Context, t *testing.T, updateConfig func(c *Confi
Web
:
WebConfig
{
Dir
:
filepath
.
Join
(
os
.
Getenv
(
"GOPATH"
),
"src/github.com/coreos/dex/web"
),
},
Logger
:
logger
,
Logger
:
logger
,
PrometheusRegistry
:
prometheus
.
NewRegistry
(),
}
if
updateConfig
!=
nil
{
updateConfig
(
&
config
)
...
...
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