From 2360488e7fc6a5b9013d121bf30157f124091ab4 Mon Sep 17 00:00:00 2001 From: Kalman Meth Date: Mon, 27 Mar 2023 12:31:29 +0300 Subject: [PATCH] addressed reviewer comments --- docs/api.md | 2 +- pkg/api/encode_prom.go | 2 +- pkg/config/pipeline_builder_test.go | 6 +++--- pkg/pipeline/encode/encode_prom.go | 4 ++-- pkg/pipeline/encode/encode_prom_test.go | 18 +++++++++--------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/api.md b/docs/api.md index 0f7c9b753..cad853881 100644 --- a/docs/api.md +++ b/docs/api.md @@ -18,7 +18,7 @@ Following is the supported API format for prometheus encode: labels: labels to be associated with the metric buckets: histogram buckets prefix: prefix added to each metric name - expiryTime: seconds of no-flow to wait before deleting prometheus data item + expiryTime: time duration of no-flow to wait before deleting prometheus data item maxMetrics: maximum number of metrics to report (default: unlimited) ## Kafka encode API diff --git a/pkg/api/encode_prom.go b/pkg/api/encode_prom.go index d78079dee..2e21869a2 100644 --- a/pkg/api/encode_prom.go +++ b/pkg/api/encode_prom.go @@ -25,7 +25,7 @@ type PromTLSConf struct { type PromEncode struct { Metrics PromMetricsItems `yaml:"metrics,omitempty" json:"metrics,omitempty" doc:"list of prometheus metric definitions, each includes:"` Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty" doc:"prefix added to each metric name"` - ExpiryTime Duration `yaml:"expiryTime,omitempty" json:"expiryTime,omitempty" doc:"seconds of no-flow to wait before deleting prometheus data item"` + ExpiryTime Duration `yaml:"expiryTime,omitempty" json:"expiryTime,omitempty" doc:"time duration of no-flow to wait before deleting prometheus data item"` MaxMetrics int `yaml:"maxMetrics,omitempty" json:"maxMetrics,omitempty" doc:"maximum number of metrics to report (default: unlimited)"` } diff --git a/pkg/config/pipeline_builder_test.go b/pkg/config/pipeline_builder_test.go index 031fec1fd..0b1007b28 100644 --- a/pkg/config/pipeline_builder_test.go +++ b/pkg/config/pipeline_builder_test.go @@ -118,8 +118,8 @@ func TestKafkaPromPipeline(t *testing.T) { GroupByKeys: api.AggregateBy{"srcAS"}, OperationType: "count", }}) - var expirtyTimeDuration api.Duration - expirtyTimeDuration.Duration = time.Duration(50 * time.Second) + var expiryTimeDuration api.Duration + expiryTimeDuration.Duration = time.Duration(50 * time.Second) pl = pl.EncodePrometheus("prom", api.PromEncode{ Metrics: api.PromMetricsItems{{ Name: "connections_per_source_as", @@ -133,7 +133,7 @@ func TestKafkaPromPipeline(t *testing.T) { Buckets: []float64{}, }}, Prefix: "flp_", - ExpiryTime: expirtyTimeDuration, + ExpiryTime: expiryTimeDuration, }) stages := pl.GetStages() require.Len(t, stages, 5) diff --git a/pkg/pipeline/encode/encode_prom.go b/pkg/pipeline/encode/encode_prom.go index 6d0beb2c6..efa2edfe6 100644 --- a/pkg/pipeline/encode/encode_prom.go +++ b/pkg/pipeline/encode/encode_prom.go @@ -32,7 +32,7 @@ import ( log "github.com/sirupsen/logrus" ) -const defaultExpiryTime = time.Duration(2 * time.Second) +const defaultExpiryTime = time.Duration(2 * time.Minute) type gaugeInfo struct { gauge *prometheus.GaugeVec @@ -268,7 +268,7 @@ func NewEncodeProm(opMetrics *operational.Metrics, params config.StageParam) (En } expiryTime := cfg.ExpiryTime - if expiryTime.Seconds() == 0 && expiryTime.Microseconds() == 0 { + if expiryTime.Duration == 0 { expiryTime.Duration = defaultExpiryTime } log.Debugf("expiryTime = %v", expiryTime) diff --git a/pkg/pipeline/encode/encode_prom_test.go b/pkg/pipeline/encode/encode_prom_test.go index eb4144587..05b91f185 100644 --- a/pkg/pipeline/encode/encode_prom_test.go +++ b/pkg/pipeline/encode/encode_prom_test.go @@ -146,11 +146,11 @@ func Test_CustomMetric(t *testing.T) { "packets": 2, "latency": 0.2, }} - var expirtyTimeDuration api.Duration - expirtyTimeDuration.Duration = time.Duration(60 * time.Second) + var expiryTimeDuration api.Duration + expiryTimeDuration.Duration = time.Duration(60 * time.Second) params := api.PromEncode{ Prefix: "test_", - ExpiryTime: expirtyTimeDuration, + ExpiryTime: expiryTimeDuration, Metrics: []api.PromMetricsItem{{ Name: "bytes_total", Type: "counter", @@ -230,11 +230,11 @@ func Test_MetricTTL(t *testing.T) { "bytes": 12, }} - var expirtyTimeDuration api.Duration - expirtyTimeDuration.Duration = time.Duration(1 * time.Second) + var expiryTimeDuration api.Duration + expiryTimeDuration.Duration = time.Duration(1 * time.Second) params := api.PromEncode{ Prefix: "test_", - ExpiryTime: expirtyTimeDuration, + ExpiryTime: expiryTimeDuration, Metrics: []api.PromMetricsItem{{ Name: "bytes_total", Type: "counter", @@ -284,11 +284,11 @@ func hundredFlows() []config.GenericMap { } func BenchmarkPromEncode(b *testing.B) { - var expirtyTimeDuration api.Duration - expirtyTimeDuration.Duration = time.Duration(60 * time.Second) + var expiryTimeDuration api.Duration + expiryTimeDuration.Duration = time.Duration(60 * time.Second) params := api.PromEncode{ Prefix: "test_", - ExpiryTime: expirtyTimeDuration, + ExpiryTime: expiryTimeDuration, Metrics: []api.PromMetricsItem{{ Name: "bytes_total", Type: "counter",