Skip to content
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

Fix "out of order" event delay metric values #18

Merged
merged 4 commits into from
Apr 2, 2024
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: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ func main() {
requestTimeout = DEFAULT_TIMEOUT_SYSLOG
}

ctl := syslogngctl.Controller{
ControlChannel: syslogngctl.NewUnixDomainSocketControlChannel(runArgs.SocketAddr),
}
ctl := syslogngctl.NewController(syslogngctl.NewUnixDomainSocketControlChannel(runArgs.SocketAddr))

mux := http.NewServeMux()
mux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 1 addition & 3 deletions pkg/syslog-ng-ctl/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func main() {
os.Exit(1)
}

ctl := syslogngctl.Controller{
ControlChannel: syslogngctl.NewUnixDomainSocketControlChannel(socketAddr),
}
ctl := syslogngctl.NewController(syslogngctl.NewUnixDomainSocketControlChannel(socketAddr))

cmds := []struct {
Args []string
Expand Down
21 changes: 14 additions & 7 deletions pkg/syslog-ng-ctl/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,37 @@ type Controller struct {
lastMetricQueryTime time.Time
}

func (c Controller) GetLicenseInfo(ctx context.Context) (string, error) {
func NewController(controlChannel ControlChannel) *Controller {
return &Controller{
ControlChannel: controlChannel,
lastMetricQueryTime: time.Now(),
}
}

func (c *Controller) GetLicenseInfo(ctx context.Context) (string, error) {
return GetLicenseInfo(ctx, c.ControlChannel)
}

func (c Controller) Ping(ctx context.Context) error {
func (c *Controller) Ping(ctx context.Context) error {
return Ping(ctx, c.ControlChannel)
}

func (c Controller) Reload(ctx context.Context) error {
func (c *Controller) Reload(ctx context.Context) error {
return Reload(ctx, c.ControlChannel)
}

func (c Controller) Stats(ctx context.Context) ([]Stat, error) {
func (c *Controller) Stats(ctx context.Context) ([]Stat, error) {
return Stats(ctx, c.ControlChannel)
}

func (c Controller) OriginalConfig(ctx context.Context) (string, error) {
func (c *Controller) OriginalConfig(ctx context.Context) (string, error) {
return OriginalConfig(ctx, c.ControlChannel)
}

func (c Controller) PreprocessedConfig(ctx context.Context) (string, error) {
func (c *Controller) PreprocessedConfig(ctx context.Context) (string, error) {
return PreprocessedConfig(ctx, c.ControlChannel)
}

func (c Controller) StatsPrometheus(ctx context.Context) ([]*io_prometheus_client.MetricFamily, error) {
func (c *Controller) StatsPrometheus(ctx context.Context) ([]*io_prometheus_client.MetricFamily, error) {
return StatsPrometheus(ctx, c.ControlChannel, &c.lastMetricQueryTime)
}
7 changes: 3 additions & 4 deletions pkg/syslog-ng-ctl/stats_prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ func transformEventDelayMetric(delayMetric *io_prometheus_client.MetricFamily, d
delayMetric := m

if d, ok := delayMetricAgeByLabel[fmt.Sprint(m.Label)]; ok {
delayMetricAge := d.GetGauge().GetValue()
delayMetricAge := int(d.GetGauge().GetValue())

lastDelaySampleTS := now.Add(time.Duration(-delayMetricAge * float64(time.Second)))
lastDelaySampleTS := now.Add(time.Duration(-delayMetricAge) * time.Second)
if lastDelaySampleTS.After(lastMetricQueryTime) {
timestampMs := timestamp.FromTime(lastDelaySampleTS)
transformedMetric = append(transformedMetric,
Expand Down Expand Up @@ -161,11 +161,11 @@ func StatsPrometheus(ctx context.Context, cc ControlChannel, lastMetricQueryTime
}

now := time.Now()
defer func() { *lastMetricQueryTime = now }()

var mfs map[string]*io_prometheus_client.MetricFamily
if strings.HasPrefix(rsp, StatsHeader) {
mfs, err = createMetricsFromLegacyStats(rsp)
*lastMetricQueryTime = now
return maps.Values(mfs), err
}

Expand Down Expand Up @@ -214,7 +214,6 @@ func StatsPrometheus(ctx context.Context, cc ControlChannel, lastMetricQueryTime
transformEventDelayMetric(delayMetric, delayMetricAge, now, *lastMetricQueryTime, mfs)
}

*lastMetricQueryTime = now
return maps.Values(mfs), err
}

Expand Down
Loading