Skip to content

Commit

Permalink
Merge pull request #311 from EngineeredVirus/main
Browse files Browse the repository at this point in the history
Merging changes back to the main branch after the 1.1.1 release
  • Loading branch information
ImTheKai authored Nov 11, 2022
2 parents 634f0ce + 0006768 commit fddc096
Show file tree
Hide file tree
Showing 44 changed files with 1,199 additions and 1,829 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-11-pmm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
name: pg-11-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
Expand All @@ -18,7 +18,7 @@ jobs:
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor

- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=11
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=11 --pgstat-monitor-branch=REL_1_1_1

- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-12-pmm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
name: pg-12-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
Expand All @@ -18,7 +18,7 @@ jobs:
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor

- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=12
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=12 --pgstat-monitor-branch=REL_1_1_1

- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-13-pmm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
name: pg-13-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
Expand All @@ -18,7 +18,7 @@ jobs:
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor

- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=13
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=13 --pgstat-monitor-branch=REL_1_1_1

- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgresql-14-pmm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
name: pg-14-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
Expand All @@ -18,7 +18,7 @@ jobs:
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor

- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=14
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=14 --pgstat-monitor-branch=REL_1_1_1

- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/postgresql-15-pmm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: postgresql-15-pmm-integration
on: push

jobs:
build:
name: pg-15-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
with:
repository: 'Percona-Lab/qa-integration'
ref: 'main'

# print branch and Repo name
- name: Get branch and Repo Name
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor

- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=15 --pgstat-monitor-branch=REL_1_1_1

- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed
run: docker exec pgsql_pgsm_15 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log

- name: Upload Tests Artifacts
uses: actions/upload-artifact@v3
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact
path: ./pmm-ui-tests/tests/output/
if-no-files-found: ignore # 'warn' or 'ignore' are also available, defaults to `warn`
4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pg_stat_monitor",
"abstract": "PostgreSQL Query Performance Monitoring Tool",
"description": "pg_stat_monitor is a PostgreSQL Query Performance Monitoring tool, based on PostgreSQL's contrib module pg_stat_statements. PostgreSQL’s pg_stat_statements provides the basic statistics, which is sometimes not enough. The major shortcoming in pg_stat_statements is that it accumulates all the queries and their statistics and does not provide aggregated statistics nor histogram information. In this case, a user would need to calculate the aggregates, which is quite an expensive operation.",
"version": "1.1.0",
"version": "1.1.1",
"maintainer": [
"ibrar.ahmed@percona.com"
],
Expand All @@ -12,7 +12,7 @@
"abstract": "PostgreSQL Query Performance Monitoring Tool",
"file": "pg_stat_monitor--1.0.sql",
"docfile": "README.md",
"version": "1.1.0"
"version": "1.1.1"
}
},
"prereqs": {
Expand Down
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Below is the complete list of release notes for every version of ``pg_stat_monitor``.

## 1.1.1

### Bugs Fixed

[PG-520](https://jira.percona.com/browse/PG-520): pg_stat_monitor does not work with PostgreSQL15


## 1.1.0

### Improvements
Expand Down
46 changes: 37 additions & 9 deletions pg_stat_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

PG_MODULE_MAGIC;

#define BUILD_VERSION "1.1.0"
#define BUILD_VERSION "1.1.1"
#define PG_STAT_STATEMENTS_COLS 53 /* maximum of above */
#define PGSM_TEXT_FILE PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat_monitor_query"

Expand Down Expand Up @@ -81,10 +81,15 @@ static int get_histogram_bucket(double q_time);
static bool IsSystemInitialized(void);
static bool dump_queries_buffer(int bucket_id, unsigned char *buf, int buf_len);
static double time_diff(struct timeval end, struct timeval start);
static void request_additional_shared_resources(void);


/* Saved hook values in case of unload */

#if PG_VERSION_NUM >= 150000
static void pgss_shmem_request(void);
static shmem_request_hook_type prev_shmem_request_hook = NULL;
#endif
#if PG_VERSION_NUM >= 130000
static planner_hook_type planner_hook_next = NULL;
#endif
Expand Down Expand Up @@ -256,17 +261,15 @@ _PG_init(void)
elog(ERROR, "pg_stat_monitor: query comments regcomp() failed, return code=(%d)\n", rc);
}

/*
* Request additional shared resources. (These are no-ops if we're not in
* the postmaster process.) We'll allocate or attach to the shared
* resources in pgss_shmem_startup().
*/
RequestAddinShmemSpace(hash_memsize() + HOOK_STATS_SIZE);
RequestNamedLWLockTranche("pg_stat_monitor", 1);

/*
* Install hooks.
*/
#if PG_VERSION_NUM >= 150000
prev_shmem_request_hook = shmem_request_hook;
shmem_request_hook = pgss_shmem_request;
#else
request_additional_shared_resources();
#endif
prev_shmem_startup_hook = shmem_startup_hook;
shmem_startup_hook = pgss_shmem_startup;
prev_post_parse_analyze_hook = post_parse_analyze_hook;
Expand Down Expand Up @@ -333,6 +336,17 @@ pgss_shmem_startup(void)
pgss_startup();
}

