Skip to content

Commit

Permalink
Merge branch 'main' into artem-debug-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov authored Apr 8, 2024
2 parents 00bc98b + 684e648 commit 05f5e2d
Show file tree
Hide file tree
Showing 29 changed files with 268 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Create pgsql dir
Expand Down
23 changes: 19 additions & 4 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@ on: [push]
jobs:
build:
name: cppcheck-test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2

- name: install cppcheck
run: sudo apt-get install cppcheck
- name: Checkout sources
uses: actions/checkout@v4

- name: Checkout cppcheck sources
uses: actions/checkout@v4
with:
repository: 'danmar/cppcheck'
ref: '2.13.4'
path: src/cppcheck

- name: Build and install cppcheck
run: |
mkdir build
cd build
cmake ..
cmake --build .
sudo cmake --install .
working-directory: src/cppcheck

- name: Execute linter check with cppcheck
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-11-pgdg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [pull_request]
jobs:
build:
name: pg-11-pgdg-package-test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-11-ppg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]
jobs:
build:
name: pg-11-ppg-package-test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-12-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Create pgsql dir
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-12-pgdg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [pull_request]
jobs:
build:
name: pg-12-pgdg-package-test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
Expand All @@ -23,7 +23,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install PG Distribution Postgresql 12
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-12-ppg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]
jobs:
build:
name: pg-12-ppg-package-test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
Expand All @@ -26,7 +26,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install percona-release script
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-13-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Create pgsql dir
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-13-pgdg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [pull_request]
jobs:
build:
name: pg-13-pgdg-package-test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
Expand All @@ -23,7 +23,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install PG Distribution Postgresql 13
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-13-ppg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]
jobs:
build:
name: pg-13-ppg-package-test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
Expand All @@ -23,7 +23,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install percona-release script
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-14-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Create pgsql dir
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-14-pgdg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [pull_request]
jobs:
build:
name: pg-14-pgdg-package-test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
Expand All @@ -22,7 +22,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install PG Distribution Postgresql 14
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-14-ppg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]
jobs:
build:
name: pg-14-ppg-package-test
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v2
Expand All @@ -23,7 +23,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install percona-release script
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-15-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Create pgsql dir
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-15-pgdg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install PG Distribution Postgresql 15
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-15-ppg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install percona-release script
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-16-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Create pgsql dir
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-16-pgdg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install PG Distribution Postgresql 16
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql-16-ppg-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
/usr/lib/postgresql /usr/include/postgresql /usr/share/postgresql \
/etc/postgresql
sudo rm -f /usr/bin/pg_config
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install IPC::Run'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
- name: Install percona-release script
Expand Down
2 changes: 1 addition & 1 deletion pg_stat_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ IsBucketValid(uint64 bucketid)

TimestampDifference(pgsm->bucket_start_time[bucketid], current_tz, &secs, &microsecs);

if (secs > (pgsm_bucket_time * pgsm_max_buckets))
if (secs > ((int64)pgsm_bucket_time * pgsm_max_buckets))
return false;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions pg_stat_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
/* the assumption of query max nested level */
#define DEFAULT_MAX_NESTED_LEVEL 10

#define MAX_QUERY_BUF (pgsm_query_shared_buffer * 1024 * 1024)
#define MAX_BUCKETS_MEM (pgsm_max * 1024 * 1024)
#define MAX_QUERY_BUF ((int64)pgsm_query_shared_buffer * 1024 * 1024)
#define MAX_BUCKETS_MEM ((int64)pgsm_max * 1024 * 1024)
#define BUCKETS_MEM_OVERFLOW() ((hash_get_num_entries(pgsm_hash) * sizeof(pgsmEntry)) >= MAX_BUCKETS_MEM)
#define MAX_BUCKET_ENTRIES (MAX_BUCKETS_MEM / sizeof(pgsmEntry))
#define QUERY_BUFFER_OVERFLOW(x,y) ((x + y + sizeof(uint64) + sizeof(uint64)) > MAX_QUERY_BUF)
Expand Down
25 changes: 24 additions & 1 deletion t/007_settings_pgsm_query_shared_buffer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_bucket_time = 360000\n";
print $conf "pg_stat_monitor.pgsm_query_shared_buffer = 1\n";
print $conf "pg_stat_monitor.pgsm_query_shared_buffer = 1\n"; # Min possible value
print $conf "pg_stat_monitor.pgsm_normalized_query = 'yes'\n";
close $conf;

Expand Down Expand Up @@ -109,6 +109,29 @@
ok($cmdret == 0, "SELECT XXX FROM pg_stat_monitor");
PGSM::append_to_file($stdout);

$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_shared_buffer = 2048\n");
$node->restart();

($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM EXTENSION");
PGSM::append_to_file($stdout);

($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT name, setting, unit, context, vartype, source, min_val, max_val, enumvals, boot_val, reset_val, pending_restart FROM pg_settings WHERE name='pg_stat_monitor.pgsm_query_shared_buffer';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM EXTENSION Settings");
PGSM::append_to_file($stdout);

$out = system ("pgbench -i -s 10 -p $port example");
print " out: $out \n";
ok($cmdret == 0, "Perform pgbench init");

$out = system ("pgbench -c 10 -j 2 -t 1000 -p $port example");
print " out: $out \n";
ok($cmdret == 0, "Run pgbench");

($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT datname, substr(query,0,150) AS query, SUM(calls) AS calls FROM pg_stat_monitor GROUP BY datname, query ORDER BY datname, query, calls DESC Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT XXX FROM pg_stat_monitor");
PGSM::append_to_file($stdout);

# DROP EXTENSION
$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "DROP PGSM EXTENSION");
Expand Down
4 changes: 2 additions & 2 deletions t/016_settings_pgsm_max.pl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# UPDATE postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_max = 1000\n";
print $conf "pg_stat_monitor.pgsm_max = 2048\n";
close $conf;

# Start server
Expand Down Expand Up @@ -62,7 +62,7 @@
ok($cmdret == 0, "Print PGSM EXTENSION Settings");
PGSM::append_to_file($stdout);

$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 10\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 10\n"); # Min possible value
$node->restart();

($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
Expand Down
63 changes: 63 additions & 0 deletions t/031_query_stat.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/perl

use strict;
use warnings;
use File::Basename;
use File::Compare;
use File::Copy;
use Test::More;
use lib 't';
use pgsm;

# Get file name and CREATE out file name and dirs WHERE requried
PGSM::setup_files_dir(basename($0));

# CREATE new PostgreSQL node and do initdb
my $node = PGSM->pgsm_init_pg();
my $pgdata = $node->data_dir;

# UPDATE postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "pg_stat_monitor.pgsm_bucket_time = 2147483647\n"; # Max value for this parameter
print $conf "pg_stat_monitor.pgsm_max_buckets = 20000\n"; # Max value for this parameter
close $conf;

# Start server
my $rt_value = $node->start;
ok($rt_value == 1, "Start Server");

# CREATE EXTENSION and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "CREATE PGSM EXTENSION");
PGSM::append_to_file($stdout);

# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM EXTENSION");
PGSM::append_to_file($stdout);

($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT 1 AS num;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print results of a test query");
PGSM::append_to_file($stdout);

($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C";', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Check query stats");
PGSM::append_to_file($stdout);

# DROP EXTENSION
$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "DROP PGSM EXTENSION");
PGSM::append_to_file($stdout);

# Stop the server
$node->stop;

# compare the expected and out file
my $compare = PGSM->compare_results();

# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");

# Done testing for this testcase file.
done_testing();
Loading

0 comments on commit 05f5e2d

Please sign in to comment.