Skip to content

Commit 7691538

Browse files
committed
all the things
Signed-off-by: Won Jun Jang <wjang@uber.com>
1 parent 831a93a commit 7691538

File tree

10 files changed

+105
-50
lines changed

10 files changed

+105
-50
lines changed

cmd/collector/app/builder/span_handler_builder.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
cascfg "github.com/uber/jaeger/pkg/cassandra/config"
3030
escfg "github.com/uber/jaeger/pkg/es/config"
3131
casSpanstore "github.com/uber/jaeger/plugin/storage/cassandra/spanstore"
32-
casSpanstoreModel "github.com/uber/jaeger/plugin/storage/cassandra/spanstore/dbmodel"
3332
esSpanstore "github.com/uber/jaeger/plugin/storage/es/spanstore"
3433
"github.com/uber/jaeger/storage/spanstore"
3534
)
@@ -96,7 +95,6 @@ func (spanHb *SpanHandlerBuilder) initCassStore(builder cascfg.SessionBuilder) (
9695
spanHb.collectorOpts.WriteCacheTTL,
9796
spanHb.metricsFactory,
9897
spanHb.logger,
99-
casSpanstoreModel.DefaultTagFilter(),
10098
), nil
10199
}
102100

plugin/storage/cassandra/spanstore/dbmodel/log_tags_filter.go renamed to plugin/storage/cassandra/spanstore/dbmodel/log_fields_filter.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ package dbmodel
1616

1717
import "github.com/uber/jaeger/model"
1818

