Skip to content

Commit eedeac8

Browse files
authored
[*] deprecate IsSuperuser source option (#706)
* [*] deprecate `IsSuperuser` source option This will be determined during runtime * fix 'getValues' is assigned a value but never used
1 parent ab23dd6 commit eedeac8

11 files changed

Lines changed: 33 additions & 56 deletions

File tree

internal/reaper/database.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,15 @@ func GetMonitoredDatabaseSettings(ctx context.Context, md *sources.SourceConn, n
173173
version(),
174174
pg_is_in_recovery(),
175175
current_database()::TEXT,
176-
system_identifier
176+
system_identifier,
177+
current_setting('is_superuser')::bool
177178
FROM
178179
pg_control_system()`
179180

180181
err := md.Conn.QueryRow(ctx, sql).
181182
Scan(&dbNewSettings.Version, &dbNewSettings.VersionStr,
182183
&dbNewSettings.IsInRecovery, &dbNewSettings.RealDbname,
183-
&dbNewSettings.SystemIdentifier)
184+
&dbNewSettings.SystemIdentifier, &dbNewSettings.IsSuperuser)
184185
if err != nil {
185186
if noCache {
186187
return dbSettings, err
@@ -205,13 +206,6 @@ FROM
205206
}
206207
}
207208

208-
l.Debugf("[%s] determining if monitoring user is a superuser...", md.Name)
209-
sqlSu := `select /* pgwatch_generated */ rolsuper from pg_roles r where rolname = session_user`
210-
211-
if err = md.Conn.QueryRow(ctx, sqlSu).Scan(&dbNewSettings.IsSuperuser); err != nil {
212-
l.Errorf("[%s] failed to determine if monitoring user is a superuser: %v", md.Name, err)
213-
}
214-
215209
l.Debugf("[%s] determining installed extensions info...", md.Name)
216210
data, err := QueryMeasurements(ctx, md.Name, sqlExtensions)
217211
if err != nil {

internal/sources/postgres.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ func (r *dbSourcesReaderWriter) updateDatabase(conn db.PgxIface, md Source) (err
5959
config_standby,
6060
preset_config,
6161
preset_config_standby,
62-
is_superuser,
6362
include_pattern,
6463
exclude_pattern,
6564
custom_tags,
6665
host_config,
6766
only_if_master)
6867
values
69-
($1, $2, $3, $4, $5, $6, NULLIF($7, ''), NULLIF($8, ''), $9, $10, $11, $12, $13, $14)
68+
($1, $2, $3, $4, $5, $6, NULLIF($7, ''), NULLIF($8, ''), $9, $10, $11, $12, $13)
7069
on conflict (name) do update set
7170
"group" = $2,
7271
dbtype = $3,
@@ -75,16 +74,15 @@ on conflict (name) do update set
7574
config_standby = $6,
7675
preset_config = NULLIF($7, ''),
7776
preset_config_standby = NULLIF($8, ''),
78-
is_superuser = $9,
79-
include_pattern = $10,
80-
exclude_pattern = $11,
81-
custom_tags = $12,
82-
host_config = $13,
83-
only_if_master = $14`
77+
include_pattern = $9,
78+
exclude_pattern = $10,
79+
custom_tags = $11,
80+
host_config = $12,
81+
only_if_master = $13`
8482
_, err = conn.Exec(context.Background(), sql,
8583
md.Name, md.Group, md.Kind,
8684
md.ConnStr, m(md.Metrics), m(md.MetricsStandby), md.PresetMetrics, md.PresetMetricsStandby,
87-
md.IsSuperuser, md.IncludePattern, md.ExcludePattern, m(md.CustomTags),
85+
md.IncludePattern, md.ExcludePattern, m(md.CustomTags),
8886
m(md.HostConfig), md.OnlyIfMaster)
8987
return err
9088
}
@@ -108,7 +106,6 @@ func (r *dbSourcesReaderWriter) GetSources() (dbs Sources, err error) {
108106
coalesce(config_standby, '{}'::jsonb) as config_standby,
109107
coalesce(preset_config, '') as preset_config,
110108
coalesce(preset_config_standby, '') as preset_config_standby,
111-
is_superuser,
112109
coalesce(include_pattern, '') as include_pattern,
113110
coalesce(exclude_pattern, '') as exclude_pattern,
114111
coalesce(custom_tags, '{}'::jsonb) as custom_tags,

internal/sources/postgres_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func TestGetMonitoredDatabases(t *testing.T) {
4343
conn.ExpectPing()
4444
conn.ExpectQuery(`select \/\* pgwatch_generated \*\/`).WillReturnRows(pgxmock.NewRows([]string{
4545
"name", "group", "dbtype", "connstr", "config", "config_standby", "preset_config",
46-
"preset_config_standby", "is_superuser", "include_pattern", "exclude_pattern",
46+
"preset_config_standby", "include_pattern", "exclude_pattern",
4747
"custom_tags", "host_config", "only_if_master", "is_enabled",
4848
}).AddRow(
4949
"db1", "group1", sources.Kind("postgres"), "postgres://user:pass@localhost:5432/db1",
5050
map[string]float64{"metric": 60}, map[string]float64{"standby_metric": 60}, "exhaustive", "exhaustive",
51-
true, ".*", `\_.+`, map[string]string{"tag": "value"}, nil, true, true,
51+
".*", `\_.+`, map[string]string{"tag": "value"}, nil, true, true,
5252
))
5353
pgrw, err := sources.NewPostgresSourcesReaderWriterConn(ctx, conn)
5454
a.NoError(err)
@@ -73,12 +73,12 @@ func TestSyncFromReader(t *testing.T) {
7373
conn.ExpectPing()
7474
conn.ExpectQuery(`select \/\* pgwatch_generated \*\/`).WillReturnRows(pgxmock.NewRows([]string{
7575
"name", "group", "dbtype", "connstr", "config", "config_standby", "preset_config",
76-
"preset_config_standby", "is_superuser", "include_pattern", "exclude_pattern",
76+
"preset_config_standby", "include_pattern", "exclude_pattern",
7777
"custom_tags", "host_config", "only_if_master", "is_enabled",
7878
}).AddRow(
7979
"db1", "group1", sources.Kind("postgres"), "postgres://user:pass@localhost:5432/db1",
8080
map[string]float64{"metric": 60}, map[string]float64{"standby_metric": 60}, "exhaustive", "exhaustive",
81-
true, ".*", `\_.+`, map[string]string{"tag": "value"}, nil, true, true,
81+
".*", `\_.+`, map[string]string{"tag": "value"}, nil, true, true,
8282
))
8383
pgrw, err := sources.NewPostgresSourcesReaderWriterConn(ctx, conn)
8484
a.NoError(err)
@@ -118,7 +118,6 @@ func TestUpdateDatabase(t *testing.T) {
118118
ConnStr: "postgres://user:pass@localhost:5432/db1",
119119
Metrics: map[string]float64{"metric": 60},
120120
MetricsStandby: map[string]float64{"standby_metric": 60},
121-
IsSuperuser: true,
122121
IncludePattern: ".*",
123122
ExcludePattern: `\_.+`,
124123
CustomTags: map[string]string{"tag": "value"},
@@ -128,7 +127,7 @@ func TestUpdateDatabase(t *testing.T) {
128127
md.Name, md.Group, md.Kind,
129128
md.ConnStr, `{"metric":60}`, `{"standby_metric":60}`,
130129
md.PresetMetrics, md.PresetMetricsStandby,
131-
md.IsSuperuser, md.IncludePattern, md.ExcludePattern, `{"tag":"value"}`,
130+
md.IncludePattern, md.ExcludePattern, `{"tag":"value"}`,
132131
nil, md.OnlyIfMaster,
133132
).WillReturnResult(pgxmock.NewResult("UPDATE", 1))
134133

@@ -154,7 +153,6 @@ func TestWriteMonitoredDatabases(t *testing.T) {
154153
ConnStr: "postgres://user:pass@localhost:5432/db1",
155154
Metrics: map[string]float64{"metric": 60},
156155
MetricsStandby: map[string]float64{"standby_metric": 60},
157-
IsSuperuser: true,
158156
IncludePattern: ".*",
159157
ExcludePattern: `\_.+`,
160158
CustomTags: map[string]string{"tag": "value"},
@@ -168,7 +166,7 @@ func TestWriteMonitoredDatabases(t *testing.T) {
168166
conn.ExpectExec(`insert into pgwatch\.source`).WithArgs(
169167
md.Name, md.Group, md.Kind,
170168
md.ConnStr, `{"metric":60}`, `{"standby_metric":60}`, md.PresetMetrics, md.PresetMetricsStandby,
171-
md.IsSuperuser, md.IncludePattern, md.ExcludePattern, `{"tag":"value"}`,
169+
md.IncludePattern, md.ExcludePattern, `{"tag":"value"}`,
172170
nil, md.OnlyIfMaster,
173171
).WillReturnResult(pgxmock.NewResult("INSERT", 1))
174172
conn.ExpectCommit()
@@ -204,7 +202,7 @@ func TestWriteMonitoredDatabases(t *testing.T) {
204202
conn.ExpectExec(`insert into pgwatch\.source`).WithArgs(
205203
md.Name, md.Group, md.Kind,
206204
md.ConnStr, `{"metric":60}`, `{"standby_metric":60}`, md.PresetMetrics, md.PresetMetricsStandby,
207-
md.IsSuperuser, md.IncludePattern, md.ExcludePattern, `{"tag":"value"}`,
205+
md.IncludePattern, md.ExcludePattern, `{"tag":"value"}`,
208206
nil, md.OnlyIfMaster,
209207
).WillReturnError(errors.New("failed insert"))
210208
conn.ExpectRollback()

internal/sources/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ type (
5252
ExcludePattern string `yaml:"exclude_pattern" db:"exclude_pattern"`
5353
PresetMetrics string `yaml:"preset_metrics" db:"preset_config"`
5454
PresetMetricsStandby string `yaml:"preset_metrics_standby" db:"preset_config_standby"`
55-
IsSuperuser bool `yaml:"is_superuser" db:"is_superuser"`
5655
IsEnabled bool `yaml:"is_enabled" db:"is_enabled"`
5756
CustomTags map[string]string `yaml:"custom_tags" db:"custom_tags"`
5857
HostConfig HostConfigAttrs `yaml:"host_config" db:"host_config"`

internal/webui/embed_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package webui
2+
3+
import (
4+
"io/fs"
5+
"testing"
6+
)
7+
8+
func TestWebUIInit(t *testing.T) {
9+
if WebUIFs == nil {
10+
t.Error("WebUIFs is nil")
11+
}
12+
if _, err := fs.Stat(WebUIFs, "index.html"); err != nil {
13+
t.Errorf("WebUIFs does not contain index.html: %v", err)
14+
}
15+
}

internal/webui/src/containers/SourceFormDialog/SourceFormDialog.consts.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const getSourceInitialValues = (data?: Source): SourceFormValues => ({
99
ConnStr: data?.ConnStr ?? "",
1010
Kind: data?.Kind ?? "postgres",
1111
IsEnabled: data?.IsEnabled ?? true,
12-
IsSuperuser: data?.IsSuperuser ?? false,
1312
Metrics: toArrayFromRecord(data?.Metrics),
1413
MetricsStandby: toArrayFromRecord(data?.MetricsStandby),
1514
PresetMetrics: data?.PresetMetrics ?? "basic",
@@ -26,7 +25,6 @@ export const createSourceRequest = (values: SourceFormValues): Source => ({
2625
ConnStr: values.ConnStr,
2726
Kind: values.Kind,
2827
IsEnabled: values.IsEnabled,
29-
IsSuperuser: values.IsSuperuser,
3028
Metrics: toRecordFromArray(values.Metrics),
3129
MetricsStandby: toRecordFromArray(values.MetricsStandby),
3230
PresetMetrics: values.PresetMetrics ?? "",

internal/webui/src/containers/SourceFormDialog/components/SourceForm/SourceForm.consts.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const sourceFormValuesValidationSchema = Yup.object({
3131
IncludePattern: Yup.string().optional().nullable(),
3232
ExcludePattern: Yup.string().optional().nullable(),
3333
IsEnabled: Yup.boolean().required(),
34-
IsSuperuser: Yup.boolean().required(),
3534
Metrics: Yup.array().of(metricsValidationSchema).test((arr, context) => {
3635
if (!arr) {
3736
return;

internal/webui/src/containers/SourceFormDialog/components/SourceForm/SourceForm.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type SourceFormGeneral = {
1010
IncludePattern?: string | null;
1111
ExcludePattern?: string | null;
1212
IsEnabled: boolean;
13-
IsSuperuser: boolean;
1413
};
1514

1615
type SourceFormMetrics = {

internal/webui/src/containers/SourceFormDialog/components/SourceForm/components/SourceFormStepGeneral.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { SourceFormValues } from "../SourceForm.types";
88
import { TestConnection } from "./TestConnection/TestConnection";
99

1010
export const SourceFormStepGeneral = () => {
11-
const { register, formState: { errors }, control, getValues, watch } = useFormContext<SourceFormValues>();
11+
const { register, formState: { errors }, control, watch } = useFormContext<SourceFormValues>();
1212
const { classes, cx } = useFormStyles();
1313

1414
const kindValue = watch("Kind");
@@ -130,19 +130,6 @@ export const SourceFormStepGeneral = () => {
130130
/>
131131
}
132132
/>
133-
<FormControlLabel
134-
className={classes.formControlCheckbox}
135-
label="Is superuser"
136-
labelPlacement="start"
137-
disabled
138-
control={
139-
<Checkbox
140-
disabled
141-
size="medium"
142-
checked={getValues("IsSuperuser")}
143-
/>
144-
}
145-
/>
146133
</div>
147134
);
148135
};

internal/webui/src/pages/SourcesPage/components/SourcesGrid/SourcesGrid.consts.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,6 @@ export const useSourcesGridColumns = (): GridColDef<Source>[] => ([
8989
headerAlign: "center",
9090
hide: true,
9191
},
92-
{
93-
field: "IsSuperuser",
94-
headerName: "Superuser",
95-
width: 120,
96-
align: "center",
97-
headerAlign: "center",
98-
renderCell: ({ row }) => getIcon(row.IsSuperuser),
99-
},
10092
{
10193
field: "IsEnabled",
10294
headerName: "Enabled",

0 commit comments

Comments
 (0)