Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
cff1cf7
Initial commit: completely useless yet
Smyatkin-Maxim Mar 23, 2023
00d0798
Add .gitignore
Smyatkin-Maxim Mar 23, 2023
a7c6387
Simple Executor{Start,Finish} logging
Smyatkin-Maxim Mar 23, 2023
8b302a2
Add GRPC into Makefile and some prototype senders
Smyatkin-Maxim Mar 24, 2023
2d9eaea
Make ExecuteStart and ExecuteFinish work (partially)
Smyatkin-Maxim Mar 25, 2023
e5a2fd5
Implement QueryInfo generation
Smyatkin-Maxim Mar 28, 2023
69dcbfd
Better protobuf filling code
Smyatkin-Maxim Mar 28, 2023
11dabf1
Fix segfault in plan text generator
Smyatkin-Maxim Mar 28, 2023
a7a6db8
Add support of spill info and
Smyatkin-Maxim Mar 29, 2023
92bc2fb
Sync with proto changes + generate normalized query and plan texts
Smyatkin-Maxim Mar 30, 2023
2157ed9
Implement the rest of statistics
Smyatkin-Maxim Apr 1, 2023
933fe68
Use llvm code style
Smyatkin-Maxim Apr 6, 2023
22a602f
Trace events using query_info_collect_hook
Smyatkin-Maxim Apr 10, 2023
0e35522
Fix two segfaults
Smyatkin-Maxim Apr 12, 2023
e49a598
Don't call hooks from UTILITY mode and increase grpc timeout
Smyatkin-Maxim Apr 14, 2023
06b6e0b
More improvements to metrics collector
Smyatkin-Maxim May 1, 2023
f4a5878
Add debian package configuration
Smyatkin-Maxim May 1, 2023
b5446ab
Try older grpcpp headers for bionic builds
Smyatkin-Maxim May 2, 2023
10c3c86
Add missing greenplum nodes to pg_stat_statements
Smyatkin-Maxim May 4, 2023
c866e5b
Move query stats reporting to ExecutorEnd hook
Smyatkin-Maxim May 4, 2023
bb6aed4
Change GRPC failure handling
Smyatkin-Maxim May 5, 2023
95d4a39
Track CDB metrics and track query nesting
Smyatkin-Maxim May 12, 2023
5609141
Change package name
Smyatkin-Maxim May 15, 2023
02b53c5
Skip nested and utility statements
Smyatkin-Maxim May 17, 2023
d640cfc
Slightly rework query skipping
Smyatkin-Maxim Jun 2, 2023
2384337
Get resource groups back into query info
Smyatkin-Maxim Jun 2, 2023
8d2d5ee
Add some configuration parameters
Smyatkin-Maxim Jun 6, 2023
f1acf98
Capture query execution system stats instead of whole process lifetime
Smyatkin-Maxim Jun 7, 2023
c94dd1d
Don't rethrow errors from metrics collector
Smyatkin-Maxim Jun 9, 2023
61b9273
Add forgotten hooks deinitialization
Smyatkin-Maxim Jun 10, 2023
0070c3f
Misc: use modern style error messages
Smyatkin-Maxim Jun 13, 2023
c67de87
Fix EventSender and GrpcConnector in forks
Smyatkin-Maxim Jun 13, 2023
abd9f22
Set ya-grpc as a dependency
Smyatkin-Maxim Jun 19, 2023
8944d7e
Fix memory leak in analyze code
Smyatkin-Maxim Aug 16, 2023
396d811
Add motion and workfile stats
Smyatkin-Maxim Sep 6, 2023
fc43eb5
Mute all PG-related signals in reconnection thread
Smyatkin-Maxim Sep 6, 2023
5fd6f36
Move debian configuration to teamcity
Smyatkin-Maxim Sep 7, 2023
ce93949
Move logs from psql to log file
Smyatkin-Maxim Sep 15, 2023
af25547
Some hardening around memory
Smyatkin-Maxim Sep 20, 2023
446c58a
Remove thread unsafe logging
Smyatkin-Maxim Sep 20, 2023
1299852
Dirty hack: make queryid eq planid
Smyatkin-Maxim Sep 21, 2023
0562fea
Remove dead code and catch thread exception
Smyatkin-Maxim Sep 22, 2023
8412300
Add GUC to filter specific users
Smyatkin-Maxim Sep 21, 2023
da46c27
Several fixes to user filtering
Smyatkin-Maxim Sep 28, 2023
7840dcb
Minor naming improvement
Smyatkin-Maxim Oct 2, 2023
5287681
Add server-side message queueing
Smyatkin-Maxim Oct 2, 2023
55a0eca
Moving to protobuf, part 1: remove GRPC
Smyatkin-Maxim Oct 31, 2023
b1a2c12
Add clang-format
Smyatkin-Maxim Oct 31, 2023
4f84185
Moving to protobuf, part2: initial implementation
Smyatkin-Maxim Oct 31, 2023
5ea67ec
Use deprecated protobuf API for bionic compatibility
Smyatkin-Maxim Nov 1, 2023
424b3bd
Replace message queue with incremental message
Smyatkin-Maxim Nov 1, 2023
960d549
Fix bug with missing query statuses
Smyatkin-Maxim Nov 2, 2023
585097e
Add runtime statistics on UDS messages
Smyatkin-Maxim Nov 13, 2023
f8cddb0
Move query msg cleanup to the right place
Smyatkin-Maxim Nov 15, 2023
6ffe3e1
Finalize query msg in DONE hook
Smyatkin-Maxim Nov 16, 2023
fee9b00
Fix some memory leaks
Smyatkin-Maxim Dec 26, 2023
2a9128a
Enable honest query_id collection
Smyatkin-Maxim Dec 26, 2023
f0b5e4b
Get resource group from current session
Smyatkin-Maxim Apr 24, 2024
831a83d
Added support for nested queries
Smyatkin-Maxim May 17, 2024
b7c57a6
Trim long text fields
Smyatkin-Maxim May 28, 2024
945118f
Report error messages for failed queries
Smyatkin-Maxim May 28, 2024
45014d9
Don't track the CANCELLING event
Smyatkin-Maxim May 30, 2024
ff28f14
Properly send runtime metrics on CANCEL/ERROR
Smyatkin-Maxim Jun 3, 2024
0f0b821
Allow anyone to disable report_nested_queries
Smyatkin-Maxim Jun 3, 2024
5254e40
Diff stats between executor start and end
Smyatkin-Maxim Jun 13, 2024
6979f95
Fix try/catch block when calling cpp code
Smyatkin-Maxim Aug 7, 2024
9bee734
Don't normalize trimmed plans
Smyatkin-Maxim Sep 12, 2024
b7e496f
Clean up forgotten text fields
Smyatkin-Maxim Oct 7, 2024
6a99e3f
[MDB-31938] Send nested queries only from master
Smyatkin-Maxim Oct 29, 2024
cdd2a5c
[MDB-31936] Add slice info
Smyatkin-Maxim Oct 30, 2024
b76c43b
Send nested queries summary stats from segments
Smyatkin-Maxim Nov 5, 2024
f8bcb85
[Refactoring] Split EventSender into submodules
Smyatkin-Maxim Nov 7, 2024
99aa17f
Ignore EXPLAIN VERBOSE errors
Smyatkin-Maxim Apr 7, 2025
3dbafff
Add support for per-slice interconnect statistics
Smyatkin-Maxim Apr 18, 2025
a0f4c33
Don't rely on IC hook for compilation
Smyatkin-Maxim May 6, 2025
85f2f32
fix: propagate ignored users on update
NJrslv Jun 9, 2025
0005ad0
propagate ignored users only when executor starts
NJrslv Jun 11, 2025
d3963c8
refactor
NJrslv Jun 16, 2025
c7d827f
fix ub in strcpy
NJrslv Jun 16, 2025
2b993d3
Add EXPLAIN ANALYZE metrics collection
NJrslv Jun 24, 2025
d9666d7
correct expand var
NJrslv Jun 27, 2025
ed603e0
parallel makefile & move link flags (#8)
NJrslv Jun 27, 2025
55f691f
fix mem leak
NJrslv Jul 15, 2025
45638c3
add safe cpp wrappers around pg funcs
NJrslv Jul 4, 2025
304d36a
log actual err msg & templatize code & make free noexcept
NJrslv Jul 11, 2025
6d5769f
change namespace name to avoid conflicts with gpos
NJrslv Jul 14, 2025
83b8b16
move template to .cpp
NJrslv Jul 15, 2025
45aced6
add metrics desc
NJrslv Aug 7, 2025
869c5ea
clear
NJrslv Aug 7, 2025
d6173b0
Fix missing states (utility statements included) (#16)
NJrslv Aug 13, 2025
cdf9ff5
fix cpp & pg memleak
NJrslv Aug 13, 2025
5af0b20
report bug queries at the end of extension (#19)
NJrslv Aug 15, 2025
647c2aa
fix defs & trim spaces (#21)
NJrslv Sep 4, 2025
30218a5
Add PG alike tests (#20)
NJrslv Sep 9, 2025
89b89aa
send analyze in text & enable it (#22)
NJrslv Sep 10, 2025
208366d
clean (#23)
NJrslv Sep 15, 2025
661caff
report utility stmt (#24)
NJrslv Sep 29, 2025
c808eba
Trim utf8 (#25)
NJrslv Dec 3, 2025
b4c9cbd
[yagp_hooks_collector] Port workfile stats from gpdb
NJrslv Jan 19, 2026
97b876f
[yagp_hooks_collector] Port YagpQueryState from gpdb
NJrslv Jan 19, 2026
f1eea80
[yagp_hooks_collector] Use updated names and func's interfaces
NJrslv Jan 19, 2026
cd90491
[yagp_hooks_collector] Del redundant funcs
NJrslv Jan 19, 2026
8eace77
[yagp_hooks_collector] Change test functions to SRF
NJrslv Jan 19, 2026
9c4029e
[yagp_hooks_collector] Change test out for part tbl
NJrslv Jan 19, 2026
577ad15
[yagp_hooks_collector] Add CI test and with option
NJrslv Jan 19, 2026
5b9fd6c
[yagp_hooks_collector] Change greenplum_path.sh to cloudberry-env.sh
NJrslv Jan 19, 2026
6c2f8bd
[yagp_hooks_collector] Add comments for func args
NJrslv Jan 19, 2026
211b33e
[yagp_hooks_collector] Correct tokens from gram.y
NJrslv Jan 19, 2026
19a5811
[yagp_hooks_collector] Add consistent filtering
NJrslv Jan 20, 2026
7605825
[yagp_hooks_collector] Add submit & done hooks
NJrslv Jan 20, 2026
d17e3e3
[yagp_hooks_collector] Add test for UDS sending
NJrslv Jan 20, 2026
fb8688d
[yagp_hooks_collector] Correct add of bytes sent
NJrslv Jan 20, 2026
1befa6d
[yagp_hooks_collector] Refactor
NJrslv Jan 20, 2026
fd7b874
[yagp_hooks_collector] Make gen of norm plan/query noexcept
NJrslv Jan 21, 2026
8fe91a1
[yagp_hooks_collector] Fix warnings and error them
NJrslv Jan 21, 2026
2184c9f
[yagp_hooks_collector] Add licence
NJrslv Jan 22, 2026
291fea9
[yagp_hooks_collector] Fix null edata access (#22)
NJrslv Feb 10, 2026
ea9c200
Move hooks collector files to the gpcontrib
Mar 18, 2026
4e8ec12
Merge branch 'main' into mergeYagpHooks
leborchuk Mar 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion .github/workflows/build-cloudberry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ jobs:
},
"enable_core_check":false
},
{"test":"gpcontrib-yagp-hooks-collector",
"make_configs":["gpcontrib/yagp_hooks_collector:installcheck"],
"extension":"yagp_hooks_collector"
},
{"test":"ic-expandshrink",
"make_configs":["src/test/isolation2:installcheck-expandshrink"]
},
Expand Down Expand Up @@ -535,10 +539,11 @@ jobs:
if: needs.check-skip.outputs.should_skip != 'true'
env:
SRC_DIR: ${{ github.workspace }}
CONFIGURE_EXTRA_OPTS: --with-yagp-hooks-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
Expand Down Expand Up @@ -1403,6 +1408,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
Expand Down Expand Up @@ -1432,6 +1438,30 @@ jobs:
PG_OPTS="$PG_OPTS -c optimizer=${{ matrix.pg_settings.optimizer }}"
fi

# Create extension if required
if [[ "${{ matrix.extension != '' }}" == "true" ]]; then
case "${{ matrix.extension }}" in
yagp_hooks_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' && \
gpstop -ra && \
echo 'CREATE EXTENSION IF NOT EXISTS yagp_hooks_collector; \
SHOW shared_preload_libraries; \
TABLE pg_extension;' | \
psql postgres"
then
echo "Error creating yagp_hooks_collector extension"
exit 1
fi
;;
*)
echo "Unknown extension: ${{ matrix.extension }}"
exit 1
;;
esac
fi

if [[ "${{ matrix.pg_settings.default_table_access_method != '' }}" == "true" ]]; then
PG_OPTS="$PG_OPTS -c default_table_access_method=${{ matrix.pg_settings.default_table_access_method }}"
fi
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ lib*.pc
/compile_commands.json
/tmp_install/
/.cache/
/install/
/install/
*.o
*.so
src/protos/
.vscode
compile_commands.json
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
# 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:
Expand Down
28 changes: 28 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ with_apr_config
with_libcurl
with_rt
with_zstd
with_yagp_hooks_collector
with_libbz2
LZ4_LIBS
LZ4_CFLAGS
Expand Down Expand Up @@ -942,6 +943,7 @@ with_zlib
with_lz4
with_libbz2
with_zstd
with_yagp_hooks_collector
with_rt
with_libcurl
with_apr_config
Expand Down Expand Up @@ -11150,6 +11152,32 @@ $as_echo "yes" >&6; }
fi
fi

#
# yagp_hooks_collector
#



# Check whether --with-yagp-hooks-collector was given.
if test "${with_yagp_hooks_collector+set}" = set; then :
withval=$with_yagp_hooks_collector;
case $withval in
yes)
:
;;
no)
:
;;
*)
as_fn_error $? "no argument expected for --with-yagp-hooks-collector option" "$LINENO" 5
;;
esac

else
with_yagp_hooks_collector=no

fi

#
# Realtime library
#
Expand Down
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,13 @@ PGAC_ARG_BOOL(with, zstd, yes, [do not build with Zstandard],
AC_MSG_RESULT([$with_zstd])
AC_SUBST(with_zstd)

#
# yagp_hooks_collector
#
PGAC_ARG_BOOL(with, yagp_hooks_collector, no,
[build with YAGP hooks collector extension])
AC_SUBST(with_yagp_hooks_collector)

if test "$with_zstd" = yes; then
dnl zstd_errors.h was renamed from error_public.h in v1.4.0
PKG_CHECK_MODULES([ZSTD], [libzstd >= 1.4.0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#
# Optional Environment Variables:
# LOG_DIR - Directory for logs (defaults to ${SRC_DIR}/build-logs)
# CONFIGURE_EXTRA_OPTS - Args to pass to configure command
# ENABLE_DEBUG - Enable debug build options (true/false, defaults to
# false)
#
Expand Down Expand Up @@ -177,7 +178,8 @@ execute_cmd ./configure --prefix=${BUILD_DESTINATION} \
--with-uuid=e2fs \
${CONFIGURE_MDBLOCALES_OPTS} \
--with-includes=/usr/local/xerces-c/include \
--with-libraries=${BUILD_DESTINATION}/lib || exit 4
--with-libraries=${BUILD_DESTINATION}/lib \
${CONFIGURE_EXTRA_OPTS:-""} || exit 4
log_section_end "Configure"

# Capture version information
Expand Down
3 changes: 3 additions & 0 deletions gpcontrib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ else
diskquota
endif

ifeq "$(with_yagp_hooks_collector)" "yes"
recurse_targets += yagp_hooks_collector
endif
ifeq "$(with_zstd)" "yes"
recurse_targets += zstd
endif
Expand Down
2 changes: 2 additions & 0 deletions gpcontrib/yagp_hooks_collector/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: LLVM
SortIncludes: false
41 changes: 41 additions & 0 deletions gpcontrib/yagp_hooks_collector/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
MODULE_big = yagp_hooks_collector
EXTENSION = yagp_hooks_collector
DATA = $(wildcard *--*.sql)
REGRESS = yagp_cursors yagp_dist yagp_select yagp_utf8_trim yagp_utility yagp_guc_cache yagp_uds yagp_locale

PROTO_BASES = yagpcc_plan yagpcc_metrics yagpcc_set_service
PROTO_OBJS = $(patsubst %,src/protos/%.pb.o,$(PROTO_BASES))

C_OBJS = $(patsubst %.c,%.o,$(wildcard src/*.c src/*/*.c))
CPP_OBJS = $(patsubst %.cpp,%.o,$(wildcard src/*.cpp src/*/*.cpp))
OBJS = $(C_OBJS) $(CPP_OBJS) $(PROTO_OBJS)

override CXXFLAGS = -Werror -fPIC -g3 -Wall -Wpointer-arith -Wendif-labels \
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv \
-Wno-unused-but-set-variable -Wno-address -Wno-format-truncation \
-Wno-stringop-truncation -g -ggdb -std=c++17 -Iinclude -Isrc/protos -Isrc -DGPBUILD

PG_CXXFLAGS += -Isrc -Iinclude
SHLIB_LINK += -lprotobuf -lpthread -lstdc++
EXTRA_CLEAN = src/protos

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = gpcontrib/yagp_hooks_collector
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
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
28 changes: 28 additions & 0 deletions gpcontrib/yagp_hooks_collector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## 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.
Loading
Loading