Skip to content

Commit

Permalink
Discover dependencies table version automatically (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
black-adder authored Feb 21, 2019
1 parent 0c9a2c9 commit e895973
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 28 additions & 0 deletions plugin/storage/cassandra/dependencystore/bootstrap.go
Original file line number Diff line number Diff line change
@@ -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
}
46 changes: 46 additions & 0 deletions plugin/storage/cassandra/dependencystore/bootstrap_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
5 changes: 1 addition & 4 deletions plugin/storage/cassandra/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
28 changes: 20 additions & 8 deletions plugin/storage/cassandra/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/cassandra/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e895973

Please sign in to comment.