diff --git a/.github/workflows/build-cloudberry-rocky8.yml b/.github/workflows/build-cloudberry-rocky8.yml index e0936c725c8..39175753a99 100644 --- a/.github/workflows/build-cloudberry-rocky8.yml +++ b/.github/workflows/build-cloudberry-rocky8.yml @@ -320,6 +320,10 @@ jobs: "gpcontrib/gp_sparse_vector:installcheck", "gpcontrib/gp_toolkit:installcheck"] }, + {"test":"gpcontrib-gp-stats-collector", + "make_configs":["gpcontrib/gp_stats_collector:installcheck"], + "extension":"gp_stats_collector" + }, {"test":"ic-fixme", "make_configs":["src/test/regress:installcheck-fixme"], "enable_core_check":false @@ -540,10 +544,11 @@ jobs: if: needs.check-skip.outputs.should_skip != 'true' env: SRC_DIR: ${{ github.workspace }} + CONFIGURE_EXTRA_OPTS: --with-gp-stats-collector run: | set -eo pipefail chmod +x "${SRC_DIR}"/devops/build/automation/cloudberry/scripts/configure-cloudberry.sh - if ! time su - gpadmin -c "cd ${SRC_DIR} && SRC_DIR=${SRC_DIR} ENABLE_DEBUG=${{ env.ENABLE_DEBUG }} ${SRC_DIR}/devops/build/automation/cloudberry/scripts/configure-cloudberry.sh"; then + if ! time su - gpadmin -c "cd ${SRC_DIR} && SRC_DIR=${SRC_DIR} ENABLE_DEBUG=${{ env.ENABLE_DEBUG }} CONFIGURE_EXTRA_OPTS=${{ env.CONFIGURE_EXTRA_OPTS }} ${SRC_DIR}/devops/build/automation/cloudberry/scripts/configure-cloudberry.sh"; then echo "::error::Configure script failed" exit 1 fi @@ -1400,6 +1405,7 @@ jobs: if: success() && needs.check-skip.outputs.should_skip != 'true' env: SRC_DIR: ${{ github.workspace }} + BUILD_DESTINATION: /usr/local/cloudberry-db shell: bash {0} run: | set -o pipefail @@ -1423,6 +1429,30 @@ jobs: # 2. Follow the same pattern as optimizer # 3. Update matrix entries to include the new setting + # Create extension if required + if [[ "${{ matrix.extension != '' }}" == "true" ]]; then + case "${{ matrix.extension }}" in + gp_stats_collector) + if ! su - gpadmin -c "source ${BUILD_DESTINATION}/cloudberry-env.sh && \ + source ${SRC_DIR}/gpAux/gpdemo/gpdemo-env.sh && \ + gpconfig -c shared_preload_libraries -v 'gp_stats_collector' && \ + gpstop -ra && \ + echo 'CREATE EXTENSION IF NOT EXISTS gp_stats_collector; \ + SHOW shared_preload_libraries; \ + TABLE pg_extension;' | \ + psql postgres" + then + echo "Error creating gp_stats_collector extension" + exit 1 + fi + ;; + *) + echo "Unknown extension: ${{ matrix.extension }}" + exit 1 + ;; + esac + fi + # Set PostgreSQL options if defined PG_OPTS="" if [[ "${{ matrix.pg_settings.optimizer != '' }}" == "true" ]]; then diff --git a/.github/workflows/build-cloudberry.yml b/.github/workflows/build-cloudberry.yml index 8484331998f..cbd4fd753dc 100644 --- a/.github/workflows/build-cloudberry.yml +++ b/.github/workflows/build-cloudberry.yml @@ -271,9 +271,9 @@ jobs: }, "enable_core_check":false }, - {"test":"gpcontrib-yagp-hooks-collector", - "make_configs":["gpcontrib/yagp_hooks_collector:installcheck"], - "extension":"yagp_hooks_collector" + {"test":"gpcontrib-gp-stats-collector", + "make_configs":["gpcontrib/gp_stats_collector:installcheck"], + "extension":"gp_stats_collector" }, {"test":"ic-expandshrink", "make_configs":["src/test/isolation2:installcheck-expandshrink"] @@ -539,7 +539,7 @@ jobs: if: needs.check-skip.outputs.should_skip != 'true' env: SRC_DIR: ${{ github.workspace }} - CONFIGURE_EXTRA_OPTS: --with-yagp-hooks-collector + CONFIGURE_EXTRA_OPTS: --with-gp-stats-collector run: | set -eo pipefail chmod +x "${SRC_DIR}"/devops/build/automation/cloudberry/scripts/configure-cloudberry.sh @@ -1441,17 +1441,17 @@ jobs: # Create extension if required if [[ "${{ matrix.extension != '' }}" == "true" ]]; then case "${{ matrix.extension }}" in - yagp_hooks_collector) + gp_stats_collector) if ! su - gpadmin -c "source ${BUILD_DESTINATION}/cloudberry-env.sh && \ source ${SRC_DIR}/gpAux/gpdemo/gpdemo-env.sh && \ - gpconfig -c shared_preload_libraries -v 'yagp_hooks_collector' && \ + gpconfig -c shared_preload_libraries -v 'gp_stats_collector' && \ gpstop -ra && \ - echo 'CREATE EXTENSION IF NOT EXISTS yagp_hooks_collector; \ + echo 'CREATE EXTENSION IF NOT EXISTS gp_stats_collector; \ SHOW shared_preload_libraries; \ TABLE pg_extension;' | \ psql postgres" then - echo "Error creating yagp_hooks_collector extension" + echo "Error creating gp_stats_collector extension" exit 1 fi ;; diff --git a/.github/workflows/build-deb-cloudberry.yml b/.github/workflows/build-deb-cloudberry.yml index 85d917b8ff0..bf85a107b31 100644 --- a/.github/workflows/build-deb-cloudberry.yml +++ b/.github/workflows/build-deb-cloudberry.yml @@ -252,6 +252,10 @@ jobs: "gpcontrib/gp_sparse_vector:installcheck", "gpcontrib/gp_toolkit:installcheck"] }, + {"test":"gpcontrib-gp-stats-collector", + "make_configs":["gpcontrib/gp_stats_collector:installcheck"], + "extension":"gp_stats_collector" + }, {"test":"ic-cbdb-parallel", "make_configs":["src/test/regress:installcheck-cbdb-parallel"] } @@ -448,13 +452,14 @@ jobs: shell: bash env: SRC_DIR: ${{ github.workspace }} + CONFIGURE_EXTRA_OPTS: --with-gp-stats-collector run: | set -eo pipefail export BUILD_DESTINATION=${SRC_DIR}/debian/build chmod +x "${SRC_DIR}"/devops/build/automation/cloudberry/scripts/configure-cloudberry.sh - if ! time su - gpadmin -c "cd ${SRC_DIR} && SRC_DIR=${SRC_DIR} ENABLE_DEBUG=${{ env.ENABLE_DEBUG }} BUILD_DESTINATION=${BUILD_DESTINATION} ${SRC_DIR}/devops/build/automation/cloudberry/scripts/configure-cloudberry.sh"; then + if ! time su - gpadmin -c "cd ${SRC_DIR} && SRC_DIR=${SRC_DIR} ENABLE_DEBUG=${{ env.ENABLE_DEBUG }} CONFIGURE_EXTRA_OPTS=${{ env.CONFIGURE_EXTRA_OPTS }} BUILD_DESTINATION=${BUILD_DESTINATION} ${SRC_DIR}/devops/build/automation/cloudberry/scripts/configure-cloudberry.sh"; then echo "::error::Configure script failed" exit 1 fi @@ -1341,6 +1346,7 @@ jobs: if: success() && needs.check-skip.outputs.should_skip != 'true' env: SRC_DIR: ${{ github.workspace }} + BUILD_DESTINATION: ${{ github.workspace }}/debian/build shell: bash {0} run: | set -o pipefail @@ -1365,6 +1371,30 @@ jobs: # 3. Update matrix entries to include the new setting + # Create extension if required + if [[ "${{ matrix.extension != '' }}" == "true" ]]; then + case "${{ matrix.extension }}" in + gp_stats_collector) + if ! su - gpadmin -c "source ${BUILD_DESTINATION}/cloudberry-env.sh && \ + source ${SRC_DIR}/gpAux/gpdemo/gpdemo-env.sh && \ + gpconfig -c shared_preload_libraries -v 'gp_stats_collector' && \ + gpstop -ra && \ + echo 'CREATE EXTENSION IF NOT EXISTS gp_stats_collector; \ + SHOW shared_preload_libraries; \ + TABLE pg_extension;' | \ + psql postgres" + then + echo "Error creating gp_stats_collector extension" + exit 1 + fi + ;; + *) + echo "Unknown extension: ${{ matrix.extension }}" + exit 1 + ;; + esac + fi + # Set PostgreSQL options if defined PG_OPTS="" if [[ "${{ matrix.pg_settings.optimizer != '' }}" == "true" ]]; then diff --git a/Makefile b/Makefile index 15c5dabb70e..e9ab3fbf2d4 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,14 @@ # to build Postgres with a different make, we have this make file # that, as a service, will look for a GNU make and invoke it, or show # an error message if none could be found. + # If the user were using GNU make now, this file would not get used # because GNU make uses a make file named "GNUmakefile" in preference # to "Makefile" if it exists. PostgreSQL is shipped with a # "GNUmakefile". If the user hasn't run the configure script yet, the # GNUmakefile won't exist yet, so we catch that case as well. + # AIX make defaults to building *every* target of the first rule. Start with # a single-target, empty rule to make the other targets non-default. all: diff --git a/configure b/configure index 598114a4b7f..13295a946ca 100755 --- a/configure +++ b/configure @@ -722,7 +722,7 @@ with_apr_config with_libcurl with_rt with_zstd -with_yagp_hooks_collector +with_gp_stats_collector with_libbz2 LZ4_LIBS LZ4_CFLAGS @@ -943,7 +943,7 @@ with_zlib with_lz4 with_libbz2 with_zstd -with_yagp_hooks_collector +with_gp_stats_collector with_rt with_libcurl with_apr_config @@ -11153,14 +11153,14 @@ fi fi # -# yagp_hooks_collector +# gp_stats_collector # -# Check whether --with-yagp-hooks-collector was given. -if test "${with_yagp_hooks_collector+set}" = set; then : - withval=$with_yagp_hooks_collector; +# Check whether --with-gp-stats-collector was given. +if test "${with_gp_stats_collector+set}" = set; then : + withval=$with_gp_stats_collector; case $withval in yes) : @@ -11169,12 +11169,12 @@ if test "${with_yagp_hooks_collector+set}" = set; then : : ;; *) - as_fn_error $? "no argument expected for --with-yagp-hooks-collector option" "$LINENO" 5 + as_fn_error $? "no argument expected for --with-gp-stats-collector option" "$LINENO" 5 ;; esac else - with_yagp_hooks_collector=no + with_gp_stats_collector=no fi diff --git a/configure.ac b/configure.ac index 792878fde4b..3024e4b9b65 100644 --- a/configure.ac +++ b/configure.ac @@ -1366,11 +1366,22 @@ AC_MSG_RESULT([$with_zstd]) AC_SUBST(with_zstd) # -# yagp_hooks_collector +# gp_stats_collector # -PGAC_ARG_BOOL(with, yagp_hooks_collector, no, - [build with YAGP hooks collector extension]) -AC_SUBST(with_yagp_hooks_collector) +PGAC_ARG_BOOL(with, gp_stats_collector, no, + [build with stats collector extension]) +AC_SUBST(with_gp_stats_collector) + +if test "$with_gp_stats_collector" = yes; then + PKG_CHECK_MODULES([PROTOBUF], [protobuf >= 3.0.0], + [], + [AC_MSG_ERROR([protobuf >= 3.0.0 is required for gp_stats_collector])] + ) + AC_PATH_PROG([PROTOC], [protoc], [no]) + if test "$PROTOC" = no; then + AC_MSG_ERROR([protoc is required for gp_stats_collector but was not found in PATH]) + fi +fi if test "$with_zstd" = yes; then dnl zstd_errors.h was renamed from error_public.h in v1.4.0 diff --git a/gpcontrib/Makefile b/gpcontrib/Makefile index 8b98dc9142c..956cb470477 100644 --- a/gpcontrib/Makefile +++ b/gpcontrib/Makefile @@ -35,8 +35,8 @@ else diskquota endif -ifeq "$(with_yagp_hooks_collector)" "yes" - recurse_targets += yagp_hooks_collector +ifeq "$(with_gp_stats_collector)" "yes" + recurse_targets += gp_stats_collector endif ifeq "$(with_zstd)" "yes" recurse_targets += zstd diff --git a/gpcontrib/yagp_hooks_collector/.clang-format b/gpcontrib/gp_stats_collector/.clang-format similarity index 100% rename from gpcontrib/yagp_hooks_collector/.clang-format rename to gpcontrib/gp_stats_collector/.clang-format diff --git a/gpcontrib/gp_stats_collector/.gitignore b/gpcontrib/gp_stats_collector/.gitignore new file mode 100644 index 00000000000..e8dfe855dad --- /dev/null +++ b/gpcontrib/gp_stats_collector/.gitignore @@ -0,0 +1,5 @@ +*.o +*.so +src/protos/ +.vscode +compile_commands.json diff --git a/gpcontrib/yagp_hooks_collector/Makefile b/gpcontrib/gp_stats_collector/Makefile similarity index 66% rename from gpcontrib/yagp_hooks_collector/Makefile rename to gpcontrib/gp_stats_collector/Makefile index 49825c55f35..c8f7b3c30fe 100644 --- a/gpcontrib/yagp_hooks_collector/Makefile +++ b/gpcontrib/gp_stats_collector/Makefile @@ -1,9 +1,9 @@ -MODULE_big = yagp_hooks_collector -EXTENSION = yagp_hooks_collector +MODULE_big = gp_stats_collector +EXTENSION = gp_stats_collector DATA = $(wildcard *--*.sql) -REGRESS = yagp_cursors yagp_dist yagp_select yagp_utf8_trim yagp_utility yagp_guc_cache yagp_uds yagp_locale +REGRESS = gpsc_cursors gpsc_dist gpsc_select gpsc_utf8_trim gpsc_utility gpsc_guc_cache gpsc_uds gpsc_locale -PROTO_BASES = yagpcc_plan yagpcc_metrics yagpcc_set_service +PROTO_BASES = gpsc_plan gpsc_metrics gpsc_set_service PROTO_OBJS = $(patsubst %,src/protos/%.pb.o,$(PROTO_BASES)) C_OBJS = $(patsubst %.c,%.o,$(wildcard src/*.c src/*/*.c)) @@ -24,7 +24,7 @@ PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) else -subdir = gpcontrib/yagp_hooks_collector +subdir = gpcontrib/gp_stats_collector top_builddir = ../.. include $(top_builddir)/src/Makefile.global include $(top_srcdir)/contrib/contrib-global.mk @@ -32,10 +32,8 @@ endif src/protos/%.pb.cpp src/protos/%.pb.h: protos/%.proto @mkdir -p src/protos - sed -i 's/optional //g' $^ - sed -i 's|cloud/mdb/yagpcc/api/proto/common/|protos/|g' $^ protoc -I /usr/include -I /usr/local/include -I . --cpp_out=src $^ mv src/protos/$*.pb.cc src/protos/$*.pb.cpp -$(CPP_OBJS): src/protos/yagpcc_metrics.pb.h src/protos/yagpcc_plan.pb.h src/protos/yagpcc_set_service.pb.h -src/protos/yagpcc_set_service.pb.o: src/protos/yagpcc_metrics.pb.h +$(CPP_OBJS): src/protos/gpsc_metrics.pb.h src/protos/gpsc_plan.pb.h src/protos/gpsc_set_service.pb.h +src/protos/gpsc_set_service.pb.o: src/protos/gpsc_metrics.pb.h diff --git a/gpcontrib/gp_stats_collector/README.md b/gpcontrib/gp_stats_collector/README.md new file mode 100644 index 00000000000..8c2d5c6868e --- /dev/null +++ b/gpcontrib/gp_stats_collector/README.md @@ -0,0 +1,47 @@ + + +## GP Stats Collector + +An extension for collecting query execution metrics and reporting them to an external agent. + +### Collected Statistics + +#### 1. Query Lifecycle +- **What:** Captures query text, normalized query text, timestamps (submit, start, end, done), and user/database info. +- **GUC:** `gpsc.enable`. + +#### 2. `EXPLAIN` data +- **What:** Triggers generation of the `EXPLAIN (TEXT, COSTS, VERBOSE)` and captures it. +- **GUC:** `gpsc.enable`. + +#### 3. `EXPLAIN ANALYZE` data +- **What:** Triggers generation of the `EXPLAIN (TEXT, ANALYZE, BUFFERS, TIMING, VERBOSE)` and captures it. +- **GUCs:** `gpsc.enable`, `gpsc.min_analyze_time`, `gpsc.enable_cdbstats`(ANALYZE), `gpsc.enable_analyze`(BUFFERS, TIMING, VERBOSE). + +#### 4. Other Metrics +- **What:** Captures Instrument, System, Network, Interconnect, Spill metrics. +- **GUC:** `gpsc.enable`. + +### General Configuration +- **Nested Queries:** When `gpsc.report_nested_queries` is `false`, only top-level queries are reported from the coordinator and segments, when `true`, both top-level and nested queries are reported from the coordinator, from segments collected as aggregates. +- **Data Destination:** All collected data is sent to a Unix Domain Socket. Configure the path with `gpsc.uds_path`. +- **User Filtering:** To exclude activity from certain roles, add them to the comma-separated list in `gpsc.ignored_users_list`. +- **Trimming plans:** Query texts and execution plans are trimmed based on `gpsc.max_text_size` and `gpsc.max_plan_size` (default: 1024KB). For now, it is not recommended to set these GUCs higher than 1024KB. +- **Analyze collection:** Analyze is sent if execution time exceeds `gpsc.min_analyze_time`, which is 10 seconds by default. Analyze is collected if `gpsc.enable_analyze` is true. diff --git a/gpcontrib/yagp_hooks_collector/expected/yagp_cursors.out b/gpcontrib/gp_stats_collector/expected/gpsc_cursors.out similarity index 73% rename from gpcontrib/yagp_hooks_collector/expected/yagp_cursors.out rename to gpcontrib/gp_stats_collector/expected/gpsc_cursors.out index df12e3e1b66..282d9ac49e1 100644 --- a/gpcontrib/yagp_hooks_collector/expected/yagp_cursors.out +++ b/gpcontrib/gp_stats_collector/expected/gpsc_cursors.out @@ -1,5 +1,5 @@ -CREATE EXTENSION yagp_hooks_collector; -CREATE FUNCTION yagp_status_order(status text) +CREATE EXTENSION gp_stats_collector; +CREATE FUNCTION gpsc_status_order(status text) RETURNS integer AS $$ BEGIN @@ -12,18 +12,18 @@ BEGIN END; END; $$ LANGUAGE plpgsql IMMUTABLE; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.enable_utility TO TRUE; -SET yagpcc.report_nested_queries TO TRUE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.enable_utility TO TRUE; +SET gpsc.report_nested_queries TO TRUE; -- DECLARE -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; BEGIN; DECLARE cursor_stats_0 CURSOR FOR SELECT 0; CLOSE cursor_stats_0; COMMIT; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+---------------------------------------------+--------------------- -1 | BEGIN; | QUERY_STATUS_SUBMIT @@ -34,25 +34,25 @@ SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND util -1 | CLOSE cursor_stats_0; | QUERY_STATUS_DONE -1 | COMMIT; | QUERY_STATUS_SUBMIT -1 | COMMIT; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (10 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- DECLARE WITH HOLD -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; BEGIN; DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 1; CLOSE cursor_stats_1; DECLARE cursor_stats_2 CURSOR WITH HOLD FOR SELECT 2; CLOSE cursor_stats_2; COMMIT; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+-------------------------------------------------------+--------------------- -1 | BEGIN; | QUERY_STATUS_SUBMIT @@ -67,24 +67,24 @@ SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND util -1 | CLOSE cursor_stats_2; | QUERY_STATUS_DONE -1 | COMMIT; | QUERY_STATUS_SUBMIT -1 | COMMIT; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (14 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- ROLLBACK -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; BEGIN; DECLARE cursor_stats_3 CURSOR FOR SELECT 1; CLOSE cursor_stats_3; DECLARE cursor_stats_4 CURSOR FOR SELECT 1; ROLLBACK; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+---------------------------------------------+--------------------- -1 | BEGIN; | QUERY_STATUS_SUBMIT @@ -97,17 +97,17 @@ SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND util -1 | DECLARE cursor_stats_4 CURSOR FOR SELECT 1; | QUERY_STATUS_DONE -1 | ROLLBACK; | QUERY_STATUS_SUBMIT -1 | ROLLBACK; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (12 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- FETCH -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; BEGIN; DECLARE cursor_stats_5 CURSOR WITH HOLD FOR SELECT 2; DECLARE cursor_stats_6 CURSOR WITH HOLD FOR SELECT 3; @@ -126,8 +126,8 @@ FETCH 1 IN cursor_stats_6; CLOSE cursor_stats_5; CLOSE cursor_stats_6; COMMIT; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+-------------------------------------------------------+--------------------- -1 | BEGIN; | QUERY_STATUS_SUBMIT @@ -146,18 +146,18 @@ SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND util -1 | CLOSE cursor_stats_6; | QUERY_STATUS_DONE -1 | COMMIT; | QUERY_STATUS_SUBMIT -1 | COMMIT; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (18 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -DROP FUNCTION yagp_status_order(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.report_nested_queries; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/yagp_hooks_collector/expected/yagp_dist.out b/gpcontrib/gp_stats_collector/expected/gpsc_dist.out similarity index 81% rename from gpcontrib/yagp_hooks_collector/expected/yagp_dist.out rename to gpcontrib/gp_stats_collector/expected/gpsc_dist.out index 3b1e3504923..92e8678767b 100644 --- a/gpcontrib/yagp_hooks_collector/expected/yagp_dist.out +++ b/gpcontrib/gp_stats_collector/expected/gpsc_dist.out @@ -1,5 +1,5 @@ -CREATE EXTENSION yagp_hooks_collector; -CREATE OR REPLACE FUNCTION yagp_status_order(status text) +CREATE EXTENSION gp_stats_collector; +CREATE OR REPLACE FUNCTION gpsc_status_order(status text) RETURNS integer AS $$ BEGIN @@ -12,14 +12,14 @@ BEGIN END; END; $$ LANGUAGE plpgsql IMMUTABLE; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.report_nested_queries TO TRUE; -SET yagpcc.enable_utility TO FALSE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.report_nested_queries TO TRUE; +SET gpsc.enable_utility TO FALSE; -- Hash distributed table CREATE TABLE test_hash_dist (id int) DISTRIBUTED BY (id); INSERT INTO test_hash_dist SELECT 1; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; SET optimizer_enable_direct_dispatch TO TRUE; -- Direct dispatch is used here, only one segment is scanned. select * from test_hash_dist where id = 1; @@ -29,9 +29,9 @@ select * from test_hash_dist where id = 1; (1 row) RESET optimizer_enable_direct_dispatch; -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; -- Should see 8 rows. -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+--------------------------------------------+--------------------- -1 | select * from test_hash_dist where id = 1; | QUERY_STATUS_SUBMIT @@ -44,12 +44,12 @@ SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yag 1 | | QUERY_STATUS_DONE (8 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; -- Scan all segments. select * from test_hash_dist; id @@ -58,8 +58,8 @@ select * from test_hash_dist; (1 row) DROP TABLE test_hash_dist; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+-------------------------------+--------------------- -1 | select * from test_hash_dist; | QUERY_STATUS_SUBMIT @@ -80,7 +80,7 @@ SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yag | | QUERY_STATUS_DONE (16 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) @@ -93,7 +93,7 @@ END; $$ LANGUAGE plpgsql VOLATILE EXECUTE ON ALL SEGMENTS; CREATE TABLE test_replicated (id int) DISTRIBUTED REPLICATED; INSERT INTO test_replicated SELECT 1; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; SELECT COUNT(*) FROM test_replicated, force_segments(); count ------- @@ -102,8 +102,8 @@ SELECT COUNT(*) FROM test_replicated, force_segments(); DROP TABLE test_replicated; DROP FUNCTION force_segments(); -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+---------------------------------------------------------+--------------------- -1 | SELECT COUNT(*) FROM test_replicated, force_segments(); | QUERY_STATUS_SUBMIT @@ -124,7 +124,7 @@ SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yag | | QUERY_STATUS_DONE (16 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) @@ -134,18 +134,18 @@ SET allow_system_table_mods = ON; CREATE TABLE test_partial_dist (id int, data text) DISTRIBUTED BY (id); UPDATE gp_distribution_policy SET numsegments = 2 WHERE localoid = 'test_partial_dist'::regclass; INSERT INTO test_partial_dist SELECT * FROM generate_series(1, 100); -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; SELECT COUNT(*) FROM test_partial_dist; count ------- 100 (1 row) -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; DROP TABLE test_partial_dist; RESET allow_system_table_mods; -- Should see 12 rows. -SELECT query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +SELECT query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; query_text | query_status -----------------------------------------+--------------------- SELECT COUNT(*) FROM test_partial_dist; | QUERY_STATUS_SUBMIT @@ -162,14 +162,14 @@ SELECT query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_statu | QUERY_STATUS_DONE (12 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -DROP FUNCTION yagp_status_order(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.report_nested_queries; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/yagp_hooks_collector/expected/yagp_guc_cache.out b/gpcontrib/gp_stats_collector/expected/gpsc_guc_cache.out similarity index 64% rename from gpcontrib/yagp_hooks_collector/expected/yagp_guc_cache.out rename to gpcontrib/gp_stats_collector/expected/gpsc_guc_cache.out index 3085cfa42e1..11a420839db 100644 --- a/gpcontrib/yagp_hooks_collector/expected/yagp_guc_cache.out +++ b/gpcontrib/gp_stats_collector/expected/gpsc_guc_cache.out @@ -8,23 +8,23 @@ -- have its DONE event rejected, creating orphaned SUBMIT entries. -- This is due to query being actually executed between SUBMIT and DONE. -- start_ignore -CREATE EXTENSION IF NOT EXISTS yagp_hooks_collector; -SELECT yagpcc.truncate_log(); +CREATE EXTENSION IF NOT EXISTS gp_stats_collector; +SELECT gpsc.truncate_log(); -- end_ignore CREATE OR REPLACE FUNCTION print_last_query(query text) RETURNS TABLE(query_status text) AS $$ SELECT query_status - FROM yagpcc.log + FROM gpsc.log WHERE segid = -1 AND query_text = query ORDER BY ccnt DESC $$ LANGUAGE sql; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.enable_utility TO TRUE; -SET yagpcc.logging_mode TO 'TBL'; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.enable_utility TO TRUE; +SET gpsc.logging_mode TO 'TBL'; -- SET below disables utility logging and DONE must still be logged. -SET yagpcc.enable_utility TO FALSE; -SELECT * FROM print_last_query('SET yagpcc.enable_utility TO FALSE;'); +SET gpsc.enable_utility TO FALSE; +SELECT * FROM print_last_query('SET gpsc.enable_utility TO FALSE;'); query_status --------------------- QUERY_STATUS_SUBMIT @@ -33,14 +33,14 @@ SELECT * FROM print_last_query('SET yagpcc.enable_utility TO FALSE;'); -- SELECT below adds current user to ignore list and DONE must still be logged. -- start_ignore -SELECT set_config('yagpcc.ignored_users_list', current_user, false); +SELECT set_config('gpsc.ignored_users_list', current_user, false); set_config ------------ gpadmin (1 row) -- end_ignore -SELECT * FROM print_last_query('SELECT set_config(''yagpcc.ignored_users_list'', current_user, false);'); +SELECT * FROM print_last_query('SELECT set_config(''gpsc.ignored_users_list'', current_user, false);'); query_status --------------------- QUERY_STATUS_SUBMIT @@ -50,8 +50,8 @@ SELECT * FROM print_last_query('SELECT set_config(''yagpcc.ignored_users_list'', (4 rows) DROP FUNCTION print_last_query(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; -RESET yagpcc.logging_mode; +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; +RESET gpsc.logging_mode; diff --git a/gpcontrib/gp_stats_collector/expected/gpsc_locale.out b/gpcontrib/gp_stats_collector/expected/gpsc_locale.out new file mode 100644 index 00000000000..a01fe0648b9 --- /dev/null +++ b/gpcontrib/gp_stats_collector/expected/gpsc_locale.out @@ -0,0 +1,23 @@ +-- The extension generates normalized query text and plan using jumbling functions. +-- Those functions may fail when translating to wide character if the current locale +-- cannot handle the character set. This test checks that even when those functions +-- fail, the plan is still generated and executed. This test is partially taken from +-- gp_locale. +-- start_ignore +DROP DATABASE IF EXISTS gpsc_test_locale; +-- end_ignore +CREATE DATABASE gpsc_test_locale WITH LC_COLLATE='C' LC_CTYPE='C' TEMPLATE=template0; +\c gpsc_test_locale +CREATE EXTENSION gp_stats_collector; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable_utility TO TRUE; +SET gpsc.enable TO TRUE; +CREATE TABLE gpsc_hi_안녕세계 (a int, 안녕세계1 text, 안녕세계2 text, 안녕세계3 text) DISTRIBUTED BY (a); +INSERT INTO gpsc_hi_안녕세계 VALUES(1, '안녕세계1 first', '안녕세2 first', '안녕세계3 first'); +-- Should not see error here +UPDATE gpsc_hi_안녕세계 SET 안녕세계1='안녕세계1 first UPDATE' WHERE 안녕세계1='안녕세계1 first'; +RESET gpsc.enable; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; +DROP TABLE gpsc_hi_안녕세계; +DROP EXTENSION gp_stats_collector; diff --git a/gpcontrib/yagp_hooks_collector/expected/yagp_select.out b/gpcontrib/gp_stats_collector/expected/gpsc_select.out similarity index 67% rename from gpcontrib/yagp_hooks_collector/expected/yagp_select.out rename to gpcontrib/gp_stats_collector/expected/gpsc_select.out index af08f2d1def..3008c8f6d55 100644 --- a/gpcontrib/yagp_hooks_collector/expected/yagp_select.out +++ b/gpcontrib/gp_stats_collector/expected/gpsc_select.out @@ -1,5 +1,5 @@ -CREATE EXTENSION yagp_hooks_collector; -CREATE OR REPLACE FUNCTION yagp_status_order(status text) +CREATE EXTENSION gp_stats_collector; +CREATE OR REPLACE FUNCTION gpsc_status_order(status text) RETURNS integer AS $$ BEGIN @@ -12,12 +12,12 @@ BEGIN END; END; $$ LANGUAGE plpgsql IMMUTABLE; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.report_nested_queries TO TRUE; -SET yagpcc.enable_utility TO FALSE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.report_nested_queries TO TRUE; +SET gpsc.enable_utility TO FALSE; -- Basic SELECT tests -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; SELECT 1; ?column? ---------- @@ -30,8 +30,8 @@ SELECT COUNT(*) FROM generate_series(1,10); 10 (1 row) -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+---------------------------------------------+--------------------- -1 | SELECT 1; | QUERY_STATUS_SUBMIT @@ -44,13 +44,13 @@ SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yag -1 | SELECT COUNT(*) FROM generate_series(1,10); | QUERY_STATUS_DONE (8 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- Transaction test -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; BEGIN; SELECT 1; ?column? @@ -59,8 +59,8 @@ SELECT 1; (1 row) COMMIT; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+------------+--------------------- -1 | SELECT 1; | QUERY_STATUS_SUBMIT @@ -69,13 +69,13 @@ SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yag -1 | SELECT 1; | QUERY_STATUS_DONE (4 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- CTE test -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; WITH t AS (VALUES (1), (2)) SELECT * FROM t; column1 @@ -84,8 +84,8 @@ SELECT * FROM t; 2 (2 rows) -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+-----------------------------+--------------------- -1 | WITH t AS (VALUES (1), (2))+| QUERY_STATUS_SUBMIT @@ -98,13 +98,13 @@ SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yag | SELECT * FROM t; | (4 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- Prepared statement test -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; PREPARE test_stmt AS SELECT 1; EXECUTE test_stmt; ?column? @@ -113,8 +113,8 @@ EXECUTE test_stmt; (1 row) DEALLOCATE test_stmt; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+--------------------------------+--------------------- -1 | PREPARE test_stmt AS SELECT 1; | QUERY_STATUS_SUBMIT @@ -123,14 +123,14 @@ SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yag -1 | PREPARE test_stmt AS SELECT 1; | QUERY_STATUS_DONE (4 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -DROP FUNCTION yagp_status_order(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.report_nested_queries; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/gp_stats_collector/expected/gpsc_uds.out b/gpcontrib/gp_stats_collector/expected/gpsc_uds.out new file mode 100644 index 00000000000..e8bca79e669 --- /dev/null +++ b/gpcontrib/gp_stats_collector/expected/gpsc_uds.out @@ -0,0 +1,42 @@ +-- Test UDS socket +-- start_ignore +CREATE EXTENSION IF NOT EXISTS gp_stats_collector; +-- end_ignore +\set UDS_PATH '/tmp/gpsc_test.sock' +-- Configure extension to send via UDS +SET gpsc.uds_path TO :'UDS_PATH'; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.logging_mode TO 'UDS'; +-- Start receiver +SELECT gpsc.__test_uds_start_server(:'UDS_PATH'); + __test_uds_start_server +------------------------- +(0 rows) + +-- Send +SELECT 1; + ?column? +---------- + 1 +(1 row) + +-- Receive +SELECT gpsc.__test_uds_receive() > 0 as received; + received +---------- + t +(1 row) + +-- Stop receiver +SELECT gpsc.__test_uds_stop_server(); + __test_uds_stop_server +------------------------ +(0 rows) + +-- Cleanup +DROP EXTENSION gp_stats_collector; +RESET gpsc.uds_path; +RESET gpsc.ignored_users_list; +RESET gpsc.enable; +RESET gpsc.logging_mode; diff --git a/gpcontrib/yagp_hooks_collector/expected/yagp_utf8_trim.out b/gpcontrib/gp_stats_collector/expected/gpsc_utf8_trim.out similarity index 65% rename from gpcontrib/yagp_hooks_collector/expected/yagp_utf8_trim.out rename to gpcontrib/gp_stats_collector/expected/gpsc_utf8_trim.out index 9de126dd882..db3949f3152 100644 --- a/gpcontrib/yagp_hooks_collector/expected/yagp_utf8_trim.out +++ b/gpcontrib/gp_stats_collector/expected/gpsc_utf8_trim.out @@ -1,24 +1,24 @@ -CREATE EXTENSION IF NOT EXISTS yagp_hooks_collector; +CREATE EXTENSION IF NOT EXISTS gp_stats_collector; CREATE OR REPLACE FUNCTION get_marked_query(marker TEXT) RETURNS TEXT AS $$ SELECT query_text - FROM yagpcc.log + FROM gpsc.log WHERE query_text LIKE '%' || marker || '%' ORDER BY datetime DESC LIMIT 1 $$ LANGUAGE sql VOLATILE; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; -- Test 1: 1 byte chars -SET yagpcc.max_text_size to 19; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.max_text_size to 19; +SET gpsc.logging_mode to 'TBL'; SELECT /*test1*/ 'HelloWorld'; ?column? ------------ HelloWorld (1 row) -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; SELECT octet_length(get_marked_query('test1')) = 19 AS correct_length; correct_length ---------------- @@ -26,15 +26,15 @@ SELECT octet_length(get_marked_query('test1')) = 19 AS correct_length; (1 row) -- Test 2: 2 byte chars -SET yagpcc.max_text_size to 19; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.max_text_size to 19; +SET gpsc.logging_mode to 'TBL'; SELECT /*test2*/ 'РУССКИЙЯЗЫК'; ?column? ------------- РУССКИЙЯЗЫК (1 row) -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; -- Character 'Р' has two bytes and cut in the middle => not included. SELECT octet_length(get_marked_query('test2')) = 18 AS correct_length; correct_length @@ -43,15 +43,15 @@ SELECT octet_length(get_marked_query('test2')) = 18 AS correct_length; (1 row) -- Test 3: 4 byte chars -SET yagpcc.max_text_size to 21; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.max_text_size to 21; +SET gpsc.logging_mode to 'TBL'; SELECT /*test3*/ '😀'; ?column? ---------- 😀 (1 row) -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; -- Emoji has 4 bytes and cut before the last byte => not included. SELECT octet_length(get_marked_query('test3')) = 18 AS correct_length; correct_length @@ -61,8 +61,8 @@ SELECT octet_length(get_marked_query('test3')) = 18 AS correct_length; -- Cleanup DROP FUNCTION get_marked_query(TEXT); -RESET yagpcc.max_text_size; -RESET yagpcc.logging_mode; -RESET yagpcc.enable; -RESET yagpcc.ignored_users_list; -DROP EXTENSION yagp_hooks_collector; +RESET gpsc.max_text_size; +RESET gpsc.logging_mode; +RESET gpsc.enable; +RESET gpsc.ignored_users_list; +DROP EXTENSION gp_stats_collector; diff --git a/gpcontrib/yagp_hooks_collector/expected/yagp_utility.out b/gpcontrib/gp_stats_collector/expected/gpsc_utility.out similarity index 57% rename from gpcontrib/yagp_hooks_collector/expected/yagp_utility.out rename to gpcontrib/gp_stats_collector/expected/gpsc_utility.out index 7df1d2816eb..e8e28614370 100644 --- a/gpcontrib/yagp_hooks_collector/expected/yagp_utility.out +++ b/gpcontrib/gp_stats_collector/expected/gpsc_utility.out @@ -1,5 +1,5 @@ -CREATE EXTENSION yagp_hooks_collector; -CREATE OR REPLACE FUNCTION yagp_status_order(status text) +CREATE EXTENSION gp_stats_collector; +CREATE OR REPLACE FUNCTION gpsc_status_order(status text) RETURNS integer AS $$ BEGIN @@ -12,19 +12,19 @@ BEGIN END; END; $$ LANGUAGE plpgsql IMMUTABLE; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.enable_utility TO TRUE; -SET yagpcc.report_nested_queries TO TRUE; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.enable_utility TO TRUE; +SET gpsc.report_nested_queries TO TRUE; +SET gpsc.logging_mode to 'TBL'; CREATE TABLE test_table (a int, b text); NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table. HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. CREATE INDEX test_idx ON test_table(a); ALTER TABLE test_table ADD COLUMN c int DEFAULT 1; DROP TABLE test_table; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+----------------------------------------------------+--------------------- -1 | CREATE TABLE test_table (a int, b text); | QUERY_STATUS_SUBMIT @@ -35,24 +35,24 @@ SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND util -1 | ALTER TABLE test_table ADD COLUMN c int DEFAULT 1; | QUERY_STATUS_DONE -1 | DROP TABLE test_table; | QUERY_STATUS_SUBMIT -1 | DROP TABLE test_table; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (10 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- Partitioning -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; CREATE TABLE pt_test (a int, b int) DISTRIBUTED BY (a) PARTITION BY RANGE (a) (START (0) END (100) EVERY (50)); DROP TABLE pt_test; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+-------------------------------------+--------------------- -1 | CREATE TABLE pt_test (a int, b int)+| QUERY_STATUS_SUBMIT @@ -65,23 +65,23 @@ SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND util | (START (0) END (100) EVERY (50)); | -1 | DROP TABLE pt_test; | QUERY_STATUS_SUBMIT -1 | DROP TABLE pt_test; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (6 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- Views and Functions -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; CREATE VIEW test_view AS SELECT 1 AS a; CREATE FUNCTION test_func(i int) RETURNS int AS $$ SELECT $1 + 1; $$ LANGUAGE SQL; DROP VIEW test_view; DROP FUNCTION test_func(int); -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+------------------------------------------------------------------------------------+--------------------- -1 | CREATE VIEW test_view AS SELECT 1 AS a; | QUERY_STATUS_SUBMIT @@ -92,17 +92,17 @@ SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND util -1 | DROP VIEW test_view; | QUERY_STATUS_DONE -1 | DROP FUNCTION test_func(int); | QUERY_STATUS_SUBMIT -1 | DROP FUNCTION test_func(int); | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (10 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- Transaction Operations -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; BEGIN; SAVEPOINT sp1; ROLLBACK TO sp1; @@ -112,37 +112,37 @@ SAVEPOINT sp2; ABORT; BEGIN; ROLLBACK; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; - segid | query_text | query_status --------+----------------------------+--------------------- - -1 | BEGIN; | QUERY_STATUS_SUBMIT - -1 | BEGIN; | QUERY_STATUS_DONE - -1 | SAVEPOINT sp1; | QUERY_STATUS_SUBMIT - -1 | ROLLBACK TO sp1; | QUERY_STATUS_SUBMIT - -1 | ROLLBACK TO sp1; | QUERY_STATUS_DONE - -1 | COMMIT; | QUERY_STATUS_SUBMIT - -1 | COMMIT; | QUERY_STATUS_DONE - -1 | BEGIN; | QUERY_STATUS_SUBMIT - -1 | BEGIN; | QUERY_STATUS_DONE - -1 | SAVEPOINT sp2; | QUERY_STATUS_SUBMIT - -1 | ABORT; | QUERY_STATUS_SUBMIT - -1 | ABORT; | QUERY_STATUS_DONE - -1 | BEGIN; | QUERY_STATUS_SUBMIT - -1 | BEGIN; | QUERY_STATUS_DONE - -1 | ROLLBACK; | QUERY_STATUS_SUBMIT - -1 | ROLLBACK; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+--------------------------+--------------------- + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | SAVEPOINT sp1; | QUERY_STATUS_SUBMIT + -1 | ROLLBACK TO sp1; | QUERY_STATUS_SUBMIT + -1 | ROLLBACK TO sp1; | QUERY_STATUS_DONE + -1 | COMMIT; | QUERY_STATUS_SUBMIT + -1 | COMMIT; | QUERY_STATUS_DONE + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | SAVEPOINT sp2; | QUERY_STATUS_SUBMIT + -1 | ABORT; | QUERY_STATUS_SUBMIT + -1 | ABORT; | QUERY_STATUS_DONE + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | ROLLBACK; | QUERY_STATUS_SUBMIT + -1 | ROLLBACK; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (18 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- DML Operations -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; CREATE TABLE dml_test (a int, b text); NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table. HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. @@ -150,33 +150,33 @@ INSERT INTO dml_test VALUES (1, 'test'); UPDATE dml_test SET b = 'updated' WHERE a = 1; DELETE FROM dml_test WHERE a = 1; DROP TABLE dml_test; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+----------------------------------------+--------------------- -1 | CREATE TABLE dml_test (a int, b text); | QUERY_STATUS_SUBMIT -1 | CREATE TABLE dml_test (a int, b text); | QUERY_STATUS_DONE -1 | DROP TABLE dml_test; | QUERY_STATUS_SUBMIT -1 | DROP TABLE dml_test; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (6 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- COPY Operations -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; CREATE TABLE copy_test (a int); NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table. HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. COPY (SELECT 1) TO STDOUT; 1 DROP TABLE copy_test; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+---------------------------------+--------------------- -1 | CREATE TABLE copy_test (a int); | QUERY_STATUS_SUBMIT @@ -185,23 +185,23 @@ SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND util -1 | COPY (SELECT 1) TO STDOUT; | QUERY_STATUS_DONE -1 | DROP TABLE copy_test; | QUERY_STATUS_SUBMIT -1 | DROP TABLE copy_test; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (8 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- Prepared Statements and error during execute -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; PREPARE test_prep(int) AS SELECT $1/0 AS value; EXECUTE test_prep(0::int); ERROR: division by zero DEALLOCATE test_prep; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; segid | query_text | query_status -------+-------------------------------------------------+--------------------- -1 | PREPARE test_prep(int) AS SELECT $1/0 AS value; | QUERY_STATUS_SUBMIT @@ -210,39 +210,39 @@ SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND util -1 | EXECUTE test_prep(0::int); | QUERY_STATUS_ERROR -1 | DEALLOCATE test_prep; | QUERY_STATUS_SUBMIT -1 | DEALLOCATE test_prep; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (8 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -- GUC Settings -SET yagpcc.logging_mode to 'TBL'; -SET yagpcc.report_nested_queries TO FALSE; -RESET yagpcc.report_nested_queries; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; - segid | query_text | query_status --------+--------------------------------------------+--------------------- - -1 | SET yagpcc.report_nested_queries TO FALSE; | QUERY_STATUS_SUBMIT - -1 | SET yagpcc.report_nested_queries TO FALSE; | QUERY_STATUS_DONE - -1 | RESET yagpcc.report_nested_queries; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.report_nested_queries; | QUERY_STATUS_DONE - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_SUBMIT - -1 | RESET yagpcc.logging_mode; | QUERY_STATUS_DONE +SET gpsc.logging_mode to 'TBL'; +SET gpsc.report_nested_queries TO FALSE; +RESET gpsc.report_nested_queries; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+------------------------------------------+--------------------- + -1 | SET gpsc.report_nested_queries TO FALSE; | QUERY_STATUS_SUBMIT + -1 | SET gpsc.report_nested_queries TO FALSE; | QUERY_STATUS_DONE + -1 | RESET gpsc.report_nested_queries; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.report_nested_queries; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE (6 rows) -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT gpsc.truncate_log() IS NOT NULL AS t; t --- (0 rows) -DROP FUNCTION yagp_status_order(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.report_nested_queries; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/gp_stats_collector/gmon.out b/gpcontrib/gp_stats_collector/gmon.out new file mode 100644 index 00000000000..ad86784f077 Binary files /dev/null and b/gpcontrib/gp_stats_collector/gmon.out differ diff --git a/gpcontrib/gp_stats_collector/gp_stats_collector--1.0--1.1.sql b/gpcontrib/gp_stats_collector/gp_stats_collector--1.0--1.1.sql new file mode 100644 index 00000000000..4e0157117e9 --- /dev/null +++ b/gpcontrib/gp_stats_collector/gp_stats_collector--1.0--1.1.sql @@ -0,0 +1,113 @@ +/* gp_stats_collector--1.0--1.1.sql */ + +-- complain if script is sourced in psql, rather than via ALTER EXTENSION +\echo Use "ALTER EXTENSION gp_stats_collector UPDATE TO '1.1'" to load this file. \quit + +CREATE SCHEMA gpsc; + +-- Unlink existing objects from extension. +ALTER EXTENSION gp_stats_collector DROP VIEW gpsc_stat_messages; +ALTER EXTENSION gp_stats_collector DROP FUNCTION gpsc_stat_messages_reset(); +ALTER EXTENSION gp_stats_collector DROP FUNCTION __gpsc_stat_messages_f_on_segments(); +ALTER EXTENSION gp_stats_collector DROP FUNCTION __gpsc_stat_messages_f_on_master(); +ALTER EXTENSION gp_stats_collector DROP FUNCTION __gpsc_stat_messages_reset_f_on_segments(); +ALTER EXTENSION gp_stats_collector DROP FUNCTION __gpsc_stat_messages_reset_f_on_master(); + +-- Now drop the objects. +DROP VIEW gpsc_stat_messages; +DROP FUNCTION gpsc_stat_messages_reset(); +DROP FUNCTION __gpsc_stat_messages_f_on_segments(); +DROP FUNCTION __gpsc_stat_messages_f_on_master(); +DROP FUNCTION __gpsc_stat_messages_reset_f_on_segments(); +DROP FUNCTION __gpsc_stat_messages_reset_f_on_master(); + +-- Recreate functions and view in new schema. +CREATE FUNCTION gpsc.__stat_messages_reset_f_on_master() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_stat_messages_reset' +LANGUAGE C EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__stat_messages_reset_f_on_segments() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_stat_messages_reset' +LANGUAGE C EXECUTE ON ALL SEGMENTS; + +CREATE FUNCTION gpsc.stat_messages_reset() +RETURNS SETOF void +AS +$$ + SELECT gpsc.__stat_messages_reset_f_on_master(); + SELECT gpsc.__stat_messages_reset_f_on_segments(); +$$ +LANGUAGE SQL EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__stat_messages_f_on_master() +RETURNS SETOF record +AS 'MODULE_PATHNAME', 'gpsc_stat_messages' +LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__stat_messages_f_on_segments() +RETURNS SETOF record +AS 'MODULE_PATHNAME', 'gpsc_stat_messages' +LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; + +CREATE VIEW gpsc.stat_messages AS + SELECT C.* + FROM gpsc.__stat_messages_f_on_master() as C ( + segid int, + total_messages bigint, + send_failures bigint, + connection_failures bigint, + other_errors bigint, + max_message_size int + ) + UNION ALL + SELECT C.* + FROM gpsc.__stat_messages_f_on_segments() as C ( + segid int, + total_messages bigint, + send_failures bigint, + connection_failures bigint, + other_errors bigint, + max_message_size int + ) +ORDER BY segid; + +-- Create new objects. +CREATE FUNCTION gpsc.__init_log_on_master() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_init_log' +LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__init_log_on_segments() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_init_log' +LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; + +-- Creates log table inside gpsc schema. +SELECT gpsc.__init_log_on_master(); +SELECT gpsc.__init_log_on_segments(); + +CREATE VIEW gpsc.log AS + SELECT * FROM gpsc.__log -- master + UNION ALL + SELECT * FROM gp_dist_random('gpsc.__log') -- segments + ORDER BY tmid, ssid, ccnt; + +CREATE FUNCTION gpsc.__truncate_log_on_master() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_truncate_log' +LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__truncate_log_on_segments() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_truncate_log' +LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; + +CREATE FUNCTION gpsc.truncate_log() +RETURNS SETOF void AS $$ +BEGIN + PERFORM gpsc.__truncate_log_on_master(); + PERFORM gpsc.__truncate_log_on_segments(); +END; +$$ LANGUAGE plpgsql VOLATILE; diff --git a/gpcontrib/gp_stats_collector/gp_stats_collector--1.0.sql b/gpcontrib/gp_stats_collector/gp_stats_collector--1.0.sql new file mode 100644 index 00000000000..ec902b02e02 --- /dev/null +++ b/gpcontrib/gp_stats_collector/gp_stats_collector--1.0.sql @@ -0,0 +1,55 @@ +/* gp_stats_collector--1.0.sql */ + +-- complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION gp_stats_collector" to load this file. \quit + +CREATE FUNCTION __gpsc_stat_messages_reset_f_on_master() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_stat_messages_reset' +LANGUAGE C EXECUTE ON MASTER; + +CREATE FUNCTION __gpsc_stat_messages_reset_f_on_segments() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_stat_messages_reset' +LANGUAGE C EXECUTE ON ALL SEGMENTS; + +CREATE FUNCTION gpsc_stat_messages_reset() +RETURNS SETOF void +AS +$$ + SELECT __gpsc_stat_messages_reset_f_on_master(); + SELECT __gpsc_stat_messages_reset_f_on_segments(); +$$ +LANGUAGE SQL EXECUTE ON MASTER; + +CREATE FUNCTION __gpsc_stat_messages_f_on_master() +RETURNS SETOF record +AS 'MODULE_PATHNAME', 'gpsc_stat_messages' +LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; + +CREATE FUNCTION __gpsc_stat_messages_f_on_segments() +RETURNS SETOF record +AS 'MODULE_PATHNAME', 'gpsc_stat_messages' +LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; + +CREATE VIEW gpsc_stat_messages AS + SELECT C.* + FROM __gpsc_stat_messages_f_on_master() as C ( + segid int, + total_messages bigint, + send_failures bigint, + connection_failures bigint, + other_errors bigint, + max_message_size int + ) + UNION ALL + SELECT C.* + FROM __gpsc_stat_messages_f_on_segments() as C ( + segid int, + total_messages bigint, + send_failures bigint, + connection_failures bigint, + other_errors bigint, + max_message_size int + ) +ORDER BY segid; diff --git a/gpcontrib/gp_stats_collector/gp_stats_collector--1.1.sql b/gpcontrib/gp_stats_collector/gp_stats_collector--1.1.sql new file mode 100644 index 00000000000..6e24207e913 --- /dev/null +++ b/gpcontrib/gp_stats_collector/gp_stats_collector--1.1.sql @@ -0,0 +1,110 @@ +/* gp_stats_collector--1.1.sql */ + +-- complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION gp_stats_collector" to load this file. \quit + +CREATE SCHEMA gpsc; + +CREATE FUNCTION gpsc.__stat_messages_reset_f_on_master() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_stat_messages_reset' +LANGUAGE C EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__stat_messages_reset_f_on_segments() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_stat_messages_reset' +LANGUAGE C EXECUTE ON ALL SEGMENTS; + +CREATE FUNCTION gpsc.stat_messages_reset() +RETURNS SETOF void +AS +$$ + SELECT gpsc.__stat_messages_reset_f_on_master(); + SELECT gpsc.__stat_messages_reset_f_on_segments(); +$$ +LANGUAGE SQL EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__stat_messages_f_on_master() +RETURNS SETOF record +AS 'MODULE_PATHNAME', 'gpsc_stat_messages' +LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__stat_messages_f_on_segments() +RETURNS SETOF record +AS 'MODULE_PATHNAME', 'gpsc_stat_messages' +LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; + +CREATE VIEW gpsc.stat_messages AS + SELECT C.* + FROM gpsc.__stat_messages_f_on_master() as C ( + segid int, + total_messages bigint, + send_failures bigint, + connection_failures bigint, + other_errors bigint, + max_message_size int + ) + UNION ALL + SELECT C.* + FROM gpsc.__stat_messages_f_on_segments() as C ( + segid int, + total_messages bigint, + send_failures bigint, + connection_failures bigint, + other_errors bigint, + max_message_size int + ) +ORDER BY segid; + +CREATE FUNCTION gpsc.__init_log_on_master() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_init_log' +LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__init_log_on_segments() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_init_log' +LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; + +-- Creates log table inside gpsc schema. +SELECT gpsc.__init_log_on_master(); +SELECT gpsc.__init_log_on_segments(); + +CREATE VIEW gpsc.log AS + SELECT * FROM gpsc.__log -- master + UNION ALL + SELECT * FROM gp_dist_random('gpsc.__log') -- segments +ORDER BY tmid, ssid, ccnt; + +CREATE FUNCTION gpsc.__truncate_log_on_master() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_truncate_log' +LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__truncate_log_on_segments() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_truncate_log' +LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; + +CREATE FUNCTION gpsc.truncate_log() +RETURNS SETOF void AS $$ +BEGIN + PERFORM gpsc.__truncate_log_on_master(); + PERFORM gpsc.__truncate_log_on_segments(); +END; +$$ LANGUAGE plpgsql VOLATILE; + +CREATE FUNCTION gpsc.__test_uds_start_server(path text) +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_test_uds_start_server' +LANGUAGE C STRICT EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__test_uds_receive(timeout_ms int DEFAULT 2000) +RETURNS SETOF bigint +AS 'MODULE_PATHNAME', 'gpsc_test_uds_receive' +LANGUAGE C STRICT EXECUTE ON MASTER; + +CREATE FUNCTION gpsc.__test_uds_stop_server() +RETURNS SETOF void +AS 'MODULE_PATHNAME', 'gpsc_test_uds_stop_server' +LANGUAGE C EXECUTE ON MASTER; diff --git a/gpcontrib/gp_stats_collector/gp_stats_collector.control b/gpcontrib/gp_stats_collector/gp_stats_collector.control new file mode 100644 index 00000000000..4aea2bd49b8 --- /dev/null +++ b/gpcontrib/gp_stats_collector/gp_stats_collector.control @@ -0,0 +1,5 @@ +# gp_stats_collector extension +comment = 'Intercept query and plan execution hooks and report them to Cloudberry monitor agents' +default_version = '1.1' +module_pathname = '$libdir/gp_stats_collector' +superuser = true diff --git a/gpcontrib/yagp_hooks_collector/metric.md b/gpcontrib/gp_stats_collector/metric.md similarity index 94% rename from gpcontrib/yagp_hooks_collector/metric.md rename to gpcontrib/gp_stats_collector/metric.md index 5df56877edb..6f168d8cd98 100644 --- a/gpcontrib/yagp_hooks_collector/metric.md +++ b/gpcontrib/gp_stats_collector/metric.md @@ -1,4 +1,23 @@ -## YAGP Hooks Collector Metrics + + +## GP Stats Collector Metrics ### States A Postgres process goes through 4 executor functions to execute a query: @@ -7,7 +26,7 @@ A Postgres process goes through 4 executor functions to execute a query: 3) `ExecutorFinish()` - cleanup. 4) `ExecutorEnd()` - cleanup. -yagp-hooks-collector sends messages with 4 states, from _Dispatcher_ and/or _Execute_ processes: `submit`, `start`, `end`, `done`, in this order: +gp-stats-collector sends messages with 4 states, from _Dispatcher_ and/or _Execute_ processes: `submit`, `start`, `end`, `done`, in this order: ``` submit -> ExecutorStart() -> start -> ExecutorRun() -> ExecutorFinish() -> end -> ExecutorEnd() -> done ``` @@ -67,8 +86,8 @@ submit -> ExecutorStart() -> start -> ExecutorRun() -> ExecutorFinish() -> end - | `temp_blks_written` | uint64 | E, D | ABS | + | Node | + | + | blocks | Temp file blocks written | | `blk_read_time` | double | E, D | ABS | + | Node | + | + | seconds | Time reading data blocks | | `blk_write_time` | double | E, D | ABS | + | Node | + | + | seconds | Time writing data blocks | -| `inherited_calls` | uint64 | E, D | ABS | - | Node | + | + | count | Nested query count (YAGPCC-specific) | -| `inherited_time` | double | E, D | ABS | - | Node | + | + | seconds | Nested query time (YAGPCC-specific) | +| `inherited_calls` | uint64 | E, D | ABS | - | Node | + | + | count | Nested query count (GPSC-specific) | +| `inherited_time` | double | E, D | ABS | - | Node | + | + | seconds | Nested query time (GPSC-specific) | | **NetworkStat (sent)** | | | | | | | | | | | `sent.total_bytes` | uint32 | D | ABS | - | Node | + | + | bytes | Bytes sent, including headers | | `sent.tuple_bytes` | uint32 | D | ABS | - | Node | + | + | bytes | Bytes of pure tuple-data sent | diff --git a/gpcontrib/yagp_hooks_collector/protos/yagpcc_metrics.proto b/gpcontrib/gp_stats_collector/protos/gpsc_metrics.proto similarity index 97% rename from gpcontrib/yagp_hooks_collector/protos/yagpcc_metrics.proto rename to gpcontrib/gp_stats_collector/protos/gpsc_metrics.proto index 91ac0c4941a..a9e26471839 100644 --- a/gpcontrib/yagp_hooks_collector/protos/yagpcc_metrics.proto +++ b/gpcontrib/gp_stats_collector/protos/gpsc_metrics.proto @@ -1,8 +1,6 @@ syntax = "proto3"; -package yagpcc; -option java_outer_classname = "SegmentYAGPCCM"; -option go_package = "a.yandex-team.ru/cloud/mdb/yagpcc/api/proto/common;greenplum"; +package gpsc; enum QueryStatus { QUERY_STATUS_UNSPECIFIED = 0; diff --git a/gpcontrib/yagp_hooks_collector/protos/yagpcc_plan.proto b/gpcontrib/gp_stats_collector/protos/gpsc_plan.proto similarity index 98% rename from gpcontrib/yagp_hooks_collector/protos/yagpcc_plan.proto rename to gpcontrib/gp_stats_collector/protos/gpsc_plan.proto index 962fab4bbdd..5a7269edd20 100644 --- a/gpcontrib/yagp_hooks_collector/protos/yagpcc_plan.proto +++ b/gpcontrib/gp_stats_collector/protos/gpsc_plan.proto @@ -1,8 +1,6 @@ syntax = "proto3"; -package yagpcc; -option java_outer_classname = "SegmentYAGPCCP"; -option go_package = "a.yandex-team.ru/cloud/mdb/yagpcc/api/proto/common;greenplum"; +package gpsc; message MetricPlan { GpdbNodeType type = 1; diff --git a/gpcontrib/yagp_hooks_collector/protos/yagpcc_set_service.proto b/gpcontrib/gp_stats_collector/protos/gpsc_set_service.proto similarity index 86% rename from gpcontrib/yagp_hooks_collector/protos/yagpcc_set_service.proto rename to gpcontrib/gp_stats_collector/protos/gpsc_set_service.proto index 0b9e34df49d..4cd795424ab 100644 --- a/gpcontrib/yagp_hooks_collector/protos/yagpcc_set_service.proto +++ b/gpcontrib/gp_stats_collector/protos/gpsc_set_service.proto @@ -2,12 +2,10 @@ syntax = "proto3"; import "google/protobuf/timestamp.proto"; -import "protos/yagpcc_metrics.proto"; -import "protos/yagpcc_plan.proto"; +import "protos/gpsc_metrics.proto"; +import "protos/gpsc_plan.proto"; -package yagpcc; -option java_outer_classname = "SegmentYAGPCCAS"; -option go_package = "a.yandex-team.ru/cloud/mdb/yagpcc/api/proto/agent_segment;greenplum"; +package gpsc; service SetQueryInfo { rpc SetMetricPlanNode (SetPlanNodeReq) returns (MetricResponse) {} diff --git a/gpcontrib/gp_stats_collector/results/gpsc_cursors.out b/gpcontrib/gp_stats_collector/results/gpsc_cursors.out new file mode 100644 index 00000000000..282d9ac49e1 --- /dev/null +++ b/gpcontrib/gp_stats_collector/results/gpsc_cursors.out @@ -0,0 +1,163 @@ +CREATE EXTENSION gp_stats_collector; +CREATE FUNCTION gpsc_status_order(status text) +RETURNS integer +AS $$ +BEGIN + RETURN CASE status + WHEN 'QUERY_STATUS_SUBMIT' THEN 1 + WHEN 'QUERY_STATUS_START' THEN 2 + WHEN 'QUERY_STATUS_END' THEN 3 + WHEN 'QUERY_STATUS_DONE' THEN 4 + ELSE 999 + END; +END; +$$ LANGUAGE plpgsql IMMUTABLE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.enable_utility TO TRUE; +SET gpsc.report_nested_queries TO TRUE; +-- DECLARE +SET gpsc.logging_mode to 'TBL'; +BEGIN; +DECLARE cursor_stats_0 CURSOR FOR SELECT 0; +CLOSE cursor_stats_0; +COMMIT; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+---------------------------------------------+--------------------- + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | DECLARE cursor_stats_0 CURSOR FOR SELECT 0; | QUERY_STATUS_SUBMIT + -1 | DECLARE cursor_stats_0 CURSOR FOR SELECT 0; | QUERY_STATUS_DONE + -1 | CLOSE cursor_stats_0; | QUERY_STATUS_SUBMIT + -1 | CLOSE cursor_stats_0; | QUERY_STATUS_DONE + -1 | COMMIT; | QUERY_STATUS_SUBMIT + -1 | COMMIT; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(10 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- DECLARE WITH HOLD +SET gpsc.logging_mode to 'TBL'; +BEGIN; +DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 1; +CLOSE cursor_stats_1; +DECLARE cursor_stats_2 CURSOR WITH HOLD FOR SELECT 2; +CLOSE cursor_stats_2; +COMMIT; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+-------------------------------------------------------+--------------------- + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 1; | QUERY_STATUS_SUBMIT + -1 | DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 1; | QUERY_STATUS_DONE + -1 | CLOSE cursor_stats_1; | QUERY_STATUS_SUBMIT + -1 | CLOSE cursor_stats_1; | QUERY_STATUS_DONE + -1 | DECLARE cursor_stats_2 CURSOR WITH HOLD FOR SELECT 2; | QUERY_STATUS_SUBMIT + -1 | DECLARE cursor_stats_2 CURSOR WITH HOLD FOR SELECT 2; | QUERY_STATUS_DONE + -1 | CLOSE cursor_stats_2; | QUERY_STATUS_SUBMIT + -1 | CLOSE cursor_stats_2; | QUERY_STATUS_DONE + -1 | COMMIT; | QUERY_STATUS_SUBMIT + -1 | COMMIT; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(14 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- ROLLBACK +SET gpsc.logging_mode to 'TBL'; +BEGIN; +DECLARE cursor_stats_3 CURSOR FOR SELECT 1; +CLOSE cursor_stats_3; +DECLARE cursor_stats_4 CURSOR FOR SELECT 1; +ROLLBACK; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+---------------------------------------------+--------------------- + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | DECLARE cursor_stats_3 CURSOR FOR SELECT 1; | QUERY_STATUS_SUBMIT + -1 | DECLARE cursor_stats_3 CURSOR FOR SELECT 1; | QUERY_STATUS_DONE + -1 | CLOSE cursor_stats_3; | QUERY_STATUS_SUBMIT + -1 | CLOSE cursor_stats_3; | QUERY_STATUS_DONE + -1 | DECLARE cursor_stats_4 CURSOR FOR SELECT 1; | QUERY_STATUS_SUBMIT + -1 | DECLARE cursor_stats_4 CURSOR FOR SELECT 1; | QUERY_STATUS_DONE + -1 | ROLLBACK; | QUERY_STATUS_SUBMIT + -1 | ROLLBACK; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(12 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- FETCH +SET gpsc.logging_mode to 'TBL'; +BEGIN; +DECLARE cursor_stats_5 CURSOR WITH HOLD FOR SELECT 2; +DECLARE cursor_stats_6 CURSOR WITH HOLD FOR SELECT 3; +FETCH 1 IN cursor_stats_5; + ?column? +---------- + 2 +(1 row) + +FETCH 1 IN cursor_stats_6; + ?column? +---------- + 3 +(1 row) + +CLOSE cursor_stats_5; +CLOSE cursor_stats_6; +COMMIT; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+-------------------------------------------------------+--------------------- + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | DECLARE cursor_stats_5 CURSOR WITH HOLD FOR SELECT 2; | QUERY_STATUS_SUBMIT + -1 | DECLARE cursor_stats_5 CURSOR WITH HOLD FOR SELECT 2; | QUERY_STATUS_DONE + -1 | DECLARE cursor_stats_6 CURSOR WITH HOLD FOR SELECT 3; | QUERY_STATUS_SUBMIT + -1 | DECLARE cursor_stats_6 CURSOR WITH HOLD FOR SELECT 3; | QUERY_STATUS_DONE + -1 | FETCH 1 IN cursor_stats_5; | QUERY_STATUS_SUBMIT + -1 | FETCH 1 IN cursor_stats_5; | QUERY_STATUS_DONE + -1 | FETCH 1 IN cursor_stats_6; | QUERY_STATUS_SUBMIT + -1 | FETCH 1 IN cursor_stats_6; | QUERY_STATUS_DONE + -1 | CLOSE cursor_stats_5; | QUERY_STATUS_SUBMIT + -1 | CLOSE cursor_stats_5; | QUERY_STATUS_DONE + -1 | CLOSE cursor_stats_6; | QUERY_STATUS_SUBMIT + -1 | CLOSE cursor_stats_6; | QUERY_STATUS_DONE + -1 | COMMIT; | QUERY_STATUS_SUBMIT + -1 | COMMIT; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(18 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/gp_stats_collector/results/gpsc_dist.out b/gpcontrib/gp_stats_collector/results/gpsc_dist.out new file mode 100644 index 00000000000..92e8678767b --- /dev/null +++ b/gpcontrib/gp_stats_collector/results/gpsc_dist.out @@ -0,0 +1,175 @@ +CREATE EXTENSION gp_stats_collector; +CREATE OR REPLACE FUNCTION gpsc_status_order(status text) +RETURNS integer +AS $$ +BEGIN + RETURN CASE status + WHEN 'QUERY_STATUS_SUBMIT' THEN 1 + WHEN 'QUERY_STATUS_START' THEN 2 + WHEN 'QUERY_STATUS_END' THEN 3 + WHEN 'QUERY_STATUS_DONE' THEN 4 + ELSE 999 + END; +END; +$$ LANGUAGE plpgsql IMMUTABLE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.report_nested_queries TO TRUE; +SET gpsc.enable_utility TO FALSE; +-- Hash distributed table +CREATE TABLE test_hash_dist (id int) DISTRIBUTED BY (id); +INSERT INTO test_hash_dist SELECT 1; +SET gpsc.logging_mode to 'TBL'; +SET optimizer_enable_direct_dispatch TO TRUE; +-- Direct dispatch is used here, only one segment is scanned. +select * from test_hash_dist where id = 1; + id +---- + 1 +(1 row) + +RESET optimizer_enable_direct_dispatch; +RESET gpsc.logging_mode; +-- Should see 8 rows. +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+--------------------------------------------+--------------------- + -1 | select * from test_hash_dist where id = 1; | QUERY_STATUS_SUBMIT + -1 | select * from test_hash_dist where id = 1; | QUERY_STATUS_START + -1 | select * from test_hash_dist where id = 1; | QUERY_STATUS_END + -1 | select * from test_hash_dist where id = 1; | QUERY_STATUS_DONE + 1 | | QUERY_STATUS_SUBMIT + 1 | | QUERY_STATUS_START + 1 | | QUERY_STATUS_END + 1 | | QUERY_STATUS_DONE +(8 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +SET gpsc.logging_mode to 'TBL'; +-- Scan all segments. +select * from test_hash_dist; + id +---- + 1 +(1 row) + +DROP TABLE test_hash_dist; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+-------------------------------+--------------------- + -1 | select * from test_hash_dist; | QUERY_STATUS_SUBMIT + -1 | select * from test_hash_dist; | QUERY_STATUS_START + -1 | select * from test_hash_dist; | QUERY_STATUS_END + -1 | select * from test_hash_dist; | QUERY_STATUS_DONE + 1 | | QUERY_STATUS_SUBMIT + 1 | | QUERY_STATUS_START + 1 | | QUERY_STATUS_END + 1 | | QUERY_STATUS_DONE + 2 | | QUERY_STATUS_SUBMIT + 2 | | QUERY_STATUS_START + 2 | | QUERY_STATUS_END + 2 | | QUERY_STATUS_DONE + | | QUERY_STATUS_SUBMIT + | | QUERY_STATUS_START + | | QUERY_STATUS_END + | | QUERY_STATUS_DONE +(16 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- Replicated table +CREATE FUNCTION force_segments() RETURNS SETOF text AS $$ +BEGIN + RETURN NEXT 'seg'; +END; +$$ LANGUAGE plpgsql VOLATILE EXECUTE ON ALL SEGMENTS; +CREATE TABLE test_replicated (id int) DISTRIBUTED REPLICATED; +INSERT INTO test_replicated SELECT 1; +SET gpsc.logging_mode to 'TBL'; +SELECT COUNT(*) FROM test_replicated, force_segments(); + count +------- + 3 +(1 row) + +DROP TABLE test_replicated; +DROP FUNCTION force_segments(); +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+---------------------------------------------------------+--------------------- + -1 | SELECT COUNT(*) FROM test_replicated, force_segments(); | QUERY_STATUS_SUBMIT + -1 | SELECT COUNT(*) FROM test_replicated, force_segments(); | QUERY_STATUS_START + -1 | SELECT COUNT(*) FROM test_replicated, force_segments(); | QUERY_STATUS_END + -1 | SELECT COUNT(*) FROM test_replicated, force_segments(); | QUERY_STATUS_DONE + 1 | | QUERY_STATUS_SUBMIT + 1 | | QUERY_STATUS_START + 1 | | QUERY_STATUS_END + 1 | | QUERY_STATUS_DONE + 2 | | QUERY_STATUS_SUBMIT + 2 | | QUERY_STATUS_START + 2 | | QUERY_STATUS_END + 2 | | QUERY_STATUS_DONE + | | QUERY_STATUS_SUBMIT + | | QUERY_STATUS_START + | | QUERY_STATUS_END + | | QUERY_STATUS_DONE +(16 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- Partially distributed table (2 numsegments) +SET allow_system_table_mods = ON; +CREATE TABLE test_partial_dist (id int, data text) DISTRIBUTED BY (id); +UPDATE gp_distribution_policy SET numsegments = 2 WHERE localoid = 'test_partial_dist'::regclass; +INSERT INTO test_partial_dist SELECT * FROM generate_series(1, 100); +SET gpsc.logging_mode to 'TBL'; +SELECT COUNT(*) FROM test_partial_dist; + count +------- + 100 +(1 row) + +RESET gpsc.logging_mode; +DROP TABLE test_partial_dist; +RESET allow_system_table_mods; +-- Should see 12 rows. +SELECT query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + query_text | query_status +-----------------------------------------+--------------------- + SELECT COUNT(*) FROM test_partial_dist; | QUERY_STATUS_SUBMIT + SELECT COUNT(*) FROM test_partial_dist; | QUERY_STATUS_START + SELECT COUNT(*) FROM test_partial_dist; | QUERY_STATUS_END + SELECT COUNT(*) FROM test_partial_dist; | QUERY_STATUS_DONE + | QUERY_STATUS_SUBMIT + | QUERY_STATUS_START + | QUERY_STATUS_END + | QUERY_STATUS_DONE + | QUERY_STATUS_SUBMIT + | QUERY_STATUS_START + | QUERY_STATUS_END + | QUERY_STATUS_DONE +(12 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/gp_stats_collector/results/gpsc_guc_cache.out b/gpcontrib/gp_stats_collector/results/gpsc_guc_cache.out new file mode 100644 index 00000000000..19c4774575d --- /dev/null +++ b/gpcontrib/gp_stats_collector/results/gpsc_guc_cache.out @@ -0,0 +1,61 @@ +-- +-- Test GUC caching for query lifecycle consistency. +-- +-- The extension logs SUBMIT and DONE events for each query. +-- GUC values that control logging (enable_utility, ignored_users_list, ...) +-- must be cached at SUBMIT time to ensure DONE uses the same filtering +-- criteria. Otherwise, a SET command that modifies these GUCs would +-- have its DONE event rejected, creating orphaned SUBMIT entries. +-- This is due to query being actually executed between SUBMIT and DONE. +-- start_ignore +CREATE EXTENSION IF NOT EXISTS gp_stats_collector; +SELECT gpsc.truncate_log(); + truncate_log +-------------- +(0 rows) + +-- end_ignore +CREATE OR REPLACE FUNCTION print_last_query(query text) +RETURNS TABLE(query_status text) AS $$ + SELECT query_status + FROM gpsc.log + WHERE segid = -1 AND query_text = query + ORDER BY ccnt DESC +$$ LANGUAGE sql; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.enable_utility TO TRUE; +SET gpsc.logging_mode TO 'TBL'; +-- SET below disables utility logging and DONE must still be logged. +SET gpsc.enable_utility TO FALSE; +SELECT * FROM print_last_query('SET gpsc.enable_utility TO FALSE;'); + query_status +--------------------- + QUERY_STATUS_SUBMIT + QUERY_STATUS_DONE +(2 rows) + +-- SELECT below adds current user to ignore list and DONE must still be logged. +-- start_ignore +SELECT set_config('gpsc.ignored_users_list', current_user, false); + set_config +------------ + gpadmin +(1 row) + +-- end_ignore +SELECT * FROM print_last_query('SELECT set_config(''gpsc.ignored_users_list'', current_user, false);'); + query_status +--------------------- + QUERY_STATUS_SUBMIT + QUERY_STATUS_START + QUERY_STATUS_END + QUERY_STATUS_DONE +(4 rows) + +DROP FUNCTION print_last_query(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; +RESET gpsc.logging_mode; diff --git a/gpcontrib/gp_stats_collector/results/gpsc_locale.out b/gpcontrib/gp_stats_collector/results/gpsc_locale.out new file mode 100644 index 00000000000..a01fe0648b9 --- /dev/null +++ b/gpcontrib/gp_stats_collector/results/gpsc_locale.out @@ -0,0 +1,23 @@ +-- The extension generates normalized query text and plan using jumbling functions. +-- Those functions may fail when translating to wide character if the current locale +-- cannot handle the character set. This test checks that even when those functions +-- fail, the plan is still generated and executed. This test is partially taken from +-- gp_locale. +-- start_ignore +DROP DATABASE IF EXISTS gpsc_test_locale; +-- end_ignore +CREATE DATABASE gpsc_test_locale WITH LC_COLLATE='C' LC_CTYPE='C' TEMPLATE=template0; +\c gpsc_test_locale +CREATE EXTENSION gp_stats_collector; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable_utility TO TRUE; +SET gpsc.enable TO TRUE; +CREATE TABLE gpsc_hi_안녕세계 (a int, 안녕세계1 text, 안녕세계2 text, 안녕세계3 text) DISTRIBUTED BY (a); +INSERT INTO gpsc_hi_안녕세계 VALUES(1, '안녕세계1 first', '안녕세2 first', '안녕세계3 first'); +-- Should not see error here +UPDATE gpsc_hi_안녕세계 SET 안녕세계1='안녕세계1 first UPDATE' WHERE 안녕세계1='안녕세계1 first'; +RESET gpsc.enable; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; +DROP TABLE gpsc_hi_안녕세계; +DROP EXTENSION gp_stats_collector; diff --git a/gpcontrib/gp_stats_collector/results/gpsc_select.out b/gpcontrib/gp_stats_collector/results/gpsc_select.out new file mode 100644 index 00000000000..3008c8f6d55 --- /dev/null +++ b/gpcontrib/gp_stats_collector/results/gpsc_select.out @@ -0,0 +1,136 @@ +CREATE EXTENSION gp_stats_collector; +CREATE OR REPLACE FUNCTION gpsc_status_order(status text) +RETURNS integer +AS $$ +BEGIN + RETURN CASE status + WHEN 'QUERY_STATUS_SUBMIT' THEN 1 + WHEN 'QUERY_STATUS_START' THEN 2 + WHEN 'QUERY_STATUS_END' THEN 3 + WHEN 'QUERY_STATUS_DONE' THEN 4 + ELSE 999 + END; +END; +$$ LANGUAGE plpgsql IMMUTABLE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.report_nested_queries TO TRUE; +SET gpsc.enable_utility TO FALSE; +-- Basic SELECT tests +SET gpsc.logging_mode to 'TBL'; +SELECT 1; + ?column? +---------- + 1 +(1 row) + +SELECT COUNT(*) FROM generate_series(1,10); + count +------- + 10 +(1 row) + +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+---------------------------------------------+--------------------- + -1 | SELECT 1; | QUERY_STATUS_SUBMIT + -1 | SELECT 1; | QUERY_STATUS_START + -1 | SELECT 1; | QUERY_STATUS_END + -1 | SELECT 1; | QUERY_STATUS_DONE + -1 | SELECT COUNT(*) FROM generate_series(1,10); | QUERY_STATUS_SUBMIT + -1 | SELECT COUNT(*) FROM generate_series(1,10); | QUERY_STATUS_START + -1 | SELECT COUNT(*) FROM generate_series(1,10); | QUERY_STATUS_END + -1 | SELECT COUNT(*) FROM generate_series(1,10); | QUERY_STATUS_DONE +(8 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- Transaction test +SET gpsc.logging_mode to 'TBL'; +BEGIN; +SELECT 1; + ?column? +---------- + 1 +(1 row) + +COMMIT; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+------------+--------------------- + -1 | SELECT 1; | QUERY_STATUS_SUBMIT + -1 | SELECT 1; | QUERY_STATUS_START + -1 | SELECT 1; | QUERY_STATUS_END + -1 | SELECT 1; | QUERY_STATUS_DONE +(4 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- CTE test +SET gpsc.logging_mode to 'TBL'; +WITH t AS (VALUES (1), (2)) +SELECT * FROM t; + column1 +--------- + 1 + 2 +(2 rows) + +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+-----------------------------+--------------------- + -1 | WITH t AS (VALUES (1), (2))+| QUERY_STATUS_SUBMIT + | SELECT * FROM t; | + -1 | WITH t AS (VALUES (1), (2))+| QUERY_STATUS_START + | SELECT * FROM t; | + -1 | WITH t AS (VALUES (1), (2))+| QUERY_STATUS_END + | SELECT * FROM t; | + -1 | WITH t AS (VALUES (1), (2))+| QUERY_STATUS_DONE + | SELECT * FROM t; | +(4 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- Prepared statement test +SET gpsc.logging_mode to 'TBL'; +PREPARE test_stmt AS SELECT 1; +EXECUTE test_stmt; + ?column? +---------- + 1 +(1 row) + +DEALLOCATE test_stmt; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+--------------------------------+--------------------- + -1 | PREPARE test_stmt AS SELECT 1; | QUERY_STATUS_SUBMIT + -1 | PREPARE test_stmt AS SELECT 1; | QUERY_STATUS_START + -1 | PREPARE test_stmt AS SELECT 1; | QUERY_STATUS_END + -1 | PREPARE test_stmt AS SELECT 1; | QUERY_STATUS_DONE +(4 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/gp_stats_collector/results/gpsc_uds.out b/gpcontrib/gp_stats_collector/results/gpsc_uds.out new file mode 100644 index 00000000000..e8bca79e669 --- /dev/null +++ b/gpcontrib/gp_stats_collector/results/gpsc_uds.out @@ -0,0 +1,42 @@ +-- Test UDS socket +-- start_ignore +CREATE EXTENSION IF NOT EXISTS gp_stats_collector; +-- end_ignore +\set UDS_PATH '/tmp/gpsc_test.sock' +-- Configure extension to send via UDS +SET gpsc.uds_path TO :'UDS_PATH'; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.logging_mode TO 'UDS'; +-- Start receiver +SELECT gpsc.__test_uds_start_server(:'UDS_PATH'); + __test_uds_start_server +------------------------- +(0 rows) + +-- Send +SELECT 1; + ?column? +---------- + 1 +(1 row) + +-- Receive +SELECT gpsc.__test_uds_receive() > 0 as received; + received +---------- + t +(1 row) + +-- Stop receiver +SELECT gpsc.__test_uds_stop_server(); + __test_uds_stop_server +------------------------ +(0 rows) + +-- Cleanup +DROP EXTENSION gp_stats_collector; +RESET gpsc.uds_path; +RESET gpsc.ignored_users_list; +RESET gpsc.enable; +RESET gpsc.logging_mode; diff --git a/gpcontrib/gp_stats_collector/results/gpsc_utf8_trim.out b/gpcontrib/gp_stats_collector/results/gpsc_utf8_trim.out new file mode 100644 index 00000000000..db3949f3152 --- /dev/null +++ b/gpcontrib/gp_stats_collector/results/gpsc_utf8_trim.out @@ -0,0 +1,68 @@ +CREATE EXTENSION IF NOT EXISTS gp_stats_collector; +CREATE OR REPLACE FUNCTION get_marked_query(marker TEXT) +RETURNS TEXT AS $$ + SELECT query_text + FROM gpsc.log + WHERE query_text LIKE '%' || marker || '%' + ORDER BY datetime DESC + LIMIT 1 +$$ LANGUAGE sql VOLATILE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +-- Test 1: 1 byte chars +SET gpsc.max_text_size to 19; +SET gpsc.logging_mode to 'TBL'; +SELECT /*test1*/ 'HelloWorld'; + ?column? +------------ + HelloWorld +(1 row) + +RESET gpsc.logging_mode; +SELECT octet_length(get_marked_query('test1')) = 19 AS correct_length; + correct_length +---------------- + t +(1 row) + +-- Test 2: 2 byte chars +SET gpsc.max_text_size to 19; +SET gpsc.logging_mode to 'TBL'; +SELECT /*test2*/ 'РУССКИЙЯЗЫК'; + ?column? +------------- + РУССКИЙЯЗЫК +(1 row) + +RESET gpsc.logging_mode; +-- Character 'Р' has two bytes and cut in the middle => not included. +SELECT octet_length(get_marked_query('test2')) = 18 AS correct_length; + correct_length +---------------- + t +(1 row) + +-- Test 3: 4 byte chars +SET gpsc.max_text_size to 21; +SET gpsc.logging_mode to 'TBL'; +SELECT /*test3*/ '😀'; + ?column? +---------- + 😀 +(1 row) + +RESET gpsc.logging_mode; +-- Emoji has 4 bytes and cut before the last byte => not included. +SELECT octet_length(get_marked_query('test3')) = 18 AS correct_length; + correct_length +---------------- + t +(1 row) + +-- Cleanup +DROP FUNCTION get_marked_query(TEXT); +RESET gpsc.max_text_size; +RESET gpsc.logging_mode; +RESET gpsc.enable; +RESET gpsc.ignored_users_list; +DROP EXTENSION gp_stats_collector; diff --git a/gpcontrib/gp_stats_collector/results/gpsc_utility.out b/gpcontrib/gp_stats_collector/results/gpsc_utility.out new file mode 100644 index 00000000000..e8e28614370 --- /dev/null +++ b/gpcontrib/gp_stats_collector/results/gpsc_utility.out @@ -0,0 +1,248 @@ +CREATE EXTENSION gp_stats_collector; +CREATE OR REPLACE FUNCTION gpsc_status_order(status text) +RETURNS integer +AS $$ +BEGIN + RETURN CASE status + WHEN 'QUERY_STATUS_SUBMIT' THEN 1 + WHEN 'QUERY_STATUS_START' THEN 2 + WHEN 'QUERY_STATUS_END' THEN 3 + WHEN 'QUERY_STATUS_DONE' THEN 4 + ELSE 999 + END; +END; +$$ LANGUAGE plpgsql IMMUTABLE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.enable_utility TO TRUE; +SET gpsc.report_nested_queries TO TRUE; +SET gpsc.logging_mode to 'TBL'; +CREATE TABLE test_table (a int, b text); +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table. +HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. +CREATE INDEX test_idx ON test_table(a); +ALTER TABLE test_table ADD COLUMN c int DEFAULT 1; +DROP TABLE test_table; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+----------------------------------------------------+--------------------- + -1 | CREATE TABLE test_table (a int, b text); | QUERY_STATUS_SUBMIT + -1 | CREATE TABLE test_table (a int, b text); | QUERY_STATUS_DONE + -1 | CREATE INDEX test_idx ON test_table(a); | QUERY_STATUS_SUBMIT + -1 | CREATE INDEX test_idx ON test_table(a); | QUERY_STATUS_DONE + -1 | ALTER TABLE test_table ADD COLUMN c int DEFAULT 1; | QUERY_STATUS_SUBMIT + -1 | ALTER TABLE test_table ADD COLUMN c int DEFAULT 1; | QUERY_STATUS_DONE + -1 | DROP TABLE test_table; | QUERY_STATUS_SUBMIT + -1 | DROP TABLE test_table; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(10 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- Partitioning +SET gpsc.logging_mode to 'TBL'; +CREATE TABLE pt_test (a int, b int) +DISTRIBUTED BY (a) +PARTITION BY RANGE (a) +(START (0) END (100) EVERY (50)); +DROP TABLE pt_test; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+-------------------------------------+--------------------- + -1 | CREATE TABLE pt_test (a int, b int)+| QUERY_STATUS_SUBMIT + | DISTRIBUTED BY (a) +| + | PARTITION BY RANGE (a) +| + | (START (0) END (100) EVERY (50)); | + -1 | CREATE TABLE pt_test (a int, b int)+| QUERY_STATUS_DONE + | DISTRIBUTED BY (a) +| + | PARTITION BY RANGE (a) +| + | (START (0) END (100) EVERY (50)); | + -1 | DROP TABLE pt_test; | QUERY_STATUS_SUBMIT + -1 | DROP TABLE pt_test; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(6 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- Views and Functions +SET gpsc.logging_mode to 'TBL'; +CREATE VIEW test_view AS SELECT 1 AS a; +CREATE FUNCTION test_func(i int) RETURNS int AS $$ SELECT $1 + 1; $$ LANGUAGE SQL; +DROP VIEW test_view; +DROP FUNCTION test_func(int); +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+------------------------------------------------------------------------------------+--------------------- + -1 | CREATE VIEW test_view AS SELECT 1 AS a; | QUERY_STATUS_SUBMIT + -1 | CREATE VIEW test_view AS SELECT 1 AS a; | QUERY_STATUS_DONE + -1 | CREATE FUNCTION test_func(i int) RETURNS int AS $$ SELECT $1 + 1; $$ LANGUAGE SQL; | QUERY_STATUS_SUBMIT + -1 | CREATE FUNCTION test_func(i int) RETURNS int AS $$ SELECT $1 + 1; $$ LANGUAGE SQL; | QUERY_STATUS_DONE + -1 | DROP VIEW test_view; | QUERY_STATUS_SUBMIT + -1 | DROP VIEW test_view; | QUERY_STATUS_DONE + -1 | DROP FUNCTION test_func(int); | QUERY_STATUS_SUBMIT + -1 | DROP FUNCTION test_func(int); | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(10 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- Transaction Operations +SET gpsc.logging_mode to 'TBL'; +BEGIN; +SAVEPOINT sp1; +ROLLBACK TO sp1; +COMMIT; +BEGIN; +SAVEPOINT sp2; +ABORT; +BEGIN; +ROLLBACK; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+--------------------------+--------------------- + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | SAVEPOINT sp1; | QUERY_STATUS_SUBMIT + -1 | ROLLBACK TO sp1; | QUERY_STATUS_SUBMIT + -1 | ROLLBACK TO sp1; | QUERY_STATUS_DONE + -1 | COMMIT; | QUERY_STATUS_SUBMIT + -1 | COMMIT; | QUERY_STATUS_DONE + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | SAVEPOINT sp2; | QUERY_STATUS_SUBMIT + -1 | ABORT; | QUERY_STATUS_SUBMIT + -1 | ABORT; | QUERY_STATUS_DONE + -1 | BEGIN; | QUERY_STATUS_SUBMIT + -1 | BEGIN; | QUERY_STATUS_DONE + -1 | ROLLBACK; | QUERY_STATUS_SUBMIT + -1 | ROLLBACK; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(18 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- DML Operations +SET gpsc.logging_mode to 'TBL'; +CREATE TABLE dml_test (a int, b text); +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table. +HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. +INSERT INTO dml_test VALUES (1, 'test'); +UPDATE dml_test SET b = 'updated' WHERE a = 1; +DELETE FROM dml_test WHERE a = 1; +DROP TABLE dml_test; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+----------------------------------------+--------------------- + -1 | CREATE TABLE dml_test (a int, b text); | QUERY_STATUS_SUBMIT + -1 | CREATE TABLE dml_test (a int, b text); | QUERY_STATUS_DONE + -1 | DROP TABLE dml_test; | QUERY_STATUS_SUBMIT + -1 | DROP TABLE dml_test; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(6 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- COPY Operations +SET gpsc.logging_mode to 'TBL'; +CREATE TABLE copy_test (a int); +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table. +HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. +COPY (SELECT 1) TO STDOUT; +1 +DROP TABLE copy_test; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+---------------------------------+--------------------- + -1 | CREATE TABLE copy_test (a int); | QUERY_STATUS_SUBMIT + -1 | CREATE TABLE copy_test (a int); | QUERY_STATUS_DONE + -1 | COPY (SELECT 1) TO STDOUT; | QUERY_STATUS_SUBMIT + -1 | COPY (SELECT 1) TO STDOUT; | QUERY_STATUS_DONE + -1 | DROP TABLE copy_test; | QUERY_STATUS_SUBMIT + -1 | DROP TABLE copy_test; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(8 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- Prepared Statements and error during execute +SET gpsc.logging_mode to 'TBL'; +PREPARE test_prep(int) AS SELECT $1/0 AS value; +EXECUTE test_prep(0::int); +ERROR: division by zero +DEALLOCATE test_prep; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+-------------------------------------------------+--------------------- + -1 | PREPARE test_prep(int) AS SELECT $1/0 AS value; | QUERY_STATUS_SUBMIT + -1 | PREPARE test_prep(int) AS SELECT $1/0 AS value; | QUERY_STATUS_DONE + -1 | EXECUTE test_prep(0::int); | QUERY_STATUS_SUBMIT + -1 | EXECUTE test_prep(0::int); | QUERY_STATUS_ERROR + -1 | DEALLOCATE test_prep; | QUERY_STATUS_SUBMIT + -1 | DEALLOCATE test_prep; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(8 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +-- GUC Settings +SET gpsc.logging_mode to 'TBL'; +SET gpsc.report_nested_queries TO FALSE; +RESET gpsc.report_nested_queries; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; + segid | query_text | query_status +-------+------------------------------------------+--------------------- + -1 | SET gpsc.report_nested_queries TO FALSE; | QUERY_STATUS_SUBMIT + -1 | SET gpsc.report_nested_queries TO FALSE; | QUERY_STATUS_DONE + -1 | RESET gpsc.report_nested_queries; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.report_nested_queries; | QUERY_STATUS_DONE + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_SUBMIT + -1 | RESET gpsc.logging_mode; | QUERY_STATUS_DONE +(6 rows) + +SELECT gpsc.truncate_log() IS NOT NULL AS t; + t +--- +(0 rows) + +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/gp_stats_collector/sql/gpsc_cursors.sql b/gpcontrib/gp_stats_collector/sql/gpsc_cursors.sql new file mode 100644 index 00000000000..8361f7b678d --- /dev/null +++ b/gpcontrib/gp_stats_collector/sql/gpsc_cursors.sql @@ -0,0 +1,85 @@ +CREATE EXTENSION gp_stats_collector; + +CREATE FUNCTION gpsc_status_order(status text) +RETURNS integer +AS $$ +BEGIN + RETURN CASE status + WHEN 'QUERY_STATUS_SUBMIT' THEN 1 + WHEN 'QUERY_STATUS_START' THEN 2 + WHEN 'QUERY_STATUS_END' THEN 3 + WHEN 'QUERY_STATUS_DONE' THEN 4 + ELSE 999 + END; +END; +$$ LANGUAGE plpgsql IMMUTABLE; + +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.enable_utility TO TRUE; +SET gpsc.report_nested_queries TO TRUE; + +-- DECLARE +SET gpsc.logging_mode to 'TBL'; + +BEGIN; +DECLARE cursor_stats_0 CURSOR FOR SELECT 0; +CLOSE cursor_stats_0; +COMMIT; + +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- DECLARE WITH HOLD +SET gpsc.logging_mode to 'TBL'; + +BEGIN; +DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 1; +CLOSE cursor_stats_1; +DECLARE cursor_stats_2 CURSOR WITH HOLD FOR SELECT 2; +CLOSE cursor_stats_2; +COMMIT; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- ROLLBACK +SET gpsc.logging_mode to 'TBL'; + +BEGIN; +DECLARE cursor_stats_3 CURSOR FOR SELECT 1; +CLOSE cursor_stats_3; +DECLARE cursor_stats_4 CURSOR FOR SELECT 1; +ROLLBACK; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- FETCH +SET gpsc.logging_mode to 'TBL'; + +BEGIN; +DECLARE cursor_stats_5 CURSOR WITH HOLD FOR SELECT 2; +DECLARE cursor_stats_6 CURSOR WITH HOLD FOR SELECT 3; +FETCH 1 IN cursor_stats_5; +FETCH 1 IN cursor_stats_6; +CLOSE cursor_stats_5; +CLOSE cursor_stats_6; +COMMIT; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/yagp_hooks_collector/sql/yagp_dist.sql b/gpcontrib/gp_stats_collector/sql/gpsc_dist.sql similarity index 53% rename from gpcontrib/yagp_hooks_collector/sql/yagp_dist.sql rename to gpcontrib/gp_stats_collector/sql/gpsc_dist.sql index d5519d0cd96..46b531a70ca 100644 --- a/gpcontrib/yagp_hooks_collector/sql/yagp_dist.sql +++ b/gpcontrib/gp_stats_collector/sql/gpsc_dist.sql @@ -1,6 +1,6 @@ -CREATE EXTENSION yagp_hooks_collector; +CREATE EXTENSION gp_stats_collector; -CREATE OR REPLACE FUNCTION yagp_status_order(status text) +CREATE OR REPLACE FUNCTION gpsc_status_order(status text) RETURNS integer AS $$ BEGIN @@ -14,36 +14,36 @@ BEGIN END; $$ LANGUAGE plpgsql IMMUTABLE; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.report_nested_queries TO TRUE; -SET yagpcc.enable_utility TO FALSE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.report_nested_queries TO TRUE; +SET gpsc.enable_utility TO FALSE; -- Hash distributed table CREATE TABLE test_hash_dist (id int) DISTRIBUTED BY (id); INSERT INTO test_hash_dist SELECT 1; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; SET optimizer_enable_direct_dispatch TO TRUE; -- Direct dispatch is used here, only one segment is scanned. select * from test_hash_dist where id = 1; RESET optimizer_enable_direct_dispatch; -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; -- Should see 8 rows. -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; -- Scan all segments. select * from test_hash_dist; DROP TABLE test_hash_dist; -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; -- Replicated table CREATE FUNCTION force_segments() RETURNS SETOF text AS $$ @@ -55,14 +55,14 @@ $$ LANGUAGE plpgsql VOLATILE EXECUTE ON ALL SEGMENTS; CREATE TABLE test_replicated (id int) DISTRIBUTED REPLICATED; INSERT INTO test_replicated SELECT 1; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; SELECT COUNT(*) FROM test_replicated, force_segments(); DROP TABLE test_replicated; DROP FUNCTION force_segments(); -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; -- Partially distributed table (2 numsegments) SET allow_system_table_mods = ON; @@ -70,19 +70,19 @@ CREATE TABLE test_partial_dist (id int, data text) DISTRIBUTED BY (id); UPDATE gp_distribution_policy SET numsegments = 2 WHERE localoid = 'test_partial_dist'::regclass; INSERT INTO test_partial_dist SELECT * FROM generate_series(1, 100); -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.logging_mode to 'TBL'; SELECT COUNT(*) FROM test_partial_dist; -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; DROP TABLE test_partial_dist; RESET allow_system_table_mods; -- Should see 12 rows. -SELECT query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - -DROP FUNCTION yagp_status_order(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.report_nested_queries; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; +SELECT query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/yagp_hooks_collector/sql/yagp_guc_cache.sql b/gpcontrib/gp_stats_collector/sql/gpsc_guc_cache.sql similarity index 58% rename from gpcontrib/yagp_hooks_collector/sql/yagp_guc_cache.sql rename to gpcontrib/gp_stats_collector/sql/gpsc_guc_cache.sql index 9e6de69d61e..6aff2ad5cf6 100644 --- a/gpcontrib/yagp_hooks_collector/sql/yagp_guc_cache.sql +++ b/gpcontrib/gp_stats_collector/sql/gpsc_guc_cache.sql @@ -8,36 +8,36 @@ -- have its DONE event rejected, creating orphaned SUBMIT entries. -- This is due to query being actually executed between SUBMIT and DONE. -- start_ignore -CREATE EXTENSION IF NOT EXISTS yagp_hooks_collector; -SELECT yagpcc.truncate_log(); +CREATE EXTENSION IF NOT EXISTS gp_stats_collector; +SELECT gpsc.truncate_log(); -- end_ignore CREATE OR REPLACE FUNCTION print_last_query(query text) RETURNS TABLE(query_status text) AS $$ SELECT query_status - FROM yagpcc.log + FROM gpsc.log WHERE segid = -1 AND query_text = query ORDER BY ccnt DESC $$ LANGUAGE sql; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.enable_utility TO TRUE; -SET yagpcc.logging_mode TO 'TBL'; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.enable_utility TO TRUE; +SET gpsc.logging_mode TO 'TBL'; -- SET below disables utility logging and DONE must still be logged. -SET yagpcc.enable_utility TO FALSE; -SELECT * FROM print_last_query('SET yagpcc.enable_utility TO FALSE;'); +SET gpsc.enable_utility TO FALSE; +SELECT * FROM print_last_query('SET gpsc.enable_utility TO FALSE;'); -- SELECT below adds current user to ignore list and DONE must still be logged. -- start_ignore -SELECT set_config('yagpcc.ignored_users_list', current_user, false); +SELECT set_config('gpsc.ignored_users_list', current_user, false); -- end_ignore -SELECT * FROM print_last_query('SELECT set_config(''yagpcc.ignored_users_list'', current_user, false);'); +SELECT * FROM print_last_query('SELECT set_config(''gpsc.ignored_users_list'', current_user, false);'); DROP FUNCTION print_last_query(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; -RESET yagpcc.logging_mode; +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; +RESET gpsc.logging_mode; diff --git a/gpcontrib/gp_stats_collector/sql/gpsc_locale.sql b/gpcontrib/gp_stats_collector/sql/gpsc_locale.sql new file mode 100644 index 00000000000..6321c93f5ab --- /dev/null +++ b/gpcontrib/gp_stats_collector/sql/gpsc_locale.sql @@ -0,0 +1,29 @@ +-- The extension generates normalized query text and plan using jumbling functions. +-- Those functions may fail when translating to wide character if the current locale +-- cannot handle the character set. This test checks that even when those functions +-- fail, the plan is still generated and executed. This test is partially taken from +-- gp_locale. + +-- start_ignore +DROP DATABASE IF EXISTS gpsc_test_locale; +-- end_ignore + +CREATE DATABASE gpsc_test_locale WITH LC_COLLATE='C' LC_CTYPE='C' TEMPLATE=template0; +\c gpsc_test_locale + +CREATE EXTENSION gp_stats_collector; + +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable_utility TO TRUE; +SET gpsc.enable TO TRUE; + +CREATE TABLE gpsc_hi_안녕세계 (a int, 안녕세계1 text, 안녕세계2 text, 안녕세계3 text) DISTRIBUTED BY (a); +INSERT INTO gpsc_hi_안녕세계 VALUES(1, '안녕세계1 first', '안녕세2 first', '안녕세계3 first'); +-- Should not see error here +UPDATE gpsc_hi_안녕세계 SET 안녕세계1='안녕세계1 first UPDATE' WHERE 안녕세계1='안녕세계1 first'; + +RESET gpsc.enable; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; +DROP TABLE gpsc_hi_안녕세계; +DROP EXTENSION gp_stats_collector; diff --git a/gpcontrib/gp_stats_collector/sql/gpsc_select.sql b/gpcontrib/gp_stats_collector/sql/gpsc_select.sql new file mode 100644 index 00000000000..673cbee0c10 --- /dev/null +++ b/gpcontrib/gp_stats_collector/sql/gpsc_select.sql @@ -0,0 +1,69 @@ +CREATE EXTENSION gp_stats_collector; + +CREATE OR REPLACE FUNCTION gpsc_status_order(status text) +RETURNS integer +AS $$ +BEGIN + RETURN CASE status + WHEN 'QUERY_STATUS_SUBMIT' THEN 1 + WHEN 'QUERY_STATUS_START' THEN 2 + WHEN 'QUERY_STATUS_END' THEN 3 + WHEN 'QUERY_STATUS_DONE' THEN 4 + ELSE 999 + END; +END; +$$ LANGUAGE plpgsql IMMUTABLE; + +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.report_nested_queries TO TRUE; +SET gpsc.enable_utility TO FALSE; + +-- Basic SELECT tests +SET gpsc.logging_mode to 'TBL'; + +SELECT 1; +SELECT COUNT(*) FROM generate_series(1,10); + +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- Transaction test +SET gpsc.logging_mode to 'TBL'; + +BEGIN; +SELECT 1; +COMMIT; + +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- CTE test +SET gpsc.logging_mode to 'TBL'; + +WITH t AS (VALUES (1), (2)) +SELECT * FROM t; + +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- Prepared statement test +SET gpsc.logging_mode to 'TBL'; + +PREPARE test_stmt AS SELECT 1; +EXECUTE test_stmt; +DEALLOCATE test_stmt; + +RESET gpsc.logging_mode; +SELECT segid, query_text, query_status FROM gpsc.log ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/gp_stats_collector/sql/gpsc_uds.sql b/gpcontrib/gp_stats_collector/sql/gpsc_uds.sql new file mode 100644 index 00000000000..14377b15c8c --- /dev/null +++ b/gpcontrib/gp_stats_collector/sql/gpsc_uds.sql @@ -0,0 +1,31 @@ +-- Test UDS socket +-- start_ignore +CREATE EXTENSION IF NOT EXISTS gp_stats_collector; +-- end_ignore + +\set UDS_PATH '/tmp/gpsc_test.sock' + +-- Configure extension to send via UDS +SET gpsc.uds_path TO :'UDS_PATH'; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.logging_mode TO 'UDS'; + +-- Start receiver +SELECT gpsc.__test_uds_start_server(:'UDS_PATH'); + +-- Send +SELECT 1; + +-- Receive +SELECT gpsc.__test_uds_receive() > 0 as received; + +-- Stop receiver +SELECT gpsc.__test_uds_stop_server(); + +-- Cleanup +DROP EXTENSION gp_stats_collector; +RESET gpsc.uds_path; +RESET gpsc.ignored_users_list; +RESET gpsc.enable; +RESET gpsc.logging_mode; diff --git a/gpcontrib/yagp_hooks_collector/sql/yagp_utf8_trim.sql b/gpcontrib/gp_stats_collector/sql/gpsc_utf8_trim.sql similarity index 58% rename from gpcontrib/yagp_hooks_collector/sql/yagp_utf8_trim.sql rename to gpcontrib/gp_stats_collector/sql/gpsc_utf8_trim.sql index c3053e4af0c..a3f8a376d55 100644 --- a/gpcontrib/yagp_hooks_collector/sql/yagp_utf8_trim.sql +++ b/gpcontrib/gp_stats_collector/sql/gpsc_utf8_trim.sql @@ -1,45 +1,45 @@ -CREATE EXTENSION IF NOT EXISTS yagp_hooks_collector; +CREATE EXTENSION IF NOT EXISTS gp_stats_collector; CREATE OR REPLACE FUNCTION get_marked_query(marker TEXT) RETURNS TEXT AS $$ SELECT query_text - FROM yagpcc.log + FROM gpsc.log WHERE query_text LIKE '%' || marker || '%' ORDER BY datetime DESC LIMIT 1 $$ LANGUAGE sql VOLATILE; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; -- Test 1: 1 byte chars -SET yagpcc.max_text_size to 19; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.max_text_size to 19; +SET gpsc.logging_mode to 'TBL'; SELECT /*test1*/ 'HelloWorld'; -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; SELECT octet_length(get_marked_query('test1')) = 19 AS correct_length; -- Test 2: 2 byte chars -SET yagpcc.max_text_size to 19; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.max_text_size to 19; +SET gpsc.logging_mode to 'TBL'; SELECT /*test2*/ 'РУССКИЙЯЗЫК'; -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; -- Character 'Р' has two bytes and cut in the middle => not included. SELECT octet_length(get_marked_query('test2')) = 18 AS correct_length; -- Test 3: 4 byte chars -SET yagpcc.max_text_size to 21; -SET yagpcc.logging_mode to 'TBL'; +SET gpsc.max_text_size to 21; +SET gpsc.logging_mode to 'TBL'; SELECT /*test3*/ '😀'; -RESET yagpcc.logging_mode; +RESET gpsc.logging_mode; -- Emoji has 4 bytes and cut before the last byte => not included. SELECT octet_length(get_marked_query('test3')) = 18 AS correct_length; -- Cleanup DROP FUNCTION get_marked_query(TEXT); -RESET yagpcc.max_text_size; -RESET yagpcc.logging_mode; -RESET yagpcc.enable; -RESET yagpcc.ignored_users_list; +RESET gpsc.max_text_size; +RESET gpsc.logging_mode; +RESET gpsc.enable; +RESET gpsc.ignored_users_list; -DROP EXTENSION yagp_hooks_collector; +DROP EXTENSION gp_stats_collector; diff --git a/gpcontrib/gp_stats_collector/sql/gpsc_utility.sql b/gpcontrib/gp_stats_collector/sql/gpsc_utility.sql new file mode 100644 index 00000000000..9abb965db37 --- /dev/null +++ b/gpcontrib/gp_stats_collector/sql/gpsc_utility.sql @@ -0,0 +1,135 @@ +CREATE EXTENSION gp_stats_collector; + +CREATE OR REPLACE FUNCTION gpsc_status_order(status text) +RETURNS integer +AS $$ +BEGIN + RETURN CASE status + WHEN 'QUERY_STATUS_SUBMIT' THEN 1 + WHEN 'QUERY_STATUS_START' THEN 2 + WHEN 'QUERY_STATUS_END' THEN 3 + WHEN 'QUERY_STATUS_DONE' THEN 4 + ELSE 999 + END; +END; +$$ LANGUAGE plpgsql IMMUTABLE; + +SET gpsc.ignored_users_list TO ''; +SET gpsc.enable TO TRUE; +SET gpsc.enable_utility TO TRUE; +SET gpsc.report_nested_queries TO TRUE; + +SET gpsc.logging_mode to 'TBL'; + +CREATE TABLE test_table (a int, b text); +CREATE INDEX test_idx ON test_table(a); +ALTER TABLE test_table ADD COLUMN c int DEFAULT 1; +DROP TABLE test_table; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- Partitioning +SET gpsc.logging_mode to 'TBL'; + +CREATE TABLE pt_test (a int, b int) +DISTRIBUTED BY (a) +PARTITION BY RANGE (a) +(START (0) END (100) EVERY (50)); +DROP TABLE pt_test; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- Views and Functions +SET gpsc.logging_mode to 'TBL'; + +CREATE VIEW test_view AS SELECT 1 AS a; +CREATE FUNCTION test_func(i int) RETURNS int AS $$ SELECT $1 + 1; $$ LANGUAGE SQL; +DROP VIEW test_view; +DROP FUNCTION test_func(int); + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- Transaction Operations +SET gpsc.logging_mode to 'TBL'; + +BEGIN; +SAVEPOINT sp1; +ROLLBACK TO sp1; +COMMIT; + +BEGIN; +SAVEPOINT sp2; +ABORT; + +BEGIN; +ROLLBACK; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- DML Operations +SET gpsc.logging_mode to 'TBL'; + +CREATE TABLE dml_test (a int, b text); +INSERT INTO dml_test VALUES (1, 'test'); +UPDATE dml_test SET b = 'updated' WHERE a = 1; +DELETE FROM dml_test WHERE a = 1; +DROP TABLE dml_test; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- COPY Operations +SET gpsc.logging_mode to 'TBL'; + +CREATE TABLE copy_test (a int); +COPY (SELECT 1) TO STDOUT; +DROP TABLE copy_test; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- Prepared Statements and error during execute +SET gpsc.logging_mode to 'TBL'; + +PREPARE test_prep(int) AS SELECT $1/0 AS value; +EXECUTE test_prep(0::int); +DEALLOCATE test_prep; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +-- GUC Settings +SET gpsc.logging_mode to 'TBL'; + +SET gpsc.report_nested_queries TO FALSE; +RESET gpsc.report_nested_queries; + +RESET gpsc.logging_mode; + +SELECT segid, query_text, query_status FROM gpsc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, gpsc_status_order(query_status) ASC; +SELECT gpsc.truncate_log() IS NOT NULL AS t; + +DROP FUNCTION gpsc_status_order(text); +DROP EXTENSION gp_stats_collector; +RESET gpsc.enable; +RESET gpsc.report_nested_queries; +RESET gpsc.enable_utility; +RESET gpsc.ignored_users_list; diff --git a/gpcontrib/yagp_hooks_collector/src/Config.cpp b/gpcontrib/gp_stats_collector/src/Config.cpp similarity index 79% rename from gpcontrib/yagp_hooks_collector/src/Config.cpp rename to gpcontrib/gp_stats_collector/src/Config.cpp index 62c16e91d1f..e117aa941fd 100644 --- a/gpcontrib/yagp_hooks_collector/src/Config.cpp +++ b/gpcontrib/gp_stats_collector/src/Config.cpp @@ -20,7 +20,7 @@ * Config.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/Config.cpp + * gpcontrib/gp_stats_collector/src/Config.cpp * *------------------------------------------------------------------------- */ @@ -62,63 +62,63 @@ static void assign_ignored_users_hook(const char *, void *) { void Config::init_gucs() { DefineCustomStringVariable( - "yagpcc.uds_path", "Sets filesystem path of the agent socket", 0LL, - &guc_uds_path, "/tmp/yagpcc_agent.sock", PGC_SUSET, + "gpsc.uds_path", "Sets filesystem path of the agent socket", 0LL, + &guc_uds_path, "/tmp/gpsc_agent.sock", PGC_SUSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC, 0LL, 0LL, 0LL); DefineCustomBoolVariable( - "yagpcc.enable", "Enable metrics collector", 0LL, &guc_enable_collector, + "gpsc.enable", "Enable metrics collector", 0LL, &guc_enable_collector, true, PGC_SUSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC, 0LL, 0LL, 0LL); DefineCustomBoolVariable( - "yagpcc.enable_analyze", "Collect analyze metrics in yagpcc", 0LL, + "gpsc.enable_analyze", "Collect analyze metrics in gpsc", 0LL, &guc_enable_analyze, true, PGC_SUSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC, 0LL, 0LL, 0LL); DefineCustomBoolVariable( - "yagpcc.enable_cdbstats", "Collect CDB metrics in yagpcc", 0LL, + "gpsc.enable_cdbstats", "Collect CDB metrics in gpsc", 0LL, &guc_enable_cdbstats, true, PGC_SUSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC, 0LL, 0LL, 0LL); DefineCustomBoolVariable( - "yagpcc.report_nested_queries", "Collect stats on nested queries", 0LL, + "gpsc.report_nested_queries", "Collect stats on nested queries", 0LL, &guc_report_nested_queries, true, PGC_USERSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC, 0LL, 0LL, 0LL); - DefineCustomStringVariable("yagpcc.ignored_users_list", - "Make yagpcc ignore queries issued by given users", + DefineCustomStringVariable("gpsc.ignored_users_list", + "Make gpsc ignore queries issued by given users", 0LL, &guc_ignored_users, "gpadmin,repl,gpperfmon,monitor", PGC_SUSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC, 0LL, assign_ignored_users_hook, 0LL); DefineCustomIntVariable( - "yagpcc.max_text_size", - "Make yagpcc trim query texts longer than configured size in bytes", NULL, + "gpsc.max_text_size", + "Make gpsc trim query texts longer than configured size in bytes", NULL, &guc_max_text_size, 1 << 20 /* 1MB */, 0, INT_MAX, PGC_SUSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC, NULL, NULL, NULL); DefineCustomIntVariable( - "yagpcc.max_plan_size", - "Make yagpcc trim plan longer than configured size", NULL, + "gpsc.max_plan_size", + "Make gpsc trim plan longer than configured size", NULL, &guc_max_plan_size, 1024, 0, INT_MAX / 1024, PGC_SUSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC | GUC_UNIT_KB, NULL, NULL, NULL); DefineCustomIntVariable( - "yagpcc.min_analyze_time", + "gpsc.min_analyze_time", "Sets the minimum execution time above which plans will be logged.", "Zero prints all plans. -1 turns this feature off.", &guc_min_analyze_time, 10000, -1, INT_MAX, PGC_USERSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC | GUC_UNIT_MS, NULL, NULL, NULL); DefineCustomEnumVariable( - "yagpcc.logging_mode", "Logging mode: UDS or PG Table", NULL, + "gpsc.logging_mode", "Logging mode: UDS or PG Table", NULL, &guc_logging_mode, LOG_MODE_UDS, logging_mode_options, PGC_SUSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC | GUC_SUPERUSER_ONLY, NULL, NULL, NULL); DefineCustomBoolVariable( - "yagpcc.enable_utility", "Collect utility statement stats", NULL, + "gpsc.enable_utility", "Collect utility statement stats", NULL, &guc_enable_utility, false, PGC_USERSET, GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC, NULL, NULL, NULL); } @@ -127,27 +127,27 @@ void Config::update_ignored_users(const char *new_guc_ignored_users) { auto new_ignored_users_set = std::make_unique(); if (new_guc_ignored_users != nullptr && new_guc_ignored_users[0] != '\0') { /* Need a modifiable copy of string */ - char *rawstring = ya_gpdb::pstrdup(new_guc_ignored_users); + char *rawstring = gpdb::pstrdup(new_guc_ignored_users); List *elemlist; ListCell *l; /* Parse string into list of identifiers */ - if (!ya_gpdb::split_identifier_string(rawstring, ',', &elemlist)) { + if (!gpdb::split_identifier_string(rawstring, ',', &elemlist)) { /* syntax error in list */ - ya_gpdb::pfree(rawstring); - ya_gpdb::list_free(elemlist); + gpdb::pfree(rawstring); + gpdb::list_free(elemlist); ereport( LOG, (errcode(ERRCODE_SYNTAX_ERROR), errmsg( - "invalid list syntax in parameter yagpcc.ignored_users_list"))); + "invalid list syntax in parameter gpsc.ignored_users_list"))); return; } foreach (l, elemlist) { new_ignored_users_set->insert((char *)lfirst(l)); } - ya_gpdb::pfree(rawstring); - ya_gpdb::list_free(elemlist); + gpdb::pfree(rawstring); + gpdb::list_free(elemlist); } ignored_users_ = std::move(new_ignored_users_set); } diff --git a/gpcontrib/yagp_hooks_collector/src/Config.h b/gpcontrib/gp_stats_collector/src/Config.h similarity index 97% rename from gpcontrib/yagp_hooks_collector/src/Config.h rename to gpcontrib/gp_stats_collector/src/Config.h index 01ae5ea328e..91a1ffe44f2 100644 --- a/gpcontrib/yagp_hooks_collector/src/Config.h +++ b/gpcontrib/gp_stats_collector/src/Config.h @@ -20,7 +20,7 @@ * Config.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/Config.h + * gpcontrib/gp_stats_collector/src/Config.h * *------------------------------------------------------------------------- */ diff --git a/gpcontrib/yagp_hooks_collector/src/EventSender.cpp b/gpcontrib/gp_stats_collector/src/EventSender.cpp similarity index 86% rename from gpcontrib/yagp_hooks_collector/src/EventSender.cpp rename to gpcontrib/gp_stats_collector/src/EventSender.cpp index 6993814ffbf..b28ceba175a 100644 --- a/gpcontrib/yagp_hooks_collector/src/EventSender.cpp +++ b/gpcontrib/gp_stats_collector/src/EventSender.cpp @@ -20,7 +20,7 @@ * EventSender.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/EventSender.cpp + * gpcontrib/gp_stats_collector/src/EventSender.cpp * *------------------------------------------------------------------------- */ @@ -106,7 +106,7 @@ bool EventSender::verify_query(QueryDesc *query_desc, QueryState state, return true; } -bool EventSender::log_query_req(const yagpcc::SetQueryReq &req, +bool EventSender::log_query_req(const gpsc::SetQueryReq &req, const std::string &event, bool utility) { bool clear_big_fields = false; switch (config.logging_mode()) { @@ -114,7 +114,7 @@ bool EventSender::log_query_req(const yagpcc::SetQueryReq &req, clear_big_fields = UDSConnector::report_query(req, event, config); break; case LOG_MODE_TBL: - ya_gpdb::insert_log(req, utility); + gpdb::insert_log(req, utility); clear_big_fields = false; break; default: @@ -170,7 +170,7 @@ void EventSender::executor_before_start(QueryDesc *query_desc, int eflags) { instr_time starttime; INSTR_TIME_SET_CURRENT(starttime); query_desc->showstatctx = - ya_gpdb::cdbexplain_showExecStatsBegin(query_desc, starttime); + gpdb::cdbexplain_showExecStatsBegin(query_desc, starttime); } } } @@ -192,12 +192,12 @@ void EventSender::executor_after_start(QueryDesc *query_desc, int /* eflags*/) { // context so it will go away at executor_end. if (query_desc->totaltime == NULL) { MemoryContext oldcxt = - ya_gpdb::mem_ctx_switch_to(query_desc->estate->es_query_cxt); - query_desc->totaltime = ya_gpdb::instr_alloc(1, INSTRUMENT_ALL, false); - ya_gpdb::mem_ctx_switch_to(oldcxt); + gpdb::mem_ctx_switch_to(query_desc->estate->es_query_cxt); + query_desc->totaltime = gpdb::instr_alloc(1, INSTRUMENT_ALL, false); + gpdb::mem_ctx_switch_to(oldcxt); } } - yagpcc::GPMetrics stats; + gpsc::GPMetrics stats; std::swap(stats, *query_msg->mutable_query_metrics()); if (log_query_req(*query_msg, "started", false /* utility */)) { clear_big_fields(query_msg); @@ -233,7 +233,7 @@ void EventSender::collect_query_submit(QueryDesc *query_desc, bool utility) { submit_query(query_desc); auto &query = get_query(query_desc); auto *query_msg = query.message.get(); - *query_msg = create_query_req(yagpcc::QueryStatus::QUERY_STATUS_SUBMIT); + *query_msg = create_query_req(gpsc::QueryStatus::QUERY_STATUS_SUBMIT); *query_msg->mutable_submit_time() = current_ts(); set_query_info(query_msg); set_qi_nesting_level(query_msg, nesting_level); @@ -256,27 +256,27 @@ void EventSender::collect_query_submit(QueryDesc *query_desc, bool utility) { void EventSender::report_query_done(QueryDesc *query_desc, QueryItem &query, QueryMetricsStatus status, bool utility, ErrorData *edata) { - yagpcc::QueryStatus query_status; + gpsc::QueryStatus query_status; std::string msg; switch (status) { case METRICS_QUERY_DONE: case METRICS_INNER_QUERY_DONE: - query_status = yagpcc::QueryStatus::QUERY_STATUS_DONE; + query_status = gpsc::QueryStatus::QUERY_STATUS_DONE; msg = "done"; break; case METRICS_QUERY_ERROR: - query_status = yagpcc::QueryStatus::QUERY_STATUS_ERROR; + query_status = gpsc::QueryStatus::QUERY_STATUS_ERROR; msg = "error"; break; case METRICS_QUERY_CANCELING: // at the moment we don't track this event, but I`ll leave this code // here just in case Assert(false); - query_status = yagpcc::QueryStatus::QUERY_STATUS_CANCELLING; + query_status = gpsc::QueryStatus::QUERY_STATUS_CANCELLING; msg = "cancelling"; break; case METRICS_QUERY_CANCELED: - query_status = yagpcc::QueryStatus::QUERY_STATUS_CANCELED; + query_status = gpsc::QueryStatus::QUERY_STATUS_CANCELED; msg = "cancelled"; break; default: @@ -285,15 +285,15 @@ void EventSender::report_query_done(QueryDesc *query_desc, QueryItem &query, } auto prev_state = query.state; update_query_state(query, QueryState::DONE, utility, - query_status == yagpcc::QueryStatus::QUERY_STATUS_DONE); + query_status == gpsc::QueryStatus::QUERY_STATUS_DONE); auto query_msg = query.message.get(); query_msg->set_query_status(query_status); if (status == METRICS_QUERY_ERROR) { bool error_flushed = elog_message() == NULL; if (error_flushed && (edata == NULL || edata->message == NULL)) { - ereport(WARNING, (errmsg("YAGPCC missing error message"))); + ereport(WARNING, (errmsg("GPSC missing error message"))); ereport(DEBUG3, - (errmsg("YAGPCC query sourceText: %s", query_desc->sourceText))); + (errmsg("GPSC query sourceText: %s", query_desc->sourceText))); } else { set_qi_error_message( query_msg, error_flushed ? edata->message : elog_message(), config); @@ -324,18 +324,18 @@ void EventSender::collect_query_done(QueryDesc *query_desc, bool utility, // Skip sending done message if query errored before submit. if (!qdesc_submitted(query_desc)) { if (status != METRICS_QUERY_ERROR) { - ereport(WARNING, (errmsg("YAGPCC trying to process DONE hook for " + ereport(WARNING, (errmsg("GPSC trying to process DONE hook for " "unsubmitted and unerrored query"))); ereport(DEBUG3, - (errmsg("YAGPCC query sourceText: %s", query_desc->sourceText))); + (errmsg("GPSC query sourceText: %s", query_desc->sourceText))); } return; } if (queries.empty()) { - ereport(WARNING, (errmsg("YAGPCC cannot find query to process DONE hook"))); + ereport(WARNING, (errmsg("GPSC cannot find query to process DONE hook"))); ereport(DEBUG3, - (errmsg("YAGPCC query sourceText: %s", query_desc->sourceText))); + (errmsg("GPSC query sourceText: %s", query_desc->sourceText))); return; } auto &query = get_query(query_desc); @@ -346,8 +346,8 @@ void EventSender::collect_query_done(QueryDesc *query_desc, bool utility, update_nested_counters(query_desc); queries.erase(QueryKey::from_qdesc(query_desc)); - pfree(query_desc->yagp_query_key); - query_desc->yagp_query_key = NULL; + pfree(query_desc->gpsc_query_key); + query_desc->gpsc_query_key = NULL; } void EventSender::ic_metrics_collect() { @@ -395,7 +395,7 @@ void EventSender::analyze_stats_collect(QueryDesc *query_desc) { } // Make sure stats accumulation is done. // (Note: it's okay if several levels of hook all do this.) - ya_gpdb::instr_end_loop(query_desc->totaltime); + gpdb::instr_end_loop(query_desc->totaltime); double ms = query_desc->totaltime->total * 1000.0; if (ms >= config.min_analyze_time()) { @@ -424,7 +424,7 @@ EventSender::EventSender() { EventSender::~EventSender() { for (const auto &[qkey, _] : queries) { - ereport(LOG, (errmsg("YAGPCC query with missing done event: " + ereport(LOG, (errmsg("GPSC query with missing done event: " "tmid=%d ssid=%d ccnt=%d nlvl=%d", qkey.tmid, qkey.ssid, qkey.ccnt, qkey.nesting_level))); } @@ -440,7 +440,7 @@ void EventSender::update_query_state(QueryItem &query, QueryState new_state, break; case QueryState::START: if (query.state == QueryState::SUBMIT) { - query.message->set_query_status(yagpcc::QueryStatus::QUERY_STATUS_START); + query.message->set_query_status(gpsc::QueryStatus::QUERY_STATUS_START); } else { Assert(false); } @@ -449,11 +449,11 @@ void EventSender::update_query_state(QueryItem &query, QueryState new_state, // Example of below assert triggering: CURSOR closes before ever being // executed Assert(query->state == QueryState::START || // IsAbortInProgress()); - query.message->set_query_status(yagpcc::QueryStatus::QUERY_STATUS_END); + query.message->set_query_status(gpsc::QueryStatus::QUERY_STATUS_END); break; case QueryState::DONE: Assert(query.state == QueryState::END || !success || utility); - query.message->set_query_status(yagpcc::QueryStatus::QUERY_STATUS_DONE); + query.message->set_query_status(gpsc::QueryStatus::QUERY_STATUS_DONE); break; default: Assert(false); @@ -464,28 +464,28 @@ void EventSender::update_query_state(QueryItem &query, QueryState new_state, EventSender::QueryItem &EventSender::get_query(QueryDesc *query_desc) { if (!qdesc_submitted(query_desc)) { ereport(WARNING, - (errmsg("YAGPCC attempting to get query that was not submitted"))); + (errmsg("GPSC attempting to get query that was not submitted"))); ereport(DEBUG3, - (errmsg("YAGPCC query sourceText: %s", query_desc->sourceText))); + (errmsg("GPSC query sourceText: %s", query_desc->sourceText))); throw std::runtime_error("Attempting to get query that was not submitted"); } return queries.find(QueryKey::from_qdesc(query_desc))->second; } void EventSender::submit_query(QueryDesc *query_desc) { - if (query_desc->yagp_query_key) { + if (query_desc->gpsc_query_key) { ereport(WARNING, - (errmsg("YAGPCC trying to submit already submitted query"))); + (errmsg("GPSC trying to submit already submitted query"))); ereport(DEBUG3, - (errmsg("YAGPCC query sourceText: %s", query_desc->sourceText))); + (errmsg("GPSC query sourceText: %s", query_desc->sourceText))); } QueryKey::register_qkey(query_desc, nesting_level); auto key = QueryKey::from_qdesc(query_desc); auto [_, inserted] = queries.emplace(key, QueryItem(QueryState::SUBMIT)); if (!inserted) { - ereport(WARNING, (errmsg("YAGPCC duplicate query submit detected"))); + ereport(WARNING, (errmsg("GPSC duplicate query submit detected"))); ereport(DEBUG3, - (errmsg("YAGPCC query sourceText: %s", query_desc->sourceText))); + (errmsg("GPSC query sourceText: %s", query_desc->sourceText))); } } @@ -498,16 +498,16 @@ void EventSender::update_nested_counters(QueryDesc *query_desc) { if (end_time >= start_time) { nested_timing += end_time - start_time; } else { - ereport(WARNING, (errmsg("YAGPCC query start_time > end_time (%f > %f)", + ereport(WARNING, (errmsg("GPSC query start_time > end_time (%f > %f)", start_time, end_time))); ereport(DEBUG3, - (errmsg("YAGPCC nested query text %s", query_desc->sourceText))); + (errmsg("GPSC nested query text %s", query_desc->sourceText))); } } } bool EventSender::qdesc_submitted(QueryDesc *query_desc) { - if (query_desc->yagp_query_key == NULL) { + if (query_desc->gpsc_query_key == NULL) { return false; } return queries.find(QueryKey::from_qdesc(query_desc)) != queries.end(); @@ -528,4 +528,4 @@ bool EventSender::filter_query(QueryDesc *query_desc) { } EventSender::QueryItem::QueryItem(QueryState st) - : message(std::make_unique()), state(st) {} + : message(std::make_unique()), state(st) {} diff --git a/gpcontrib/yagp_hooks_collector/src/EventSender.h b/gpcontrib/gp_stats_collector/src/EventSender.h similarity index 84% rename from gpcontrib/yagp_hooks_collector/src/EventSender.h rename to gpcontrib/gp_stats_collector/src/EventSender.h index ef7dcb0bf8c..154c2c0dceb 100644 --- a/gpcontrib/yagp_hooks_collector/src/EventSender.h +++ b/gpcontrib/gp_stats_collector/src/EventSender.h @@ -20,7 +20,7 @@ * EventSender.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/EventSender.h + * gpcontrib/gp_stats_collector/src/EventSender.h * *------------------------------------------------------------------------- */ @@ -45,7 +45,7 @@ extern "C" { class UDSConnector; struct QueryDesc; -namespace yagpcc { +namespace gpsc { class SetQueryReq; } @@ -67,24 +67,24 @@ struct QueryKey { } static void register_qkey(QueryDesc *query_desc, size_t nesting_level) { - query_desc->yagp_query_key = - (YagpQueryKey *)ya_gpdb::palloc0(sizeof(YagpQueryKey)); + query_desc->gpsc_query_key = + (GpscQueryKey *)gpdb::palloc0(sizeof(GpscQueryKey)); int32 tmid; gp_gettmid(&tmid); - query_desc->yagp_query_key->tmid = tmid; - query_desc->yagp_query_key->ssid = gp_session_id; - query_desc->yagp_query_key->ccnt = gp_command_count; - query_desc->yagp_query_key->nesting_level = nesting_level; - query_desc->yagp_query_key->query_desc_addr = (uintptr_t)query_desc; + query_desc->gpsc_query_key->tmid = tmid; + query_desc->gpsc_query_key->ssid = gp_session_id; + query_desc->gpsc_query_key->ccnt = gp_command_count; + query_desc->gpsc_query_key->nesting_level = nesting_level; + query_desc->gpsc_query_key->query_desc_addr = (uintptr_t)query_desc; } static QueryKey from_qdesc(QueryDesc *query_desc) { return { - .tmid = query_desc->yagp_query_key->tmid, - .ssid = query_desc->yagp_query_key->ssid, - .ccnt = query_desc->yagp_query_key->ccnt, - .nesting_level = query_desc->yagp_query_key->nesting_level, - .query_desc_addr = query_desc->yagp_query_key->query_desc_addr, + .tmid = query_desc->gpsc_query_key->tmid, + .ssid = query_desc->gpsc_query_key->ssid, + .ccnt = query_desc->gpsc_query_key->ccnt, + .nesting_level = query_desc->gpsc_query_key->nesting_level, + .query_desc_addr = query_desc->gpsc_query_key->query_desc_addr, }; } }; @@ -130,13 +130,13 @@ class EventSender { enum QueryState { SUBMIT, START, END, DONE }; struct QueryItem { - std::unique_ptr message; + std::unique_ptr message; QueryState state; explicit QueryItem(QueryState st); }; - bool log_query_req(const yagpcc::SetQueryReq &req, const std::string &event, + bool log_query_req(const gpsc::SetQueryReq &req, const std::string &event, bool utility); bool verify_query(QueryDesc *query_desc, QueryState state, bool utility); void update_query_state(QueryItem &query, QueryState new_state, bool utility, diff --git a/gpcontrib/yagp_hooks_collector/src/YagpStat.cpp b/gpcontrib/gp_stats_collector/src/GpscStat.cpp similarity index 78% rename from gpcontrib/yagp_hooks_collector/src/YagpStat.cpp rename to gpcontrib/gp_stats_collector/src/GpscStat.cpp index 3a760b6ea97..c4029f085cf 100644 --- a/gpcontrib/yagp_hooks_collector/src/YagpStat.cpp +++ b/gpcontrib/gp_stats_collector/src/GpscStat.cpp @@ -17,15 +17,15 @@ * specific language governing permissions and limitations * under the License. * - * YagpStat.cpp + * GpscStat.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/YagpStat.cpp + * gpcontrib/gp_stats_collector/src/GpscStat.cpp * *------------------------------------------------------------------------- */ -#include "YagpStat.h" +#include "GpscStat.h" #include @@ -41,21 +41,21 @@ extern "C" { namespace { struct ProtectedData { slock_t mutex; - YagpStat::Data data; + GpscStat::Data data; }; shmem_startup_hook_type prev_shmem_startup_hook = NULL; ProtectedData *data = nullptr; -void yagp_shmem_startup() { +void gpsc_shmem_startup() { if (prev_shmem_startup_hook) prev_shmem_startup_hook(); LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); bool found; data = reinterpret_cast( - ShmemInitStruct("yagp_stat_messages", sizeof(ProtectedData), &found)); + ShmemInitStruct("gpsc_stat_messages", sizeof(ProtectedData), &found)); if (!found) { SpinLockInit(&data->mutex); - data->data = YagpStat::Data(); + data->data = GpscStat::Data(); } LWLockRelease(AddinShmemInitLock); } @@ -70,49 +70,49 @@ class LockGuard { }; } // namespace -void YagpStat::init() { +void GpscStat::init() { if (!process_shared_preload_libraries_in_progress) return; RequestAddinShmemSpace(sizeof(ProtectedData)); prev_shmem_startup_hook = shmem_startup_hook; - shmem_startup_hook = yagp_shmem_startup; + shmem_startup_hook = gpsc_shmem_startup; } -void YagpStat::deinit() { shmem_startup_hook = prev_shmem_startup_hook; } +void GpscStat::deinit() { shmem_startup_hook = prev_shmem_startup_hook; } -void YagpStat::reset() { +void GpscStat::reset() { LockGuard lg(&data->mutex); - data->data = YagpStat::Data(); + data->data = GpscStat::Data(); } -void YagpStat::report_send(int32_t msg_size) { +void GpscStat::report_send(int32_t msg_size) { LockGuard lg(&data->mutex); data->data.total++; data->data.max_message_size = std::max(msg_size, data->data.max_message_size); } -void YagpStat::report_bad_connection() { +void GpscStat::report_bad_connection() { LockGuard lg(&data->mutex); data->data.total++; data->data.failed_connects++; } -void YagpStat::report_bad_send(int32_t msg_size) { +void GpscStat::report_bad_send(int32_t msg_size) { LockGuard lg(&data->mutex); data->data.total++; data->data.failed_sends++; data->data.max_message_size = std::max(msg_size, data->data.max_message_size); } -void YagpStat::report_error() { +void GpscStat::report_error() { LockGuard lg(&data->mutex); data->data.total++; data->data.failed_other++; } -YagpStat::Data YagpStat::get_stats() { +GpscStat::Data GpscStat::get_stats() { LockGuard lg(&data->mutex); return data->data; } -bool YagpStat::loaded() { return data != nullptr; } +bool GpscStat::loaded() { return data != nullptr; } diff --git a/gpcontrib/yagp_hooks_collector/src/YagpStat.h b/gpcontrib/gp_stats_collector/src/GpscStat.h similarity index 94% rename from gpcontrib/yagp_hooks_collector/src/YagpStat.h rename to gpcontrib/gp_stats_collector/src/GpscStat.h index 57fc90cd4d1..af1a1261776 100644 --- a/gpcontrib/yagp_hooks_collector/src/YagpStat.h +++ b/gpcontrib/gp_stats_collector/src/GpscStat.h @@ -17,10 +17,10 @@ * specific language governing permissions and limitations * under the License. * - * YagpStat.h + * GpscStat.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/YagpStat.h + * gpcontrib/gp_stats_collector/src/GpscStat.h * *------------------------------------------------------------------------- */ @@ -29,7 +29,7 @@ #include -class YagpStat { +class GpscStat { public: struct Data { int64_t total, failed_sends, failed_connects, failed_other; diff --git a/gpcontrib/yagp_hooks_collector/src/PgUtils.cpp b/gpcontrib/gp_stats_collector/src/PgUtils.cpp similarity index 83% rename from gpcontrib/yagp_hooks_collector/src/PgUtils.cpp rename to gpcontrib/gp_stats_collector/src/PgUtils.cpp index ed4bf4d7e64..3dbee97061b 100644 --- a/gpcontrib/yagp_hooks_collector/src/PgUtils.cpp +++ b/gpcontrib/gp_stats_collector/src/PgUtils.cpp @@ -20,7 +20,7 @@ * PgUtils.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/PgUtils.cpp + * gpcontrib/gp_stats_collector/src/PgUtils.cpp * *------------------------------------------------------------------------- */ @@ -37,31 +37,31 @@ extern "C" { std::string get_user_name() { // username is allocated on stack, we don't need to pfree it. const char *username = - ya_gpdb::get_config_option("session_authorization", false, false); + gpdb::get_config_option("session_authorization", false, false); return username ? std::string(username) : ""; } std::string get_db_name() { - char *dbname = ya_gpdb::get_database_name(MyDatabaseId); + char *dbname = gpdb::get_database_name(MyDatabaseId); if (dbname) { std::string result(dbname); - ya_gpdb::pfree(dbname); + gpdb::pfree(dbname); return result; } return ""; } std::string get_rg_name() { - auto groupId = ya_gpdb::get_rg_id_by_session_id(MySessionState->sessionId); + auto groupId = gpdb::get_rg_id_by_session_id(MySessionState->sessionId); if (!OidIsValid(groupId)) return ""; - char *rgname = ya_gpdb::get_rg_name_for_id(groupId); + char *rgname = gpdb::get_rg_name_for_id(groupId); if (rgname == nullptr) return ""; std::string result(rgname); - ya_gpdb::pfree(rgname); + gpdb::pfree(rgname); return result; } @@ -77,7 +77,7 @@ std::string get_rg_name() { * segment. An example would be `select a from tbl where is_good_value(b);`. In * this case master will issue one top-level statement, but segments will change * contexts for UDF execution and execute is_good_value(b) once for each tuple - * as a nested query. Creating massive load on gpcc agent. + * as a nested query. Creating massive load on external agent. * * Hence, here is a decision: * 1) ignore all queries that are nested on segments @@ -87,8 +87,8 @@ std::string get_rg_name() { */ bool is_top_level_query(QueryDesc *query_desc, int nesting_level) { - if (query_desc->yagp_query_key == NULL) { + if (query_desc->gpsc_query_key == NULL) { return nesting_level == 0; } - return query_desc->yagp_query_key->nesting_level == 0; + return query_desc->gpsc_query_key->nesting_level == 0; } diff --git a/gpcontrib/yagp_hooks_collector/src/PgUtils.h b/gpcontrib/gp_stats_collector/src/PgUtils.h similarity index 96% rename from gpcontrib/yagp_hooks_collector/src/PgUtils.h rename to gpcontrib/gp_stats_collector/src/PgUtils.h index 5113fadbff2..d9f673e7cbc 100644 --- a/gpcontrib/yagp_hooks_collector/src/PgUtils.h +++ b/gpcontrib/gp_stats_collector/src/PgUtils.h @@ -20,7 +20,7 @@ * PgUtils.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/PgUtils.h + * gpcontrib/gp_stats_collector/src/PgUtils.h * *------------------------------------------------------------------------- */ diff --git a/gpcontrib/yagp_hooks_collector/src/ProcStats.cpp b/gpcontrib/gp_stats_collector/src/ProcStats.cpp similarity index 92% rename from gpcontrib/yagp_hooks_collector/src/ProcStats.cpp rename to gpcontrib/gp_stats_collector/src/ProcStats.cpp index 72a12e8ca00..9c557879fc6 100644 --- a/gpcontrib/yagp_hooks_collector/src/ProcStats.cpp +++ b/gpcontrib/gp_stats_collector/src/ProcStats.cpp @@ -20,13 +20,13 @@ * ProcStats.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/ProcStats.cpp + * gpcontrib/gp_stats_collector/src/ProcStats.cpp * *------------------------------------------------------------------------- */ #include "ProcStats.h" -#include "yagpcc_metrics.pb.h" +#include "gpsc_metrics.pb.h" #include #include #include @@ -42,7 +42,7 @@ namespace { proc_stat >> tmp >> stat_name; \ stats->set_##stat_name(stat_name - stats->stat_name()); -void fill_io_stats(yagpcc::SystemStat *stats) { +void fill_io_stats(gpsc::SystemStat *stats) { std::ifstream proc_stat("/proc/self/io"); std::string tmp; FILL_IO_STAT(rchar); @@ -54,7 +54,7 @@ void fill_io_stats(yagpcc::SystemStat *stats) { FILL_IO_STAT(cancelled_write_bytes); } -void fill_cpu_stats(yagpcc::SystemStat *stats) { +void fill_cpu_stats(gpsc::SystemStat *stats) { static const int UTIME_ID = 13; static const int STIME_ID = 14; static const int VSIZE_ID = 22; @@ -92,7 +92,7 @@ void fill_cpu_stats(yagpcc::SystemStat *stats) { } } -void fill_status_stats(yagpcc::SystemStat *stats) { +void fill_status_stats(gpsc::SystemStat *stats) { std::ifstream proc_stat("/proc/self/status"); std::string key, measure; while (proc_stat >> key) { @@ -118,7 +118,7 @@ void fill_status_stats(yagpcc::SystemStat *stats) { } } // namespace -void fill_self_stats(yagpcc::SystemStat *stats) { +void fill_self_stats(gpsc::SystemStat *stats) { fill_io_stats(stats); fill_cpu_stats(stats); fill_status_stats(stats); diff --git a/gpcontrib/yagp_hooks_collector/src/ProcStats.h b/gpcontrib/gp_stats_collector/src/ProcStats.h similarity index 89% rename from gpcontrib/yagp_hooks_collector/src/ProcStats.h rename to gpcontrib/gp_stats_collector/src/ProcStats.h index 7629edd0aea..4473125f875 100644 --- a/gpcontrib/yagp_hooks_collector/src/ProcStats.h +++ b/gpcontrib/gp_stats_collector/src/ProcStats.h @@ -20,15 +20,15 @@ * ProcStats.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/ProcStats.h + * gpcontrib/gp_stats_collector/src/ProcStats.h * *------------------------------------------------------------------------- */ #pragma once -namespace yagpcc { +namespace gpsc { class SystemStat; } -void fill_self_stats(yagpcc::SystemStat *stats); \ No newline at end of file +void fill_self_stats(gpsc::SystemStat *stats); \ No newline at end of file diff --git a/gpcontrib/yagp_hooks_collector/src/ProtoUtils.cpp b/gpcontrib/gp_stats_collector/src/ProtoUtils.cpp similarity index 85% rename from gpcontrib/yagp_hooks_collector/src/ProtoUtils.cpp rename to gpcontrib/gp_stats_collector/src/ProtoUtils.cpp index b449ae20900..c9ceff4739b 100644 --- a/gpcontrib/yagp_hooks_collector/src/ProtoUtils.cpp +++ b/gpcontrib/gp_stats_collector/src/ProtoUtils.cpp @@ -20,7 +20,7 @@ * ProtoUtils.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/ProtoUtils.cpp + * gpcontrib/gp_stats_collector/src/ProtoUtils.cpp * *------------------------------------------------------------------------- */ @@ -74,7 +74,7 @@ google::protobuf::Timestamp current_ts() { return current_ts; } -void set_query_key(yagpcc::QueryKey *key) { +void set_query_key(gpsc::QueryKey *key) { key->set_ccnt(gp_command_count); key->set_ssid(gp_session_id); int32 tmid = 0; @@ -82,7 +82,7 @@ void set_query_key(yagpcc::QueryKey *key) { key->set_tmid(tmid); } -void set_segment_key(yagpcc::SegmentKey *key) { +void set_segment_key(gpsc::SegmentKey *key) { key->set_dbid(GpIdentity.dbid); key->set_segindex(GpIdentity.segindex); } @@ -109,51 +109,51 @@ std::string trim_str_shrink_utf8(const char *str, size_t len, size_t lim) { return std::string(str, cut_pos); } -void set_query_plan(yagpcc::SetQueryReq *req, QueryDesc *query_desc, +void set_query_plan(gpsc::SetQueryReq *req, QueryDesc *query_desc, const Config &config) { if (Gp_role == GP_ROLE_DISPATCH && query_desc->plannedstmt) { auto qi = req->mutable_query_info(); qi->set_generator(query_desc->plannedstmt->planGen == PLANGEN_OPTIMIZER - ? yagpcc::PlanGenerator::PLAN_GENERATOR_OPTIMIZER - : yagpcc::PlanGenerator::PLAN_GENERATOR_PLANNER); + ? gpsc::PlanGenerator::PLAN_GENERATOR_OPTIMIZER + : gpsc::PlanGenerator::PLAN_GENERATOR_PLANNER); MemoryContext oldcxt = - ya_gpdb::mem_ctx_switch_to(query_desc->estate->es_query_cxt); - ExplainState es = ya_gpdb::get_explain_state(query_desc, true); + gpdb::mem_ctx_switch_to(query_desc->estate->es_query_cxt); + ExplainState es = gpdb::get_explain_state(query_desc, true); if (es.str) { *qi->mutable_plan_text() = trim_str_shrink_utf8(es.str->data, es.str->len, config.max_plan_size()); - StringInfo norm_plan = ya_gpdb::gen_normplan(es.str->data); + StringInfo norm_plan = gpdb::gen_normplan(es.str->data); if (norm_plan) { *qi->mutable_template_plan_text() = trim_str_shrink_utf8( norm_plan->data, norm_plan->len, config.max_plan_size()); qi->set_plan_id( hash_any((unsigned char *)norm_plan->data, norm_plan->len)); - ya_gpdb::pfree(norm_plan->data); + gpdb::pfree(norm_plan->data); } qi->set_query_id(query_desc->plannedstmt->queryId); - ya_gpdb::pfree(es.str->data); + gpdb::pfree(es.str->data); } - ya_gpdb::mem_ctx_switch_to(oldcxt); + gpdb::mem_ctx_switch_to(oldcxt); } } -void set_query_text(yagpcc::SetQueryReq *req, QueryDesc *query_desc, +void set_query_text(gpsc::SetQueryReq *req, QueryDesc *query_desc, const Config &config) { if (Gp_role == GP_ROLE_DISPATCH && query_desc->sourceText) { auto qi = req->mutable_query_info(); *qi->mutable_query_text() = trim_str_shrink_utf8( query_desc->sourceText, strlen(query_desc->sourceText), config.max_text_size()); - char *norm_query = ya_gpdb::gen_normquery(query_desc->sourceText); + char *norm_query = gpdb::gen_normquery(query_desc->sourceText); if (norm_query) { *qi->mutable_template_query_text() = trim_str_shrink_utf8( norm_query, strlen(norm_query), config.max_text_size()); - ya_gpdb::pfree(norm_query); + gpdb::pfree(norm_query); } } } -void clear_big_fields(yagpcc::SetQueryReq *req) { +void clear_big_fields(gpsc::SetQueryReq *req) { if (Gp_role == GP_ROLE_DISPATCH) { auto qi = req->mutable_query_info(); qi->clear_plan_text(); @@ -164,7 +164,7 @@ void clear_big_fields(yagpcc::SetQueryReq *req) { } } -void set_query_info(yagpcc::SetQueryReq *req) { +void set_query_info(gpsc::SetQueryReq *req) { if (Gp_role == GP_ROLE_DISPATCH) { auto qi = req->mutable_query_info(); qi->set_username(get_user_name()); @@ -174,24 +174,24 @@ void set_query_info(yagpcc::SetQueryReq *req) { } } -void set_qi_nesting_level(yagpcc::SetQueryReq *req, int nesting_level) { +void set_qi_nesting_level(gpsc::SetQueryReq *req, int nesting_level) { auto aqi = req->mutable_add_info(); aqi->set_nested_level(nesting_level); } -void set_qi_slice_id(yagpcc::SetQueryReq *req) { +void set_qi_slice_id(gpsc::SetQueryReq *req) { auto aqi = req->mutable_add_info(); aqi->set_slice_id(currentSliceId); } -void set_qi_error_message(yagpcc::SetQueryReq *req, const char *err_msg, +void set_qi_error_message(gpsc::SetQueryReq *req, const char *err_msg, const Config &config) { auto aqi = req->mutable_add_info(); *aqi->mutable_error_message() = trim_str_shrink_utf8(err_msg, strlen(err_msg), config.max_text_size()); } -void set_metric_instrumentation(yagpcc::MetricInstrumentation *metrics, +void set_metric_instrumentation(gpsc::MetricInstrumentation *metrics, QueryDesc *query_desc, int nested_calls, double nested_time) { auto instrument = query_desc->planstate->instrument; @@ -233,7 +233,7 @@ void set_metric_instrumentation(yagpcc::MetricInstrumentation *metrics, metrics->set_inherited_time(nested_time); } -void set_gp_metrics(yagpcc::GPMetrics *metrics, QueryDesc *query_desc, +void set_gp_metrics(gpsc::GPMetrics *metrics, QueryDesc *query_desc, int nested_calls, double nested_time) { if (query_desc->planstate && query_desc->planstate->instrument) { set_metric_instrumentation(metrics->mutable_instrumentation(), query_desc, @@ -256,7 +256,7 @@ void set_gp_metrics(yagpcc::GPMetrics *metrics, QueryDesc *query_desc, metrics->mutable_interconnect()->proto_name() <= \ ic_statistics->stat_name) -void set_ic_stats(yagpcc::MetricInstrumentation *metrics, +void set_ic_stats(gpsc::MetricInstrumentation *metrics, const ICStatistics *ic_statistics) { #ifdef IC_TEARDOWN_HOOK UPDATE_IC_STATS(total_recv_queue_size, totalRecvQueueSize); @@ -279,8 +279,8 @@ void set_ic_stats(yagpcc::MetricInstrumentation *metrics, #endif } -yagpcc::SetQueryReq create_query_req(yagpcc::QueryStatus status) { - yagpcc::SetQueryReq req; +gpsc::SetQueryReq create_query_req(gpsc::QueryStatus status) { + gpsc::SetQueryReq req; req.set_query_status(status); *req.mutable_datetime() = current_ts(); set_query_key(req.mutable_query_key()); @@ -292,7 +292,7 @@ double protots_to_double(const google::protobuf::Timestamp &ts) { return double(ts.seconds()) + double(ts.nanos()) / 1000000000.0; } -void set_analyze_plan_text(QueryDesc *query_desc, yagpcc::SetQueryReq *req, +void set_analyze_plan_text(QueryDesc *query_desc, gpsc::SetQueryReq *req, const Config &config) { // Make sure it is a valid txn and it is not an utility // statement for ExplainPrintPlan() later. @@ -300,10 +300,10 @@ void set_analyze_plan_text(QueryDesc *query_desc, yagpcc::SetQueryReq *req, return; } MemoryContext oldcxt = - ya_gpdb::mem_ctx_switch_to(query_desc->estate->es_query_cxt); - ExplainState es = ya_gpdb::get_analyze_state( + gpdb::mem_ctx_switch_to(query_desc->estate->es_query_cxt); + ExplainState es = gpdb::get_analyze_state( query_desc, query_desc->instrument_options && config.enable_analyze()); - ya_gpdb::mem_ctx_switch_to(oldcxt); + gpdb::mem_ctx_switch_to(oldcxt); if (es.str) { // Remove last line break. if (es.str->len > 0 && es.str->data[es.str->len - 1] == '\n') { @@ -312,6 +312,6 @@ void set_analyze_plan_text(QueryDesc *query_desc, yagpcc::SetQueryReq *req, auto trimmed_analyze = trim_str_shrink_utf8(es.str->data, es.str->len, config.max_plan_size()); req->mutable_query_info()->set_analyze_text(trimmed_analyze); - ya_gpdb::pfree(es.str->data); + gpdb::pfree(es.str->data); } } diff --git a/gpcontrib/yagp_hooks_collector/src/ProtoUtils.h b/gpcontrib/gp_stats_collector/src/ProtoUtils.h similarity index 65% rename from gpcontrib/yagp_hooks_collector/src/ProtoUtils.h rename to gpcontrib/gp_stats_collector/src/ProtoUtils.h index c954545494f..5ddcd42d308 100644 --- a/gpcontrib/yagp_hooks_collector/src/ProtoUtils.h +++ b/gpcontrib/gp_stats_collector/src/ProtoUtils.h @@ -20,35 +20,35 @@ * ProtoUtils.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/ProtoUtils.h + * gpcontrib/gp_stats_collector/src/ProtoUtils.h * *------------------------------------------------------------------------- */ #pragma once -#include "protos/yagpcc_set_service.pb.h" +#include "protos/gpsc_set_service.pb.h" struct QueryDesc; struct ICStatistics; class Config; google::protobuf::Timestamp current_ts(); -void set_query_plan(yagpcc::SetQueryReq *req, QueryDesc *query_desc, +void set_query_plan(gpsc::SetQueryReq *req, QueryDesc *query_desc, const Config &config); -void set_query_text(yagpcc::SetQueryReq *req, QueryDesc *query_desc, +void set_query_text(gpsc::SetQueryReq *req, QueryDesc *query_desc, const Config &config); -void clear_big_fields(yagpcc::SetQueryReq *req); -void set_query_info(yagpcc::SetQueryReq *req); -void set_qi_nesting_level(yagpcc::SetQueryReq *req, int nesting_level); -void set_qi_slice_id(yagpcc::SetQueryReq *req); -void set_qi_error_message(yagpcc::SetQueryReq *req, const char *err_msg, +void clear_big_fields(gpsc::SetQueryReq *req); +void set_query_info(gpsc::SetQueryReq *req); +void set_qi_nesting_level(gpsc::SetQueryReq *req, int nesting_level); +void set_qi_slice_id(gpsc::SetQueryReq *req); +void set_qi_error_message(gpsc::SetQueryReq *req, const char *err_msg, const Config &config); -void set_gp_metrics(yagpcc::GPMetrics *metrics, QueryDesc *query_desc, +void set_gp_metrics(gpsc::GPMetrics *metrics, QueryDesc *query_desc, int nested_calls, double nested_time); -void set_ic_stats(yagpcc::MetricInstrumentation *metrics, +void set_ic_stats(gpsc::MetricInstrumentation *metrics, const ICStatistics *ic_statistics); -yagpcc::SetQueryReq create_query_req(yagpcc::QueryStatus status); +gpsc::SetQueryReq create_query_req(gpsc::QueryStatus status); double protots_to_double(const google::protobuf::Timestamp &ts); -void set_analyze_plan_text(QueryDesc *query_desc, yagpcc::SetQueryReq *message, +void set_analyze_plan_text(QueryDesc *query_desc, gpsc::SetQueryReq *message, const Config &config); diff --git a/gpcontrib/yagp_hooks_collector/src/UDSConnector.cpp b/gpcontrib/gp_stats_collector/src/UDSConnector.cpp similarity index 87% rename from gpcontrib/yagp_hooks_collector/src/UDSConnector.cpp rename to gpcontrib/gp_stats_collector/src/UDSConnector.cpp index d13a82a5ca9..9a01d4033d0 100644 --- a/gpcontrib/yagp_hooks_collector/src/UDSConnector.cpp +++ b/gpcontrib/gp_stats_collector/src/UDSConnector.cpp @@ -20,14 +20,14 @@ * UDSConnector.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/UDSConnector.cpp + * gpcontrib/gp_stats_collector/src/UDSConnector.cpp * *------------------------------------------------------------------------- */ #include "UDSConnector.h" #include "Config.h" -#include "YagpStat.h" +#include "GpscStat.h" #include "memory/gpdbwrappers.h" #include "log/LogOps.h" @@ -44,14 +44,14 @@ extern "C" { #include "postgres.h" } -static void inline log_tracing_failure(const yagpcc::SetQueryReq &req, +static void inline log_tracing_failure(const gpsc::SetQueryReq &req, const std::string &event) { ereport(LOG, (errmsg("Query {%d-%d-%d} %s tracing failed with error %m", req.query_key().tmid(), req.query_key().ssid(), req.query_key().ccnt(), event.c_str()))); } -bool UDSConnector::report_query(const yagpcc::SetQueryReq &req, +bool UDSConnector::report_query(const gpsc::SetQueryReq &req, const std::string &event, const Config &config) { sockaddr_un address{}; @@ -60,7 +60,7 @@ bool UDSConnector::report_query(const yagpcc::SetQueryReq &req, if (uds_path.size() >= sizeof(address.sun_path)) { ereport(WARNING, (errmsg("UDS path is too long for socket buffer"))); - YagpStat::report_error(); + GpscStat::report_error(); return false; } strcpy(address.sun_path, uds_path.c_str()); @@ -68,7 +68,7 @@ bool UDSConnector::report_query(const yagpcc::SetQueryReq &req, const auto sockfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sockfd == -1) { log_tracing_failure(req, event); - YagpStat::report_error(); + GpscStat::report_error(); return false; } @@ -83,24 +83,24 @@ bool UDSConnector::report_query(const yagpcc::SetQueryReq &req, // visible to an end-user and admins. ereport(WARNING, (errmsg("Unable to create non-blocking socket connection %m"))); - YagpStat::report_error(); + GpscStat::report_error(); return false; } if (connect(sockfd, reinterpret_cast(&address), sizeof(address)) == -1) { log_tracing_failure(req, event); - YagpStat::report_bad_connection(); + GpscStat::report_bad_connection(); return false; } const auto data_size = req.ByteSizeLong(); const auto total_size = data_size + sizeof(uint32_t); - auto *buf = static_cast(ya_gpdb::palloc(total_size)); + auto *buf = static_cast(gpdb::palloc(total_size)); // Free buf automatically on error path. struct BufGuard { void *p; - ~BufGuard() { ya_gpdb::pfree(p); } + ~BufGuard() { gpdb::pfree(p); } } buf_guard{buf}; *reinterpret_cast(buf) = data_size; @@ -121,10 +121,10 @@ bool UDSConnector::report_query(const yagpcc::SetQueryReq &req, if (sent < 0) { log_tracing_failure(req, event); - YagpStat::report_bad_send(total_size); + GpscStat::report_bad_send(total_size); return false; } - YagpStat::report_send(total_size); + GpscStat::report_send(total_size); return true; } diff --git a/gpcontrib/yagp_hooks_collector/src/UDSConnector.h b/gpcontrib/gp_stats_collector/src/UDSConnector.h similarity index 88% rename from gpcontrib/yagp_hooks_collector/src/UDSConnector.h rename to gpcontrib/gp_stats_collector/src/UDSConnector.h index be5ab1ef413..a91d22f9df1 100644 --- a/gpcontrib/yagp_hooks_collector/src/UDSConnector.h +++ b/gpcontrib/gp_stats_collector/src/UDSConnector.h @@ -20,19 +20,19 @@ * UDSConnector.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/UDSConnector.h + * gpcontrib/gp_stats_collector/src/UDSConnector.h * *------------------------------------------------------------------------- */ #pragma once -#include "protos/yagpcc_set_service.pb.h" +#include "protos/gpsc_set_service.pb.h" class Config; class UDSConnector { public: - bool static report_query(const yagpcc::SetQueryReq &req, + bool static report_query(const gpsc::SetQueryReq &req, const std::string &event, const Config &config); }; diff --git a/gpcontrib/yagp_hooks_collector/src/yagp_hooks_collector.c b/gpcontrib/gp_stats_collector/src/gp_stats_collector.c similarity index 79% rename from gpcontrib/yagp_hooks_collector/src/yagp_hooks_collector.c rename to gpcontrib/gp_stats_collector/src/gp_stats_collector.c index 271bceee178..d930f72246d 100644 --- a/gpcontrib/yagp_hooks_collector/src/yagp_hooks_collector.c +++ b/gpcontrib/gp_stats_collector/src/gp_stats_collector.c @@ -17,10 +17,10 @@ * specific language governing permissions and limitations * under the License. * - * yagp_hooks_collector.c + * gp_stats_collector.c * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/yagp_hooks_collector.c + * gpcontrib/gp_stats_collector/src/gp_stats_collector.c * *------------------------------------------------------------------------- */ @@ -36,14 +36,14 @@ PG_MODULE_MAGIC; void _PG_init(void); void _PG_fini(void); -PG_FUNCTION_INFO_V1(yagp_stat_messages_reset); -PG_FUNCTION_INFO_V1(yagp_stat_messages); -PG_FUNCTION_INFO_V1(yagp_init_log); -PG_FUNCTION_INFO_V1(yagp_truncate_log); +PG_FUNCTION_INFO_V1(gpsc_stat_messages_reset); +PG_FUNCTION_INFO_V1(gpsc_stat_messages); +PG_FUNCTION_INFO_V1(gpsc_init_log); +PG_FUNCTION_INFO_V1(gpsc_truncate_log); -PG_FUNCTION_INFO_V1(yagp_test_uds_start_server); -PG_FUNCTION_INFO_V1(yagp_test_uds_receive); -PG_FUNCTION_INFO_V1(yagp_test_uds_stop_server); +PG_FUNCTION_INFO_V1(gpsc_test_uds_start_server); +PG_FUNCTION_INFO_V1(gpsc_test_uds_receive); +PG_FUNCTION_INFO_V1(gpsc_test_uds_stop_server); void _PG_init(void) { if (Gp_role == GP_ROLE_DISPATCH || Gp_role == GP_ROLE_EXECUTE) @@ -55,23 +55,23 @@ void _PG_fini(void) { hooks_deinit(); } -Datum yagp_stat_messages_reset(PG_FUNCTION_ARGS) { +Datum gpsc_stat_messages_reset(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; if (SRF_IS_FIRSTCALL()) { funcctx = SRF_FIRSTCALL_INIT(); - yagp_functions_reset(); + gpsc_functions_reset(); } funcctx = SRF_PERCALL_SETUP(); SRF_RETURN_DONE(funcctx); } -Datum yagp_stat_messages(PG_FUNCTION_ARGS) { - return yagp_functions_get(fcinfo); +Datum gpsc_stat_messages(PG_FUNCTION_ARGS) { + return gpsc_functions_get(fcinfo); } -Datum yagp_init_log(PG_FUNCTION_ARGS) { +Datum gpsc_init_log(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; if (SRF_IS_FIRSTCALL()) { @@ -83,7 +83,7 @@ Datum yagp_init_log(PG_FUNCTION_ARGS) { SRF_RETURN_DONE(funcctx); } -Datum yagp_truncate_log(PG_FUNCTION_ARGS) { +Datum gpsc_truncate_log(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; if (SRF_IS_FIRSTCALL()) { @@ -95,7 +95,7 @@ Datum yagp_truncate_log(PG_FUNCTION_ARGS) { SRF_RETURN_DONE(funcctx); } -Datum yagp_test_uds_start_server(PG_FUNCTION_ARGS) { +Datum gpsc_test_uds_start_server(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; if (SRF_IS_FIRSTCALL()) { @@ -109,7 +109,7 @@ Datum yagp_test_uds_start_server(PG_FUNCTION_ARGS) { SRF_RETURN_DONE(funcctx); } -Datum yagp_test_uds_receive(PG_FUNCTION_ARGS) { +Datum gpsc_test_uds_receive(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; int64 *result; @@ -137,7 +137,7 @@ Datum yagp_test_uds_receive(PG_FUNCTION_ARGS) { SRF_RETURN_DONE(funcctx); } -Datum yagp_test_uds_stop_server(PG_FUNCTION_ARGS) { +Datum gpsc_test_uds_stop_server(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; if (SRF_IS_FIRSTCALL()) { diff --git a/gpcontrib/yagp_hooks_collector/src/hook_wrappers.cpp b/gpcontrib/gp_stats_collector/src/hook_wrappers.cpp similarity index 84% rename from gpcontrib/yagp_hooks_collector/src/hook_wrappers.cpp rename to gpcontrib/gp_stats_collector/src/hook_wrappers.cpp index cb4970d60d9..0a40b4cb359 100644 --- a/gpcontrib/yagp_hooks_collector/src/hook_wrappers.cpp +++ b/gpcontrib/gp_stats_collector/src/hook_wrappers.cpp @@ -20,7 +20,7 @@ * hook_wrappers.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/hook_wrappers.cpp + * gpcontrib/gp_stats_collector/src/hook_wrappers.cpp * *------------------------------------------------------------------------- */ @@ -48,7 +48,7 @@ extern "C" { #undef typeid #include "Config.h" -#include "YagpStat.h" +#include "GpscStat.h" #include "EventSender.h" #include "hook_wrappers.h" #include "memory/gpdbwrappers.h" @@ -67,20 +67,20 @@ static ic_teardown_hook_type previous_ic_teardown_hook = nullptr; #endif static ProcessUtility_hook_type previous_ProcessUtility_hook = nullptr; -static void ya_ExecutorStart_hook(QueryDesc *query_desc, int eflags); -static void ya_ExecutorRun_hook(QueryDesc *query_desc, ScanDirection direction, +static void gpsc_ExecutorStart_hook(QueryDesc *query_desc, int eflags); +static void gpsc_ExecutorRun_hook(QueryDesc *query_desc, ScanDirection direction, uint64 count, bool execute_once); -static void ya_ExecutorFinish_hook(QueryDesc *query_desc); -static void ya_ExecutorEnd_hook(QueryDesc *query_desc); -static void ya_query_info_collect_hook(QueryMetricsStatus status, void *arg); +static void gpsc_ExecutorFinish_hook(QueryDesc *query_desc); +static void gpsc_ExecutorEnd_hook(QueryDesc *query_desc); +static void gpsc_query_info_collect_hook(QueryMetricsStatus status, void *arg); #ifdef IC_TEARDOWN_HOOK -static void ya_ic_teardown_hook(ChunkTransportState *transportStates, +static void gpsc_ic_teardown_hook(ChunkTransportState *transportStates, bool hasErrors); #endif #ifdef ANALYZE_STATS_COLLECT_HOOK -static void ya_analyze_stats_collect_hook(QueryDesc *query_desc); +static void gpsc_analyze_stats_collect_hook(QueryDesc *query_desc); #endif -static void ya_process_utility_hook(PlannedStmt *pstmt, const char *queryString, +static void gpsc_process_utility_hook(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, @@ -108,34 +108,34 @@ R cpp_call(T *obj, R (T::*func)(Args...), Args... args) { try { return (obj->*func)(args...); } catch (const std::exception &e) { - ereport(FATAL, (errmsg("Unexpected exception in yagpcc %s", e.what()))); + ereport(FATAL, (errmsg("Unexpected exception in gpsc %s", e.what()))); } } void hooks_init() { Config::init_gucs(); - YagpStat::init(); + GpscStat::init(); previous_ExecutorStart_hook = ExecutorStart_hook; - ExecutorStart_hook = ya_ExecutorStart_hook; + ExecutorStart_hook = gpsc_ExecutorStart_hook; previous_ExecutorRun_hook = ExecutorRun_hook; - ExecutorRun_hook = ya_ExecutorRun_hook; + ExecutorRun_hook = gpsc_ExecutorRun_hook; previous_ExecutorFinish_hook = ExecutorFinish_hook; - ExecutorFinish_hook = ya_ExecutorFinish_hook; + ExecutorFinish_hook = gpsc_ExecutorFinish_hook; previous_ExecutorEnd_hook = ExecutorEnd_hook; - ExecutorEnd_hook = ya_ExecutorEnd_hook; + ExecutorEnd_hook = gpsc_ExecutorEnd_hook; previous_query_info_collect_hook = query_info_collect_hook; - query_info_collect_hook = ya_query_info_collect_hook; + query_info_collect_hook = gpsc_query_info_collect_hook; #ifdef IC_TEARDOWN_HOOK previous_ic_teardown_hook = ic_teardown_hook; - ic_teardown_hook = ya_ic_teardown_hook; + ic_teardown_hook = gpsc_ic_teardown_hook; #endif #ifdef ANALYZE_STATS_COLLECT_HOOK previous_analyze_stats_collect_hook = analyze_stats_collect_hook; - analyze_stats_collect_hook = ya_analyze_stats_collect_hook; + analyze_stats_collect_hook = gpsc_analyze_stats_collect_hook; #endif stat_statements_parser_init(); previous_ProcessUtility_hook = ProcessUtility_hook; - ProcessUtility_hook = ya_process_utility_hook; + ProcessUtility_hook = gpsc_process_utility_hook; } void hooks_deinit() { @@ -154,11 +154,11 @@ void hooks_deinit() { if (sender) { delete sender; } - YagpStat::deinit(); + GpscStat::deinit(); ProcessUtility_hook = previous_ProcessUtility_hook; } -void ya_ExecutorStart_hook(QueryDesc *query_desc, int eflags) { +void gpsc_ExecutorStart_hook(QueryDesc *query_desc, int eflags) { cpp_call(get_sender(), &EventSender::executor_before_start, query_desc, eflags); if (previous_ExecutorStart_hook) { @@ -170,7 +170,7 @@ void ya_ExecutorStart_hook(QueryDesc *query_desc, int eflags) { eflags); } -void ya_ExecutorRun_hook(QueryDesc *query_desc, ScanDirection direction, +void gpsc_ExecutorRun_hook(QueryDesc *query_desc, ScanDirection direction, uint64 count, bool execute_once) { get_sender()->incr_depth(); PG_TRY(); @@ -189,7 +189,7 @@ void ya_ExecutorRun_hook(QueryDesc *query_desc, ScanDirection direction, PG_END_TRY(); } -void ya_ExecutorFinish_hook(QueryDesc *query_desc) { +void gpsc_ExecutorFinish_hook(QueryDesc *query_desc) { get_sender()->incr_depth(); PG_TRY(); { @@ -207,7 +207,7 @@ void ya_ExecutorFinish_hook(QueryDesc *query_desc) { PG_END_TRY(); } -void ya_ExecutorEnd_hook(QueryDesc *query_desc) { +void gpsc_ExecutorEnd_hook(QueryDesc *query_desc) { cpp_call(get_sender(), &EventSender::executor_end, query_desc); if (previous_ExecutorEnd_hook) { (*previous_ExecutorEnd_hook)(query_desc); @@ -216,7 +216,7 @@ void ya_ExecutorEnd_hook(QueryDesc *query_desc) { } } -void ya_query_info_collect_hook(QueryMetricsStatus status, void *arg) { +void gpsc_query_info_collect_hook(QueryMetricsStatus status, void *arg) { cpp_call(get_sender(), &EventSender::query_metrics_collect, status, arg /* queryDesc */, false /* utility */, (ErrorData *)NULL); if (previous_query_info_collect_hook) { @@ -225,7 +225,7 @@ void ya_query_info_collect_hook(QueryMetricsStatus status, void *arg) { } #ifdef IC_TEARDOWN_HOOK -void ya_ic_teardown_hook(ChunkTransportState *transportStates, bool hasErrors) { +void gpsc_ic_teardown_hook(ChunkTransportState *transportStates, bool hasErrors) { cpp_call(get_sender(), &EventSender::ic_metrics_collect); if (previous_ic_teardown_hook) { (*previous_ic_teardown_hook)(transportStates, hasErrors); @@ -234,7 +234,7 @@ void ya_ic_teardown_hook(ChunkTransportState *transportStates, bool hasErrors) { #endif #ifdef ANALYZE_STATS_COLLECT_HOOK -void ya_analyze_stats_collect_hook(QueryDesc *query_desc) { +void gpsc_analyze_stats_collect_hook(QueryDesc *query_desc) { cpp_call(get_sender(), &EventSender::analyze_stats_collect, query_desc); if (previous_analyze_stats_collect_hook) { (*previous_analyze_stats_collect_hook)(query_desc); @@ -242,7 +242,7 @@ void ya_analyze_stats_collect_hook(QueryDesc *query_desc) { } #endif -static void ya_process_utility_hook(PlannedStmt *pstmt, const char *queryString, +static void gpsc_process_utility_hook(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, @@ -296,22 +296,22 @@ static void ya_process_utility_hook(PlannedStmt *pstmt, const char *queryString, } static void check_stats_loaded() { - if (!YagpStat::loaded()) { + if (!GpscStat::loaded()) { ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("yagp_hooks_collector must be loaded via " + errmsg("gp_stats_collector must be loaded via " "shared_preload_libraries"))); } } -void yagp_functions_reset() { +void gpsc_functions_reset() { check_stats_loaded(); - YagpStat::reset(); + GpscStat::reset(); } -Datum yagp_functions_get(FunctionCallInfo fcinfo) { +Datum gpsc_functions_get(FunctionCallInfo fcinfo) { const int ATTNUM = 6; check_stats_loaded(); - auto stats = YagpStat::get_stats(); + auto stats = GpscStat::get_stats(); TupleDesc tupdesc = CreateTemplateTupleDesc(ATTNUM); TupleDescInitEntry(tupdesc, (AttrNumber)1, "segid", INT4OID, -1 /* typmod */, 0 /* attdim */); @@ -335,7 +335,7 @@ Datum yagp_functions_get(FunctionCallInfo fcinfo) { values[3] = Int64GetDatum(stats.failed_connects); values[4] = Int64GetDatum(stats.failed_other); values[5] = Int32GetDatum(stats.max_message_size); - HeapTuple tuple = ya_gpdb::heap_form_tuple(tupdesc, values, nulls); + HeapTuple tuple = gpdb::heap_form_tuple(tupdesc, values, nulls); Datum result = HeapTupleGetDatum(tuple); PG_RETURN_DATUM(result); } diff --git a/gpcontrib/yagp_hooks_collector/src/hook_wrappers.h b/gpcontrib/gp_stats_collector/src/hook_wrappers.h similarity index 89% rename from gpcontrib/yagp_hooks_collector/src/hook_wrappers.h rename to gpcontrib/gp_stats_collector/src/hook_wrappers.h index 443406a5259..06c8d064404 100644 --- a/gpcontrib/yagp_hooks_collector/src/hook_wrappers.h +++ b/gpcontrib/gp_stats_collector/src/hook_wrappers.h @@ -20,7 +20,7 @@ * hook_wrappers.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/hook_wrappers.h + * gpcontrib/gp_stats_collector/src/hook_wrappers.h * *------------------------------------------------------------------------- */ @@ -33,8 +33,8 @@ extern "C" { extern void hooks_init(); extern void hooks_deinit(); -extern void yagp_functions_reset(); -extern Datum yagp_functions_get(FunctionCallInfo fcinfo); +extern void gpsc_functions_reset(); +extern Datum gpsc_functions_get(FunctionCallInfo fcinfo); extern void init_log(); extern void truncate_log(); diff --git a/gpcontrib/yagp_hooks_collector/src/log/LogOps.cpp b/gpcontrib/gp_stats_collector/src/log/LogOps.cpp similarity index 91% rename from gpcontrib/yagp_hooks_collector/src/log/LogOps.cpp rename to gpcontrib/gp_stats_collector/src/log/LogOps.cpp index e8c927ece84..ef4f39c0749 100644 --- a/gpcontrib/yagp_hooks_collector/src/log/LogOps.cpp +++ b/gpcontrib/gp_stats_collector/src/log/LogOps.cpp @@ -20,12 +20,12 @@ * LogOps.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/log/LogOps.cpp + * gpcontrib/gp_stats_collector/src/log/LogOps.cpp * *------------------------------------------------------------------------- */ -#include "protos/yagpcc_set_service.pb.h" +#include "protos/gpsc_set_service.pb.h" #include "LogOps.h" #include "LogSchema.h" @@ -82,14 +82,14 @@ void init_log() { /* Table can be dropped only via DROP EXTENSION */ recordDependencyOn(&tableAddr, &schemaAddr, DEPENDENCY_EXTENSION); } else { - ereport(NOTICE, (errmsg("YAGPCC failed to create log table or schema"))); + ereport(NOTICE, (errmsg("GPSC failed to create log table or schema"))); } /* Make changes visible */ CommandCounterIncrement(); } -void insert_log(const yagpcc::SetQueryReq &req, bool utility) { +void insert_log(const gpsc::SetQueryReq &req, bool utility) { Oid namespaceId; Oid relationId; Relation rel; @@ -112,15 +112,15 @@ void insert_log(const yagpcc::SetQueryReq &req, bool utility) { return; } - bool nulls[natts_yagp_log]; - Datum values[natts_yagp_log]; + bool nulls[natts_gpsc_log]; + Datum values[natts_gpsc_log]; memset(nulls, true, sizeof(nulls)); memset(values, 0, sizeof(values)); extract_query_req(req, "", values, nulls); - nulls[attnum_yagp_log_utility] = false; - values[attnum_yagp_log_utility] = BoolGetDatum(utility); + nulls[attnum_gpsc_log_utility] = false; + values[attnum_gpsc_log_utility] = BoolGetDatum(utility); rel = heap_open(relationId, RowExclusiveLock); diff --git a/gpcontrib/yagp_hooks_collector/src/log/LogOps.h b/gpcontrib/gp_stats_collector/src/log/LogOps.h similarity index 83% rename from gpcontrib/yagp_hooks_collector/src/log/LogOps.h rename to gpcontrib/gp_stats_collector/src/log/LogOps.h index 1fc30c21030..f784270bb8f 100644 --- a/gpcontrib/yagp_hooks_collector/src/log/LogOps.h +++ b/gpcontrib/gp_stats_collector/src/log/LogOps.h @@ -20,7 +20,7 @@ * LogOps.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/log/LogOps.h + * gpcontrib/gp_stats_collector/src/log/LogOps.h * *------------------------------------------------------------------------- */ @@ -35,12 +35,12 @@ extern "C" { } extern "C" { -/* CREATE TABLE yagpcc.__log (...); */ +/* CREATE TABLE gpsc.__log (...); */ void init_log(); -/* TRUNCATE yagpcc.__log */ +/* TRUNCATE gpsc.__log */ void truncate_log(); } -/* INSERT INTO yagpcc.__log VALUES (...) */ -void insert_log(const yagpcc::SetQueryReq &req, bool utility); +/* INSERT INTO gpsc.__log VALUES (...) */ +void insert_log(const gpsc::SetQueryReq &req, bool utility); diff --git a/gpcontrib/yagp_hooks_collector/src/log/LogSchema.cpp b/gpcontrib/gp_stats_collector/src/log/LogSchema.cpp similarity index 94% rename from gpcontrib/yagp_hooks_collector/src/log/LogSchema.cpp rename to gpcontrib/gp_stats_collector/src/log/LogSchema.cpp index a391b1a2209..f9f43fac2fd 100644 --- a/gpcontrib/yagp_hooks_collector/src/log/LogSchema.cpp +++ b/gpcontrib/gp_stats_collector/src/log/LogSchema.cpp @@ -20,7 +20,7 @@ * LogSchema.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/log/LogSchema.cpp + * gpcontrib/gp_stats_collector/src/log/LogSchema.cpp * *------------------------------------------------------------------------- */ @@ -36,7 +36,7 @@ const std::unordered_map &proto_name_to_col_idx() { std::unordered_map map; map.reserve(log_tbl_desc.size()); - for (size_t idx = 0; idx < natts_yagp_log; ++idx) { + for (size_t idx = 0; idx < natts_gpsc_log; ++idx) { map.emplace(log_tbl_desc[idx].proto_field_name, idx); } @@ -46,9 +46,9 @@ const std::unordered_map &proto_name_to_col_idx() { } TupleDesc DescribeTuple() { - TupleDesc tupdesc = CreateTemplateTupleDesc(natts_yagp_log); + TupleDesc tupdesc = CreateTemplateTupleDesc(natts_gpsc_log); - for (size_t anum = 1; anum <= natts_yagp_log; ++anum) { + for (size_t anum = 1; anum <= natts_gpsc_log; ++anum) { TupleDescInitEntry(tupdesc, anum, log_tbl_desc[anum - 1].pg_att_name.data(), log_tbl_desc[anum - 1].type_oid, -1 /* typmod */, 0 /* attdim */); @@ -104,7 +104,7 @@ void process_field(const google::protobuf::FieldDescriptor *field, if (it == proto_idx_map.end()) { ereport(NOTICE, - (errmsg("YAGPCC protobuf field %s is not registered in log table", + (errmsg("GPSC protobuf field %s is not registered in log table", field_name.c_str()))); return; } diff --git a/gpcontrib/yagp_hooks_collector/src/log/LogSchema.h b/gpcontrib/gp_stats_collector/src/log/LogSchema.h similarity index 98% rename from gpcontrib/yagp_hooks_collector/src/log/LogSchema.h rename to gpcontrib/gp_stats_collector/src/log/LogSchema.h index f78acec7ce9..8754741823a 100644 --- a/gpcontrib/yagp_hooks_collector/src/log/LogSchema.h +++ b/gpcontrib/gp_stats_collector/src/log/LogSchema.h @@ -20,7 +20,7 @@ * LogSchema.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/log/LogSchema.h + * gpcontrib/gp_stats_collector/src/log/LogSchema.h * *------------------------------------------------------------------------- */ @@ -50,7 +50,7 @@ class Timestamp; } // namespace protobuf } // namespace google -inline constexpr std::string_view schema_name = "yagpcc"; +inline constexpr std::string_view schema_name = "gpsc"; inline constexpr std::string_view log_relname = "__log"; struct LogDesc { @@ -165,8 +165,8 @@ inline constexpr std::array log_tbl_desc = { }; /* clang-format on */ -inline constexpr size_t natts_yagp_log = log_tbl_desc.size(); -inline constexpr size_t attnum_yagp_log_utility = natts_yagp_log - 1; +inline constexpr size_t natts_gpsc_log = log_tbl_desc.size(); +inline constexpr size_t attnum_gpsc_log_utility = natts_gpsc_log - 1; const std::unordered_map &proto_name_to_col_idx(); diff --git a/gpcontrib/yagp_hooks_collector/src/memory/gpdbwrappers.cpp b/gpcontrib/gp_stats_collector/src/memory/gpdbwrappers.cpp similarity index 81% rename from gpcontrib/yagp_hooks_collector/src/memory/gpdbwrappers.cpp rename to gpcontrib/gp_stats_collector/src/memory/gpdbwrappers.cpp index 22083e8bdaf..4e3f6dae99f 100644 --- a/gpcontrib/yagp_hooks_collector/src/memory/gpdbwrappers.cpp +++ b/gpcontrib/gp_stats_collector/src/memory/gpdbwrappers.cpp @@ -20,7 +20,7 @@ * gpdbwrappers.cpp * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/memory/gpdbwrappers.cpp + * gpcontrib/gp_stats_collector/src/memory/gpdbwrappers.cpp * *------------------------------------------------------------------------- */ @@ -125,22 +125,22 @@ auto wrap_noexcept(Func &&func, Args &&...args) noexcept } } // namespace -void *ya_gpdb::palloc(Size size) { return wrap_throw(::palloc, size); } +void *gpdb::palloc(Size size) { return wrap_throw(::palloc, size); } -void *ya_gpdb::palloc0(Size size) { return wrap_throw(::palloc0, size); } +void *gpdb::palloc0(Size size) { return wrap_throw(::palloc0, size); } -char *ya_gpdb::pstrdup(const char *str) { return wrap_throw(::pstrdup, str); } +char *gpdb::pstrdup(const char *str) { return wrap_throw(::pstrdup, str); } -char *ya_gpdb::get_database_name(Oid dbid) noexcept { +char *gpdb::get_database_name(Oid dbid) noexcept { return wrap_noexcept(::get_database_name, dbid); } -bool ya_gpdb::split_identifier_string(char *rawstring, char separator, +bool gpdb::split_identifier_string(char *rawstring, char separator, List **namelist) noexcept { return wrap_noexcept(SplitIdentifierString, rawstring, separator, namelist); } -ExplainState ya_gpdb::get_explain_state(QueryDesc *query_desc, +ExplainState gpdb::get_explain_state(QueryDesc *query_desc, bool costs) noexcept { return wrap_noexcept([&]() { ExplainState *es = NewExplainState(); @@ -154,7 +154,7 @@ ExplainState ya_gpdb::get_explain_state(QueryDesc *query_desc, }); } -ExplainState ya_gpdb::get_analyze_state(QueryDesc *query_desc, +ExplainState gpdb::get_analyze_state(QueryDesc *query_desc, bool analyze) noexcept { return wrap_noexcept([&]() { ExplainState *es = NewExplainState(); @@ -174,12 +174,12 @@ ExplainState ya_gpdb::get_analyze_state(QueryDesc *query_desc, }); } -Instrumentation *ya_gpdb::instr_alloc(size_t n, int instrument_options, +Instrumentation *gpdb::instr_alloc(size_t n, int instrument_options, bool async_mode) { return wrap_throw(InstrAlloc, n, instrument_options, async_mode); } -HeapTuple ya_gpdb::heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, +HeapTuple gpdb::heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull) { if (!tupleDescriptor || !values || !isnull) throw std::runtime_error( @@ -188,7 +188,7 @@ HeapTuple ya_gpdb::heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, return wrap_throw(::heap_form_tuple, tupleDescriptor, values, isnull); } -void ya_gpdb::pfree(void *pointer) noexcept { +void gpdb::pfree(void *pointer) noexcept { // Note that ::pfree asserts that pointer != NULL. if (!pointer) return; @@ -196,11 +196,11 @@ void ya_gpdb::pfree(void *pointer) noexcept { wrap_noexcept(::pfree, pointer); } -MemoryContext ya_gpdb::mem_ctx_switch_to(MemoryContext context) noexcept { +MemoryContext gpdb::mem_ctx_switch_to(MemoryContext context) noexcept { return MemoryContextSwitchTo(context); } -const char *ya_gpdb::get_config_option(const char *name, bool missing_ok, +const char *gpdb::get_config_option(const char *name, bool missing_ok, bool restrict_superuser) noexcept { if (!name) return nullptr; @@ -208,7 +208,7 @@ const char *ya_gpdb::get_config_option(const char *name, bool missing_ok, return wrap_noexcept(GetConfigOption, name, missing_ok, restrict_superuser); } -void ya_gpdb::list_free(List *list) noexcept { +void gpdb::list_free(List *list) noexcept { if (!list) return; @@ -216,7 +216,7 @@ void ya_gpdb::list_free(List *list) noexcept { } CdbExplain_ShowStatCtx * -ya_gpdb::cdbexplain_showExecStatsBegin(QueryDesc *query_desc, +gpdb::cdbexplain_showExecStatsBegin(QueryDesc *query_desc, instr_time starttime) { if (!query_desc) throw std::runtime_error("Invalid query descriptor"); @@ -224,29 +224,29 @@ ya_gpdb::cdbexplain_showExecStatsBegin(QueryDesc *query_desc, return wrap_throw(::cdbexplain_showExecStatsBegin, query_desc, starttime); } -void ya_gpdb::instr_end_loop(Instrumentation *instr) { +void gpdb::instr_end_loop(Instrumentation *instr) { if (!instr) throw std::runtime_error("Invalid instrumentation pointer"); wrap_throw(::InstrEndLoop, instr); } -char *ya_gpdb::gen_normquery(const char *query) noexcept { +char *gpdb::gen_normquery(const char *query) noexcept { return wrap_noexcept(::gen_normquery, query); } -StringInfo ya_gpdb::gen_normplan(const char *exec_plan) noexcept { +StringInfo gpdb::gen_normplan(const char *exec_plan) noexcept { return wrap_noexcept(::gen_normplan, exec_plan); } -char *ya_gpdb::get_rg_name_for_id(Oid group_id) { +char *gpdb::get_rg_name_for_id(Oid group_id) { return wrap_throw(GetResGroupNameForId, group_id); } -Oid ya_gpdb::get_rg_id_by_session_id(int session_id) { +Oid gpdb::get_rg_id_by_session_id(int session_id) { return wrap_throw(ResGroupGetGroupIdBySessionId, session_id); } -void ya_gpdb::insert_log(const yagpcc::SetQueryReq &req, bool utility) { +void gpdb::insert_log(const gpsc::SetQueryReq &req, bool utility) { return wrap_throw(::insert_log, req, utility); } diff --git a/gpcontrib/yagp_hooks_collector/src/memory/gpdbwrappers.h b/gpcontrib/gp_stats_collector/src/memory/gpdbwrappers.h similarity index 92% rename from gpcontrib/yagp_hooks_collector/src/memory/gpdbwrappers.h rename to gpcontrib/gp_stats_collector/src/memory/gpdbwrappers.h index fe9b3ba0487..576007f6c7c 100644 --- a/gpcontrib/yagp_hooks_collector/src/memory/gpdbwrappers.h +++ b/gpcontrib/gp_stats_collector/src/memory/gpdbwrappers.h @@ -20,7 +20,7 @@ * gpdbwrappers.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/memory/gpdbwrappers.h + * gpcontrib/gp_stats_collector/src/memory/gpdbwrappers.h * *------------------------------------------------------------------------- */ @@ -43,11 +43,11 @@ extern "C" { #include #include -namespace yagpcc { +namespace gpsc { class SetQueryReq; -} // namespace yagpcc +} // namespace gpsc -namespace ya_gpdb { +namespace gpdb { // Functions that call palloc(). // Make sure correct memory context is set. @@ -68,7 +68,7 @@ void instr_end_loop(Instrumentation *instr); char *gen_normquery(const char *query) noexcept; StringInfo gen_normplan(const char *executionPlan) noexcept; char *get_rg_name_for_id(Oid group_id); -void insert_log(const yagpcc::SetQueryReq &req, bool utility); +void insert_log(const gpsc::SetQueryReq &req, bool utility); // Palloc-free functions. void pfree(void *pointer) noexcept; @@ -78,4 +78,4 @@ const char *get_config_option(const char *name, bool missing_ok, void list_free(List *list) noexcept; Oid get_rg_id_by_session_id(int session_id); -} // namespace ya_gpdb +} // namespace gpdb diff --git a/gpcontrib/gp_stats_collector/src/stat_statements_parser/README.md b/gpcontrib/gp_stats_collector/src/stat_statements_parser/README.md new file mode 100644 index 00000000000..927189474fe --- /dev/null +++ b/gpcontrib/gp_stats_collector/src/stat_statements_parser/README.md @@ -0,0 +1,20 @@ + + +This directory contains a slightly modified subset of pg_stat_statements for PG v9.4 to be used in query and plan ID generation. diff --git a/gpcontrib/yagp_hooks_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.c b/gpcontrib/gp_stats_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.c similarity index 99% rename from gpcontrib/yagp_hooks_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.c rename to gpcontrib/gp_stats_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.c index 7404208055f..e24f53536a4 100644 --- a/gpcontrib/yagp_hooks_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.c +++ b/gpcontrib/gp_stats_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.c @@ -20,7 +20,7 @@ * pg_stat_statements_ya_parser.c * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.c + * gpcontrib/gp_stats_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.c * *------------------------------------------------------------------------- */ diff --git a/gpcontrib/yagp_hooks_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.h b/gpcontrib/gp_stats_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.h similarity index 93% rename from gpcontrib/yagp_hooks_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.h rename to gpcontrib/gp_stats_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.h index 96c6a776dba..a613ba04259 100644 --- a/gpcontrib/yagp_hooks_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.h +++ b/gpcontrib/gp_stats_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.h @@ -20,7 +20,7 @@ * pg_stat_statements_ya_parser.h * * IDENTIFICATION - * gpcontrib/yagp_hooks_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.h + * gpcontrib/gp_stats_collector/src/stat_statements_parser/pg_stat_statements_ya_parser.h * *------------------------------------------------------------------------- */ diff --git a/gpcontrib/yagp_hooks_collector/README.md b/gpcontrib/yagp_hooks_collector/README.md deleted file mode 100644 index 9f465a190cb..00000000000 --- a/gpcontrib/yagp_hooks_collector/README.md +++ /dev/null @@ -1,28 +0,0 @@ -## YAGP Hooks Collector - -An extension for collecting greenplum query execution metrics and reporting them to an external agent. - -### Collected Statistics - -#### 1. Query Lifecycle -- **What:** Captures query text, normalized query text, timestamps (submit, start, end, done), and user/database info. -- **GUC:** `yagpcc.enable`. - -#### 2. `EXPLAIN` data -- **What:** Triggers generation of the `EXPLAIN (TEXT, COSTS, VERBOSE)` and captures it. -- **GUC:** `yagpcc.enable`. - -#### 3. `EXPLAIN ANALYZE` data -- **What:** Triggers generation of the `EXPLAIN (TEXT, ANALYZE, BUFFERS, TIMING, VERBOSE)` and captures it. -- **GUCs:** `yagpcc.enable`, `yagpcc.min_analyze_time`, `yagpcc.enable_cdbstats`(ANALYZE), `yagpcc.enable_analyze`(BUFFERS, TIMING, VERBOSE). - -#### 4. Other Metrics -- **What:** Captures Instrument, Greenplum, System, Network, Interconnect, Spill metrics. -- **GUC:** `yagpcc.enable`. - -### General Configuration -- **Nested Queries:** When `yagpcc.report_nested_queries` is `false`, only top-level queries are reported from the coordinator and segments, when `true`, both top-level and nested queries are reported from the coordinator, from segments collected as aggregates. -- **Data Destination:** All collected data is sent to a Unix Domain Socket. Configure the path with `yagpcc.uds_path`. -- **User Filtering:** To exclude activity from certain roles, add them to the comma-separated list in `yagpcc.ignored_users_list`. -- **Trimming plans:** Query texts and execution plans are trimmed based on `yagpcc.max_text_size` and `yagpcc.max_plan_size` (default: 1024KB). For now, it is not recommended to set these GUCs higher than 1024KB. -- **Analyze collection:** Analyze is sent if execution time exceeds `yagpcc.min_analyze_time`, which is 10 seconds by default. Analyze is collected if `yagpcc.enable_analyze` is true. diff --git a/gpcontrib/yagp_hooks_collector/expected/yagp_locale.out b/gpcontrib/yagp_hooks_collector/expected/yagp_locale.out deleted file mode 100644 index 6689b6a4ed3..00000000000 --- a/gpcontrib/yagp_hooks_collector/expected/yagp_locale.out +++ /dev/null @@ -1,23 +0,0 @@ --- The extension generates normalized query text and plan using jumbling functions. --- Those functions may fail when translating to wide character if the current locale --- cannot handle the character set. This test checks that even when those functions --- fail, the plan is still generated and executed. This test is partially taken from --- gp_locale. --- start_ignore -DROP DATABASE IF EXISTS yagp_test_locale; --- end_ignore -CREATE DATABASE yagp_test_locale WITH LC_COLLATE='C' LC_CTYPE='C' TEMPLATE=template0; -\c yagp_test_locale -CREATE EXTENSION yagp_hooks_collector; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable_utility TO TRUE; -SET yagpcc.enable TO TRUE; -CREATE TABLE yagp_hi_안녕세계 (a int, 안녕세계1 text, 안녕세계2 text, 안녕세계3 text) DISTRIBUTED BY (a); -INSERT INTO yagp_hi_안녕세계 VALUES(1, '안녕세계1 first', '안녕세2 first', '안녕세계3 first'); --- Should not see error here -UPDATE yagp_hi_안녕세계 SET 안녕세계1='안녕세계1 first UPDATE' WHERE 안녕세계1='안녕세계1 first'; -RESET yagpcc.enable; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; -DROP TABLE yagp_hi_안녕세계; -DROP EXTENSION yagp_hooks_collector; diff --git a/gpcontrib/yagp_hooks_collector/expected/yagp_uds.out b/gpcontrib/yagp_hooks_collector/expected/yagp_uds.out deleted file mode 100644 index d04929ffb4a..00000000000 --- a/gpcontrib/yagp_hooks_collector/expected/yagp_uds.out +++ /dev/null @@ -1,42 +0,0 @@ --- Test UDS socket --- start_ignore -CREATE EXTENSION IF NOT EXISTS yagp_hooks_collector; --- end_ignore -\set UDS_PATH '/tmp/yagpcc_test.sock' --- Configure extension to send via UDS -SET yagpcc.uds_path TO :'UDS_PATH'; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.logging_mode TO 'UDS'; --- Start receiver -SELECT yagpcc.__test_uds_start_server(:'UDS_PATH'); - __test_uds_start_server -------------------------- -(0 rows) - --- Send -SELECT 1; - ?column? ----------- - 1 -(1 row) - --- Receive -SELECT yagpcc.__test_uds_receive() > 0 as received; - received ----------- - t -(1 row) - --- Stop receiver -SELECT yagpcc.__test_uds_stop_server(); - __test_uds_stop_server ------------------------- -(0 rows) - --- Cleanup -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.uds_path; -RESET yagpcc.ignored_users_list; -RESET yagpcc.enable; -RESET yagpcc.logging_mode; diff --git a/gpcontrib/yagp_hooks_collector/sql/yagp_cursors.sql b/gpcontrib/yagp_hooks_collector/sql/yagp_cursors.sql deleted file mode 100644 index f56351e0d43..00000000000 --- a/gpcontrib/yagp_hooks_collector/sql/yagp_cursors.sql +++ /dev/null @@ -1,85 +0,0 @@ -CREATE EXTENSION yagp_hooks_collector; - -CREATE FUNCTION yagp_status_order(status text) -RETURNS integer -AS $$ -BEGIN - RETURN CASE status - WHEN 'QUERY_STATUS_SUBMIT' THEN 1 - WHEN 'QUERY_STATUS_START' THEN 2 - WHEN 'QUERY_STATUS_END' THEN 3 - WHEN 'QUERY_STATUS_DONE' THEN 4 - ELSE 999 - END; -END; -$$ LANGUAGE plpgsql IMMUTABLE; - -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.enable_utility TO TRUE; -SET yagpcc.report_nested_queries TO TRUE; - --- DECLARE -SET yagpcc.logging_mode to 'TBL'; - -BEGIN; -DECLARE cursor_stats_0 CURSOR FOR SELECT 0; -CLOSE cursor_stats_0; -COMMIT; - -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- DECLARE WITH HOLD -SET yagpcc.logging_mode to 'TBL'; - -BEGIN; -DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 1; -CLOSE cursor_stats_1; -DECLARE cursor_stats_2 CURSOR WITH HOLD FOR SELECT 2; -CLOSE cursor_stats_2; -COMMIT; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- ROLLBACK -SET yagpcc.logging_mode to 'TBL'; - -BEGIN; -DECLARE cursor_stats_3 CURSOR FOR SELECT 1; -CLOSE cursor_stats_3; -DECLARE cursor_stats_4 CURSOR FOR SELECT 1; -ROLLBACK; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- FETCH -SET yagpcc.logging_mode to 'TBL'; - -BEGIN; -DECLARE cursor_stats_5 CURSOR WITH HOLD FOR SELECT 2; -DECLARE cursor_stats_6 CURSOR WITH HOLD FOR SELECT 3; -FETCH 1 IN cursor_stats_5; -FETCH 1 IN cursor_stats_6; -CLOSE cursor_stats_5; -CLOSE cursor_stats_6; -COMMIT; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - -DROP FUNCTION yagp_status_order(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.report_nested_queries; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; diff --git a/gpcontrib/yagp_hooks_collector/sql/yagp_locale.sql b/gpcontrib/yagp_hooks_collector/sql/yagp_locale.sql deleted file mode 100644 index 65d867d1680..00000000000 --- a/gpcontrib/yagp_hooks_collector/sql/yagp_locale.sql +++ /dev/null @@ -1,29 +0,0 @@ --- The extension generates normalized query text and plan using jumbling functions. --- Those functions may fail when translating to wide character if the current locale --- cannot handle the character set. This test checks that even when those functions --- fail, the plan is still generated and executed. This test is partially taken from --- gp_locale. - --- start_ignore -DROP DATABASE IF EXISTS yagp_test_locale; --- end_ignore - -CREATE DATABASE yagp_test_locale WITH LC_COLLATE='C' LC_CTYPE='C' TEMPLATE=template0; -\c yagp_test_locale - -CREATE EXTENSION yagp_hooks_collector; - -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable_utility TO TRUE; -SET yagpcc.enable TO TRUE; - -CREATE TABLE yagp_hi_안녕세계 (a int, 안녕세계1 text, 안녕세계2 text, 안녕세계3 text) DISTRIBUTED BY (a); -INSERT INTO yagp_hi_안녕세계 VALUES(1, '안녕세계1 first', '안녕세2 first', '안녕세계3 first'); --- Should not see error here -UPDATE yagp_hi_안녕세계 SET 안녕세계1='안녕세계1 first UPDATE' WHERE 안녕세계1='안녕세계1 first'; - -RESET yagpcc.enable; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; -DROP TABLE yagp_hi_안녕세계; -DROP EXTENSION yagp_hooks_collector; diff --git a/gpcontrib/yagp_hooks_collector/sql/yagp_select.sql b/gpcontrib/yagp_hooks_collector/sql/yagp_select.sql deleted file mode 100644 index 90e972ae4c1..00000000000 --- a/gpcontrib/yagp_hooks_collector/sql/yagp_select.sql +++ /dev/null @@ -1,69 +0,0 @@ -CREATE EXTENSION yagp_hooks_collector; - -CREATE OR REPLACE FUNCTION yagp_status_order(status text) -RETURNS integer -AS $$ -BEGIN - RETURN CASE status - WHEN 'QUERY_STATUS_SUBMIT' THEN 1 - WHEN 'QUERY_STATUS_START' THEN 2 - WHEN 'QUERY_STATUS_END' THEN 3 - WHEN 'QUERY_STATUS_DONE' THEN 4 - ELSE 999 - END; -END; -$$ LANGUAGE plpgsql IMMUTABLE; - -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.report_nested_queries TO TRUE; -SET yagpcc.enable_utility TO FALSE; - --- Basic SELECT tests -SET yagpcc.logging_mode to 'TBL'; - -SELECT 1; -SELECT COUNT(*) FROM generate_series(1,10); - -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- Transaction test -SET yagpcc.logging_mode to 'TBL'; - -BEGIN; -SELECT 1; -COMMIT; - -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- CTE test -SET yagpcc.logging_mode to 'TBL'; - -WITH t AS (VALUES (1), (2)) -SELECT * FROM t; - -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- Prepared statement test -SET yagpcc.logging_mode to 'TBL'; - -PREPARE test_stmt AS SELECT 1; -EXECUTE test_stmt; -DEALLOCATE test_stmt; - -RESET yagpcc.logging_mode; -SELECT segid, query_text, query_status FROM yagpcc.log ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - -DROP FUNCTION yagp_status_order(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.report_nested_queries; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; diff --git a/gpcontrib/yagp_hooks_collector/sql/yagp_uds.sql b/gpcontrib/yagp_hooks_collector/sql/yagp_uds.sql deleted file mode 100644 index 3eef697a4e7..00000000000 --- a/gpcontrib/yagp_hooks_collector/sql/yagp_uds.sql +++ /dev/null @@ -1,31 +0,0 @@ --- Test UDS socket --- start_ignore -CREATE EXTENSION IF NOT EXISTS yagp_hooks_collector; --- end_ignore - -\set UDS_PATH '/tmp/yagpcc_test.sock' - --- Configure extension to send via UDS -SET yagpcc.uds_path TO :'UDS_PATH'; -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.logging_mode TO 'UDS'; - --- Start receiver -SELECT yagpcc.__test_uds_start_server(:'UDS_PATH'); - --- Send -SELECT 1; - --- Receive -SELECT yagpcc.__test_uds_receive() > 0 as received; - --- Stop receiver -SELECT yagpcc.__test_uds_stop_server(); - --- Cleanup -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.uds_path; -RESET yagpcc.ignored_users_list; -RESET yagpcc.enable; -RESET yagpcc.logging_mode; diff --git a/gpcontrib/yagp_hooks_collector/sql/yagp_utility.sql b/gpcontrib/yagp_hooks_collector/sql/yagp_utility.sql deleted file mode 100644 index cf9c1d253d0..00000000000 --- a/gpcontrib/yagp_hooks_collector/sql/yagp_utility.sql +++ /dev/null @@ -1,135 +0,0 @@ -CREATE EXTENSION yagp_hooks_collector; - -CREATE OR REPLACE FUNCTION yagp_status_order(status text) -RETURNS integer -AS $$ -BEGIN - RETURN CASE status - WHEN 'QUERY_STATUS_SUBMIT' THEN 1 - WHEN 'QUERY_STATUS_START' THEN 2 - WHEN 'QUERY_STATUS_END' THEN 3 - WHEN 'QUERY_STATUS_DONE' THEN 4 - ELSE 999 - END; -END; -$$ LANGUAGE plpgsql IMMUTABLE; - -SET yagpcc.ignored_users_list TO ''; -SET yagpcc.enable TO TRUE; -SET yagpcc.enable_utility TO TRUE; -SET yagpcc.report_nested_queries TO TRUE; - -SET yagpcc.logging_mode to 'TBL'; - -CREATE TABLE test_table (a int, b text); -CREATE INDEX test_idx ON test_table(a); -ALTER TABLE test_table ADD COLUMN c int DEFAULT 1; -DROP TABLE test_table; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- Partitioning -SET yagpcc.logging_mode to 'TBL'; - -CREATE TABLE pt_test (a int, b int) -DISTRIBUTED BY (a) -PARTITION BY RANGE (a) -(START (0) END (100) EVERY (50)); -DROP TABLE pt_test; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- Views and Functions -SET yagpcc.logging_mode to 'TBL'; - -CREATE VIEW test_view AS SELECT 1 AS a; -CREATE FUNCTION test_func(i int) RETURNS int AS $$ SELECT $1 + 1; $$ LANGUAGE SQL; -DROP VIEW test_view; -DROP FUNCTION test_func(int); - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- Transaction Operations -SET yagpcc.logging_mode to 'TBL'; - -BEGIN; -SAVEPOINT sp1; -ROLLBACK TO sp1; -COMMIT; - -BEGIN; -SAVEPOINT sp2; -ABORT; - -BEGIN; -ROLLBACK; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- DML Operations -SET yagpcc.logging_mode to 'TBL'; - -CREATE TABLE dml_test (a int, b text); -INSERT INTO dml_test VALUES (1, 'test'); -UPDATE dml_test SET b = 'updated' WHERE a = 1; -DELETE FROM dml_test WHERE a = 1; -DROP TABLE dml_test; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- COPY Operations -SET yagpcc.logging_mode to 'TBL'; - -CREATE TABLE copy_test (a int); -COPY (SELECT 1) TO STDOUT; -DROP TABLE copy_test; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- Prepared Statements and error during execute -SET yagpcc.logging_mode to 'TBL'; - -PREPARE test_prep(int) AS SELECT $1/0 AS value; -EXECUTE test_prep(0::int); -DEALLOCATE test_prep; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - --- GUC Settings -SET yagpcc.logging_mode to 'TBL'; - -SET yagpcc.report_nested_queries TO FALSE; -RESET yagpcc.report_nested_queries; - -RESET yagpcc.logging_mode; - -SELECT segid, query_text, query_status FROM yagpcc.log WHERE segid = -1 AND utility = true ORDER BY segid, ccnt, yagp_status_order(query_status) ASC; -SELECT yagpcc.truncate_log() IS NOT NULL AS t; - -DROP FUNCTION yagp_status_order(text); -DROP EXTENSION yagp_hooks_collector; -RESET yagpcc.enable; -RESET yagpcc.report_nested_queries; -RESET yagpcc.enable_utility; -RESET yagpcc.ignored_users_list; diff --git a/gpcontrib/yagp_hooks_collector/src/stat_statements_parser/README.md b/gpcontrib/yagp_hooks_collector/src/stat_statements_parser/README.md deleted file mode 100644 index 291e31a3099..00000000000 --- a/gpcontrib/yagp_hooks_collector/src/stat_statements_parser/README.md +++ /dev/null @@ -1 +0,0 @@ -This directory contains a slightly modified subset of pg_stat_statements for PG v9.4 to be used in query and plan ID generation. diff --git a/gpcontrib/yagp_hooks_collector/yagp_hooks_collector--1.0--1.1.sql b/gpcontrib/yagp_hooks_collector/yagp_hooks_collector--1.0--1.1.sql deleted file mode 100644 index 8684ca73915..00000000000 --- a/gpcontrib/yagp_hooks_collector/yagp_hooks_collector--1.0--1.1.sql +++ /dev/null @@ -1,113 +0,0 @@ -/* yagp_hooks_collector--1.0--1.1.sql */ - --- complain if script is sourced in psql, rather than via ALTER EXTENSION -\echo Use "ALTER EXTENSION yagp_hooks_collector UPDATE TO '1.1'" to load this file. \quit - -CREATE SCHEMA yagpcc; - --- Unlink existing objects from extension. -ALTER EXTENSION yagp_hooks_collector DROP VIEW yagp_stat_messages; -ALTER EXTENSION yagp_hooks_collector DROP FUNCTION yagp_stat_messages_reset(); -ALTER EXTENSION yagp_hooks_collector DROP FUNCTION __yagp_stat_messages_f_on_segments(); -ALTER EXTENSION yagp_hooks_collector DROP FUNCTION __yagp_stat_messages_f_on_master(); -ALTER EXTENSION yagp_hooks_collector DROP FUNCTION __yagp_stat_messages_reset_f_on_segments(); -ALTER EXTENSION yagp_hooks_collector DROP FUNCTION __yagp_stat_messages_reset_f_on_master(); - --- Now drop the objects. -DROP VIEW yagp_stat_messages; -DROP FUNCTION yagp_stat_messages_reset(); -DROP FUNCTION __yagp_stat_messages_f_on_segments(); -DROP FUNCTION __yagp_stat_messages_f_on_master(); -DROP FUNCTION __yagp_stat_messages_reset_f_on_segments(); -DROP FUNCTION __yagp_stat_messages_reset_f_on_master(); - --- Recreate functions and view in new schema. -CREATE FUNCTION yagpcc.__stat_messages_reset_f_on_master() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_stat_messages_reset' -LANGUAGE C EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__stat_messages_reset_f_on_segments() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_stat_messages_reset' -LANGUAGE C EXECUTE ON ALL SEGMENTS; - -CREATE FUNCTION yagpcc.stat_messages_reset() -RETURNS SETOF void -AS -$$ - SELECT yagpcc.__stat_messages_reset_f_on_master(); - SELECT yagpcc.__stat_messages_reset_f_on_segments(); -$$ -LANGUAGE SQL EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__stat_messages_f_on_master() -RETURNS SETOF record -AS 'MODULE_PATHNAME', 'yagp_stat_messages' -LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__stat_messages_f_on_segments() -RETURNS SETOF record -AS 'MODULE_PATHNAME', 'yagp_stat_messages' -LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; - -CREATE VIEW yagpcc.stat_messages AS - SELECT C.* - FROM yagpcc.__stat_messages_f_on_master() as C ( - segid int, - total_messages bigint, - send_failures bigint, - connection_failures bigint, - other_errors bigint, - max_message_size int - ) - UNION ALL - SELECT C.* - FROM yagpcc.__stat_messages_f_on_segments() as C ( - segid int, - total_messages bigint, - send_failures bigint, - connection_failures bigint, - other_errors bigint, - max_message_size int - ) -ORDER BY segid; - --- Create new objects. -CREATE FUNCTION yagpcc.__init_log_on_master() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_init_log' -LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__init_log_on_segments() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_init_log' -LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; - --- Creates log table inside yagpcc schema. -SELECT yagpcc.__init_log_on_master(); -SELECT yagpcc.__init_log_on_segments(); - -CREATE VIEW yagpcc.log AS - SELECT * FROM yagpcc.__log -- master - UNION ALL - SELECT * FROM gp_dist_random('yagpcc.__log') -- segments - ORDER BY tmid, ssid, ccnt; - -CREATE FUNCTION yagpcc.__truncate_log_on_master() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_truncate_log' -LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__truncate_log_on_segments() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_truncate_log' -LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; - -CREATE FUNCTION yagpcc.truncate_log() -RETURNS SETOF void AS $$ -BEGIN - PERFORM yagpcc.__truncate_log_on_master(); - PERFORM yagpcc.__truncate_log_on_segments(); -END; -$$ LANGUAGE plpgsql VOLATILE; diff --git a/gpcontrib/yagp_hooks_collector/yagp_hooks_collector--1.0.sql b/gpcontrib/yagp_hooks_collector/yagp_hooks_collector--1.0.sql deleted file mode 100644 index 270cab92382..00000000000 --- a/gpcontrib/yagp_hooks_collector/yagp_hooks_collector--1.0.sql +++ /dev/null @@ -1,55 +0,0 @@ -/* yagp_hooks_collector--1.0.sql */ - --- complain if script is sourced in psql, rather than via CREATE EXTENSION -\echo Use "CREATE EXTENSION yagp_hooks_collector" to load this file. \quit - -CREATE FUNCTION __yagp_stat_messages_reset_f_on_master() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_stat_messages_reset' -LANGUAGE C EXECUTE ON MASTER; - -CREATE FUNCTION __yagp_stat_messages_reset_f_on_segments() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_stat_messages_reset' -LANGUAGE C EXECUTE ON ALL SEGMENTS; - -CREATE FUNCTION yagp_stat_messages_reset() -RETURNS SETOF void -AS -$$ - SELECT __yagp_stat_messages_reset_f_on_master(); - SELECT __yagp_stat_messages_reset_f_on_segments(); -$$ -LANGUAGE SQL EXECUTE ON MASTER; - -CREATE FUNCTION __yagp_stat_messages_f_on_master() -RETURNS SETOF record -AS 'MODULE_PATHNAME', 'yagp_stat_messages' -LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; - -CREATE FUNCTION __yagp_stat_messages_f_on_segments() -RETURNS SETOF record -AS 'MODULE_PATHNAME', 'yagp_stat_messages' -LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; - -CREATE VIEW yagp_stat_messages AS - SELECT C.* - FROM __yagp_stat_messages_f_on_master() as C ( - segid int, - total_messages bigint, - send_failures bigint, - connection_failures bigint, - other_errors bigint, - max_message_size int - ) - UNION ALL - SELECT C.* - FROM __yagp_stat_messages_f_on_segments() as C ( - segid int, - total_messages bigint, - send_failures bigint, - connection_failures bigint, - other_errors bigint, - max_message_size int - ) -ORDER BY segid; diff --git a/gpcontrib/yagp_hooks_collector/yagp_hooks_collector--1.1.sql b/gpcontrib/yagp_hooks_collector/yagp_hooks_collector--1.1.sql deleted file mode 100644 index 83bfb553638..00000000000 --- a/gpcontrib/yagp_hooks_collector/yagp_hooks_collector--1.1.sql +++ /dev/null @@ -1,110 +0,0 @@ -/* yagp_hooks_collector--1.1.sql */ - --- complain if script is sourced in psql, rather than via CREATE EXTENSION -\echo Use "CREATE EXTENSION yagp_hooks_collector" to load this file. \quit - -CREATE SCHEMA yagpcc; - -CREATE FUNCTION yagpcc.__stat_messages_reset_f_on_master() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_stat_messages_reset' -LANGUAGE C EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__stat_messages_reset_f_on_segments() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_stat_messages_reset' -LANGUAGE C EXECUTE ON ALL SEGMENTS; - -CREATE FUNCTION yagpcc.stat_messages_reset() -RETURNS SETOF void -AS -$$ - SELECT yagpcc.__stat_messages_reset_f_on_master(); - SELECT yagpcc.__stat_messages_reset_f_on_segments(); -$$ -LANGUAGE SQL EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__stat_messages_f_on_master() -RETURNS SETOF record -AS 'MODULE_PATHNAME', 'yagp_stat_messages' -LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__stat_messages_f_on_segments() -RETURNS SETOF record -AS 'MODULE_PATHNAME', 'yagp_stat_messages' -LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; - -CREATE VIEW yagpcc.stat_messages AS - SELECT C.* - FROM yagpcc.__stat_messages_f_on_master() as C ( - segid int, - total_messages bigint, - send_failures bigint, - connection_failures bigint, - other_errors bigint, - max_message_size int - ) - UNION ALL - SELECT C.* - FROM yagpcc.__stat_messages_f_on_segments() as C ( - segid int, - total_messages bigint, - send_failures bigint, - connection_failures bigint, - other_errors bigint, - max_message_size int - ) -ORDER BY segid; - -CREATE FUNCTION yagpcc.__init_log_on_master() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_init_log' -LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__init_log_on_segments() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_init_log' -LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; - --- Creates log table inside yagpcc schema. -SELECT yagpcc.__init_log_on_master(); -SELECT yagpcc.__init_log_on_segments(); - -CREATE VIEW yagpcc.log AS - SELECT * FROM yagpcc.__log -- master - UNION ALL - SELECT * FROM gp_dist_random('yagpcc.__log') -- segments -ORDER BY tmid, ssid, ccnt; - -CREATE FUNCTION yagpcc.__truncate_log_on_master() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_truncate_log' -LANGUAGE C STRICT VOLATILE EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__truncate_log_on_segments() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_truncate_log' -LANGUAGE C STRICT VOLATILE EXECUTE ON ALL SEGMENTS; - -CREATE FUNCTION yagpcc.truncate_log() -RETURNS SETOF void AS $$ -BEGIN - PERFORM yagpcc.__truncate_log_on_master(); - PERFORM yagpcc.__truncate_log_on_segments(); -END; -$$ LANGUAGE plpgsql VOLATILE; - -CREATE FUNCTION yagpcc.__test_uds_start_server(path text) -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_test_uds_start_server' -LANGUAGE C STRICT EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__test_uds_receive(timeout_ms int DEFAULT 2000) -RETURNS SETOF bigint -AS 'MODULE_PATHNAME', 'yagp_test_uds_receive' -LANGUAGE C STRICT EXECUTE ON MASTER; - -CREATE FUNCTION yagpcc.__test_uds_stop_server() -RETURNS SETOF void -AS 'MODULE_PATHNAME', 'yagp_test_uds_stop_server' -LANGUAGE C EXECUTE ON MASTER; diff --git a/gpcontrib/yagp_hooks_collector/yagp_hooks_collector.control b/gpcontrib/yagp_hooks_collector/yagp_hooks_collector.control deleted file mode 100644 index cb5906a1302..00000000000 --- a/gpcontrib/yagp_hooks_collector/yagp_hooks_collector.control +++ /dev/null @@ -1,5 +0,0 @@ -# yagp_hooks_collector extension -comment = 'Intercept query and plan execution hooks and report them to Yandex GPCC agents' -default_version = '1.1' -module_pathname = '$libdir/yagp_hooks_collector' -superuser = true diff --git a/pom.xml b/pom.xml index aada6870658..ef2f1e5c0a6 100644 --- a/pom.xml +++ b/pom.xml @@ -153,14 +153,6 @@ code or new licensing patterns. gpcontrib/gp_exttable_fdw/data/** gpcontrib/gp_exttable_fdw/gp_exttable_fdw.control - gpcontrib/diskquota/** - gpcontrib/yagp_hooks_collector/yagp_hooks_collector.control - gpcontrib/yagp_hooks_collector/protos/yagpcc_set_service.proto - gpcontrib/yagp_hooks_collector/protos/yagpcc_plan.proto - gpcontrib/yagp_hooks_collector/protos/yagpcc_metrics.proto - gpcontrib/yagp_hooks_collector/.clang-format - gpcontrib/yagp_hooks_collector/Makefile - getversion .git-blame-ignore-revs .dir-locals.el @@ -1275,6 +1267,16 @@ code or new licensing patterns. src/include/task/task_states.h src/include/task/job_metadata.h + + gpcontrib/gp_stats_collector/gp_stats_collector.control + gpcontrib/gp_stats_collector/protos/gpsc_set_service.proto + gpcontrib/gp_stats_collector/protos/gpsc_plan.proto + gpcontrib/gp_stats_collector/protos/gpsc_metrics.proto + gpcontrib/gp_stats_collector/.clang-format + gpcontrib/gp_stats_collector/Makefile + diff --git a/src/Makefile.global.in b/src/Makefile.global.in index edc49b72e05..234d09a56b2 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -271,7 +271,7 @@ with_zstd = @with_zstd@ ZSTD_CFLAGS = @ZSTD_CFLAGS@ ZSTD_LIBS = @ZSTD_LIBS@ EVENT_LIBS = @EVENT_LIBS@ -with_yagp_hooks_collector = @with_yagp_hooks_collector@ +with_gp_stats_collector = @with_gp_stats_collector@ ########################################################################## # diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index 553830e8599..0ea5874e884 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -376,7 +376,7 @@ PortalCleanup(Portal portal) CurrentResourceOwner = saveResourceOwner; } else { /* GPDB hook for collecting query info */ - if (queryDesc->yagp_query_key && query_info_collect_hook) + if (queryDesc->gpsc_query_key && query_info_collect_hook) (*query_info_collect_hook)(METRICS_QUERY_ERROR, queryDesc); } } diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index 7c1dbc480bc..e5512bb8271 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -127,8 +127,8 @@ CreateQueryDesc(PlannedStmt *plannedstmt, if (Gp_role != GP_ROLE_EXECUTE) increment_command_count(); - /* null this field until set by YAGP Hooks collector */ - qd->yagp_query_key = NULL; + /* null this field until set by GP Stats Collector */ + qd->gpsc_query_key = NULL; return qd; } diff --git a/src/include/executor/execdesc.h b/src/include/executor/execdesc.h index e469945a4c5..d50d3e48f6b 100644 --- a/src/include/executor/execdesc.h +++ b/src/include/executor/execdesc.h @@ -22,14 +22,14 @@ struct CdbExplain_ShowStatCtx; /* private, in "cdb/cdbexplain.c" */ -typedef struct YagpQueryKey +typedef struct GpscQueryKey { int tmid; /* transaction time */ int ssid; /* session id */ int ccnt; /* command count */ int nesting_level; uintptr_t query_desc_addr; -} YagpQueryKey; +} GpscQueryKey; /* * SerializedParams is used to serialize external query parameters @@ -339,8 +339,8 @@ typedef struct QueryDesc /* This is always set NULL by the core system, but plugins can change it */ struct Instrumentation *totaltime; /* total time spent in ExecutorRun */ - /* YAGP Hooks collector */ - YagpQueryKey *yagp_query_key; + /* GP Stats Collector */ + GpscQueryKey *gpsc_query_key; } QueryDesc; /* in pquery.c */