You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by dj...@apache.org on 2026/04/02 08:25:03 UTC
(cloudberry) 13/49: [yagp_hooks_collector] Add ignored_users_list GUC
This is an automated email from the ASF dual-hosted git repository.
djwang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit ce10c577fbe7e0f815acef5009a13b690edd8e3f
Author: Maxim Smyatkin <sm...@gmail.com>
AuthorDate: Thu Sep 21 15:16:35 2023 +0300
[yagp_hooks_collector] Add ignored_users_list GUC
Add a comma-separated GUC to suppress metrics collection for specified
roles. Parse using SplitIdentifierString and cache in an unordered_set.
---
src/Config.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++
src/Config.h | 1 +
src/EventSender.cpp | 5 +++--
src/EventSender.h | 2 +-
4 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/src/Config.cpp b/src/Config.cpp
index d97e5d45984..c5c2c15f7e9 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -1,4 +1,7 @@
#include "Config.h"
+#include <unordered_set>
+#include <memory>
+#include <string>
extern "C" {
#include "postgres.h"
@@ -10,6 +13,8 @@ static char *guc_uds_path = nullptr;
static bool guc_enable_analyze = true;
static bool guc_enable_cdbstats = true;
static bool guc_enable_collector = true;
+static char *guc_ignored_users = nullptr;
+static std::unique_ptr<std::unordered_set<std::string>> ignored_users = nullptr;
void Config::init() {
DefineCustomStringVariable(
@@ -30,9 +35,47 @@ void Config::init() {
"yagpcc.enable_cdbstats", "Collect CDB metrics in yagpcc", 0LL,
&guc_enable_cdbstats, true, PGC_SUSET,
GUC_NOT_IN_SAMPLE | GUC_GPDB_NEED_SYNC, 0LL, 0LL, 0LL);
+
+ DefineCustomStringVariable(
+ "yagpcc.ignored_users_list",
+ "Make yagpcc 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, 0LL, 0LL);
}
std::string Config::uds_path() { return guc_uds_path; }
bool Config::enable_analyze() { return guc_enable_analyze; }
bool Config::enable_cdbstats() { return guc_enable_cdbstats; }
bool Config::enable_collector() { return guc_enable_collector; }
+
+bool Config::filter_user(const std::string *username) {
+ if (!ignored_users) {
+ ignored_users.reset(new std::unordered_set<std::string>());
+ if (guc_ignored_users == nullptr || guc_ignored_users[0] == '0') {
+ return false;
+ }
+ /* Need a modifiable copy of string */
+ char *rawstring = pstrdup(guc_ignored_users);
+ List *elemlist;
+ ListCell *l;
+
+ /* Parse string into list of identifiers */
+ if (!SplitIdentifierString(rawstring, ',', &elemlist)) {
+ /* syntax error in list */
+ pfree(rawstring);
+ list_free(elemlist);
+ ereport(
+ LOG,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg(
+ "invalid list syntax in parameter yagpcc.ignored_users_list")));
+ return false;
+ }
+ foreach (l, elemlist) {
+ ignored_users->insert((char *)lfirst(l));
+ }
+ pfree(rawstring);
+ list_free(elemlist);
+ }
+ return !username || ignored_users->find(*username) != ignored_users->end();
+}
diff --git a/src/Config.h b/src/Config.h
index 117481f219b..999d0300640 100644
--- a/src/Config.h
+++ b/src/Config.h
@@ -9,4 +9,5 @@ public:
static bool enable_analyze();
static bool enable_cdbstats();
static bool enable_collector();
+ static bool filter_user(const std::string *username);
};
\ No newline at end of file
diff --git a/src/EventSender.cpp b/src/EventSender.cpp
index 57fe6f13391..9146078fd0e 100644
--- a/src/EventSender.cpp
+++ b/src/EventSender.cpp
@@ -33,7 +33,8 @@ extern "C" {
#define need_collect() \
(nesting_level == 0 && gp_command_count != 0 && \
- query_desc->sourceText != nullptr && Config::enable_collector())
+ query_desc->sourceText != nullptr && Config::enable_collector() && \
+ !Config::filter_user(get_user_name()))
namespace {
@@ -325,7 +326,7 @@ void EventSender::collect_query_done(QueryDesc *query_desc,
}
EventSender::EventSender() {
- if (Config::enable_collector()) {
+ if (Config::enable_collector() && !Config::filter_user(get_user_name())) {
try {
connector = new GrpcConnector();
} catch (const std::exception &e) {
diff --git a/src/EventSender.h b/src/EventSender.h
index ee0db2f0938..2af8b7ffa03 100644
--- a/src/EventSender.h
+++ b/src/EventSender.h
@@ -23,6 +23,6 @@ public:
private:
void collect_query_submit(QueryDesc *query_desc);
void collect_query_done(QueryDesc *query_desc, const std::string &status);
- GrpcConnector *connector;
+ GrpcConnector *connector = nullptr;
int nesting_level = 0;
};
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org