Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Prometheus metrics #1155

Merged
merged 2 commits into from
Dec 21, 2017
Merged

Add Prometheus metrics #1155

merged 2 commits into from
Dec 21, 2017

Conversation

brancz
Copy link
Contributor

@brancz brancz commented Dec 19, 2017

This adds the Prometheus part of #778.

@ericchiang @rithujohn191 @diegs

glide.yaml Outdated
@@ -1,36 +1,20 @@
# For detailed docs on how to add new dependencies or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these comments deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I ran glide I'm assuming

server/server.go Outdated
@@ -258,6 +260,7 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
handleFunc("/callback/{connector}", s.handleConnectorCallback)
handleFunc("/approval", s.handleApproval)
handleFunc("/healthz", s.handleHealth)
r.Handle("/metrics", promhttp.HandlerFor(prometheusRegistry, promhttp.HandlerOpts{}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to use handleFunc, which uses the correct relative paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, there are actually some low hanging fruit here, I'll also instrument the http handlers

server/server.go Outdated
@@ -137,14 +139,14 @@ type Server struct {
}

// NewServer constructs a server from the provided config.
func NewServer(ctx context.Context, c Config) (*Server, error) {
func NewServer(ctx context.Context, c Config, prometheusRegistry prometheus.Gatherer) (*Server, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prometheusRegistry should be part of Config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about this one, and didn't look into config too much, I felt it was just the unmarshaled config, but I'll gladly add it.

Copy link
Contributor

@diegs diegs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

cmd/dex/serve.go Outdated
@@ -14,6 +14,8 @@ import (
"time"

"github.com/ghodss/yaml"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no _ in go package alias

When renaming an imported package, the local name should follow the same guidelines as package names (lower case, no under_scores or mixedCaps).

https://blog.golang.org/package-names

@rphillips
Copy link

lgtm

cmd/dex/serve.go Outdated
grpcMetrics := grpcprometheus.NewServerMetrics()
err = prometheusRegistry.Register(grpcMetrics)
if err != nil {
return fmt.Errorf("failed to register process metrics: %v", err)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: failed to register gRPC server metrics?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed :) thanks for noticing

@ericchiang
Copy link
Contributor

Yay, I see metrics

$ curl http://localhost:5556/dex/metrics
# ...
go_memstats_mallocs_total 23587                     
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures.                       
# TYPE go_memstats_mcache_inuse_bytes gauge         
go_memstats_mcache_inuse_bytes 6944                 
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system.     
# TYPE go_memstats_mcache_sys_bytes gauge           
go_memstats_mcache_sys_bytes 16384                  
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures.                         
# TYPE go_memstats_mspan_inuse_bytes gauge          
go_memstats_mspan_inuse_bytes 39824                 
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system.       
# TYPE go_memstats_mspan_sys_bytes gauge            
go_memstats_mspan_sys_bytes 65536                   
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place.      
# TYPE go_memstats_next_gc_bytes gauge              
go_memstats_next_gc_bytes 4.194304e+06              
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations.                    
# TYPE go_memstats_other_sys_bytes gauge            
go_memstats_other_sys_bytes 1.286239e+06            
# HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator.                      
# TYPE go_memstats_stack_inuse_bytes gauge          
go_memstats_stack_inuse_bytes 491520                
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator.             
# TYPE go_memstats_stack_sys_bytes gauge            
go_memstats_stack_sys_bytes 491520                  
# HELP go_memstats_sys_bytes Number of bytes obtained from system.                                       
# TYPE go_memstats_sys_bytes gauge                  
go_memstats_sys_bytes 8.362232e+06                  
# HELP go_threads Number of OS threads created.     
# TYPE go_threads gauge                             
go_threads 9                                        
# HELP http_requests_total Count of all HTTP requests.                                                   
# TYPE http_requests_total counter                  
http_requests_total{code="200",handler="/metrics",method="GET"} 3                                        
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.                        
# TYPE process_cpu_seconds_total counter            
process_cpu_seconds_total 0.22                      
# HELP process_max_fds Maximum number of open file descriptors.                                          
# TYPE process_max_fds gauge                        
process_max_fds 1024                                
# HELP process_open_fds Number of open file descriptors.                                                 
# TYPE process_open_fds gauge                       
process_open_fds 8                                  
# HELP process_resident_memory_bytes Resident memory size in bytes.                                      
# TYPE process_resident_memory_bytes gauge          
process_resident_memory_bytes 1.6908288e+07         
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.                 
# TYPE process_start_time_seconds gauge             
process_start_time_seconds 1.51381900121e+09        
# HELP process_virtual_memory_bytes Virtual memory size in bytes.                                        
# TYPE process_virtual_memory_bytes gauge           
process_virtual_memory_bytes 5.60570368e+08    

server/server.go Outdated
@@ -258,6 +281,7 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
handleFunc("/callback/{connector}", s.handleConnectorCallback)
handleFunc("/approval", s.handleApproval)
handleFunc("/healthz", s.handleHealth)
handleFunc("/metrics", promhttp.HandlerFor(c.PrometheusRegistry, promhttp.HandlerOpts{}).ServeHTTP)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay that we're serving these at a public endpoint? Request to dex are unauthenticated. Should it be a separate listener?

Copy link
Contributor Author

@brancz brancz Dec 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. These metrics may be security sensitive, I'd say we at least put them on a separate listener, then we can segment by network, which should be enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me

Copy link
Contributor

@ericchiang ericchiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. thanks!

@ericchiang ericchiang merged commit 6ef8cd5 into dexidp:master Dec 21, 2017
@brancz brancz deleted the prometheus branch December 21, 2017 20:34
mmrath pushed a commit to mmrath/dex that referenced this pull request Sep 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants