@@ -21,12 +21,20 @@ import (
2121 "github.com/blang/semver/v4"
2222 "github.com/go-kit/log/level"
2323 "gopkg.in/yaml.v2"
24+
25+ "github.com/percona/postgres_exporter/distribution"
26+ )
27+
28+ const (
29+ // '!' is a reserved character indicating that the query is not supported on Aurora and should be skipped for Aurora instances.
30+ notSupportedByAurora = "!"
2431)
2532
26- // UserQuery represents a user defined query
33+ // UserQuery represents a user defined query, including support for Aurora, if needed
2734type UserQuery struct {
28- Query string `yaml:"query"`
29- Metrics []Mapping `yaml:"metrics"`
35+ Query string `yaml:"query"` // Standard query
36+ QueryAurora string `yaml:"query_aurora"` // Aurora specific query
37+ Metrics []Mapping `yaml:"metrics"` // Metrics to be collected
3038 Master bool `yaml:"master"` // Querying only for master database
3139 CacheSeconds uint64 `yaml:"cache_seconds"` // Number of seconds to cache the namespace result metrics for.
3240 RunOnServer string `yaml:"runonserver"` // Querying to run on which server version
@@ -197,7 +205,7 @@ func makeQueryOverrideMap(pgVersion semver.Version, queryOverrides map[string][]
197205 return resultMap
198206}
199207
200- func parseUserQueries (content []byte ) (map [string ]intermediateMetricMap , map [string ]string , error ) {
208+ func parseUserQueries (content []byte , dist string ) (map [string ]intermediateMetricMap , map [string ]string , error ) {
201209 var userQueries UserQueries
202210
203211 err := yaml .Unmarshal (content , & userQueries )
@@ -211,7 +219,25 @@ func parseUserQueries(content []byte) (map[string]intermediateMetricMap, map[str
211219
212220 for metric , specs := range userQueries {
213221 level .Debug (logger ).Log ("msg" , "New user metric namespace from YAML metric" , "metric" , metric , "cache_seconds" , specs .CacheSeconds )
214- newQueryOverrides [metric ] = specs .Query
222+
223+ // Query selection logic:
224+ // For Aurora: use query_aurora if defined and not empty, otherwise use query if defined and not empty.
225+ // If query_aurora is set to '!', skip this query for Aurora (not supported).
226+ // For standard (non-Aurora): always use query.
227+ switch dist {
228+ case distribution .Aurora :
229+ if specs .QueryAurora != "" {
230+ if specs .QueryAurora == notSupportedByAurora {
231+ continue
232+ }
233+ newQueryOverrides [metric ] = specs .QueryAurora
234+ } else {
235+ newQueryOverrides [metric ] = specs .Query
236+ }
237+ default :
238+ newQueryOverrides [metric ] = specs .Query
239+ }
240+
215241 metricMap , ok := metricMaps [metric ]
216242 if ! ok {
217243 // Namespace for metric not found - add it.
@@ -251,7 +277,7 @@ func parseUserQueries(content []byte) (map[string]intermediateMetricMap, map[str
251277// TODO: test code for all cu.
252278// TODO: the YAML this supports is "non-standard" - we should move away from it.
253279func addQueries (content []byte , pgVersion semver.Version , server * Server ) error {
254- metricMaps , newQueryOverrides , err := parseUserQueries (content )
280+ metricMaps , newQueryOverrides , err := parseUserQueries (content , server . distribution )
255281 if err != nil {
256282 return err
257283 }
0 commit comments