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

Fix es-archive namespace default values #2865

Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Changes by Version

1.23.0 (unreleased)
-------------------
### Backend Changes

#### Breaking Changes

* Remove unused `--es-archive.max-span-age` flag ([#2865](https://github.com/jaegertracing/jaeger/pull/2865), [@albertteoh](https://github.com/albertteoh)):

1.22.0 (2021-02-23)
-------------------
Expand Down
64 changes: 37 additions & 27 deletions plugin/storage/es/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,41 @@ type namespaceConfig struct {
// NewOptions creates a new Options struct.
func NewOptions(primaryNamespace string, otherNamespaces ...string) *Options {
// TODO all default values should be defined via cobra flags
defaultConfig := config.Configuration{
Username: "",
Password: "",
Sniffer: false,
MaxSpanAge: 72 * time.Hour,
NumShards: 5,
NumReplicas: 1,
BulkSize: 5 * 1000 * 1000,
BulkWorkers: 1,
BulkActions: 1000,
BulkFlushInterval: time.Millisecond * 200,
Tags: config.TagsAsFields{
DotReplacement: "@",
},
Enabled: true,
CreateIndexTemplates: true,
Version: 0,
Servers: []string{defaultServerURL},
MaxDocCount: defaultMaxDocCount,
}
options := &Options{
Primary: namespaceConfig{
Configuration: config.Configuration{
Username: "",
Password: "",
Sniffer: false,
MaxSpanAge: 72 * time.Hour,
NumShards: 5,
NumReplicas: 1,
BulkSize: 5 * 1000 * 1000,
BulkWorkers: 1,
BulkActions: 1000,
BulkFlushInterval: time.Millisecond * 200,
Tags: config.TagsAsFields{
DotReplacement: "@",
},
Enabled: true,
CreateIndexTemplates: true,
Version: 0,
Servers: []string{defaultServerURL},
MaxDocCount: defaultMaxDocCount,
},
namespace: primaryNamespace,
Configuration: defaultConfig,
namespace: primaryNamespace,
},
others: make(map[string]*namespaceConfig, len(otherNamespaces)),
}

// Other namespaces need to be explicitly enabled.
defaultConfig.Enabled = false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should fix both the failing ES integration tests and Crossdock builds.

The cause was due to archive mode being enabled by default and attempting to either ping a non-existent ES for a version (failing ES integration test) or attempting to communicate with ES on the wrong (default) IP address (failing Crossdock builds).

The original behaviour was to have archive mode disabled.

for _, namespace := range otherNamespaces {
options.others[namespace] = &namespaceConfig{namespace: namespace}
options.others[namespace] = &namespaceConfig{
Configuration: defaultConfig,
namespace: namespace,
}
}

return options
Expand Down Expand Up @@ -158,10 +164,6 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
nsConfig.namespace+suffixTimeout,
nsConfig.Timeout,
"Timeout used for queries. A Timeout of zero means no timeout")
flagSet.Duration(
nsConfig.namespace+suffixMaxSpanAge,
nsConfig.MaxSpanAge,
"The maximum lookback for spans in Elasticsearch")
flagSet.Int64(
nsConfig.namespace+suffixNumShards,
nsConfig.NumShards,
Expand Down Expand Up @@ -215,7 +217,7 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
nsConfig.UseReadWriteAliases,
"Use read and write aliases for indices. Use this option with Elasticsearch rollover "+
"API. It requires an external component to create aliases before startup and then performing its management. "+
"Note that "+nsConfig.namespace+suffixMaxSpanAge+" will influence trace search window start times.")
"Note that es"+suffixMaxSpanAge+" will influence trace search window start times.")
flagSet.Bool(
nsConfig.namespace+suffixUseILM,
nsConfig.UseILM,
Expand All @@ -238,11 +240,19 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
nsConfig.namespace+suffixMaxDocCount,
nsConfig.MaxDocCount,
"The maximum document count to return from an Elasticsearch query. This will also apply to aggregations.")

if nsConfig.namespace == archiveNamespace {
flagSet.Bool(
nsConfig.namespace+suffixEnabled,
nsConfig.Enabled,
"Enable extra storage")
} else {
// MaxSpanAge is only relevant when searching for unarchived traces.
// Archived traces are searched with no look-back limit.
flagSet.Duration(
nsConfig.namespace+suffixMaxSpanAge,
nsConfig.MaxSpanAge,
"The maximum lookback for spans in Elasticsearch")
}
nsConfig.getTLSFlagsConfig().AddFlags(flagSet)
}
Expand Down
16 changes: 13 additions & 3 deletions plugin/storage/es/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

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

"github.com/jaegertracing/jaeger/pkg/config"
)
Expand All @@ -45,7 +46,7 @@ func TestOptions(t *testing.T) {
func TestOptionsWithFlags(t *testing.T) {
opts := NewOptions("es", "es.aux")
v, command := config.Viperize(opts.AddFlags)
command.ParseFlags([]string{
err := command.ParseFlags([]string{
"--es.server-urls=1.1.1.1, 2.2.2.2",
"--es.username=hello",
"--es.password=world",
Expand All @@ -69,6 +70,7 @@ func TestOptionsWithFlags(t *testing.T) {
"--es.tags-as-fields.dot-replacement=!",
"--es.use-ilm=true",
})
require.NoError(t, err)
opts.InitFromViper(v)

primary := opts.GetPrimary()
Expand All @@ -89,18 +91,26 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, []string{"3.3.3.3", "4.4.4.4"}, aux.Servers)
assert.Equal(t, "hello", aux.Username)
assert.Equal(t, "world", aux.Password)
assert.Equal(t, int64(20), aux.NumShards)
assert.Equal(t, int64(5), aux.NumShards)
assert.Equal(t, int64(10), aux.NumReplicas)
assert.Equal(t, 24*time.Hour, aux.MaxSpanAge)
assert.True(t, aux.Sniffer)
assert.True(t, aux.Tags.AllAsFields)
assert.Equal(t, "!", aux.Tags.DotReplacement)
assert.Equal(t, "@", aux.Tags.DotReplacement)
assert.Equal(t, "./file.txt", aux.Tags.File)
assert.Equal(t, "test,tags", aux.Tags.Include)
assert.Equal(t, "2006.01.02", aux.IndexDateLayout)
assert.True(t, primary.UseILM)
}

func TestMaxSpanAgeSetErrorInArchiveMode(t *testing.T) {
opts := NewOptions("es", archiveNamespace)
_, command := config.Viperize(opts.AddFlags)
flags := []string{"--es-archive.max-span-age=24h"}
err := command.ParseFlags(flags)
assert.EqualError(t, err, "unknown flag: --es-archive.max-span-age")
}

func TestMaxDocCount(t *testing.T) {
testCases := []struct {
name string
Expand Down