Skip to content

Commit 2a6902b

Browse files
committed
Merge branch '239-last-time-activity' into 'master'
fix: extract the last time activity for ChatOps queries (#239) # Description Consider the `duration` label as a sign of user activity Closes #239 See merge request postgres-ai/database-lab!274
2 parents 2c11aa3 + 7ea130d commit 2a6902b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pkg/util/pglog/activity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (s *Selector) FilterOldFilesInList() {
125125

126126
// ParsePostgresLastActivity extracts the time of last session activity.
127127
func ParsePostgresLastActivity(logTime, text string) (*time.Time, error) {
128-
if logTime == "" || !strings.Contains(text, "statement:") {
128+
if logTime == "" || !(strings.Contains(text, "statement:") || strings.Contains(text, "duration:")) {
129129
return nil, nil
130130
}
131131

pkg/util/pglog/activity_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func TestGetPostgresLastActivity(t *testing.T) {
3535
logMessage: "duration: 9.893 ms statement: SELECT 1;",
3636
timeActivity: nil,
3737
},
38+
{
39+
logTime: "2021-03-24 15:33:56.135 UTC",
40+
logMessage: "duration: 0.544 ms execute lrupsc_28_0: EXPLAIN (FORMAT TEXT) select 1",
41+
timeActivity: pointer.ToTime(time.Date(2021, 3, 24, 15, 33, 56, 135000000, time.UTC)),
42+
},
3843
}
3944

4045
for _, tc := range testCases {

0 commit comments

Comments
 (0)