Skip to content

Commit

Permalink
Merge branch 'main' into feature/callstack
Browse files Browse the repository at this point in the history
  • Loading branch information
amitschendel authored Jan 26, 2025
2 parents da76958 + 4aaba20 commit 3837f09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions pkg/registry/file/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"reflect"
"strings"
"syscall"
"time"

"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
Expand Down Expand Up @@ -203,9 +204,14 @@ func (s *StorageImpl) Create(ctx context.Context, key string, obj, metaOut runti
span.SetAttributes(attribute.String("key", key))
defer span.End()
_, spanLock := otel.Tracer("").Start(ctx, "waiting for lock")
beforeLock := time.Now()
s.locks.Lock(key)
defer s.locks.Unlock(key)
spanLock.End()
lockDuration := time.Since(beforeLock)
if lockDuration > time.Second {
logger.L().Debug("Create", helpers.String("key", key), helpers.String("lockDuration", lockDuration.String()))
}
// check if object already exists
if _, err := s.appFs.Stat(makePayloadPath(filepath.Join(s.root, key))); err == nil {
return storage.NewKeyExistsError(key, 0)
Expand Down Expand Up @@ -240,9 +246,14 @@ func (s *StorageImpl) Delete(ctx context.Context, key string, metaOut runtime.Ob
span.SetAttributes(attribute.String("key", key))
defer span.End()
_, spanLock := otel.Tracer("").Start(ctx, "waiting for lock")
beforeLock := time.Now()
s.locks.Lock(key)
defer s.locks.Unlock(key)
spanLock.End()
lockDuration := time.Since(beforeLock)
if lockDuration > time.Second {
logger.L().Debug("Delete", helpers.String("key", key), helpers.String("lockDuration", lockDuration.String()))
}
p := filepath.Join(s.root, key)
// delete metadata in SQLite
conn, err := s.pool.Take(context.Background())
Expand Down Expand Up @@ -289,9 +300,14 @@ func (s *StorageImpl) Get(ctx context.Context, key string, opts storage.GetOptio
span.SetAttributes(attribute.String("key", key))
defer span.End()
_, spanLock := otel.Tracer("").Start(ctx, "waiting for lock")
beforeLock := time.Now()
s.locks.RLock(key)
defer s.locks.RUnlock(key)
spanLock.End()
lockDuration := time.Since(beforeLock)
if lockDuration > time.Second {
logger.L().Debug("Get", helpers.String("key", key), helpers.String("lockDuration", lockDuration.String()))
}
return s.get(ctx, key, opts, objPtr)
}

Expand Down Expand Up @@ -520,9 +536,14 @@ func (s *StorageImpl) GuaranteedUpdate(
span.SetAttributes(attribute.String("key", key))
defer span.End()
_, spanLock := otel.Tracer("").Start(ctx, "waiting for lock")
beforeLock := time.Now()
s.locks.Lock(key)
defer s.locks.Unlock(key)
spanLock.End()
lockDuration := time.Since(beforeLock)
if lockDuration > time.Second {
logger.L().Debug("GuaranteedUpdate/", helpers.String("key", key), helpers.String("lockDuration", lockDuration.String()))
}

// key preparation is skipped
// otel span tracking is skipped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
return labels.Set(apiserver.ObjectMeta.Labels), SelectableFields(apiserver), nil
}

// ConfigurationScanSummary is the filter used by the generic etcd backend to watch events
// MatchConfigurationScanSummary is the filter used by the generic etcd backend to watch events
// from etcd to clients of the apiserver only interested in specific labels/fields.
func MatchConfigurationScanSummary(label labels.Selector, field fields.Selector) storage.SelectionPredicate {
return storage.SelectionPredicate{
Expand Down

0 comments on commit 3837f09

Please sign in to comment.