Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 37b268a

Browse files
authored
Rename tail sampling tag as attribute (#544)
BREAKING CHANGE!!! Addresses #532 Changes: * `numeric-tag-filter` > `numeric-attribute-filter` * `string-tag-filter` > `string-attribute-filter` * `tag` > `key`
1 parent 926bd44 commit 37b268a

File tree

9 files changed

+99
-99
lines changed

9 files changed

+99
-99
lines changed

PERFORMANCE.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ It is important to note that the performance of the OpenCensus Collector depends
1313
on a variety of factors including:
1414

1515
* The receiving format: Jaeger thrift (14268) or Zipkin v2 JSON (9411)
16-
* The size of the spans (tests are based on number of tags): 20
16+
* The size of the spans (tests are based on number of attributes): 20
1717
* Whether tail-sampling is enabled or not
1818
* CPU / Memory allocation
1919
* Operating System: Linux

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- [OpenCensus Agent](#opencensus-agent)
2020
- [Usage](#agent-usage)
2121
- [OpenCensus Collector](#opencensus-collector)
22-
- [Global Tags](#global-tags)
22+
- [Global Attributes](#global-attributes)
2323
- [Intelligent Sampling](#tail-sampling)
2424
- [Usage](#collector-usage)
2525

@@ -275,10 +275,10 @@ The collector also serves as a control plane for agents/clients by supplying
275275
them updated configuration (e.g. trace sampling policies), and reporting
276276
agent/client health information/inventory metadata to downstream exporters.
277277

278-
### <a name="global-tags"></a> Global Tags
278+
### <a name="global-attributes"></a> Global Attributes
279279

280280
The collector also takes some global configurations that modify its behavior for all receivers / exporters. One of the configurations
281-
available is to add Attributes or Tags to all spans passing through this collector. These additional tags can be configured to either overwrite
281+
available is to add Attributes or Tags to all spans passing through this collector. These additional attributes can be configured to either overwrite
282282
attributes if they already exists on the span, or respect the original values. An example of this is provided below.
283283
```yaml
284284
global:
@@ -303,22 +303,22 @@ sampling:
303303
num-traces: 10000
304304
policies:
305305
# user-defined policy name
306-
my-string-tag-filter:
306+
my-string-attribute-filter:
307307
# exporters the policy applies to
308308
exporters:
309309
- jaeger
310-
policy: string-tag-filter
310+
policy: string-attribute-filter
311311
configuration:
312-
tag: tag1
312+
key: key1
313313
values:
314314
- value1
315315
- value2
316-
my-numeric-tag-filter:
316+
my-numeric-attribute-filter:
317317
exporters:
318318
- zipkin
319-
policy: numeric-tag-filter
319+
policy: numeric-attribute-filter
320320
configuration:
321-
tag: tag1
321+
key: key1
322322
min-value: 0
323323
max-value: 100
324324
```

cmd/occollector/app/builder/builder_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,39 +143,39 @@ func TestTailSamplingPoliciesConfiguration(t *testing.T) {
143143
wCfg.Mode = TailSampling
144144
wCfg.Policies = []*PolicyCfg{
145145
{
146-
Name: "string-tag-filter1",
147-
Type: StringTagFilter,
146+
Name: "string-attribute-filter1",
147+
Type: StringAttributeFilter,
148148
Exporters: []string{"jaeger1"},
149-
Configuration: &StringTagFilterCfg{
150-
Tag: "test",
149+
Configuration: &StringAttributeFilterCfg{
150+
Key: "test",
151151
Values: []string{"value 1", "value 2"},
152152
},
153153
},
154154
{
155-
Name: "numeric-tag-filter2",
156-
Type: NumericTagFilter,
155+
Name: "numeric-attribute-filter2",
156+
Type: NumericAttributeFilter,
157157
Exporters: []string{"jaeger2"},
158-
Configuration: &NumericTagFilterCfg{
159-
Tag: "http.status_code",
158+
Configuration: &NumericAttributeFilterCfg{
159+
Key: "http.status_code",
160160
MinValue: 400,
161161
MaxValue: 999,
162162
},
163163
},
164164
{
165-
Name: "string-tag-filter3",
166-
Type: StringTagFilter,
165+
Name: "string-attribute-filter3",
166+
Type: StringAttributeFilter,
167167
Exporters: []string{"jaeger3"},
168-
Configuration: &StringTagFilterCfg{
169-
Tag: "test.different",
168+
Configuration: &StringAttributeFilterCfg{
169+
Key: "test.different",
170170
Values: []string{"key 1", "key 2"},
171171
},
172172
},
173173
{
174-
Name: "numeric-tag-filter4",
175-
Type: NumericTagFilter,
174+
Name: "numeric-attribute-filter4",
175+
Type: NumericAttributeFilter,
176176
Exporters: []string{"jaeger4", "jaeger5"},
177-
Configuration: &NumericTagFilterCfg{
178-
Tag: "http.status_code",
177+
Configuration: &NumericAttributeFilterCfg{
178+
Key: "http.status_code",
179179
MinValue: 400,
180180
MaxValue: 999,
181181
},

cmd/occollector/app/builder/sampling_builder.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ type PolicyType string
4444
const (
4545
// AlwaysSample samples all traces, typically used for debugging.
4646
AlwaysSample PolicyType = "always-sample"
47-
// NumericTagFilter sample traces that have a given numberic tag in a specified
48-
// range, e.g.: tag "http.status_code" >= 399 and <= 999.
49-
NumericTagFilter PolicyType = "numeric-tag-filter"
50-
// StringTagFilter sample traces that a tag, of type string, matching
47+
// NumericAttributeFilter sample traces that have a given numeric attribute in a specified
48+
// range, e.g.: attribute "http.status_code" >= 399 and <= 999.
49+
NumericAttributeFilter PolicyType = "numeric-attribute-filter"
50+
// StringAttributeFilter sample traces that a attribute, of type string, matching
5151
// one of the listed values.
52-
StringTagFilter PolicyType = "string-tag-filter"
52+
StringAttributeFilter PolicyType = "string-attribute-filter"
5353
// RateLimiting allows all traces until the specified limits are satisfied.
5454
RateLimiting PolicyType = "rate-limiting"
5555
)
@@ -67,27 +67,27 @@ type PolicyCfg struct {
6767
Configuration interface{}
6868
}
6969

70-
// NumericTagFilterCfg holds the configurable settings to create a numeric tag filter
70+
// NumericAttributeFilterCfg holds the configurable settings to create a numeric attribute filter
7171
// sampling policy evaluator.
72-
type NumericTagFilterCfg struct {
72+
type NumericAttributeFilterCfg struct {
7373
// Tag that the filter is going to be matching against.
74-
Tag string `mapstructure:"tag"`
75-
// MinValue is the minimum value of the tag to be considered a match.
74+
Key string `mapstructure:"key"`
75+
// MinValue is the minimum value of the attribute to be considered a match.
7676
MinValue int64 `mapstructure:"min-value"`
77-
// MaxValue is the maximum value of the tag to be considered a match.
77+
// MaxValue is the maximum value of the attribute to be considered a match.
7878
MaxValue int64 `mapstructure:"max-value"`
7979
}
8080

81-
// StringTagFilterCfg holds the configurable settings to create a string tag filter
81+
// StringAttributeFilterCfg holds the configurable settings to create a string attribute filter
8282
// sampling policy evaluator.
83-
type StringTagFilterCfg struct {
83+
type StringAttributeFilterCfg struct {
8484
// Tag that the filter is going to be matching against.
85-
Tag string `mapstructure:"tag"`
86-
// Values is the set of tag values that if any is equal to the actual tag valueto be considered a match.
85+
Key string `mapstructure:"key"`
86+
// Values is the set of attribute values that if any is equal to the actual attribute value to be considered a match.
8787
Values []string `mapstructure:"values"`
8888
}
8989

90-
// RateLimitingCfg holds the configurable settings to create a string tag filter
90+
// RateLimitingCfg holds the configurable settings to create a string attribute filter
9191
// sampling policy evaluator.
9292
type RateLimitingCfg struct {
9393
// SpansPerSecond limit to the number of spans per second
@@ -135,12 +135,12 @@ func (sCfg *SamplingCfg) InitFromViper(v *viper.Viper) *SamplingCfg {
135135
// As the number of polices grow this likely should be in a map.
136136
var cfg interface{}
137137
switch polCfg.Type {
138-
case NumericTagFilter:
139-
numTagFilterCfg := &NumericTagFilterCfg{}
140-
cfg = numTagFilterCfg
141-
case StringTagFilter:
142-
strTagFilterCfg := &StringTagFilterCfg{}
143-
cfg = strTagFilterCfg
138+
case NumericAttributeFilter:
139+
numAttributeFilterCfg := &NumericAttributeFilterCfg{}
140+
cfg = numAttributeFilterCfg
141+
case StringAttributeFilter:
142+
strAttributeFilterCfg := &StringAttributeFilterCfg{}
143+
cfg = strAttributeFilterCfg
144144
case RateLimiting:
145145
rateLimitingCfg := &RateLimitingCfg{}
146146
cfg = rateLimitingCfg

cmd/occollector/app/builder/testdata/sampling_config.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,38 @@ sampling:
2929
decision-wait: 31s
3030
num-traces: 20001
3131
policies:
32-
string-tag-filter1:
32+
string-attribute-filter1:
3333
exporters:
3434
- jaeger1
35-
policy: string-tag-filter
35+
policy: string-attribute-filter
3636
configuration:
37-
tag: "test"
37+
key: "test"
3838
values:
3939
- "value 1"
4040
- "value 2"
41-
numeric-tag-filter2:
41+
numeric-attribute-filter2:
4242
exporters:
4343
- jaeger2
44-
policy: numeric-tag-filter
44+
policy: numeric-attribute-filter
4545
configuration:
46-
tag: "http.status_code"
46+
key: "http.status_code"
4747
min-value: 400
4848
max-value: 999
49-
string-tag-filter3:
49+
string-attribute-filter3:
5050
exporters:
5151
- jaeger3
52-
policy: string-tag-filter
52+
policy: string-attribute-filter
5353
configuration:
54-
tag: "test.different"
54+
key: "test.different"
5555
values:
5656
- "key 1"
5757
- "key 2"
58-
numeric-tag-filter4:
58+
numeric-attribute-filter4:
5959
exporters:
6060
- jaeger4
6161
- jaeger5
62-
policy: numeric-tag-filter
62+
policy: numeric-attribute-filter
6363
configuration:
64-
tag: "http.status_code"
64+
key: "http.status_code"
6565
min-value: 400
6666
max-value: 999

cmd/occollector/app/collector/processors.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ func buildSamplingProcessor(cfg *builder.SamplingCfg, nameToTraceConsumer map[st
176176
switch polCfg.Type {
177177
case builder.AlwaysSample:
178178
policy.Evaluator = sampling.NewAlwaysSample()
179-
case builder.NumericTagFilter:
180-
numTagFilterCfg := polCfg.Configuration.(*builder.NumericTagFilterCfg)
181-
policy.Evaluator = sampling.NewNumericTagFilter(numTagFilterCfg.Tag, numTagFilterCfg.MinValue, numTagFilterCfg.MaxValue)
182-
case builder.StringTagFilter:
183-
strTagFilterCfg := polCfg.Configuration.(*builder.StringTagFilterCfg)
184-
policy.Evaluator = sampling.NewStringTagFilter(strTagFilterCfg.Tag, strTagFilterCfg.Values)
179+
case builder.NumericAttributeFilter:
180+
numAttributeFilterCfg := polCfg.Configuration.(*builder.NumericAttributeFilterCfg)
181+
policy.Evaluator = sampling.NewNumericAttributeFilter(numAttributeFilterCfg.Key, numAttributeFilterCfg.MinValue, numAttributeFilterCfg.MaxValue)
182+
case builder.StringAttributeFilter:
183+
strAttributeFilterCfg := polCfg.Configuration.(*builder.StringAttributeFilterCfg)
184+
policy.Evaluator = sampling.NewStringAttributeFilter(strAttributeFilterCfg.Key, strAttributeFilterCfg.Values)
185185
case builder.RateLimiting:
186186
rateLimitingCfg := polCfg.Configuration.(*builder.RateLimitingCfg)
187187
policy.Evaluator = sampling.NewRateLimiting(rateLimitingCfg.SpansPerSecond)

exporter/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ sampling:
2323
policy: rate-limiting
2424
configuration:
2525
spans-per-second: 1000
26-
my-string-tag-filter:
26+
my-string-attribute-filter:
2727
exporters:
2828
- jaeger
2929
- omnition
30-
policy: string-tag-filter
30+
policy: string-attribute-filter
3131
configuration:
32-
tag: tag1
32+
key: key1
3333
values:
3434
- value1
3535
- value2
36-
my-numeric-tag-filter:
36+
my-numeric-attribute-filter:
3737
exporters:
3838
- jaeger
3939
- omnition
40-
policy: numeric-tag-filter
40+
policy: numeric-attribute-filter
4141
configuration:
42-
tag: tag1
42+
key: key1
4343
min-value: 0
4444
max-value: 100
4545
my-always-sample:

internal/collector/sampling/numeric_tag_filter.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ package sampling
1616

1717
import tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
1818

19-
type numericTagFilter struct {
20-
tag string
19+
type numericAttributeFilter struct {
20+
key string
2121
minValue, maxValue int64
2222
}
2323

24-
var _ PolicyEvaluator = (*numericTagFilter)(nil)
24+
var _ PolicyEvaluator = (*numericAttributeFilter)(nil)
2525

26-
// NewNumericTagFilter creates a policy evaluator that samples all traces with
27-
// the given tag in the given numeric range.
28-
func NewNumericTagFilter(tag string, minValue, maxValue int64) PolicyEvaluator {
29-
return &numericTagFilter{
30-
tag: tag,
26+
// NewNumericAttributeFilter creates a policy evaluator that samples all traces with
27+
// the given attribute in the given numeric range.
28+
func NewNumericAttributeFilter(key string, minValue, maxValue int64) PolicyEvaluator {
29+
return &numericAttributeFilter{
30+
key: key,
3131
minValue: minValue,
3232
maxValue: maxValue,
3333
}
@@ -37,12 +37,12 @@ func NewNumericTagFilter(tag string, minValue, maxValue int64) PolicyEvaluator {
3737
// after the sampling decision was already taken for the trace.
3838
// This gives the evaluator a chance to log any message/metrics and/or update any
3939
// related internal state.
40-
func (ntf *numericTagFilter) OnLateArrivingSpans(earlyDecision Decision, spans []*tracepb.Span) error {
40+
func (naf *numericAttributeFilter) OnLateArrivingSpans(earlyDecision Decision, spans []*tracepb.Span) error {
4141
return nil
4242
}
4343

4444
// Evaluate looks at the trace data and returns a corresponding SamplingDecision.
45-
func (ntf *numericTagFilter) Evaluate(traceID []byte, trace *TraceData) (Decision, error) {
45+
func (naf *numericAttributeFilter) Evaluate(traceID []byte, trace *TraceData) (Decision, error) {
4646
trace.Lock()
4747
batches := trace.ReceivedBatches
4848
trace.Unlock()
@@ -51,9 +51,9 @@ func (ntf *numericTagFilter) Evaluate(traceID []byte, trace *TraceData) (Decisio
5151
if span == nil || span.Attributes == nil {
5252
continue
5353
}
54-
if v, ok := span.Attributes.AttributeMap[ntf.tag]; ok {
54+
if v, ok := span.Attributes.AttributeMap[naf.key]; ok {
5555
value := v.GetIntValue()
56-
if value >= ntf.minValue && value <= ntf.maxValue {
56+
if value >= naf.minValue && value <= naf.maxValue {
5757
return Sampled, nil
5858
}
5959
}
@@ -65,6 +65,6 @@ func (ntf *numericTagFilter) Evaluate(traceID []byte, trace *TraceData) (Decisio
6565

6666
// OnDroppedSpans is called when the trace needs to be dropped, due to memory
6767
// pressure, before the decision_wait time has been reached.
68-
func (ntf *numericTagFilter) OnDroppedSpans(traceID []byte, trace *TraceData) (Decision, error) {
68+
func (naf *numericAttributeFilter) OnDroppedSpans(traceID []byte, trace *TraceData) (Decision, error) {
6969
return NotSampled, nil
7070
}

0 commit comments

Comments
 (0)