Skip to content

Show pg_stat_activity before each test run

Thong Kuah requested to merge check_pg_stat_activity into master

What does this MR do?

If ENV['PG_STAT_WARNING_THRESHOLD'] is set, show pg_stat_activity before each test run to debug https://gitlab.com/gitlab-org/gitlab-ce/issues/55232

Example output:

tkgl:gitlab tkuah$ PG_STAT_WARNING_THRESHOLD=50 ss spec/services/groups/destroy_service_spec.rb 
Running via Spring preloader in process 91649
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:38: warning: already initialized constant Gitlab::COM_URL
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:38: warning: previous definition of COM_URL was here
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:39: warning: already initialized constant Gitlab::APP_DIRS_PATTERN
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:39: warning: previous definition of APP_DIRS_PATTERN was here
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:40: warning: already initialized constant Gitlab::SUBDOMAIN_REGEX
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:40: warning: previous definition of SUBDOMAIN_REGEX was here
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:41: warning: already initialized constant Gitlab::VERSION
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:41: warning: previous definition of VERSION was here
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:42: warning: already initialized constant Gitlab::INSTALLATION_TYPE
/Users/tkuah/code/gdk-ce/gitlab/lib/gitlab.rb:42: warning: previous definition of INSTALLATION_TYPE was here

==> Setting up GitLab Shell...
    GitLab Shell set up in 0.151688 seconds...

==> Setting up Gitaly...
Checking gitaly-ruby bundle...
The Gemfile's dependencies are satisfied
Trying to connect to gitaly: ..... OK
    Gitaly set up in 0.914538 seconds...
pg_stat_activity count: 9
.pg_stat_activity count: 9
.pg_stat_activity count: 9
.pg_stat_activity count: 9
.pg_stat_activity count: 9
.pg_stat_activity count: 9
.pg_stat_activity count: 9
.pg_stat_activity count: 9
WARNING:  there is no transaction in progress
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.pg_stat_activity count: 11
.

If the rows exceed `ENV['PG_STAT_WARNING_THRESHOLD']`, also show the contents. Example output in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/25723#note_147287641

Finished in 10.49 seconds (files took 1.28 seconds to load)
23 examples, 0 failures

What are the relevant issue numbers?

Does this MR meet the acceptance criteria?

Edited by Thong Kuah

Merge request reports