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(badger): Add missing SamplingStoreFactory.CreateLock method #4966

Merged
merged 4 commits into from
Nov 27, 2023
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
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) {
slayer321 marked this conversation as resolved.
Show resolved Hide resolved
slayer321 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading