From acd176483a20e9dff2b9bec0c77373f6de32f848 Mon Sep 17 00:00:00 2001 From: nghialv Date: Thu, 2 Jun 2022 13:19:46 +0900 Subject: [PATCH 1/2] Refactor analyzer log to show the actually used queries --- pkg/app/piped/executor/analysis/analysis.go | 4 +++- pkg/app/piped/executor/analysis/metrics_analyzer.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/app/piped/executor/analysis/analysis.go b/pkg/app/piped/executor/analysis/analysis.go index d230055514..1304161d1c 100644 --- a/pkg/app/piped/executor/analysis/analysis.go +++ b/pkg/app/piped/executor/analysis/analysis.go @@ -137,11 +137,13 @@ func (e *Executor) Execute(sig executor.StopSignal) model.StageStatus { e.LogPersister.Errorf("Failed to generate metrics provider: %v", err) return model.StageStatus_STAGE_FAILURE } + id := fmt.Sprintf("metrics-%d", i) args := e.buildAppArgs(options.Metrics[i].Template.AppArgs) analyzer := newMetricsAnalyzer(id, *cfg, e.startTime, provider, e.AnalysisResultStore, args, e.Logger, e.LogPersister) + eg.Go(func() error { - e.LogPersister.Infof("[%s] Start metrics analyzer. Every %s it runs this query: %q", analyzer.id, cfg.Interval.Duration(), cfg.Query) + e.LogPersister.Infof("[%s] Start metrics analyzer every %s with query template: %q", analyzer.id, cfg.Interval.Duration(), cfg.Query) return analyzer.run(ctxWithTimeout) }) } diff --git a/pkg/app/piped/executor/analysis/metrics_analyzer.go b/pkg/app/piped/executor/analysis/metrics_analyzer.go index c198623761..11854ee59b 100644 --- a/pkg/app/piped/executor/analysis/metrics_analyzer.go +++ b/pkg/app/piped/executor/analysis/metrics_analyzer.go @@ -132,6 +132,8 @@ func (a *metricsAnalyzer) analyzeWithThreshold(ctx context.Context) (bool, error From: now.Add(-a.cfg.Interval.Duration()), To: now, } + + a.logPersister.Infof("[%s] Run query: %q, in range: %s", a.cfg.Query, queryRange) points, err := a.provider.QueryPoints(ctx, a.cfg.Query, queryRange) if err != nil { return false, fmt.Errorf("failed to run query: %w", err) @@ -168,6 +170,8 @@ func (a *metricsAnalyzer) analyzeWithPrevious(ctx context.Context) (expected, fi From: now.Add(-a.cfg.Interval.Duration()), To: now, } + + a.logPersister.Infof("[%s] Run query: %q, in range: %s", a.cfg.Query, queryRange) points, err := a.provider.QueryPoints(ctx, a.cfg.Query, queryRange) if err != nil { return false, false, fmt.Errorf("failed to run query: %w: performed query: %q", err, a.cfg.Query) @@ -194,6 +198,8 @@ func (a *metricsAnalyzer) analyzeWithPrevious(ctx context.Context) (expected, fi From: prevFrom, To: prevTo, } + + a.logPersister.Infof("[%s] Run query: %q, in range: %s", a.cfg.Query, prevQueryRange) prevPoints, err := a.provider.QueryPoints(ctx, a.cfg.Query, prevQueryRange) if err != nil { return false, false, fmt.Errorf("failed to run query to fetch metrics for the previous deployment: %w: performed query: %q", err, a.cfg.Query) @@ -246,6 +252,7 @@ func (a *metricsAnalyzer) analyzeWithCanaryBaseline(ctx context.Context) (bool, } // Fetch data points from Canary. + a.logPersister.Infof("[%s] Run query: %q, in range: %s", canaryQuery, queryRange) canaryPoints, err := a.provider.QueryPoints(ctx, canaryQuery, queryRange) if err != nil { return false, fmt.Errorf("failed to run query to fetch metrics for the Canary variant: %w: query range: %s: performed query: %q", err, &queryRange, canaryQuery) @@ -258,6 +265,7 @@ func (a *metricsAnalyzer) analyzeWithCanaryBaseline(ctx context.Context) (bool, } // Fetch data points from Baseline. + a.logPersister.Infof("[%s] Run query: %q, in range: %s", baselineQuery, queryRange) baselinePoints, err := a.provider.QueryPoints(ctx, baselineQuery, queryRange) if err != nil { return false, fmt.Errorf("failed to run query to fetch metrics for the Baseline variant: %w: query range: %s: performed query: %q", err, &queryRange, baselineQuery) @@ -311,6 +319,7 @@ func (a *metricsAnalyzer) analyzeWithCanaryPrimary(ctx context.Context) (bool, e return false, fmt.Errorf("failed to render query template for Primary: %w", err) } + a.logPersister.Infof("[%s] Run query: %q, in range: %s", canaryQuery, queryRange) canaryPoints, err := a.provider.QueryPoints(ctx, canaryQuery, queryRange) if err != nil { return false, fmt.Errorf("failed to run query to fetch metrics for the Canary variant: %w: performed query: %q", err, canaryQuery) @@ -321,6 +330,8 @@ func (a *metricsAnalyzer) analyzeWithCanaryPrimary(ctx context.Context) (bool, e for i := range canaryPoints { canaryValues = append(canaryValues, canaryPoints[i].Value) } + + a.logPersister.Infof("[%s] Run query: %q, in range: %s", primaryQuery, queryRange) primaryPoints, err := a.provider.QueryPoints(ctx, primaryQuery, queryRange) if err != nil { return false, fmt.Errorf("failed to run query to fetch metrics for the Primary variant: %w: performed query: %q", err, primaryQuery) From de904ca33091f3021cedbb740d2b1fa860c426ee Mon Sep 17 00:00:00 2001 From: nghialv Date: Thu, 2 Jun 2022 13:33:21 +0900 Subject: [PATCH 2/2] Fix missing param --- .../piped/executor/analysis/metrics_analyzer.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/app/piped/executor/analysis/metrics_analyzer.go b/pkg/app/piped/executor/analysis/metrics_analyzer.go index 11854ee59b..98415d4845 100644 --- a/pkg/app/piped/executor/analysis/metrics_analyzer.go +++ b/pkg/app/piped/executor/analysis/metrics_analyzer.go @@ -133,7 +133,7 @@ func (a *metricsAnalyzer) analyzeWithThreshold(ctx context.Context) (bool, error To: now, } - a.logPersister.Infof("[%s] Run query: %q, in range: %s", a.cfg.Query, queryRange) + a.logPersister.Infof("[%s] Run query: %q, in range: %v", a.id, a.cfg.Query, queryRange) points, err := a.provider.QueryPoints(ctx, a.cfg.Query, queryRange) if err != nil { return false, fmt.Errorf("failed to run query: %w", err) @@ -171,7 +171,7 @@ func (a *metricsAnalyzer) analyzeWithPrevious(ctx context.Context) (expected, fi To: now, } - a.logPersister.Infof("[%s] Run query: %q, in range: %s", a.cfg.Query, queryRange) + a.logPersister.Infof("[%s] Run query: %q, in range: %v", a.id, a.cfg.Query, queryRange) points, err := a.provider.QueryPoints(ctx, a.cfg.Query, queryRange) if err != nil { return false, false, fmt.Errorf("failed to run query: %w: performed query: %q", err, a.cfg.Query) @@ -199,7 +199,7 @@ func (a *metricsAnalyzer) analyzeWithPrevious(ctx context.Context) (expected, fi To: prevTo, } - a.logPersister.Infof("[%s] Run query: %q, in range: %s", a.cfg.Query, prevQueryRange) + a.logPersister.Infof("[%s] Run query: %q, in range: %v", a.id, a.cfg.Query, prevQueryRange) prevPoints, err := a.provider.QueryPoints(ctx, a.cfg.Query, prevQueryRange) if err != nil { return false, false, fmt.Errorf("failed to run query to fetch metrics for the previous deployment: %w: performed query: %q", err, a.cfg.Query) @@ -252,7 +252,7 @@ func (a *metricsAnalyzer) analyzeWithCanaryBaseline(ctx context.Context) (bool, } // Fetch data points from Canary. - a.logPersister.Infof("[%s] Run query: %q, in range: %s", canaryQuery, queryRange) + a.logPersister.Infof("[%s] Run query: %q, in range: %v", a.id, canaryQuery, queryRange) canaryPoints, err := a.provider.QueryPoints(ctx, canaryQuery, queryRange) if err != nil { return false, fmt.Errorf("failed to run query to fetch metrics for the Canary variant: %w: query range: %s: performed query: %q", err, &queryRange, canaryQuery) @@ -265,7 +265,7 @@ func (a *metricsAnalyzer) analyzeWithCanaryBaseline(ctx context.Context) (bool, } // Fetch data points from Baseline. - a.logPersister.Infof("[%s] Run query: %q, in range: %s", baselineQuery, queryRange) + a.logPersister.Infof("[%s] Run query: %q, in range: %v", a.id, baselineQuery, queryRange) baselinePoints, err := a.provider.QueryPoints(ctx, baselineQuery, queryRange) if err != nil { return false, fmt.Errorf("failed to run query to fetch metrics for the Baseline variant: %w: query range: %s: performed query: %q", err, &queryRange, baselineQuery) @@ -319,7 +319,7 @@ func (a *metricsAnalyzer) analyzeWithCanaryPrimary(ctx context.Context) (bool, e return false, fmt.Errorf("failed to render query template for Primary: %w", err) } - a.logPersister.Infof("[%s] Run query: %q, in range: %s", canaryQuery, queryRange) + a.logPersister.Infof("[%s] Run query: %q, in range: %v", a.id, canaryQuery, queryRange) canaryPoints, err := a.provider.QueryPoints(ctx, canaryQuery, queryRange) if err != nil { return false, fmt.Errorf("failed to run query to fetch metrics for the Canary variant: %w: performed query: %q", err, canaryQuery) @@ -331,7 +331,7 @@ func (a *metricsAnalyzer) analyzeWithCanaryPrimary(ctx context.Context) (bool, e canaryValues = append(canaryValues, canaryPoints[i].Value) } - a.logPersister.Infof("[%s] Run query: %q, in range: %s", primaryQuery, queryRange) + a.logPersister.Infof("[%s] Run query: %q, in range: %v", a.id, primaryQuery, queryRange) primaryPoints, err := a.provider.QueryPoints(ctx, primaryQuery, queryRange) if err != nil { return false, fmt.Errorf("failed to run query to fetch metrics for the Primary variant: %w: performed query: %q", err, primaryQuery)