From 1e1172b38a5f9b8005448078781b120a290316da Mon Sep 17 00:00:00 2001 From: panigs7 Date: Tue, 7 Nov 2023 05:06:36 -0500 Subject: [PATCH] make separate goroutines for metrics collection method calls --- internal/entrypoint/run.go | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/internal/entrypoint/run.go b/internal/entrypoint/run.go index c76002c..a080aca 100644 --- a/internal/entrypoint/run.go +++ b/internal/entrypoint/run.go @@ -21,6 +21,7 @@ import ( "fmt" "os" "runtime" + "sync" "time" pstoreServices "github.com/dell/csm-metrics-powerstore/internal/service" @@ -116,6 +117,8 @@ func Run(ctx context.Context, config *Config, exporter otlexporters.Otlexporter, select { case <-volumeTicker.C: ctx, span := tracer.GetTracer(ctx, "volume-metrics") + wg := new(sync.WaitGroup) + if !config.LeaderElector.IsLeader() { logger.Info("not leader pod to collect metrics") span.End() @@ -126,9 +129,15 @@ func Run(ctx context.Context, config *Config, exporter otlexporters.Otlexporter, span.End() continue } - powerStoreSvc.ExportVolumeStatistics(ctx) + wg.Add(1) + go func() { + defer wg.Done() + powerStoreSvc.ExportVolumeStatistics(ctx) + + }() span.End() case <-spaceTicker.C: + wg := new(sync.WaitGroup) ctx, span := tracer.GetTracer(ctx, "volume-space-metrics") if !config.LeaderElector.IsLeader() { logger.Info("not leader pod to collect metrics") @@ -140,9 +149,15 @@ func Run(ctx context.Context, config *Config, exporter otlexporters.Otlexporter, span.End() continue } - powerStoreSvc.ExportSpaceVolumeMetrics(ctx) + wg.Add(1) + go func() { + defer wg.Done() + powerStoreSvc.ExportSpaceVolumeMetrics(ctx) + + }() span.End() case <-arrayTicker.C: + wg := new(sync.WaitGroup) ctx, span := tracer.GetTracer(ctx, "array-space-metrics") if !config.LeaderElector.IsLeader() { logger.Info("not leader pod to collect metrics") @@ -154,9 +169,15 @@ func Run(ctx context.Context, config *Config, exporter otlexporters.Otlexporter, span.End() continue } - powerStoreSvc.ExportArraySpaceMetrics(ctx) + wg.Add(1) + go func() { + defer wg.Done() + powerStoreSvc.ExportArraySpaceMetrics(ctx) + + }() span.End() case <-filesystemTicker.C: + wg := new(sync.WaitGroup) ctx, span := tracer.GetTracer(ctx, "filesystem-metrics") if !config.LeaderElector.IsLeader() { logger.Info("not leader pod to collect metrics") @@ -168,7 +189,12 @@ func Run(ctx context.Context, config *Config, exporter otlexporters.Otlexporter, span.End() continue } - powerStoreSvc.ExportFileSystemStatistics(ctx) + wg.Add(1) + go func() { + defer wg.Done() + powerStoreSvc.ExportFileSystemStatistics(ctx) + + }() span.End() case err := <-errCh: if err == nil {