Skip to content

Commit

Permalink
[-] fix update metrics in PostgreSQL, fixes #532 (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
pashagolub authored Aug 29, 2024
1 parent af4696b commit 01dc560
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/db/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type PgxPoolIface interface {
Stat() *pgxpool.Stat
}

func MarshallParam(v any) any {
func MarshallParamToJSONB(v any) any {
if v == nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/db/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func TestMarshallParam(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := db.MarshallParam(tt.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("MarshallParam() = %v, want %v", got, tt.want)
if got := db.MarshallParamToJSONB(tt.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("MarshallParamToJSONB() = %v, want %v", got, tt.want)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions internal/metrics/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func (dmrw *dbMetricReaderWriter) UpdateMetric(metricName string, metric Metric)
_, err := dmrw.configDb.Exec(dmrw.ctx, `UPDATE pgwatch.metric SET
sqls = $2, init_sql = $3, description = $4, node_status = $5, gauges = $6, is_instance_level = $7, storage_name = $8
WHERE name = $1`,
metricName, db.MarshallParam(metric.SQLs), metric.InitSQL, metric.Description,
metric.NodeStatus, db.MarshallParam(metric.Gauges), metric.IsInstanceLevel, metric.StorageName)
metricName, db.MarshallParamToJSONB(metric.SQLs), metric.InitSQL, metric.Description,
metric.NodeStatus, metric.Gauges, metric.IsInstanceLevel, metric.StorageName)
return err
}

Expand All @@ -145,6 +145,6 @@ func (dmrw *dbMetricReaderWriter) DeletePreset(presetName string) error {
func (dmrw *dbMetricReaderWriter) UpdatePreset(presetName string, preset Preset) error {
sql := `INSERT INTO pgwatch.preset(name, description, metrics) VALUES ($1, $2, $3)
ON CONFLICT (name) DO UPDATE SET description = $2, metrics = $3`
_, err := dmrw.configDb.Exec(dmrw.ctx, sql, presetName, preset.Description, db.MarshallParam(preset.Metrics))
_, err := dmrw.configDb.Exec(dmrw.ctx, sql, presetName, preset.Description, db.MarshallParamToJSONB(preset.Metrics))
return err
}
2 changes: 1 addition & 1 deletion internal/sources/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r *dbSourcesReaderWriter) WriteSources(dbs Sources) error {
}

func (r *dbSourcesReaderWriter) updateDatabase(conn db.PgxIface, md Source) (err error) {
m := db.MarshallParam
m := db.MarshallParamToJSONB
sql := `insert into pgwatch.source(
name,
"group",
Expand Down

0 comments on commit 01dc560

Please sign in to comment.