-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix badger storage to pass all the integration tests and enable integ…
…ration tests for badger
- Loading branch information
Michael Burman
committed
May 3, 2018
1 parent
097907e
commit 71aeaab
Showing
5 changed files
with
224 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package dependencystore | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
const ( | ||
dependencyKeyPrefix byte = 0xC0 // Dependency PKs have first two bits set to 1 | ||
) | ||
|
||
// DependencyStore handles all queries and insertions to Cassandra dependencies | ||
type DependencyStore struct { | ||
// session cassandra.Session | ||
// dependencyDataFrequency time.Duration | ||
// dependenciesTableMetrics *casMetrics.Table | ||
// logger *zap.Logger | ||
} | ||
|
||
// NewDependencyStore returns a DependencyStore | ||
func NewDependencyStore() *DependencyStore { | ||
// session cassandra.Session, | ||
// dependencyDataFrequency time.Duration, | ||
// metricsFactory metrics.Factory, | ||
// logger *zap.Logger, | ||
// ) *DependencyStore { | ||
// return &DependencyStore{ | ||
// session: session, | ||
// dependencyDataFrequency: dependencyDataFrequency, | ||
// dependenciesTableMetrics: casMetrics.NewTable(metricsFactory, "Dependencies"), | ||
// logger: logger, | ||
// } | ||
return nil | ||
} | ||
|
||
// WriteDependencies implements dependencystore.Writer#WriteDependencies. | ||
func (s *DependencyStore) WriteDependencies(ts time.Time, dependencies []model.DependencyLink) error { | ||
// deps := make([]Dependency, len(dependencies)) | ||
// for i, d := range dependencies { | ||
// deps[i] = Dependency{ | ||
// Parent: d.Parent, | ||
// Child: d.Child, | ||
// CallCount: int64(d.CallCount), | ||
// } | ||
// } | ||
// query := s.session.Query(depsInsertStmt, ts, ts, deps) | ||
// return s.dependenciesTableMetrics.Exec(query, s.logger) | ||
return nil | ||
} | ||
|
||
// GetDependencies returns all interservice dependencies | ||
func (s *DependencyStore) GetDependencies(endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) { | ||
// query := s.session.Query(depsSelectStmt, endTs.Add(-1*lookback), endTs) | ||
// iter := query.Consistency(cassandra.One).Iter() | ||
|
||
// var mDependency []model.DependencyLink | ||
// var dependencies []Dependency | ||
// var ts time.Time | ||
// for iter.Scan(&ts, &dependencies) { | ||
// for _, dependency := range dependencies { | ||
// mDependency = append(mDependency, model.DependencyLink{ | ||
// Parent: dependency.Parent, | ||
// Child: dependency.Child, | ||
// CallCount: uint64(dependency.CallCount), | ||
// }) | ||
// } | ||
// } | ||
|
||
// if err := iter.Close(); err != nil { | ||
// s.logger.Error("Failure to read Dependencies", zap.Time("endTs", endTs), zap.Duration("lookback", lookback), zap.Error(err)) | ||
// return nil, errors.Wrap(err, "Error reading dependencies from storage") | ||
// } | ||
// return mDependency, nil | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"testing" | ||
|
||
"github.com/jaegertracing/jaeger/pkg/testutils" | ||
"github.com/jaegertracing/jaeger/plugin/storage/badger" | ||
assert "github.com/stretchr/testify/require" | ||
"github.com/uber/jaeger-lib/metrics" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type BadgerIntegrationStorage struct { | ||
StorageIntegration | ||
} | ||
|
||
func (s *BadgerIntegrationStorage) initialize() error { | ||
f := badger.NewFactory() | ||
err := f.Initialize(metrics.NullFactory, zap.NewNop()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sw, err := f.CreateSpanWriter() | ||
if err != nil { | ||
return err | ||
} | ||
sr, err := f.CreateSpanReader() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s.SpanReader = sr | ||
s.SpanWriter = sw | ||
|
||
s.Refresh = s.refresh | ||
s.CleanUp = s.cleanUp | ||
|
||
logger, _ := testutils.NewLogger() | ||
s.logger = logger | ||
|
||
return nil | ||
} | ||
|
||
func (s *BadgerIntegrationStorage) clear() error { | ||
if closer, ok := s.SpanWriter.(io.Closer); ok { | ||
err := closer.Close() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
return fmt.Errorf("BadgerIntegrationStorage did not implement io.Closer, unable to close and cleanup the storage correctly") | ||
} | ||
|
||
func (s *BadgerIntegrationStorage) cleanUp() error { | ||
err := s.clear() | ||
if err != nil { | ||
return err | ||
} | ||
return s.initialize() | ||
} | ||
|
||
func (s *BadgerIntegrationStorage) refresh() error { | ||
return nil | ||
} | ||
|
||
func TestBadgerStorage(t *testing.T) { | ||
if os.Getenv("STORAGE") != "badger" { | ||
t.Skip("Integration test against Badger skipped; set STORAGE env var to badger to run this") | ||
} | ||
s := &BadgerIntegrationStorage{} | ||
assert.NoError(t, s.initialize()) | ||
s.IntegrationTestAll(t) | ||
defer s.clear() | ||
} |