From a6779a539f1a97556441f912af70be4240019865 Mon Sep 17 00:00:00 2001 From: louiseschmidtgen Date: Wed, 7 Aug 2024 19:00:54 +0200 Subject: [PATCH 1/3] update kine metrics --- cmd/root.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 152a1cce..bd3a08bd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -72,12 +72,20 @@ var ( } } + var metricsServer *http.Server + if rootCmdOpts.metrics { + metricsServer := &http.Server{ + Addr: rootCmdOpts.metricsAddress, + Handler: http.NewServeMux(), + } + metricsServer.Handler.(*http.ServeMux).Handle("/metrics", promhttp.Handler()) + go func() { logrus.WithField("address", rootCmdOpts.metricsAddress).Print("Enable metrics endpoint") - mux := http.NewServeMux() - mux.Handle("/metrics", promhttp.Handler()) - http.ListenAndServe(rootCmdOpts.metricsAddress, mux) + if err := metricsServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { + logrus.WithError(err).Fatal("Failed to start metrics endpoint") + } }() } @@ -130,6 +138,11 @@ var ( logrus.WithError(err).Warning("Failed to shutdown OpenTelemetry SDK") } } + if rootCmdOpts.metrics && metricsServer != nil { + if err := metricsServer.Shutdown(stopCtx); err != nil { + logrus.WithError(err).Fatal("Failed to shutdown metrics endpoint") + } + } }, } ) @@ -152,7 +165,7 @@ func init() { rootCmd.Flags().BoolVar(&rootCmdOpts.diskMode, "disk-mode", false, "(experimental) run dqlite store in disk mode") rootCmd.Flags().UintVar(&rootCmdOpts.clientSessionCacheSize, "tls-client-session-cache-size", 0, "ClientCacheSession size for dial TLS config") rootCmd.Flags().StringVar(&rootCmdOpts.minTLSVersion, "min-tls-version", "tls12", "Minimum TLS version for dqlite endpoint (tls10|tls11|tls12|tls13). Default is tls12") - rootCmd.Flags().BoolVar(&rootCmdOpts.metrics, "metrics", true, "enable metrics endpoint") + rootCmd.Flags().BoolVar(&rootCmdOpts.metrics, "metrics", false, "enable metrics endpoint") rootCmd.Flags().BoolVar(&rootCmdOpts.otel, "otel", false, "enable traces endpoint") rootCmd.Flags().StringVar(&rootCmdOpts.otelAddress, "otel-listen", "127.0.0.1:4317", "listen address for OpenTelemetry endpoint") rootCmd.Flags().StringVar(&rootCmdOpts.metricsAddress, "metrics-listen", "127.0.0.1:9042", "listen address for metrics endpoint") @@ -160,7 +173,7 @@ func init() { rootCmd.Flags().Uint64Var(&rootCmdOpts.watchAvailableStorageMinBytes, "watch-storage-available-size-min-bytes", 10*1024*1024, "Minimum required available disk size (in bytes) to continue operation. If available disk space gets below this threshold, then the --low-available-storage-action is performed") rootCmd.Flags().StringVar(&rootCmdOpts.lowAvailableStorageAction, "low-available-storage-action", "none", "Action to perform in case the available storage is low. One of (none|handover|terminate). none means no action is performed. handover means the dqlite node will handover its leadership role, if any. terminate means this dqlite node will shutdown") rootCmd.Flags().StringVar(&rootCmdOpts.admissionControlPolicy, "admission-control-policy", "allow-all", "Transaction admission control policy to use. One of (allow-all|limit-concurrent-transactions). Set to allow-all to disable the admission control") - // TODO(MK-1408): This value is highly dependend on underlying hardware, thus making the default value a bit useless. The linked card will implement a dynamic way to set this value. + // TODO(MK-1408): This value is highly depends on underlying hardware, thus making the default value a bit useless. The linked card will implement a dynamic way to set this value. rootCmd.Flags().Int64Var(&rootCmdOpts.acpLimitMaxConcurrentTxn, "admission-control-policy-limit-max-concurrent-transactions", 300, "Maximum number of transactions that are allowed to run concurrently. Transactions will not be admitted after the limit is reached.") rootCmd.Flags().BoolVar(&rootCmdOpts.acpOnlyWriteQueries, "admission-control-only-for-write-queries", false, "If set, admission control will only be applied to write queries.") From 9b78b145b2c6fac07e97bb07824a90113263c687 Mon Sep 17 00:00:00 2001 From: louiseschmidtgen Date: Thu, 8 Aug 2024 10:38:54 +0200 Subject: [PATCH 2/3] add check --- cmd/root.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index bd3a08bd..48bf83d6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -79,14 +79,19 @@ var ( Addr: rootCmdOpts.metricsAddress, Handler: http.NewServeMux(), } - metricsServer.Handler.(*http.ServeMux).Handle("/metrics", promhttp.Handler()) - - go func() { - logrus.WithField("address", rootCmdOpts.metricsAddress).Print("Enable metrics endpoint") - if err := metricsServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { - logrus.WithError(err).Fatal("Failed to start metrics endpoint") - } - }() + mux, ok := metricsServer.Handler.(*http.ServeMux) + if !ok { + logrus.Fatal("Failed to create metrics endpoint") + } else { + mux.Handle("/metrics", promhttp.Handler()) + + go func() { + logrus.WithField("address", rootCmdOpts.metricsAddress).Print("Enable metrics endpoint") + if err := metricsServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { + logrus.WithError(err).Fatal("Failed to start metrics endpoint") + } + }() + } } instance, err := server.New( From 16794ae57bfd766b5c9884209eb8c6ef215309ff Mon Sep 17 00:00:00 2001 From: louiseschmidtgen Date: Thu, 8 Aug 2024 12:02:16 +0200 Subject: [PATCH 3/3] comments --- cmd/root.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 48bf83d6..180a81c7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -143,7 +143,7 @@ var ( logrus.WithError(err).Warning("Failed to shutdown OpenTelemetry SDK") } } - if rootCmdOpts.metrics && metricsServer != nil { + if metricsServer != nil { if err := metricsServer.Shutdown(stopCtx); err != nil { logrus.WithError(err).Fatal("Failed to shutdown metrics endpoint") } @@ -178,7 +178,7 @@ func init() { rootCmd.Flags().Uint64Var(&rootCmdOpts.watchAvailableStorageMinBytes, "watch-storage-available-size-min-bytes", 10*1024*1024, "Minimum required available disk size (in bytes) to continue operation. If available disk space gets below this threshold, then the --low-available-storage-action is performed") rootCmd.Flags().StringVar(&rootCmdOpts.lowAvailableStorageAction, "low-available-storage-action", "none", "Action to perform in case the available storage is low. One of (none|handover|terminate). none means no action is performed. handover means the dqlite node will handover its leadership role, if any. terminate means this dqlite node will shutdown") rootCmd.Flags().StringVar(&rootCmdOpts.admissionControlPolicy, "admission-control-policy", "allow-all", "Transaction admission control policy to use. One of (allow-all|limit-concurrent-transactions). Set to allow-all to disable the admission control") - // TODO(MK-1408): This value is highly depends on underlying hardware, thus making the default value a bit useless. The linked card will implement a dynamic way to set this value. + // TODO(MK-1408): This value is highly dependent on underlying hardware, thus making the default value a bit useless. The linked card will implement a dynamic way to set this value. rootCmd.Flags().Int64Var(&rootCmdOpts.acpLimitMaxConcurrentTxn, "admission-control-policy-limit-max-concurrent-transactions", 300, "Maximum number of transactions that are allowed to run concurrently. Transactions will not be admitted after the limit is reached.") rootCmd.Flags().BoolVar(&rootCmdOpts.acpOnlyWriteQueries, "admission-control-only-for-write-queries", false, "If set, admission control will only be applied to write queries.")