static void
request_additional_shared_resources(void)
{
/*
* Request additional shared resources. (These are no-ops if we're not in
* the postmaster process.) We'll allocate or attach to the shared
* resources in pgss_shmem_startup().
*/
RequestAddinShmemSpace(hash_memsize() + HOOK_STATS_SIZE);
RequestNamedLWLockTranche("pg_stat_monitor", 1);
}
/*
* Select the version of pg_stat_monitor.
*/
Expand All @@ -342,6 +356,20 @@ pg_stat_monitor_version(PG_FUNCTION_ARGS)
PG_RETURN_TEXT_P(cstring_to_text(BUILD_VERSION));
}

#if PG_VERSION_NUM >= 150000
/*
* shmem_request hook: request additional shared resources. We'll allocate or
* attach to the shared resources in pgss_shmem_startup().
*/
static void
pgss_shmem_request(void)
{
if (prev_shmem_request_hook)
prev_shmem_request_hook();
request_additional_shared_resources();
}
#endif

#if PG_VERSION_NUM >= 140000
/*
* Post-parse-analysis hook: mark query with a queryId
Expand Down
73 changes: 73 additions & 0 deletions regression/expected/histogram_3.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
CREATE OR REPLACE FUNCTION generate_histogram()
RETURNS TABLE (
range TEXT, freq INT, bar TEXT
) AS $$
Declare
bucket_id integer;
query_id text;
BEGIN
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
--RAISE INFO 'bucket_id %', bucket_id;
--RAISE INFO 'query_id %', query_id;
return query
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
DECLARE
loops ALIAS FOR $1;
BEGIN
FOR i IN 1..loops LOOP
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
RAISE INFO 'Sleep % seconds', i;
PERFORM pg_sleep(i);
END LOOP;
END;
$$ LANGUAGE 'plpgsql' STRICT;
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------

(1 row)

Set pg_stat_monitor.pgsm_track='all';
select run_pg_sleep(5);
INFO: Sleep 1 seconds
INFO: Sleep 2 seconds
INFO: Sleep 3 seconds
INFO: Sleep 4 seconds
INFO: Sleep 5 seconds
run_pg_sleep
--------------

(1 row)

SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | resp_calls
---------------------------------------------------+-------+-----------------------
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,3,0,0,0}
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,0,2,0,0}
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
(6 rows)

select * from generate_histogram();
range | freq | bar
--------------------+------+--------------------------------------------------------------------------------------------
(0 - 3)} | 0 |
(3 - 10)} | 0 |
(10 - 31)} | 0 |
(31 - 100)} | 0 |
(100 - 316)} | 0 |
(316 - 1000)} | 0 |
(1000 - 3162)} | 3 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
(3162 - 10000)} | 0 |
(10000 - 31622)} | 0 |
(31622 - 100000)} | 0 |
(10 rows)

DROP EXTENSION pg_stat_monitor;
73 changes: 73 additions & 0 deletions regression/expected/histogram_4.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
CREATE OR REPLACE FUNCTION generate_histogram()
RETURNS TABLE (
range TEXT, freq INT, bar TEXT
) AS $$
Declare
bucket_id integer;
query_id text;
BEGIN
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
--RAISE INFO 'bucket_id %', bucket_id;
--RAISE INFO 'query_id %', query_id;
return query
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
DECLARE
loops ALIAS FOR $1;
BEGIN
FOR i IN 1..loops LOOP
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
RAISE INFO 'Sleep % seconds', i;
PERFORM pg_sleep(i);
END LOOP;
END;
$$ LANGUAGE 'plpgsql' STRICT;
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------

(1 row)

Set pg_stat_monitor.pgsm_track='all';
select run_pg_sleep(5);
INFO: Sleep 1 seconds
INFO: Sleep 2 seconds
INFO: Sleep 3 seconds
INFO: Sleep 4 seconds
INFO: Sleep 5 seconds
run_pg_sleep
--------------

(1 row)

SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | resp_calls
---------------------------------------------------+-------+-----------------------
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,3,0,0,0}
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,0,2,0,0}
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
(6 rows)

select * from generate_histogram();
range | freq | bar
--------------------+------+--------------------------------
(0 - 3)} | 0 |
(3 - 10)} | 0 |
(10 - 31)} | 0 |
(31 - 100)} | 0 |
(100 - 316)} | 0 |
(316 - 1000)} | 0 |
(1000 - 3162)} | 3 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
(3162 - 10000)} | 0 |
(10000 - 31622)} | 0 |
(31622 - 100000)} | 0 |
(10 rows)

DROP EXTENSION pg_stat_monitor;
Loading

0 comments on commit fddc096

Please sign in to comment.