Skip to content

Commit 6043f55

Browse files
committed
Adjust comments about cache and add debug logs
1 parent 94ac4ba commit 6043f55

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

components/buildless-serverless/internal/controller/cache/cache.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type InMemoryCache interface {
1515
Delete(any)
1616
}
1717

18-
// inMemoryManifestCache provides an in-memory processor to store serverless Spec and rendered chart manifest. By using sync.Map for caching,
18+
// inMemoryCache provides an in-memory processor to store buildless serverless key values pairs with timestamp. By using sync.Map for caching,
1919
// concurrent operations to the processor from diverse reconciliations are considered safe.
2020
//
21-
// Inside the processor is stored chart manifest with used custom flags by client.ObjectKey key.
21+
// Inside the processor is stored last commit with which was git function created by repository url and reference as the key.
2222
type inMemoryCache struct {
2323
processor sync.Map
2424
timeout time.Duration
@@ -29,15 +29,15 @@ type storageObject struct {
2929
value string
3030
}
3131

32-
// NewInMemoryManifestCache returns a new instance of inMemoryManifestCache.
32+
// NewInMemoryCache returns a new instance of inMemoryCache.
3333
func NewInMemoryCache(timeout time.Duration) *inMemoryCache {
3434
return &inMemoryCache{
3535
processor: sync.Map{},
3636
timeout: timeout,
3737
}
3838
}
3939

40-
// Get loads the ServerlessSpecManifest from inMemoryManifestCache for the passed client.ObjectKey.
40+
// Get loads from inMemoryCache for the passed key.
4141
func (r *inMemoryCache) Get(key any) string {
4242
rawValue, ok := r.processor.Load(key)
4343
if !ok {
@@ -51,13 +51,13 @@ func (r *inMemoryCache) Get(key any) string {
5151
return value.value
5252
}
5353

54-
// Set saves the passed flags and manifest into inMemoryManifestCache for the client.ObjectKey.
54+
// Set saves the passed last commit with which was git function created in inMemoryCache for the passed key.
5555
func (r *inMemoryCache) Set(key any, lastCommit string) {
5656
now := time.Now()
5757
r.processor.Store(key, &storageObject{now, lastCommit})
5858
}
5959

60-
// Delete deletes flags and manifest from inMemoryManifestCache for the passed client.ObjectKey.
60+
// Delete deletes last commit with which was git function created from inMemoryCache for the passed key.
6161
func (r *inMemoryCache) Delete(key any) {
6262
r.processor.Delete(key)
6363
}

components/buildless-serverless/internal/controller/fsm/fsm.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ func New(client client.Client, functionConfig config.FunctionConfig, instance *s
106106
FunctionConfig: functionConfig,
107107
Client: client,
108108
Scheme: scheme,
109-
GitChecker: git.GoGitCommitChecker{Cache: cache},
109+
GitChecker: git.GoGitCommitChecker{Cache: cache,
110+
Log: log},
110111
}
111112
sm.State.saveStatusSnapshot()
112113
return &sm

components/buildless-serverless/internal/controller/git/commit_checker.go

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/go-git/go-git/v5/storage/memory"
77
"github.com/kyma-project/serverless/internal/controller/cache"
88
"github.com/pkg/errors"
9+
"go.uber.org/zap"
910
)
1011

1112
//go:generate mockery --name=LastCommitChecker --output=automock --outpkg=automock --case=underscore
@@ -15,6 +16,7 @@ type LastCommitChecker interface {
1516

1617
type GoGitCommitChecker struct {
1718
Cache cache.InMemoryCache
19+
Log *zap.SugaredLogger
1820
}
1921

2022
type LastCommitKey struct {
@@ -32,6 +34,7 @@ func (g GoGitCommitChecker) GetLatestCommit(url, reference string, gitAuth *GitA
3234
lastCommit = g.Cache.Get(commitKey)
3335
}
3436
if lastCommit != "" {
37+
g.Log.Debugf("Last commit from cache for %s %s is %s", url, reference, lastCommit)
3538
return lastCommit, nil
3639
}
3740

@@ -60,6 +63,7 @@ func (g GoGitCommitChecker) GetLatestCommit(url, reference string, gitAuth *GitA
6063
}
6164

6265
lastCommit = ref.Hash().String()
66+
g.Log.Debugf("Last commit from repository for %s %s is %s ", url, reference, lastCommit)
6367
g.Cache.Set(commitKey, lastCommit)
6468

6569
return lastCommit, nil

0 commit comments

Comments
 (0)