@@ -12,13 +12,12 @@ import (
12
12
)
13
13
14
14
type Gauges struct {
15
- name string
16
- db * sqlx.DB
17
- interval time.Duration
18
- timeout time.Duration
19
- labels prometheus.Labels
20
- Errs prometheus.Gauge
21
- isSuperuser bool
15
+ name string
16
+ db * sqlx.DB
17
+ interval time.Duration
18
+ timeout time.Duration
19
+ labels prometheus.Labels
20
+ Errs prometheus.Gauge
22
21
}
23
22
24
23
func New (name string , db * sql.DB , interval , timeout time.Duration ) * Gauges {
@@ -27,12 +26,11 @@ func New(name string, db *sql.DB, interval, timeout time.Duration) *Gauges {
27
26
}
28
27
var dbx = sqlx .NewDb (db , "postgres" )
29
28
return & Gauges {
30
- name : name ,
31
- db : dbx ,
32
- interval : interval ,
33
- timeout : timeout ,
34
- labels : labels ,
35
- isSuperuser : isSuperuser (dbx , timeout ),
29
+ name : name ,
30
+ db : dbx ,
31
+ interval : interval ,
32
+ timeout : timeout ,
33
+ labels : labels ,
36
34
Errs : prometheus .NewGauge (
37
35
prometheus.GaugeOpts {
38
36
Name : "postgresql_query_errors" ,
@@ -43,25 +41,6 @@ func New(name string, db *sql.DB, interval, timeout time.Duration) *Gauges {
43
41
}
44
42
}
45
43
46
- func isSuperuser (db * sqlx.DB , timeout time.Duration ) (super bool ) {
47
- ctx , cancel := context .WithDeadline (
48
- context .Background (),
49
- time .Now ().Add (timeout ),
50
- )
51
- defer func () {
52
- <- ctx .Done ()
53
- }()
54
- if err := db .GetContext (
55
- ctx ,
56
- & super ,
57
- "select usesuper from pg_user where usename = CURRENT_USER" ,
58
- ); err != nil {
59
- log .WithError (err ).Error ("failed to detect user privileges" )
60
- }
61
- cancel ()
62
- return
63
- }
64
-
65
44
func (g * Gauges ) hasSharedPreloadLibrary (lib string ) bool {
66
45
var libs []string
67
46
if err := g .query ("SHOW shared_preload_libraries" , & libs , emptyParams ); err != nil {
0 commit comments