diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ed4c62aac3..9333e54ed33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ Changes by Version ================== -1.11.0 (unreleased) +1.10.1 (2019-02-21) ------------------ #### Backend Changes +- Discover dependencies table version automatically ([#1364]https://github.com/jaegertracing/jaeger/pull/1364) + ##### Breaking Changes ##### New Features diff --git a/plugin/storage/cassandra/dependencystore/bootstrap.go b/plugin/storage/cassandra/dependencystore/bootstrap.go new file mode 100644 index 00000000000..01f019e60a4 --- /dev/null +++ b/plugin/storage/cassandra/dependencystore/bootstrap.go @@ -0,0 +1,28 @@ +// Copyright (c) 2019 Uber Technologies, Inc. +// +// 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 dependencystore + +import ( + "github.com/jaegertracing/jaeger/pkg/cassandra" +) + +// GetDependencyVersion attempts to determine the version of the dependencies table. +// TODO: Remove this once we've migrated to V2 permanently. https://github.com/jaegertracing/jaeger/issues/1344 +func GetDependencyVersion(s cassandra.Session) Version { + if err := s.Query("SELECT ts from dependencies_v2 limit 1;").Exec(); err != nil { + return V1 + } + return V2 +} diff --git a/plugin/storage/cassandra/dependencystore/bootstrap_test.go b/plugin/storage/cassandra/dependencystore/bootstrap_test.go new file mode 100644 index 00000000000..8017e95bdc1 --- /dev/null +++ b/plugin/storage/cassandra/dependencystore/bootstrap_test.go @@ -0,0 +1,46 @@ +// Copyright (c) 2019 Uber Technologies, Inc. +// +// 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 dependencystore + +import ( + "testing" + + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + + "github.com/jaegertracing/jaeger/pkg/cassandra/mocks" +) + +func TestGetDependencyVersionV1(t *testing.T) { + var ( + session = &mocks.Session{} + query = &mocks.Query{} + ) + session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query) + query.On("Exec").Return(errors.New("error")) + + assert.Equal(t, V1, GetDependencyVersion(session)) +} + +func TestGetDependencyVersionV2(t *testing.T) { + var ( + session = &mocks.Session{} + query = &mocks.Query{} + ) + session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query) + query.On("Exec").Return(nil) + assert.Equal(t, V2, GetDependencyVersion(session)) +} diff --git a/plugin/storage/cassandra/factory.go b/plugin/storage/cassandra/factory.go index 372b06a558c..468888fcf8b 100644 --- a/plugin/storage/cassandra/factory.go +++ b/plugin/storage/cassandra/factory.go @@ -106,10 +106,7 @@ func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) { // CreateDependencyReader implements storage.Factory func (f *Factory) CreateDependencyReader() (dependencystore.Reader, error) { - version := cDepStore.V1 - if f.Options.GetPrimary().EnableDependenciesV2 { - version = cDepStore.V2 - } + version := cDepStore.GetDependencyVersion(f.primarySession) return cDepStore.NewDependencyStore(f.primarySession, f.primaryMetricsFactory, f.logger, version) } diff --git a/plugin/storage/cassandra/factory_test.go b/plugin/storage/cassandra/factory_test.go index d0c7bcc60b7..465ea6fc5ac 100644 --- a/plugin/storage/cassandra/factory_test.go +++ b/plugin/storage/cassandra/factory_test.go @@ -19,6 +19,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -33,14 +34,19 @@ var _ storage.Factory = new(Factory) var _ storage.ArchiveFactory = new(Factory) type mockSessionBuilder struct { - err error + session *mocks.Session + err error } -func (m *mockSessionBuilder) NewSession() (cassandra.Session, error) { - if m.err == nil { - return &mocks.Session{}, nil +func newMockSessionBuilder(session *mocks.Session, err error) *mockSessionBuilder { + return &mockSessionBuilder{ + session: session, + err: err, } - return nil, m.err +} + +func (m *mockSessionBuilder) NewSession() (cassandra.Session, error) { + return m.session, m.err } func TestCassandraFactory(t *testing.T) { @@ -52,11 +58,17 @@ func TestCassandraFactory(t *testing.T) { // after InitFromViper, f.primaryConfig points to a real session builder that will fail in unit tests, // so we override it with a mock. - f.primaryConfig = &mockSessionBuilder{err: errors.New("made-up error")} + f.primaryConfig = newMockSessionBuilder(nil, errors.New("made-up error")) assert.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error") - f.primaryConfig = &mockSessionBuilder{} - f.archiveConfig = &mockSessionBuilder{err: errors.New("made-up error")} + var ( + session = &mocks.Session{} + query = &mocks.Query{} + ) + session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query) + query.On("Exec").Return(nil) + f.primaryConfig = newMockSessionBuilder(session, nil) + f.archiveConfig = newMockSessionBuilder(nil, errors.New("made-up error")) assert.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error") f.archiveConfig = nil diff --git a/plugin/storage/cassandra/options.go b/plugin/storage/cassandra/options.go index 66a850d8a70..d4db5b58253 100644 --- a/plugin/storage/cassandra/options.go +++ b/plugin/storage/cassandra/options.go @@ -201,7 +201,7 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) { flagSet.Bool( nsConfig.namespace+suffixEnableDependenciesV2, nsConfig.EnableDependenciesV2, - "Disable (or enable) the dependencies v2 table. Only set this to true if you've migrated the dependencies table to v2") + "DEPRECATED: Jaeger will automatically detect the version of the dependencies table") } // InitFromViper initializes Options with properties from viper