Skip to content

[*] drop support for discontinued Azure Single Server #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions internal/reaper/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import (
var monitoredDbCache map[string]*sources.SourceConn
var monitoredDbCacheLock sync.RWMutex

var lastDBSizeMB = make(map[string]int64)
var lastDBSizeFetchTime = make(map[string]time.Time) // cached for DB_SIZE_CACHING_INTERVAL
var lastDBSizeCheckLock sync.RWMutex

var lastSQLFetchError sync.Map

func UpdateMonitoredDBCache(data sources.SourceConns) {
Expand Down
40 changes: 0 additions & 40 deletions internal/reaper/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,6 @@ func QueryMeasurements(ctx context.Context, dbUnique string, sql string, args ..
return nil, err
}

func DBGetSizeMB(ctx context.Context, dbUnique string) (sizeMB int64, err error) {
sqlDbSize := `select /* pgwatch_generated */ pg_database_size(current_database());`

lastDBSizeCheckLock.RLock()
lastDBSizeCheckTime := lastDBSizeFetchTime[dbUnique]
lastDBSize, ok := lastDBSizeMB[dbUnique]
lastDBSizeCheckLock.RUnlock()

if !ok || lastDBSizeCheckTime.Add(dbSizeCachingInterval).Before(time.Now()) {
md, err := GetMonitoredDatabaseByUniqueName(ctx, dbUnique)
if err != nil {
return 0, err
}
err = md.FetchRuntimeInfo(ctx, false)
if err != nil || (md.ExecEnv != sources.EnvAzureSingle) || (md.ExecEnv == sources.EnvAzureSingle && md.ApproxDBSizeB < 1e12) {
log.GetLogger(ctx).Debugf("[%s] determining DB size ...", dbUnique)
err = md.Conn.QueryRow(ctx, sqlDbSize).Scan(&sizeMB)
if err != nil {
log.GetLogger(ctx).Errorf("[%s] failed to determine DB size...cannot apply --min-db-size-mb flag. err: %v ...", dbUnique, err)
return 0, err
}
} else {
log.GetLogger(ctx).Debugf("[%s] Using approx DB size for the --min-db-size-mb filter ...", dbUnique)
sizeMB = md.ApproxDBSizeB / 1048576
}

log.GetLogger(ctx).Debugf("[%s] DB size = %d MB, caching for %v ...", dbUnique, sizeMB, dbSizeCachingInterval)

lastDBSizeCheckLock.Lock()
lastDBSizeFetchTime[dbUnique] = time.Now()
lastDBSizeMB[dbUnique] = sizeMB
lastDBSizeCheckLock.Unlock()

return sizeMB, nil

}
log.GetLogger(ctx).Debugf("[%s] using cached DBsize %d MB for the --min-db-size-mb filter check", dbUnique, lastDBSize)
return lastDBSize, nil
}

func DetectSprocChanges(ctx context.Context, md *sources.SourceConn, storageCh chan<- []metrics.MeasurementEnvelope, hostState map[string]map[string]string) ChangeDetectionResults {
detectedChanges := make(metrics.Measurements, 0)
var firstRun bool
Expand Down
27 changes: 5 additions & 22 deletions internal/reaper/reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,12 @@ func (r *Reaper) Reap(ctx context.Context) (err error) {
r.CreateSourceHelpers(ctx, srcL, monitoredSource)

if monitoredSource.IsPostgresSource() {
var DBSizeMB int64

if r.Sources.MinDbSizeMB >= 8 { // an empty DB is a bit less than 8MB
DBSizeMB, _ = DBGetSizeMB(ctx, monitoredSource.Name) // ignore errors, i.e. only remove from monitoring when we're certain it's under the threshold
if DBSizeMB != 0 {
if DBSizeMB < r.Sources.MinDbSizeMB {
srcL.Infof("ignored due to the --min-db-size-mb filter, current size %d MB", DBSizeMB)
hostsToShutDownDueToRoleChange[monitoredSource.Name] = true // for the case when DB size was previosly above the threshold
continue
}
DBSizeMB := monitoredSource.ApproxDbSize / 1048576 // only remove from monitoring when we're certain it's under the threshold
if DBSizeMB != 0 && DBSizeMB < r.Sources.MinDbSizeMB {
srcL.Infof("ignored due to the --min-db-size-mb filter, current size %d MB", DBSizeMB)
hostsToShutDownDueToRoleChange[monitoredSource.Name] = true // for the case when DB size was previosly above the threshold
continue
}
}

Expand Down Expand Up @@ -463,8 +459,6 @@ func (r *Reaper) AddSysinfoToMeasurements(data metrics.Measurements, ver *source
}

func (r *Reaper) FetchMetric(ctx context.Context, msg MetricFetchConfig, hostState map[string]map[string]string) (*metrics.MeasurementEnvelope, error) {

// var dbSettings MonitoredDatabaseSettings
var dbVersion int
var err error
var sql string
Expand All @@ -486,18 +480,7 @@ func (r *Reaper) FetchMetric(ctx context.Context, msg MetricFetchConfig, hostSta
if err = md.FetchRuntimeInfo(ctx, false); err != nil {
return nil, err
}
if msg.MetricName == specialMetricDbSize || msg.MetricName == specialMetricTableStats {
if md.ExecEnv == sources.EnvAzureSingle && md.ApproxDBSizeB > 1e12 { // 1TB
subsMetricName := msg.MetricName + "_approx"
mvpApprox, ok := metricDefs.GetMetricDef(subsMetricName)
if ok && mvpApprox.StorageName == msg.MetricName {
log.GetLogger(ctx).Infof("[%s:%s] Transparently swapping metric to %s due to hard-coded rules...", msg.DBUniqueName, msg.MetricName, subsMetricName)
msg.MetricName = subsMetricName
}
}
}
dbVersion = md.Version

if msg.Source == sources.SourcePgBouncer {
dbVersion = 0 // version is 0.0 for all pgbouncer sql per convention
}
Expand Down
3 changes: 0 additions & 3 deletions internal/reaper/recommendations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const (
specialMetricServerLogEventCounts = "server_log_event_counts"
specialMetricPgpoolStats = "pgpool_stats"
specialMetricInstanceUp = "instance_up"
specialMetricDbSize = "db_size" // can be transparently switched to db_size_approx on instances with very slow FS access (Azure Single Server)
specialMetricTableStats = "table_stats" // can be transparently switched to table_stats_approx on instances with very slow FS (Azure Single Server)

)

var specialMetrics = map[string]bool{recoMetricName: true, specialMetricChangeEvents: true, specialMetricServerLogEventCounts: true}
Expand Down
4 changes: 2 additions & 2 deletions internal/sources/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type RuntimeInfo struct {
IsSuperuser bool
Extensions map[string]int
ExecEnv string
ApproxDBSizeB int64
ApproxDbSize int64
}

// SourceConn represents a single connection to monitor. Unlike source, it contains a database connection.
Expand Down Expand Up @@ -181,7 +181,7 @@ FROM
}

dbNewSettings.ExecEnv = md.DiscoverPlatform(ctx)
dbNewSettings.ApproxDBSizeB = md.FetchApproxSize(ctx)
dbNewSettings.ApproxDbSize = md.FetchApproxSize(ctx)

sqlExtensions := `select /* pgwatch_generated */ extname::text, (regexp_matches(extversion, $$\d+\.?\d+?$$))[1]::text as extversion from pg_extension order by 1;`
var res pgx.Rows
Expand Down
Loading