Skip to content

Commit

Permalink
[*] replace --no-helper-functions with --create-helpers , closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
pashagolub authored Oct 14, 2024
1 parent 17188fc commit 3f13ba1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/metrics/cmdopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package metrics
// CmdOpts specifies metric command-line options
type CmdOpts struct {
Metrics string `short:"m" long:"metrics" mapstructure:"metrics" description:"File or folder of YAML files with metrics definitions" env:"PW_METRICS"`
NoHelperFunctions bool `long:"no-helper-functions" mapstructure:"no-helper-functions" description:"Ignore metric definitions using helper functions (in form get_smth()) and don't also roll out any helpers automatically" env:"PW_NO_HELPER_FUNCTIONS"`
CreateHelpers bool `long:"create-helpers" mapstructure:"create-helpers" description:"Create helper database objects from metric definitions" env:"PW_CREATE_HELPERS"`
DirectOSStats bool `long:"direct-os-stats" mapstructure:"direct-os-stats" description:"Extract OS related psutil statistics not via PL/Python wrappers but directly on host" env:"PW_DIRECT_OS_STATS"`
InstanceLevelCacheMaxSeconds int64 `long:"instance-level-cache-max-seconds" mapstructure:"instance-level-cache-max-seconds" description:"Max allowed staleness for instance level metric data shared between DBs of an instance. Affects 'continuous' host types only. Set to 0 to disable" env:"PW_INSTANCE_LEVEL_CACHE_MAX_SECONDS" default:"30"`
EmergencyPauseTriggerfile string `long:"emergency-pause-triggerfile" mapstructure:"emergency-pause-triggerfile" description:"When the file exists no metrics will be temporarily fetched / scraped" env:"PW_EMERGENCY_PAUSE_TRIGGERFILE" default:"/tmp/pgwatch-emergency-pause"`
Expand Down
18 changes: 8 additions & 10 deletions internal/reaper/reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ func (r *Reaper) Reap(mainContext context.Context) (err error) {
logger.
WithField("sources", len(monitoredDbs)).
WithField("metrics", len(metricDefinitionMap.MetricDefs)).
WithField("presets", len(metricDefinitionMap.PresetDefs)).
Log(func() logrus.Level {
if firstLoop && len(monitoredDbs)*len(metricDefinitionMap.MetricDefs) == 0 {
return logrus.WarnLevel
}
return logrus.InfoLevel
}(), "host info refreshed")
}(), "sources and metrics refreshed")

firstLoop = false // only used for failing when 1st config reading fails

Expand Down Expand Up @@ -124,7 +125,7 @@ func (r *Reaper) Reap(mainContext context.Context) (err error) {
logger.Errorf("could not start metric gathering due to connection problem: %s", err)
continue
}
logger.Infof("Connect OK. Version: %s (in recovery: %v)", ver.VersionStr, ver.IsInRecovery)
logger.WithField("source", monitoredDB.Name).Infof("Connect OK. Version: %s (in recovery: %v)", ver.VersionStr, ver.IsInRecovery)
if ver.IsInRecovery && monitoredDB.OnlyIfMaster {
logger.Infof("not added to monitoring due to 'master only' property")
continue
Expand All @@ -151,14 +152,11 @@ func (r *Reaper) Reap(mainContext context.Context) (err error) {
}()
}

if monitoredDB.IsPostgresSource() && !ver.IsInRecovery {
if opts.Metrics.NoHelperFunctions {
logger.Infof("[%s] skipping rollout out helper functions due to the --no-helper-functions flag ...", dbUnique)
} else {
logger.Infof("Trying to create helper functions if missing for \"%s\"...", dbUnique)
if err = TryCreateMetricsFetchingHelpers(mainContext, monitoredDB); err != nil {
logger.Warningf("Failed to create helper functions for \"%s\": %w", dbUnique, err)
}
if monitoredDB.IsPostgresSource() && !ver.IsInRecovery && opts.Metrics.CreateHelpers {
ls := logger.WithField("source", dbUnique)
ls.Info("trying to create helper objects if missing")
if err = TryCreateMetricsFetchingHelpers(mainContext, monitoredDB); err != nil {
ls.Warning("failed to create helper functions: %w", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/sinks/multiwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewMultiWriter(ctx context.Context, opts *CmdOpts, metricDefs *metrics.Metr
return nil, err
}
mw.AddWriter(w)
l.Info(`measurements sink actviated`)
l.Info(`measurements sink activated`)
}

if len(mw.writers) == 0 {
Expand Down

0 comments on commit 3f13ba1

Please sign in to comment.