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

Support collector tags, similar to agent tags #1854

Merged
merged 31 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
46c32f3
Update CONTRIBUTING.md #1834 (#1843)
rneha725 Oct 9, 2019
2f31ecd
Collector tags. https://github.com/jaegertracing/jaeger/issues/1844
radekg Oct 9, 2019
5979d7e
Collector tags - tests
radekg Oct 11, 2019
4532ea3
Fix flaky ES span reader test due to date differences (#1847)
pavolloffay Oct 9, 2019
e37ebbe
Fix ordering of indexScanKeys after TraceID parsing, closes #1808 (#1…
burmanm Oct 9, 2019
2d69ce6
Propagate TraceNotFound error from grpc storage plugins #1741 (#1814)
chandresh-pancholi Oct 9, 2019
6664502
Automated fuzzing (#1787)
bookmoons Oct 10, 2019
ecb6b26
Use correct context on ES search methods (#1850)
rubenvp8510 Oct 10, 2019
a7f39d4
Add Fuzzit badge (#1852)
bookmoons Oct 10, 2019
4f17830
Separate community from CI badges (#1853)
yurishkuro Oct 10, 2019
e5d26fb
Use collector namespaced jaeger tags flag - take all-in-one into cons…
radekg Oct 14, 2019
8b3caf6
Enable logs from all-in-one integration test (#1857)
yurishkuro Oct 13, 2019
4d5dab4
Name the flag collector.tags, add agent --agent.tags, deprecate agent…
radekg Oct 14, 2019
aa39098
Fix all-in-one for jaeger.tags deprectaion expecting a logger
radekg Oct 14, 2019
2df44f9
Add an all-in-one setup context. Allows testing if running in all-in-…
radekg Oct 24, 2019
5c0a295
Add documentation how the current badger storage is modeled (#1859)
burmanm Oct 14, 2019
0893b2e
Update gopkg.in/yaml.v2 dependency to v2.2.4 (#1865)
objectiser Oct 15, 2019
1bcd99c
Add Truncate and ReadOnly options to Badger storage backend, closes #…
burmanm Oct 16, 2019
f182e99
Change the default value of the flag '--ingester.deadlockInterval' to…
jpkrohling Oct 19, 2019
02e431f
Use node 10 when building docker images (#1871)
pavolloffay Oct 22, 2019
4ba0823
Use Elasticsearch 6 in xdock (#1872)
pavolloffay Oct 23, 2019
a97f7b7
all-in-one setup context remove testing, add collector tags to span p…
radekg Oct 28, 2019
944bebe
format
radekg Oct 28, 2019
263df5d
Add rudimentary test for code coverage
radekg Oct 28, 2019
54c3a45
make fmt neeeds to be run after git add
radekg Oct 28, 2019
94c389e
fix failing test
radekg Oct 28, 2019
0fc7625
Merge branch 'master' into collector-tags
radekg Oct 28, 2019
45e3828
Merged with upstream/master
radekg Nov 17, 2019
2bf33de
Merge branch 'master' into collector-tags
radekg Nov 29, 2019
2cda551
Merge branch 'master' into collector-tags
jpkrohling Dec 2, 2019
5f07676
Merge branch 'master' into collector-tags
jpkrohling Dec 5, 2019
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
2 changes: 1 addition & 1 deletion cmd/agent/app/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestCreateCollectorProxy(t *testing.T) {
err := command.ParseFlags(test.flags)
require.NoError(t, err)

rOpts := new(reporter.Options).InitFromViper(v)
rOpts := new(reporter.Options).InitFromViper(v, zap.NewNop())
tchan := tchannel.NewBuilder().InitFromViper(v, zap.NewNop())
grpcBuilder := grpc.NewConnBuilder().InitFromViper(v)

Expand Down
63 changes: 19 additions & 44 deletions cmd/agent/app/reporter/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ package reporter
import (
"flag"
"fmt"
"os"
"strings"

"github.com/spf13/viper"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/all-in-one/setupcontext"
"github.com/jaegertracing/jaeger/cmd/flags"
)

const (
// Whether to use grpc or tchannel reporter.
reporterType = "reporter.type"
// Agent tags
agentTags = "jaeger.tags"
agentTagsDeprecated = "jaeger.tags"
agentTags = "agent.tags"
// TCHANNEL is name of tchannel reporter.
TCHANNEL Type = "tchannel"
// GRPC is name of gRPC reporter.
Expand All @@ -46,51 +49,23 @@ type Options struct {
// AddFlags adds flags for Options.
func AddFlags(flags *flag.FlagSet) {
flags.String(reporterType, string(GRPC), fmt.Sprintf("Reporter type to use e.g. %s, %s", string(GRPC), string(TCHANNEL)))
flags.String(agentTags, "", "One or more tags to be added to the Process tags of all spans passing through this agent. Ex: key1=value1,key2=${envVar:defaultValue}")
if !setupcontext.IsAllInOne() {
flags.String(agentTagsDeprecated, "", "(deprecated) see --"+agentTags)
flags.String(agentTags, "", "One or more tags to be added to the Process tags of all spans passing through this agent. Ex: key1=value1,key2=${envVar:defaultValue}")
}
}

// InitFromViper initializes Options with properties retrieved from Viper.
func (b *Options) InitFromViper(v *viper.Viper) *Options {
func (b *Options) InitFromViper(v *viper.Viper, logger *zap.Logger) *Options {
b.ReporterType = Type(v.GetString(reporterType))
b.AgentTags = parseAgentTags(v.GetString(agentTags))
return b
}

// Parsing logic borrowed from jaegertracing/jaeger-client-go
func parseAgentTags(agentTags string) map[string]string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this package currently has 100% coverage

$ go test -cover ./cmd/agent/app/reporter/
ok  	github.com/jaegertracing/jaeger/cmd/agent/app/reporter	0.069s	coverage: 100.0% of statements

which means there is a test covering this function, which should also move to the new location.

Copy link
Contributor Author

@radekg radekg Oct 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if moving this test out of there is a good idea? It does what it should be doing, parses agent options with tags. I've added additional tests to cmd/flags. I could remove TestBindFlags test from cmd/agent/app/reporter/flags_test.go but I think that would leave the actual option handling without coverage?

Moving the complete test from cmd/agent/app/reporter/flags_test.go to cmd/flags/flags_test.go does not seem to be an option as it results in circular import.

if agentTags == "" {
return nil
}
tagPairs := strings.Split(string(agentTags), ",")
tags := make(map[string]string)
for _, p := range tagPairs {
kv := strings.SplitN(p, "=", 2)
k, v := strings.TrimSpace(kv[0]), strings.TrimSpace(kv[1])

if strings.HasPrefix(v, "${") && strings.HasSuffix(v, "}") {
skipWhenEmpty := false

ed := strings.SplitN(string(v[2:len(v)-1]), ":", 2)
if len(ed) == 1 {
// no default value specified, set to empty
skipWhenEmpty = true
ed = append(ed, "")
}

e, d := ed[0], ed[1]
v = os.Getenv(e)
if v == "" && d != "" {
v = d
}

// no value is set, skip this entry
if v == "" && skipWhenEmpty {
continue
}
if !setupcontext.IsAllInOne() {
if len(v.GetString(agentTagsDeprecated)) > 0 {
logger.Warn("Using deprecated configuration", zap.String("option", agentTagsDeprecated))
b.AgentTags = flags.ParseJaegerTags(v.GetString(agentTagsDeprecated))
}
if len(v.GetString(agentTags)) > 0 {
b.AgentTags = flags.ParseJaegerTags(v.GetString(agentTags))
}

tags[k] = v
}

return tags
return b
}
39 changes: 35 additions & 4 deletions cmd/agent/app/reporter/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/all-in-one/setupcontext"
)

func TestBindFlags_NoJaegerTags(t *testing.T) {
Expand All @@ -40,7 +43,7 @@ func TestBindFlags_NoJaegerTags(t *testing.T) {
require.NoError(t, err)

b := &Options{}
b.InitFromViper(v)
b.InitFromViper(v, zap.NewNop())
assert.Equal(t, Type("grpc"), b.ReporterType)
assert.Len(t, b.AgentTags, 0)
}
Expand All @@ -53,7 +56,7 @@ func TestBindFlags(t *testing.T) {
command.PersistentFlags().AddGoFlagSet(flags)
v.BindPFlags(command.PersistentFlags())

jaegerTags := fmt.Sprintf("%s,%s,%s,%s,%s,%s",
agentTags := fmt.Sprintf("%s,%s,%s,%s,%s,%s",
"key=value",
"envVar1=${envKey1:defaultVal1}",
"envVar2=${envKey2:defaultVal2}",
Expand All @@ -64,7 +67,7 @@ func TestBindFlags(t *testing.T) {

err := command.ParseFlags([]string{
"--reporter.type=grpc",
"--jaeger.tags=" + jaegerTags,
"--agent.tags=" + agentTags,
})
require.NoError(t, err)

Expand All @@ -75,7 +78,7 @@ func TestBindFlags(t *testing.T) {
os.Setenv("envKey4", "envVal4")
defer os.Unsetenv("envKey4")

b.InitFromViper(v)
b.InitFromViper(v, zap.NewNop())

expectedTags := map[string]string{
"key": "value",
Expand All @@ -88,3 +91,31 @@ func TestBindFlags(t *testing.T) {
assert.Equal(t, Type("grpc"), b.ReporterType)
assert.Equal(t, expectedTags, b.AgentTags)
}

func TestBindFlagsAllInOne(t *testing.T) {

setupcontext.SetAllInOne()
defer setupcontext.UnsetAllInOne()

v := viper.New()
command := cobra.Command{}
flags := &flag.FlagSet{}
AddFlags(flags)
command.PersistentFlags().AddGoFlagSet(flags)
v.BindPFlags(command.PersistentFlags())

agentTags := fmt.Sprintf("%s,%s,%s,%s,%s,%s",
"key=value",
"envVar1=${envKey1:defaultVal1}",
"envVar2=${envKey2:defaultVal2}",
"envVar3=${envKey3}",
"envVar4=${envKey4}",
"envVar5=${envVar5:}",
)

err := command.ParseFlags([]string{
"--reporter.type=grpc",
"--agent.tags=" + agentTags,
})
require.Error(t, err)
}
2 changes: 1 addition & 1 deletion cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
Namespace(metrics.NSOptions{Name: "jaeger"}).
Namespace(metrics.NSOptions{Name: "agent"})

rOpts := new(reporter.Options).InitFromViper(v)
rOpts := new(reporter.Options).InitFromViper(v, logger)
tchanBuilder := tchannel.NewBuilder().InitFromViper(v, logger)
grpcBuilder := grpc.NewConnBuilder().InitFromViper(v)
cp, err := app.CreateCollectorProxy(rOpts, tchanBuilder, grpcBuilder, logger, mFactory)
Expand Down
6 changes: 5 additions & 1 deletion cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
agentRep "github.com/jaegertracing/jaeger/cmd/agent/app/reporter"
agentGrpcRep "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/grpc"
agentTchanRep "github.com/jaegertracing/jaeger/cmd/agent/app/reporter/tchannel"
"github.com/jaegertracing/jaeger/cmd/all-in-one/setupcontext"
basic "github.com/jaegertracing/jaeger/cmd/builder"
collectorApp "github.com/jaegertracing/jaeger/cmd/collector/app"
collector "github.com/jaegertracing/jaeger/cmd/collector/app/builder"
Expand Down Expand Up @@ -71,6 +72,9 @@ import (

// all-in-one/main is a standalone full-stack jaeger backend, backed by a memory store
func main() {

setupcontext.SetAllInOne()

svc := flags.NewService(ports.CollectorAdminHTTP)

if os.Getenv(storage.SpanStorageTypeEnvVar) == "" {
Expand Down Expand Up @@ -121,7 +125,7 @@ by default uses only in-memory database.`,
strategyStore := initSamplingStrategyStore(strategyStoreFactory, metricsFactory, logger)

aOpts := new(agentApp.Builder).InitFromViper(v)
repOpts := new(agentRep.Options).InitFromViper(v)
repOpts := new(agentRep.Options).InitFromViper(v, logger)
tchanBuilder := agentTchanRep.NewBuilder().InitFromViper(v, logger)
grpcBuilder := agentGrpcRep.NewConnBuilder().InitFromViper(v)
cOpts := new(collector.CollectorOptions).InitFromViper(v)
Expand Down
32 changes: 32 additions & 0 deletions cmd/all-in-one/setupcontext/setupcontext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2019 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package setupcontext

var isAllInOne bool

// SetAllInOne sets the internal flag to all in one on.
func SetAllInOne() {
isAllInOne = true
}

// UnsetAllInOne unsets the internal all-in-one flag.
func UnsetAllInOne() {
isAllInOne = false
}

// IsAllInOne returns true when all in one mode is on.
func IsAllInOne() bool {
return isAllInOne
}
28 changes: 28 additions & 0 deletions cmd/all-in-one/setupcontext/setupcontext_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2019 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package setupcontext

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestSetupContext(t *testing.T) {
// purely for code coverage
SetAllInOne()
defer UnsetAllInOne()
assert.True(t, IsAllInOne())
}
6 changes: 6 additions & 0 deletions cmd/collector/app/builder/builder_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/spf13/viper"

"github.com/jaegertracing/jaeger/cmd/collector/app"
"github.com/jaegertracing/jaeger/cmd/flags"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/ports"
)
Expand All @@ -31,6 +32,7 @@ const (
collectorPort = "collector.port"
collectorHTTPPort = "collector.http-port"
collectorGRPCPort = "collector.grpc-port"
collectorTags = "collector.tags"
collectorZipkinHTTPort = "collector.zipkin.http-port"
collectorZipkinAllowedOrigins = "collector.zipkin.allowed-origins"
collectorZipkinAllowedHeaders = "collector.zipkin.allowed-headers"
Expand All @@ -56,6 +58,8 @@ type CollectorOptions struct {
CollectorGRPCPort int
// TLS configures secure transport
TLS tlscfg.Options
// CollectorTags is the string representing collector tags to append to each and every span
CollectorTags map[string]string
// CollectorZipkinHTTPPort is the port that the Zipkin collector service listens in on for http requests
CollectorZipkinHTTPPort int
// CollectorZipkinAllowedOrigins is a list of origins a cross-domain request to the Zipkin collector service can be executed from
Expand All @@ -71,6 +75,7 @@ func AddFlags(flags *flag.FlagSet) {
flags.Int(collectorPort, ports.CollectorTChannel, "The TChannel port for the collector service")
flags.Int(collectorHTTPPort, ports.CollectorHTTP, "The HTTP port for the collector service")
flags.Int(collectorGRPCPort, ports.CollectorGRPC, "The gRPC port for the collector service")
flags.String(collectorTags, "", "One or more tags to be added to the Process tags of all spans passing through this collector. Ex: key1=value1,key2=${envVar:defaultValue}")
flags.Int(collectorZipkinHTTPort, 0, "The HTTP port for the Zipkin collector service e.g. 9411")
flags.String(collectorZipkinAllowedOrigins, "*", "Comma separated list of allowed origins for the Zipkin collector service, default accepts all")
flags.String(collectorZipkinAllowedHeaders, "content-type", "Comma separated list of allowed headers for the Zipkin collector service, default content-type")
Expand All @@ -84,6 +89,7 @@ func (cOpts *CollectorOptions) InitFromViper(v *viper.Viper) *CollectorOptions {
cOpts.CollectorPort = v.GetInt(collectorPort)
cOpts.CollectorHTTPPort = v.GetInt(collectorHTTPPort)
cOpts.CollectorGRPCPort = v.GetInt(collectorGRPCPort)
cOpts.CollectorTags = flags.ParseJaegerTags(v.GetString(collectorTags))
cOpts.CollectorZipkinHTTPPort = v.GetInt(collectorZipkinHTTPort)
cOpts.CollectorZipkinAllowedOrigins = v.GetString(collectorZipkinAllowedOrigins)
cOpts.CollectorZipkinAllowedHeaders = v.GetString(collectorZipkinAllowedHeaders)
Expand Down
1 change: 1 addition & 0 deletions cmd/collector/app/builder/span_handler_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (spanHb *SpanHandlerBuilder) BuildHandlers() (
app.Options.SpanFilter(defaultSpanFilter),
app.Options.NumWorkers(spanHb.collectorOpts.NumWorkers),
app.Options.QueueSize(spanHb.collectorOpts.QueueSize),
app.Options.CollectorTags(spanHb.collectorOpts.CollectorTags),
)

return app.NewZipkinSpanHandler(spanHb.logger, spanProcessor, zs.NewChainedSanitizer(zs.StandardSanitizers...)),
Expand Down
8 changes: 8 additions & 0 deletions cmd/collector/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type options struct {
queueSize int
reportBusy bool
extraFormatTypes []SpanFormat
collectorTags map[string]string
}

// Option is a function that sets some option on StorageBuilder.
Expand Down Expand Up @@ -135,6 +136,13 @@ func (options) ExtraFormatTypes(extraFormatTypes []SpanFormat) Option {
}
}

// CollectorTags creates an Option that initializes the extra tags to append to the spans flowing through this collector
func (options) CollectorTags(extraTags map[string]string) Option {
return func(b *options) {
b.collectorTags = extraTags
}
}

func (o options) apply(opts ...Option) options {
ret := options{}
for _, opt := range opts {
Expand Down
3 changes: 3 additions & 0 deletions cmd/collector/app/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ func TestAllOptionSet(t *testing.T) {
Options.Sanitizer(func(span *model.Span) *model.Span { return span }),
Options.QueueSize(10),
Options.PreSave(func(span *model.Span) {}),
Options.CollectorTags(map[string]string{"extra": "tags"}),
)
assert.EqualValues(t, 5, opts.numWorkers)
assert.EqualValues(t, 10, opts.queueSize)
assert.EqualValues(t, map[string]string{"extra": "tags"}, opts.collectorTags)
}

func TestNoOptionsSet(t *testing.T) {
opts := Options.apply()
assert.EqualValues(t, DefaultNumWorkers, opts.numWorkers)
assert.EqualValues(t, 0, opts.queueSize)
assert.Nil(t, opts.collectorTags)
assert.False(t, opts.reportBusy)
assert.False(t, opts.blockingSubmit)
assert.NotPanics(t, func() { opts.preProcessSpans(nil) })
Expand Down
Loading