Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 26388a5

Browse files
committed
Remove isSuperuser function
1 parent 8943501 commit 26388a5

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

gauges/gauge.go

+11-32
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ import (
1212
)
1313

1414
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
2221
}
2322

2423
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 {
2726
}
2827
var dbx = sqlx.NewDb(db, "postgres")
2928
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,
3634
Errs: prometheus.NewGauge(
3735
prometheus.GaugeOpts{
3836
Name: "postgresql_query_errors",
@@ -43,25 +41,6 @@ func New(name string, db *sql.DB, interval, timeout time.Duration) *Gauges {
4341
}
4442
}
4543

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-
6544
func (g *Gauges) hasSharedPreloadLibrary(lib string) bool {
6645
var libs []string
6746
if err := g.query("SHOW shared_preload_libraries", &libs, emptyParams); err != nil {

0 commit comments

Comments
 (0)