Skip to content

Commit

Permalink
fix(ROX-15587): expose metrics on different port to rest of server (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tommartensen authored Mar 12, 2024
1 parent 3e9a588 commit a0e9821
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions chart/infra-server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ spec:
ports:
- name: https
containerPort: 8443
- name: metrics
containerPort: 9101
imagePullPolicy: Always
volumeMounts:
- mountPath: /configuration
Expand Down
10 changes: 6 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ type AuthOidcConfig struct {
// ServerConfig represents the configuration used for running the HTTP & GRPC
// servers, and providing TLS.
type ServerConfig struct {
Port int `json:"port"`
CertFile string `json:"cert"`
KeyFile string `json:"key"`
StaticDir string `json:"static"`
Port int `json:"port"`
CertFile string `json:"cert"`
KeyFile string `json:"key"`
StaticDir string `json:"static"`
MetricsPort int `json:"metricsPort"`
MetricsIncludeHistogram bool `json:"metricsIncludeHistogram"`
}

// SlackConfig represents the configuration used for sending cluster lifecycle
Expand Down
24 changes: 21 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"

"github.com/prometheus/client_golang/prometheus/promhttp"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
Expand Down Expand Up @@ -84,7 +83,27 @@ func (s *server) RunServer() (<-chan error, error) {
apiSvc.RegisterServiceServer(server)
}

grpc_prometheus.Register(server)
// Metrics server
go func() {
listenAddress := fmt.Sprintf("0.0.0.0:%d", s.cfg.Server.MetricsPort)
log.Infow("starting metrics server", "listenAddress", listenAddress)

if s.cfg.Server.MetricsIncludeHistogram {
grpc_prometheus.EnableHandlingTimeHistogram()
}
grpc_prometheus.Register(server)

mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())

if err := http.ListenAndServeTLS(
listenAddress,
s.cfg.Server.CertFile, s.cfg.Server.KeyFile,
mux,
); err != nil {
errCh <- err
}
}()

// muxHandler is a HTTP handler that can route both HTTP/2 gRPC and HTTP1.1
// requests.
Expand Down Expand Up @@ -134,7 +153,6 @@ func (s *server) RunServer() (<-chan error, error) {
// login/logout/static, and also gRPC-Gateway routes.
routeMux.Handle("/", serveApplicationResources(s.cfg.Server.StaticDir, s.oidc))
routeMux.Handle("/v1/", gwMux)
routeMux.Handle("/metrics", promhttp.Handler())
s.oidc.Handle(routeMux)

mux.Handle("/",
Expand Down

0 comments on commit a0e9821

Please sign in to comment.