From 06b6069396a620973802c129f2b58056a079cec5 Mon Sep 17 00:00:00 2001 From: Maggie Nolan Date: Tue, 14 Jul 2020 15:36:07 -0700 Subject: [PATCH] feat(profiler): update proftest to support parsing floating-point backoff durations (#2588) The first duration string in the Python profiling agent's backoff log messages has the form "2400.000s". This change allows the backoff durations to be parsed correctly for the Python agent. TESTED: I originally tested this change by trying to parse exact log message printed by the python agent in the unit test, then simplified the unit test. --- profiler/proftest/proftest.go | 2 +- profiler/proftest/proftest_test.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/profiler/proftest/proftest.go b/profiler/proftest/proftest.go index ebe2e31eec6..86c21aaa7a6 100644 --- a/profiler/proftest/proftest.go +++ b/profiler/proftest/proftest.go @@ -45,7 +45,7 @@ const ( var ( logtimeRE = regexp.MustCompile(`[A-Z][a-z]{2} [A-Z][a-z]{2} ?\d+ \d\d:\d\d:\d\d [A-Z]{3} \d{4}`) - backoffTimeRE = regexp.MustCompile(`(\d+(h|m|s|ms|us))+`) + backoffTimeRE = regexp.MustCompile(`(\d+(\.\d+)?(h|m|s|ms|us))+`) ) // BaseStartupTmpl is the common part of the startup script that diff --git a/profiler/proftest/proftest_test.go b/profiler/proftest/proftest_test.go index e99ff948f6a..f22beda103e 100644 --- a/profiler/proftest/proftest_test.go +++ b/profiler/proftest/proftest_test.go @@ -124,6 +124,11 @@ func TestParseBackoffDuration(t *testing.T) { line: "Fri May 15 22:05:01 UTC 2020: benchmark 0: failed to create profile, will retry: rpc error: code = Aborted desc = generic::aborted: action throttled, backoff for 32m0s", wantBackoffDur: 32 * time.Minute, }, + { + desc: "a floating-point backoff duration is parsed correctly", + line: "Fri May 15 22:05:01 UTC 2020: benchmark 0: failed to create profile, will retry: rpc error: code = Aborted desc = generic::aborted: action throttled, backoff for 2000.000s", + wantBackoffDur: 2000 * time.Second, + }, { desc: "an error is returned when the backoff duration is invalid", line: "Fri May 15 22:05:01 UTC 2020: benchmark 0: failed to create profile, will retry: rpc error: code = Aborted desc = generic::aborted: action throttled, backoff for 32..0.s", @@ -139,7 +144,7 @@ func TestParseBackoffDuration(t *testing.T) { return } if backoffDur != tc.wantBackoffDur { - t.Errorf("got log time = %v, want %v", backoffDur, tc.wantBackoffDur) + t.Errorf("backoff duration: got %v, want %v", backoffDur, tc.wantBackoffDur) } }) }