You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// ArgumentList struct that holds all PostgreSQL arguments
12
11
typeArgumentListstruct {
13
12
sdkArgs.DefaultArgumentList
14
-
Usernamestring`default:"" help:"The username for the PostgreSQL database"`
15
-
Passwordstring`default:"" help:"The password for the specified username"`
16
-
Hostnamestring`default:"localhost" help:"The PostgreSQL hostname to connect to"`
17
-
Databasestring`default:"postgres" help:"The PostgreSQL database name to connect to"`
18
-
Portstring`default:"5432" help:"The port to connect to the PostgreSQL database"`
19
-
CollectionListstring`default:"{}" help:"A JSON object which defines the databases, schemas, tables, and indexes to collect. Can also be a JSON array that list databases to be collected. Can also be the string literal 'ALL' to collect everything. Collects nothing by default."`
20
-
CollectionIgnoreDatabaseListstring`default:"[]" help:"A JSON array that list databases that will be excluded from collection. Nothing is excluded by default."`
21
-
CollectionIgnoreTableListstring`default:"[]" help:"A JSON array that list tables that will be excluded from collection. Nothing is excluded by default."`
22
-
SSLRootCertLocationstring`default:"" help:"Absolute path to PEM encoded root certificate file"`
23
-
SSLCertLocationstring`default:"" help:"Absolute path to PEM encoded client cert file"`
24
-
SSLKeyLocationstring`default:"" help:"Absolute path to PEM encoded client key file"`
25
-
Timeoutstring`default:"10" help:"Maximum wait for connection, in seconds. Set 0 for no timeout"`
26
-
CustomMetricsQuerystring`default:"" help:"A SQL query to collect custom metrics. Must have the columns metric_name, metric_type, and metric_value. Additional columns are added as attributes"`
27
-
CustomMetricsConfigstring`default:"" help:"YAML configuration with one or more custom SQL queries to collect"`
28
-
EnableSSLbool`default:"false" help:"If true will use SSL encryption, false will not use encryption"`
29
-
TrustServerCertificatebool`default:"false" help:"If true server certificate is not verified for SSL. If false certificate will be verified against supplied certificate"`
30
-
Pgbouncerbool`default:"false" help:"Collects metrics from PgBouncer instance. Assumes connection is through PgBouncer."`
31
-
CollectDbLockMetricsbool`default:"false" help:"If true, enables collection of lock metrics for the specified database. (Note: requires that the 'tablefunc' extension is installed)"`//nolint: stylecheck
32
-
CollectBloatMetricsbool`default:"true" help:"Enable collecting bloat metrics which can be performance intensive"`
33
-
ShowVersionbool`default:"false" help:"Print build information and exit"`
13
+
Usernamestring`default:"" help:"The username for the PostgreSQL database"`
14
+
Passwordstring`default:"" help:"The password for the specified username"`
15
+
Hostnamestring`default:"localhost" help:"The PostgreSQL hostname to connect to"`
16
+
Databasestring`default:"postgres" help:"The PostgreSQL database name to connect to"`
17
+
Portstring`default:"5432" help:"The port to connect to the PostgreSQL database"`
18
+
CollectionListstring`default:"{}" help:"A JSON object which defines the databases, schemas, tables, and indexes to collect. Can also be a JSON array that list databases to be collected. Can also be the string literal 'ALL' to collect everything. Collects nothing by default."`
19
+
CollectionIgnoreDatabaseListstring`default:"[]" help:"A JSON array that list databases that will be excluded from collection. Nothing is excluded by default."`
20
+
CollectionIgnoreTableListstring`default:"[]" help:"A JSON array that list tables that will be excluded from collection. Nothing is excluded by default."`
21
+
SSLRootCertLocationstring`default:"" help:"Absolute path to PEM encoded root certificate file"`
22
+
SSLCertLocationstring`default:"" help:"Absolute path to PEM encoded client cert file"`
23
+
SSLKeyLocationstring`default:"" help:"Absolute path to PEM encoded client key file"`
24
+
Timeoutstring`default:"10" help:"Maximum wait for connection, in seconds. Set 0 for no timeout"`
25
+
CustomMetricsQuerystring`default:"" help:"A SQL query to collect custom metrics. Must have the columns metric_name, metric_type, and metric_value. Additional columns are added as attributes"`
26
+
CustomMetricsConfigstring`default:"" help:"YAML configuration with one or more custom SQL queries to collect"`
27
+
EnableSSLbool`default:"false" help:"If true will use SSL encryption, false will not use encryption"`
28
+
TrustServerCertificatebool`default:"false" help:"If true server certificate is not verified for SSL. If false certificate will be verified against supplied certificate"`
29
+
Pgbouncerbool`default:"false" help:"Collects metrics from PgBouncer instance. Assumes connection is through PgBouncer."`
30
+
CollectDbLockMetricsbool`default:"false" help:"If true, enables collection of lock metrics for the specified database. (Note: requires that the 'tablefunc' extension is installed)"`//nolint: stylecheck
31
+
CollectBloatMetricsbool`default:"true" help:"Enable collecting bloat metrics which can be performance intensive"`
32
+
ShowVersionbool`default:"false" help:"Print build information and exit"`
33
+
EnableQueryMonitoringbool`default:"false" help:"Enable collection of detailed query performance metrics."`
34
+
QueryMonitoringResponseTimeThresholdint`default:"500" help:"Threshold in milliseconds for query response time. If response time for the individual query exceeds this threshold, the individual query is reported in metrics"`
35
+
QueryMonitoringCountThresholdint`default:"20" help:"The number of records for each query performance metrics"`
34
36
}
35
37
36
38
// Validate validates PostgreSQl arguments
37
39
func (alArgumentList) Validate() error {
38
40
ifal.Username==""||al.Password=="" {
39
41
returnerrors.New("invalid configuration: must specify a username and password")
funcvalidateAndGetQueryMonitoringResponseTimeThreshold(args args.ArgumentList) int {
38
+
ifargs.QueryMonitoringResponseTimeThreshold<0 {
39
+
log.Warn("QueryResponseTimeThreshold should be greater than or equal to 0 but the input is %d, setting value to default which is %d", args.QueryMonitoringResponseTimeThreshold, DefaultQueryResponseTimeThreshold)
40
+
returnDefaultQueryResponseTimeThreshold
41
+
}
42
+
returnargs.QueryMonitoringResponseTimeThreshold
43
+
}
44
+
45
+
funcvalidateAndGetQueryMonitoringCountThreshold(args args.ArgumentList) int {
46
+
ifargs.QueryMonitoringCountThreshold<0 {
47
+
log.Warn("QueryCountThreshold should be greater than 0 but the input is %d, setting value to default which is %d", args.QueryMonitoringCountThreshold, DefaultQueryMonitoringCountThreshold)
log.Warn("QueryCountThreshold should be less than or equal to max limit but the input is %d, setting value to max limit which is %d", args.QueryMonitoringCountThreshold, MaxQueryCountThreshold)
sort.Strings(dbListKeys) // Sort the keys to ensure consistent order
14
+
dbList:= collection.DatabaseList{}
15
+
for_, key:=rangedbListKeys {
16
+
dbList[key] = collection.SchemaList{}
17
+
}
18
+
expected:="'db1'"
19
+
result:=GetDatabaseListInString(dbList)
20
+
assert.Equal(t, expected, result)
21
+
22
+
// Test with empty database list
23
+
dbList= collection.DatabaseList{}
24
+
expected=""
25
+
result=GetDatabaseListInString(dbList)
26
+
assert.Equal(t, expected, result)
27
+
}
28
+
29
+
funcTestAnonymizeQueryText(t*testing.T) {
30
+
query:="SELECT * FROM users WHERE id = 1 AND name = 'John'"
31
+
expected:="SELECT * FROM users WHERE id = ? AND name = ?"
32
+
result:=AnonymizeQueryText(query)
33
+
assert.Equal(t, expected, result)
34
+
query="SELECT * FROM employees WHERE id = 10 OR name <> 'John Doe' OR name != 'John Doe' OR age < 30 OR age <= 30 OR salary > 50000OR salary >= 50000 OR department LIKE 'Sales%' OR department ILIKE 'sales%'OR join_date BETWEEN '2023-01-01' AND '2023-12-31' OR department IN ('HR', 'Engineering', 'Marketing') OR department IS NOT NULL OR department IS NULL;"
35
+
expected="SELECT * FROM employees WHERE id = ? OR name <> ? OR name != ? OR age < ? OR age <= ? OR salary > ?OR salary >= ? OR department LIKE ? OR department ILIKE ?OR join_date BETWEEN ? AND ? OR department IN (?, ?, ?) OR department IS NOT NULL OR department IS NULL;"
0 commit comments