Skip to content

Commit

Permalink
feat(profiler): update proftest to support parsing floating-point bac…
Browse files Browse the repository at this point in the history
…koff 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.
  • Loading branch information
nolanmar511 committed Jul 14, 2020
1 parent d1ef23f commit 06b6069
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion profiler/proftest/proftest.go
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion profiler/proftest/proftest_test.go
Expand Up @@ -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",
Expand All @@ -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)
}
})
}
Expand Down

0 comments on commit 06b6069

Please sign in to comment.