Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
[dual sampling] introduced option to disable dual sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
ufoot committed Dec 27, 2017
1 parent c07dd27 commit 48a5831
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 19 deletions.
28 changes: 19 additions & 9 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,25 @@ func (a *Agent) Process(t model.Trace) {

var samplers []*Sampler
priority, ok := root.Metrics[samplingPriorityKey]
if priority == 0 {
// Use score engine for traces with no priority or priority set to 0
samplers = append(samplers, a.ScoreEngine)
}
if a.PriorityEngine != nil && ok {
// If Priority is defined, send to priority sampling, regardless of priority value.
// The sampler will keep or discard the trace, but we send everything so that it
// gets the big picture and can set the sampling rates accordingly.
samplers = append(samplers, a.PriorityEngine)
if a.conf.ScorePriority0Traces {
// Send traces to possibly several score engines.
if priority == 0 {
// Use score engine for traces with no priority or priority set to 0
samplers = append(samplers, a.ScoreEngine)
}
if a.PriorityEngine != nil && ok {
// If Priority is defined, send to priority sampling, regardless of priority value.
// The sampler will keep or discard the trace, but we send everything so that it
// gets the big picture and can set the sampling rates accordingly.
samplers = append(samplers, a.PriorityEngine)
}
} else {
// Send traces to one single engine, either Priority or Score
if ok {
samplers = []*Sampler{a.PriorityEngine}
} else {
samplers = []*Sampler{a.ScoreEngine}
}
}

priorityPtr := &ts.TracesPriorityNone
Expand Down
25 changes: 15 additions & 10 deletions config/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ type AgentConfig struct {
ExtraAggregators []string

// Sampler configuration
ExtraSampleRate float64
PreSampleRate float64
MaxTPS float64
PrioritySampling bool
ExtraSampleRate float64
PreSampleRate float64
MaxTPS float64
PrioritySampling bool
ScorePriority0Traces bool

// Receiver
ReceiverHost string
Expand Down Expand Up @@ -171,10 +172,11 @@ func NewDefaultAgentConfig() *AgentConfig {
BucketInterval: time.Duration(10) * time.Second,
ExtraAggregators: []string{"http.status_code"},

ExtraSampleRate: 1.0,
PreSampleRate: 1.0,
MaxTPS: 10,
PrioritySampling: true,
ExtraSampleRate: 1.0,
PreSampleRate: 1.0,
MaxTPS: 10,
PrioritySampling: true,
ScorePriority0Traces: true,

ReceiverHost: "localhost",
ReceiverPort: 8126,
Expand Down Expand Up @@ -324,8 +326,11 @@ APM_CONF:
if v, e := conf.GetFloat("trace.sampler", "max_traces_per_second"); e == nil {
c.MaxTPS = v
}
if v := strings.ToLower(conf.GetDefault("trace.sampler", "priority_sampling", "")); v == "yes" || v == "true" {
c.PrioritySampling = true
if v := strings.ToLower(conf.GetDefault("trace.sampler", "priority_sampling", "yes")); v != "yes" && v != "true" {
c.PrioritySampling = false
}
if v := strings.ToLower(conf.GetDefault("trace.sampler", "score_priority_0_traces", "yes")); v != "yes" && v != "true" {
c.ScorePriority0Traces = false
}

if v, e := conf.GetInt("trace.receiver", "receiver_port"); e == nil {
Expand Down
41 changes: 41 additions & 0 deletions config/agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package config

import (
"strings"

"github.com/stretchr/testify/assert"

"testing"

"github.com/go-ini/ini"
)

func TestPrioritySamplerConfig(t *testing.T) {
assert := assert.New(t)
agentConfig := NewDefaultAgentConfig()

assert.True(agentConfig.PrioritySampling)
assert.True(agentConfig.ScorePriority0Traces)

dd, _ := ini.Load([]byte(strings.Join([]string{
"[trace.sampler]",
}, "\n")))

conf := &File{instance: dd, Path: "whatever"}
agentConfig, _ = NewAgentConfig(conf, nil)

assert.True(agentConfig.PrioritySampling)
assert.True(agentConfig.ScorePriority0Traces)

dd, _ = ini.Load([]byte(strings.Join([]string{
"[trace.sampler]",
"priority_sampling = no",
"score_priority_0_traces = no",
}, "\n")))

conf = &File{instance: dd, Path: "whatever"}
agentConfig, _ = NewAgentConfig(conf, nil)

assert.False(agentConfig.PrioritySampling)
assert.False(agentConfig.ScorePriority0Traces)
}

0 comments on commit 48a5831

Please sign in to comment.