From 75780fdf3e68b2005ffe0828e6d93828da8e1126 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Tue, 16 Jan 2024 14:51:46 +0100 Subject: [PATCH] refactor(minipipeline): allow avoiding linear analysis (#1448) This is yak shaving for https://github.com/ooni/probe/issues/2640. --- internal/cmd/minipipeline/main.go | 4 ++-- internal/cmd/qatool/main.go | 4 ++-- .../webconnectivitylte/analysisclassic.go | 2 +- internal/minipipeline/analysis.go | 13 ++++++++++--- internal/minipipeline/qa_test.go | 4 ++-- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/internal/cmd/minipipeline/main.go b/internal/cmd/minipipeline/main.go index c1578ffdc0..ede5f9e4fb 100644 --- a/internal/cmd/minipipeline/main.go +++ b/internal/cmd/minipipeline/main.go @@ -67,11 +67,11 @@ func main() { // generate and write observations analysis analysisPath := filepath.Join(*destdirFlag, *prefixFlag+"analysis.json") - analysis := minipipeline.AnalyzeWebObservations(container) + analysis := minipipeline.AnalyzeWebObservationsWithLinearAnalysis(container) mustWriteFileFn(analysisPath, must.MarshalAndIndentJSON(analysis, "", " "), 0600) // generate and write the classic analysis classicAnalysisPath := filepath.Join(*destdirFlag, *prefixFlag+"analysis_classic.json") - analysisClassic := minipipeline.AnalyzeWebObservations(containerClassic) + analysisClassic := minipipeline.AnalyzeWebObservationsWithLinearAnalysis(containerClassic) mustWriteFileFn(classicAnalysisPath, must.MarshalAndIndentJSON(analysisClassic, "", " "), 0600) } diff --git a/internal/cmd/qatool/main.go b/internal/cmd/qatool/main.go index 694ee8bb8b..1b08d47856 100644 --- a/internal/cmd/qatool/main.go +++ b/internal/cmd/qatool/main.go @@ -86,13 +86,13 @@ func runWebConnectivityLTE(tc *webconnectivityqa.TestCase) { mustSerializeMkdirAllAndWriteFile(actualDestdir, "observations_classic.json", observationsContainerClassic) // analyze the observations - analysis := minipipeline.AnalyzeWebObservations(observationsContainer) + analysis := minipipeline.AnalyzeWebObservationsWithLinearAnalysis(observationsContainer) // serialize the observations analysis mustSerializeMkdirAllAndWriteFile(actualDestdir, "analysis.json", analysis) // perform the classic analysis - analysisClassic := minipipeline.AnalyzeWebObservations(observationsContainerClassic) + analysisClassic := minipipeline.AnalyzeWebObservationsWithLinearAnalysis(observationsContainerClassic) // serialize the classic analysis results mustSerializeMkdirAllAndWriteFile(actualDestdir, "analysis_classic.json", analysisClassic) diff --git a/internal/experiment/webconnectivitylte/analysisclassic.go b/internal/experiment/webconnectivitylte/analysisclassic.go index ca0e8594fd..daaa75c574 100644 --- a/internal/experiment/webconnectivitylte/analysisclassic.go +++ b/internal/experiment/webconnectivitylte/analysisclassic.go @@ -36,7 +36,7 @@ func (tk *TestKeys) analysisClassic(logger model.Logger) { classic := minipipeline.ClassicFilter(container) // 3. produce a web observations analysis based on the web observations - woa := minipipeline.AnalyzeWebObservations(classic) + woa := minipipeline.AnalyzeWebObservationsWithLinearAnalysis(classic) // 4. determine the DNS consistency tk.DNSConsistency = analysisClassicDNSConsistency(woa) diff --git a/internal/minipipeline/analysis.go b/internal/minipipeline/analysis.go index f538fcd074..7b66a4d0a3 100644 --- a/internal/minipipeline/analysis.go +++ b/internal/minipipeline/analysis.go @@ -92,8 +92,9 @@ func NewLinearWebAnalysis(input *WebObservationsContainer) (output []*WebObserva return } -// AnalyzeWebObservations generates a [*WebAnalysis] from a [*WebObservationsContainer]. -func AnalyzeWebObservations(container *WebObservationsContainer) *WebAnalysis { +// AnalyzeWebObservationsWithoutLinearAnalysis generates a [*WebAnalysis] from a [*WebObservationsContainer] +// but avoids calling [NewLinearyAnalysis] to generate a linear analysis. +func AnalyzeWebObservationsWithoutLinearAnalysis(container *WebObservationsContainer) *WebAnalysis { analysis := &WebAnalysis{} analysis.dnsComputeSuccessMetrics(container) @@ -105,8 +106,14 @@ func AnalyzeWebObservations(container *WebObservationsContainer) *WebAnalysis { analysis.httpComputeFailureMetrics(container) analysis.httpComputeFinalResponseMetrics(container) - analysis.Linear = NewLinearWebAnalysis(container) + return analysis +} +// AnalyzeWebObservationsWithLinearAnalysis generates a [*WebAnalysis] from a [*WebObservationsContainer] +// and ensures we also use [NewLinearyAnalysis] to generate a linear analysis. +func AnalyzeWebObservationsWithLinearAnalysis(container *WebObservationsContainer) *WebAnalysis { + analysis := AnalyzeWebObservationsWithoutLinearAnalysis(container) + analysis.Linear = NewLinearWebAnalysis(container) return analysis } diff --git a/internal/minipipeline/qa_test.go b/internal/minipipeline/qa_test.go index 715fe50bfc..0346f2481d 100644 --- a/internal/minipipeline/qa_test.go +++ b/internal/minipipeline/qa_test.go @@ -72,10 +72,10 @@ func testMustRunAllWebTestCases(t *testing.T, topdir string) { gotClassicContainerData := minipipeline.ClassicFilter(gotContainerData) // analyze the measurement - gotAnalysisData := minipipeline.AnalyzeWebObservations(gotContainerData) + gotAnalysisData := minipipeline.AnalyzeWebObservationsWithLinearAnalysis(gotContainerData) // perform the classic web-connectivity-v0.4-like analysis - gotClassicAnalysisData := minipipeline.AnalyzeWebObservations(gotClassicContainerData) + gotClassicAnalysisData := minipipeline.AnalyzeWebObservationsWithLinearAnalysis(gotClassicContainerData) // // Note: if tests fail, you likely need to regenerate the static test