19-
// FilterLogTags returns a filter that filters span.Logs.
20-
func FilterLogTags() FilterTags {
21-
return filterLogTags
19+
// LogFieldsFilter filters all span.Logs.Fields.
20+
type LogFieldsFilter struct {
21+
tagFilterImpl
2222
}
2323

24-
func filterLogTags(span *model.Span) model.KeyValues {
25-
return append(span.Tags, span.Process.Tags...)
24+
// NewLogFieldsFilter return a filter that filters all span.Logs.Fields.
25+
func NewLogFieldsFilter() *LogFieldsFilter {
26+
return &LogFieldsFilter{}
27+
}
28+
29+
// FilterLogFields implements TagFilter#FilterLogFields
30+
func (f *LogFieldsFilter) FilterLogFields(logFields model.KeyValues) model.KeyValues {
31+
return model.KeyValues{}
2632
}

plugin/storage/cassandra/spanstore/dbmodel/log_tags_filter_test.go renamed to plugin/storage/cassandra/spanstore/dbmodel/log_fields_filter_test.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,23 @@ package dbmodel
1717
import (
1818
"testing"
1919

20-
"github.com/uber/jaeger/model"
21-
2220
"github.com/kr/pretty"
2321
"github.com/stretchr/testify/assert"
2422
)
2523

24+
var filter TagFilter = &LogFieldsFilter{} // Check API compliance
25+
2626
func TestFilterLogTags(t *testing.T) {
27-
expectedTags := model.KeyValues{
28-
model.String(someStringTagKey, someStringTagValue),
29-
model.Bool(someBoolTagKey, someBoolTagValue),
30-
model.Int64(someLongTagKey, someLongTagValue),
31-
}
32-
testSpan := getTestJaegerSpan()
33-
testSpan.Tags = expectedTags
34-
testSpan.Process.Tags = model.KeyValues{}
35-
testSpan.Logs = []model.Log{
36-
{
37-
Timestamp: someLogTimestamp,
38-
Fields: model.KeyValues{
39-
model.Float64(someDoubleTagKey, someDoubleTagValue),
40-
},
41-
},
27+
span := getTestJaegerSpan()
28+
filter := NewLogFieldsFilter()
29+
expectedTags := append(someTags, someTags...)
30+
filteredTags := filter.FilterProcessTags(span.Process.Tags)
31+
filteredTags = append(filteredTags, filter.FilterTags(span.Tags)...)
32+
for _, log := range span.Logs {
33+
filteredTags = append(filteredTags, filter.FilterLogFields(log.Fields)...)
4234
}
43-
uniqueTags := FilterLogTags()(testSpan)
44-
if !assert.EqualValues(t, expectedTags, uniqueTags) {
45-
for _, diff := range pretty.Diff(expectedTags, uniqueTags) {
35+
if !assert.EqualValues(t, expectedTags, filteredTags) {
36+
for _, diff := range pretty.Diff(expectedTags, filteredTags) {
4637
t.Log(diff)
4738
}
4839
}

plugin/storage/cassandra/spanstore/dbmodel/tag_filter.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@ import (
1818
"github.com/uber/jaeger/model"
1919
)
2020

21-
// FilterTags filters out any tags that should not be persisted.
22-
type FilterTags func(span *model.Span) model.KeyValues
21+
// TODO (black-adder) add a chain filter
22+
23+
// TagFilter filters out any tags that should not be indexed.
24+
type TagFilter interface {
25+
FilterProcessTags(processTags model.KeyValues) model.KeyValues
26+
FilterTags(tags model.KeyValues) model.KeyValues
27+
FilterLogFields(logFields model.KeyValues) model.KeyValues
28+
}
2329

2430
// DefaultTagFilter returns a filter that retrieves all tags from span.Tags, span.Logs, and span.Process.
25-
func DefaultTagFilter() FilterTags {
26-
return filterNothing
31+
var DefaultTagFilter = tagFilterImpl{}
32+
33+
type tagFilterImpl struct{}
34+
35+
func (f tagFilterImpl) FilterProcessTags(processTags model.KeyValues) model.KeyValues {
36+
return processTags
37+
}
38+
39+
func (f tagFilterImpl) FilterTags(tags model.KeyValues) model.KeyValues {
40+
return tags
2741
}
2842

29-
func filterNothing(span *model.Span) model.KeyValues {
30-
process := span.Process
31-
allTags := span.Tags
32-
allTags = append(allTags, process.Tags...)
33-
for _, log := range span.Logs {
34-
allTags = append(allTags, log.Fields...)
35-
}
36-
return allTags
43+
func (f tagFilterImpl) FilterLogFields(logFields model.KeyValues) model.KeyValues {
44+
return logFields
3745
}

plugin/storage/cassandra/spanstore/dbmodel/tag_filter_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ import (
2222
)
2323

2424
func TestDefaultTagFilter(t *testing.T) {
25+
span := getTestJaegerSpan()
2526
expectedTags := append(append(someTags, someTags...), someTags...)
26-
filteredTags := DefaultTagFilter()(getTestJaegerSpan())
27+
filteredTags := DefaultTagFilter.FilterProcessTags(span.Process.Tags)
28+
filteredTags = append(filteredTags, DefaultTagFilter.FilterTags(span.Tags)...)
29+
for _, log := range span.Logs {
30+
filteredTags = append(filteredTags, DefaultTagFilter.FilterLogFields(log.Fields)...)
31+
}
2732
if !assert.EqualValues(t, expectedTags, filteredTags) {
2833
for _, diff := range pretty.Diff(expectedTags, filteredTags) {
2934
t.Log(diff)

plugin/storage/cassandra/spanstore/dbmodel/unique_tags.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ package dbmodel
1717
import "github.com/uber/jaeger/model"
1818

1919
// GetAllUniqueTags creates a list of all unique tags from a set of filtered tags.
20-
func GetAllUniqueTags(span *model.Span, tagFilter FilterTags) []TagInsertion {
21-
tags := tagFilter(span)
20+
func GetAllUniqueTags(span *model.Span, tagFilter TagFilter) []TagInsertion {
21+
tags := tagFilter.FilterProcessTags(span.Process.Tags)
22+
tags = append(tags, tagFilter.FilterTags(span.Tags)...)
23+
for _, log := range span.Logs {
24+
tags = append(tags, tagFilter.FilterLogFields(log.Fields)...)
25+
}
2226
tags.Sort()
2327
uniqueTags := make([]TagInsertion, 0, len(tags))
2428
for i := range tags {

plugin/storage/cassandra/spanstore/dbmodel/unique_tags_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
func TestGetUniqueTags(t *testing.T) {
2525
expectedTags := getTestUniqueTags()
26-
uniqueTags := GetAllUniqueTags(getTestJaegerSpan(), DefaultTagFilter())
26+
uniqueTags := GetAllUniqueTags(getTestJaegerSpan(), DefaultTagFilter)
2727
if !assert.EqualValues(t, expectedTags, uniqueTags) {
2828
for _, diff := range pretty.Diff(expectedTags, uniqueTags) {
2929
t.Log(diff)

plugin/storage/cassandra/spanstore/writer.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type SpanWriter struct {
8686
logger *zap.Logger
8787
tagIndexSkipped metrics.Counter
8888
bucketCounter uint32
89-
tagFilter dbmodel.FilterTags
89+
tagFilter dbmodel.TagFilter
9090
}
9191

9292
// NewSpanWriter returns a SpanWriter
@@ -95,14 +95,12 @@ func NewSpanWriter(
9595
writeCacheTTL time.Duration,
9696
metricsFactory metrics.Factory,
9797
logger *zap.Logger,
98-
tagFilter dbmodel.FilterTags,
98+
options ...Option,
9999
) *SpanWriter {
100100
serviceNamesStorage := NewServiceNamesStorage(session, writeCacheTTL, metricsFactory, logger)
101101
operationNamesStorage := NewOperationNamesStorage(session, writeCacheTTL, metricsFactory, logger)
102102
tagIndexSkipped := metricsFactory.Counter("tagIndexSkipped", nil)
103-
if tagFilter == nil {
104-
tagFilter = dbmodel.DefaultTagFilter()
105-
}
103+
opts := applyOptions(options...)
106104
return &SpanWriter{
107105
session: session,
108106
serviceNamesWriter: serviceNamesStorage.Write,
@@ -116,7 +114,7 @@ func NewSpanWriter(
116114
},
117115
logger: logger,
118116
tagIndexSkipped: tagIndexSkipped,
119-
tagFilter: tagFilter,
117+
tagFilter: opts.tagFilter,
120118
}
121119
}
122120

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2017 Uber Technologies, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package spanstore
16+
17+
import (
18+
"github.com/uber/jaeger/plugin/storage/cassandra/spanstore/dbmodel"
19+
)
20+
21+
// Option is a function that sets some option on the writer.
22+
type Option func(c *Options)
23+
24+
// Options control behavior of the writer.
25+
type Options struct {
26+
tagFilter dbmodel.TagFilter
27+
}
28+
29+
// TagFilter can be provided to filter any tags that should not be indexed.
30+
func TagFilter(tagFilter dbmodel.TagFilter) Option {
31+
return func(o *Options) {
32+
o.tagFilter = tagFilter
33+
}
34+
}
35+
36+
func applyOptions(opts ...Option) Options {
37+
o := Options{}
38+
for _, opt := range opts {
39+
opt(&o)
40+
}
41+
if o.tagFilter == nil {
42+
o.tagFilter = dbmodel.DefaultTagFilter
43+
}
44+
return o
45+
}

plugin/storage/cassandra/spanstore/writer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func withSpanWriter(writeCacheTTL time.Duration, fn func(w *spanWriterTest)) {
4646
session: session,
4747
logger: logger,
4848
logBuffer: logBuffer,
49-
writer: NewSpanWriter(session, writeCacheTTL, metricsFactory, logger, nil),
49+
writer: NewSpanWriter(session, writeCacheTTL, metricsFactory, logger),
5050
}
5151
fn(w)
5252
}

0 commit comments

Comments
 (0)