Skip to content

Commit

Permalink
Merge branch 'main' into init-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
lindnerby authored Dec 15, 2023
2 parents ebbe460 + e6acc2f commit 565643f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion runtime-watcher/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/go-logr/logr v1.3.0
github.com/google/uuid v1.4.0
github.com/google/uuid v1.5.0
github.com/kyma-project/runtime-watcher/listener v0.0.0-20231011102033-b8383d92883e
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/gomega v1.30.0
Expand Down
4 changes: 2 additions & 2 deletions runtime-watcher/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20230222194610-99052d3372e7 h1:pNFnpaSXfibgW7aUbk9pwLmI7LNwh/iR46x/YwN/lNg=
github.com/google/pprof v0.0.0-20230222194610-99052d3372e7/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
35 changes: 26 additions & 9 deletions runtime-watcher/internal/serverconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ import (
)

const (
minPort, maxPort = 1, 65535
defaultPort = 8443
envWebhookPort = "WEBHOOK_PORT"
envCACert = "CA_CERT"
envTLSCert = "TLS_CERT"
envTLSKey = "TLS_KEY"
envKCPAddress = "KCP_ADDR"
envKCPContract = "KCP_CONTRACT"
minPort, maxPort = 1, 65535
defaultWebhookPort = 8443
defaultMetricsPort = 2112
envWebhookPort = "WEBHOOK_PORT"
envMetricsPort = "METRICS_PORT"
envCACert = "CA_CERT"
envTLSCert = "TLS_CERT"
envTLSKey = "TLS_KEY"
envKCPAddress = "KCP_ADDR"
envKCPContract = "KCP_CONTRACT"
)

type ServerConfig struct {
Port int
MetricsPort int
CACertPath string
TLSCertPath string
TLSKeyPath string
Expand All @@ -34,7 +37,7 @@ func ParseFromEnv(logger logr.Logger) (ServerConfig, error) {

config := ServerConfig{}

config.Port = defaultPort
config.Port = defaultWebhookPort
webhookPort, found := os.LookupEnv(envWebhookPort)
if found {
port, err := strconv.Atoi(webhookPort)
Expand All @@ -48,6 +51,20 @@ func ParseFromEnv(logger logr.Logger) (ServerConfig, error) {
}
}

config.MetricsPort = defaultMetricsPort
metricsPort, found := os.LookupEnv(envMetricsPort)
if found {
port, err := strconv.Atoi(metricsPort)
if err != nil {
logger.Error(err, flagError(envMetricsPort).Error())
}
if err = validatePortRange(port); err != nil {
logger.Error(err, flagError(envMetricsPort).Error())
} else {
config.MetricsPort = port
}
}

config.CACertPath = os.Getenv(envCACert)
if config.CACertPath == "" {
return config, flagError(envCACert)
Expand Down
10 changes: 10 additions & 0 deletions runtime-watcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ func main() {
return
}

http.Handle("/metrics", promhttp.Handler())
metricsServer := &http.Server{
Addr: fmt.Sprintf(":%d", config.MetricsPort),
ReadHeaderTimeout: internal.HTTPTimeout,
}
err = metricsServer.ListenAndServe()
if err != nil {
logger.Error(err, "failed to wire up metrics endpoint")
}

restConfig := ctrl.GetConfigOrDie()
restClient, err := client.New(restConfig, client.Options{})
if err != nil {
Expand Down

0 comments on commit 565643f

Please sign in to comment.