From 2f7bdcfeb0d65fca86f9ae292ae5922a8b77cfd2 Mon Sep 17 00:00:00 2001 From: Kalman Meth Date: Thu, 9 Mar 2023 10:11:15 +0200 Subject: [PATCH 1/2] suppress Go metrics and document metrics settings --- README.md | 39 +++++++++++++++++++++++++---------- cmd/flowlogs-pipeline/main.go | 10 ++++++++- pkg/config/config.go | 11 +++++----- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index eb63823ec..300db35f3 100644 --- a/README.md +++ b/README.md @@ -49,15 +49,15 @@ Usage: flowlogs-pipeline [flags] Flags: - --config string config file (default is $HOME/.flowlogs-pipeline) - --health.address string Health server address (default "0.0.0.0") - --health.port string Health server port (default "8080") - -h, --help help for flowlogs-pipeline - --log-level string Log level: debug, info, warning, error (default "error") - --metricsSettings string json for global metrics settings - --parameters string json of config file parameters field - --pipeline string json of config file pipeline field - --profile.port int Go pprof tool port (default: disabled) + --config string config file (default is $HOME/.flowlogs-pipeline) + --health.address string Health server address (default "0.0.0.0") + --health.port string Health server port (default "8080") + -h, --help help for flowlogs-pipeline + --log-level string Log level: debug, info, warning, error (default "error") + --metrics-settings string json for global metrics settings + --parameters string json of config file parameters field + --pipeline string json of config file pipeline field + --profile.port int Go pprof tool port (default: disabled) ``` @@ -757,8 +757,6 @@ parameters: encode: type: prom prom: - address: 0.0.0.0 - port: 9103 prefix: test_ metrics: - name: Bytes @@ -852,6 +850,25 @@ The object header contains the following fields: `version`, `capture_start_time` If no flow logs arrive within the `writeTimeout` period, then an object is created with no flows. An object is created either when we have accumulated `batchSize` flow logs or when `writeTimeout` has passed. +### Metrics Settings + +Some global metrics settings may be set in the configuration file. +A sample is the following: + +``` +metricsSettings: + suppressGoMetrics: true + prefix: flp_operational_ + port: 9102 + +``` + +FLP metrics are reported to a prometheus client interface. +In addition, there are default metrics reported by `Go`, which are also directed to the prometheus client interface. +The port to which these metrics are made available is specified in the `port` configuration parameter. +If a `prefix` is specified, then the specified prefix is prepended to each of the operational metrics generated by FLP. +A different `prefix` may be specified on an `encode prom` stage to be prepended to the prometheus metrics defined in that stage. +The `suppressGoMetrics` parameter may be set to `true` in order to suppress the reporting of the `Go` and process metrics in the prometheus client interface. # Development diff --git a/cmd/flowlogs-pipeline/main.go b/cmd/flowlogs-pipeline/main.go index 24292d84a..0aaab9c99 100644 --- a/cmd/flowlogs-pipeline/main.go +++ b/cmd/flowlogs-pipeline/main.go @@ -35,6 +35,7 @@ import ( "github.com/netobserv/flowlogs-pipeline/pkg/operational" "github.com/netobserv/flowlogs-pipeline/pkg/pipeline" "github.com/netobserv/flowlogs-pipeline/pkg/pipeline/utils" + "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -144,7 +145,7 @@ func initFlags() { rootCmd.PersistentFlags().IntVar(&opts.Profile.Port, "profile.port", 0, "Go pprof tool port (default: disabled)") rootCmd.PersistentFlags().StringVar(&opts.PipeLine, "pipeline", "", "json of config file pipeline field") rootCmd.PersistentFlags().StringVar(&opts.Parameters, "parameters", "", "json of config file parameters field") - rootCmd.PersistentFlags().StringVar(&opts.MetricsSettings, "metricsSettings", "", "json for global metrics settings") + rootCmd.PersistentFlags().StringVar(&opts.MetricsSettings, "metrics-settings", "", "json for global metrics settings") } func main() { @@ -179,6 +180,13 @@ func run() { // Setup (threads) exit manager utils.SetupElegantExit() + // set up private prometheus registry + if cfg.MetricsSettings.SuppressGoMetrics { + reg := prometheus.NewRegistry() + prometheus.DefaultRegisterer = reg + prometheus.DefaultGatherer = reg + } + // create prometheus server for operational metrics // if value of address is empty, then by default it will take 0.0.0.0 addr := fmt.Sprintf("%s:%v", cfg.MetricsSettings.Address, cfg.MetricsSettings.Port) diff --git a/pkg/config/config.go b/pkg/config/config.go index 3ad3c81af..445367d8a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -55,11 +55,12 @@ type Profile struct { // Also, currently FLP doesn't support defining more than one PromEncode stage. If this feature is added later, these global settings // will help configuring common setting for all PromEncode stages - PromEncode settings would then act as overrides. type MetricsSettings struct { - Address string `yaml:"address,omitempty" json:"address,omitempty" doc:"address to expose \"/metrics\" endpoint"` - Port int `yaml:"port,omitempty" json:"port,omitempty" doc:"port number to expose \"/metrics\" endpoint"` - TLS *api.PromTLSConf `yaml:"tls,omitempty" json:"tls,omitempty" doc:"TLS configuration for the prometheus endpoint"` - Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"` - NoPanic bool `yaml:"noPanic,omitempty" json:"noPanic,omitempty"` + Address string `yaml:"address,omitempty" json:"address,omitempty" doc:"address to expose \"/metrics\" endpoint"` + Port int `yaml:"port,omitempty" json:"port,omitempty" doc:"port number to expose \"/metrics\" endpoint"` + TLS *api.PromTLSConf `yaml:"tls,omitempty" json:"tls,omitempty" doc:"TLS configuration for the prometheus endpoint"` + Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty" doc:"prefix for names of the operational metrics"` + NoPanic bool `yaml:"noPanic,omitempty" json:"noPanic,omitempty"` + SuppressGoMetrics bool `yaml:"suppressGoMetrics,omitempty" json:"suppressGoMetrics,omitempty" doc:"filter out Go and process metrics"` } // PerfSettings allows setting some internal configuration parameters From af9f1124b3c8c9bb3b691134a9576f057098156d Mon Sep 17 00:00:00 2001 From: Kalman Meth Date: Thu, 9 Mar 2023 11:42:44 +0200 Subject: [PATCH 2/2] changed metrics-settings back to metricsSettings --- README.md | 18 +++++++++--------- cmd/flowlogs-pipeline/main.go | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 300db35f3..d330d1dfc 100644 --- a/README.md +++ b/README.md @@ -49,15 +49,15 @@ Usage: flowlogs-pipeline [flags] Flags: - --config string config file (default is $HOME/.flowlogs-pipeline) - --health.address string Health server address (default "0.0.0.0") - --health.port string Health server port (default "8080") - -h, --help help for flowlogs-pipeline - --log-level string Log level: debug, info, warning, error (default "error") - --metrics-settings string json for global metrics settings - --parameters string json of config file parameters field - --pipeline string json of config file pipeline field - --profile.port int Go pprof tool port (default: disabled) + --config string config file (default is $HOME/.flowlogs-pipeline) + --health.address string Health server address (default "0.0.0.0") + --health.port string Health server port (default "8080") + -h, --help help for flowlogs-pipeline + --log-level string Log level: debug, info, warning, error (default "error") + --metricsSettings string json for global metrics settings + --parameters string json of config file parameters field + --pipeline string json of config file pipeline field + --profile.port int Go pprof tool port (default: disabled) ``` diff --git a/cmd/flowlogs-pipeline/main.go b/cmd/flowlogs-pipeline/main.go index 0aaab9c99..c2e1fac9e 100644 --- a/cmd/flowlogs-pipeline/main.go +++ b/cmd/flowlogs-pipeline/main.go @@ -145,7 +145,7 @@ func initFlags() { rootCmd.PersistentFlags().IntVar(&opts.Profile.Port, "profile.port", 0, "Go pprof tool port (default: disabled)") rootCmd.PersistentFlags().StringVar(&opts.PipeLine, "pipeline", "", "json of config file pipeline field") rootCmd.PersistentFlags().StringVar(&opts.Parameters, "parameters", "", "json of config file parameters field") - rootCmd.PersistentFlags().StringVar(&opts.MetricsSettings, "metrics-settings", "", "json for global metrics settings") + rootCmd.PersistentFlags().StringVar(&opts.MetricsSettings, "metricsSettings", "", "json for global metrics settings") } func main() {