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

Set default metrics interval to 30s #322

Merged
merged 1 commit into from
Nov 21, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased](https://github.com/elastic/apm-agent-go/compare/v1.0.0...master)

- Stop pooling Transaction/Span/Error, introduce internal pooled objects (#319)
- Enable metrics collection with default interval of 30s (#322)

## [v1.0.0](https://github.com/elastic/apm-agent-go/releases/tag/v1.0.0)

Expand Down
2 changes: 1 addition & 1 deletion env.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
defaultAPIRequestTime = 10 * time.Second
defaultAPIBufferSize = 1 * apmconfig.MByte
defaultMetricsBufferSize = 100 * apmconfig.KByte
defaultMetricsInterval = 0 // disabled by default
defaultMetricsInterval = 30 * time.Second
defaultMaxSpans = 500
defaultCaptureBody = CaptureBodyOff
defaultSpanFramesMinDuration = 5 * time.Millisecond
Expand Down
37 changes: 24 additions & 13 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,10 @@ func (t *Tracer) loop() {
var metrics Metrics
var sentMetrics chan<- struct{}
var gatheringMetrics bool
var metricsTimerStart time.Time
metricsBuffer := ringbuffer.New(t.metricsBufferSize)
gatheredMetrics := make(chan struct{}, 1)
metricsTimer := time.NewTimer(0)
metricsTimerActive := false
if !metricsTimer.Stop() {
<-metricsTimer.C
}
Expand Down Expand Up @@ -561,15 +561,26 @@ func (t *Tracer) loop() {
case cmd := <-t.configCommands:
oldMetricsInterval := cfg.metricsInterval
cmd(&cfg)
if cfg.metricsInterval != oldMetricsInterval {
if !metricsTimerActive && !gatheringMetrics && oldMetricsInterval <= 0 && cfg.metricsInterval > 0 {
metricsTimer.Reset(cfg.metricsInterval)
metricsTimerActive = true
} else if metricsTimerActive && oldMetricsInterval > 0 && cfg.metricsInterval <= 0 {
if !metricsTimer.Stop() {
<-metricsTimer.C
if !gatheringMetrics && cfg.metricsInterval != oldMetricsInterval {
if metricsTimerStart.IsZero() {
if cfg.metricsInterval > 0 {
metricsTimer.Reset(cfg.metricsInterval)
metricsTimerStart = time.Now()
}
} else {
if cfg.metricsInterval <= 0 {
metricsTimerStart = time.Time{}
if !metricsTimer.Stop() {
<-metricsTimer.C
}
} else {
alreadyPassed := time.Since(metricsTimerStart)
if alreadyPassed >= cfg.metricsInterval {
metricsTimer.Reset(0)
} else {
metricsTimer.Reset(cfg.metricsInterval - alreadyPassed)
}
}
metricsTimerActive = false
}
}
continue
Expand All @@ -585,22 +596,22 @@ func (t *Tracer) loop() {
requestTimerActive = false
closeRequest = true
case <-metricsTimer.C:
metricsTimerActive = false
metricsTimerStart = time.Time{}
gatherMetrics = !gatheringMetrics
case sentMetrics = <-t.forceSendMetrics:
if metricsTimerActive {
if !metricsTimerStart.IsZero() {
if !metricsTimer.Stop() {
<-metricsTimer.C
}
metricsTimerActive = false
metricsTimerStart = time.Time{}
}
gatherMetrics = !gatheringMetrics
case <-gatheredMetrics:
modelWriter.writeMetrics(&metrics)
gatheringMetrics = false
flushRequest = true
if cfg.metricsInterval > 0 {
metricsTimerActive = true
metricsTimerStart = time.Now()
metricsTimer.Reset(cfg.metricsInterval)
}
case flushed = <-t.forceFlush:
Expand Down