Skip to content

Commit

Permalink
fix(badger): Add missing SamplingStoreFactory.CreateLock method (jaeg…
Browse files Browse the repository at this point in the history
  • Loading branch information
slayer321 authored Nov 27, 2023
1 parent 076cd87 commit 115c692
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
10 changes: 7 additions & 3 deletions plugin/storage/badger/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/spf13/viper"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/pkg/distributedlock"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/plugin"
depStore "github.com/jaegertracing/jaeger/plugin/storage/badger/dependencystore"
Expand All @@ -52,9 +53,7 @@ var ( // interface comformance checks
// TODO badger could implement archive storage
// _ storage.ArchiveFactory = (*Factory)(nil)

// TODO CreateLock function is missing
// Being fixed in https://github.com/jaegertracing/jaeger/pull/4966
// _ storage.SamplingStoreFactory = (*Factory)(nil)
_ storage.SamplingStoreFactory = (*Factory)(nil)
)

// Factory implements storage.Factory for Badger backend.
Expand Down Expand Up @@ -186,6 +185,11 @@ func (f *Factory) CreateSamplingStore(maxBuckets int) (samplingstore.Store, erro
return badgerSampling.NewSamplingStore(f.store), nil
}

// CreateLock implements storage.SamplingStoreFactory
func (f *Factory) CreateLock() (distributedlock.Lock, error) {
return &lock{}, nil
}

// Close Implements io.Closer and closes the underlying storage
func (f *Factory) Close() error {
close(f.maintenanceDone)
Expand Down
4 changes: 4 additions & 0 deletions plugin/storage/badger/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func TestForCodecov(t *testing.T) {
_, err = f.CreateDependencyReader()
assert.NoError(t, err)

lock, err := f.CreateLock()
assert.NoError(t, err)
assert.NotNil(t, lock)

// Now, remove the badger directories
err = os.RemoveAll(f.tmpDir)
assert.NoError(t, err)
Expand Down
29 changes: 29 additions & 0 deletions plugin/storage/badger/lock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2023 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 badger

import "time"

type lock struct{}

// Acquire always returns true for badgerdb as no lock is needed
func (l *lock) Acquire(resource string, ttl time.Duration) (bool, error) {
return true, nil
}

// Forfeit always returns true for badgerdb as no lock is needed
func (l *lock) Forfeit(resource string) (bool, error) {
return true, nil
}
36 changes: 36 additions & 0 deletions plugin/storage/badger/lock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023 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 badger

import (
"testing"
"time"

"github.com/crossdock/crossdock-go/assert"
)

func TestAcquire(t *testing.T) {
l := &lock{}
ok, err := l.Acquire("resource", time.Duration(1))
assert.True(t, ok)
assert.NoError(t, err)
}

func TestForfeit(t *testing.T) {
l := &lock{}
ok, err := l.Forfeit("resource")
assert.True(t, ok)
assert.NoError(t, err)
}
2 changes: 1 addition & 1 deletion plugin/storage/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestCreateError(t *testing.T) {
}

func TestAllSamplingStorageTypes(t *testing.T) {
assert.Equal(t, AllSamplingStorageTypes(), []string{"cassandra", "memory"})
assert.Equal(t, []string{"cassandra", "memory", "badger"}, AllSamplingStorageTypes())
}

func TestCreateSamplingStoreFactory(t *testing.T) {
Expand Down

0 comments on commit 115c692

Please sign in to comment.