Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func newRunCommand() *runCommand {
runCommand.cmd.Flags().IntVar(&globalConfig.HttpPort, "http-port", getEnvInt("HTTP_PORT", server.DefaultHttpPort), "Port to serve HTTP traffic on")
runCommand.cmd.Flags().IntVar(&globalConfig.HttpsPort, "https-port", getEnvInt("HTTPS_PORT", server.DefaultHttpsPort), "Port to serve HTTPS traffic on")
runCommand.cmd.Flags().IntVar(&globalConfig.MetricsPort, "metrics-port", getEnvInt("METRICS_PORT", 0), "Publish metrics on the specified port (default zero to disable)")
runCommand.cmd.Flags().BoolVar(&globalConfig.MetricsHttps, "metrics-https", getEnvBool("METRICS_HTTPS", false), "Enable HTTPS for the metrics port (default false for HTTP)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small thing, but I think we could refer to this as METRICS_TLS. That's really the layer we're adding here, and it's how we refer to this when deploying services as well.

I agree with your thoughts that we don't need two ports here; just being able to switch on or off TLS seems sufficient.


return runCommand
}
Expand Down
10 changes: 5 additions & 5 deletions internal/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const (
)

type Config struct {
Bind string
HttpPort int
HttpsPort int
MetricsPort int

Bind string
HttpPort int
HttpsPort int
MetricsPort int
MetricsHttps bool
AlternateConfigDir string
}

Expand Down
13 changes: 10 additions & 3 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,17 @@ func (s *Server) startMetricsServer() error {
Addr: addr,
Handler: handler,
}
if s.config.MetricsHttps {
s.metricsServer.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS13,
GetCertificate: s.router.GetCertificate,
}
go s.metricsServer.ServeTLS(s.metricsListener, "", "")
} else {
go s.metricsServer.Serve(s.metricsListener)
}

go s.metricsServer.Serve(s.metricsListener)

slog.Info("Metrics enabled", "address", addr)
slog.Info("Metrics enabled", "port", s.config.MetricsPort, "https", s.config.MetricsHttps)

return nil
}
Expand Down