From 091e6c8ed9f737b3b84a3610c5836953677d122c Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 18 Sep 2022 16:13:27 +0200 Subject: [PATCH] Add explicit logging in `GetBranchTimestamp` (#130) - Logs are currently indicating that it's returning `nil` in valid scenarios, therefor this patch adds extra logging in this code to better understand what it is doing in this function. Co-authored-by: Gusted Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/130 Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Gusted Co-committed-by: Gusted --- server/handler.go | 2 +- server/upstream/helper.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/handler.go b/server/handler.go index ed06659..fb8b419 100644 --- a/server/handler.go +++ b/server/handler.go @@ -296,7 +296,7 @@ func Handler(mainDomainSuffix, rawDomain []byte, return } - log.Info().Msg("tryBranch, now trying upstream 7 %s") + log.Info().Msg("tryBranch, now trying upstream 7") tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOptions, targetOwner, targetRepo, targetBranch, targetPath, canonicalDomainCache, branchTimestampCache, fileResponseCache) diff --git a/server/upstream/helper.go b/server/upstream/helper.go index 0714dcd..28f4474 100644 --- a/server/upstream/helper.go +++ b/server/upstream/helper.go @@ -9,6 +9,7 @@ import ( "codeberg.org/codeberg/pages/server/cache" "codeberg.org/codeberg/pages/server/gitea" + "github.com/rs/zerolog/log" ) type branchTimestamp struct { @@ -19,10 +20,13 @@ type branchTimestamp struct { // GetBranchTimestamp finds the default branch (if branch is "") and returns the last modification time of the branch // (or nil if the branch doesn't exist) func GetBranchTimestamp(giteaClient *gitea.Client, owner, repo, branch string, branchTimestampCache cache.SetGetKey) *branchTimestamp { + log := log.With().Strs("BranchInfo", []string{owner, repo, branch}).Logger() if result, ok := branchTimestampCache.Get(owner + "/" + repo + "/" + branch); ok { if result == nil { + log.Debug().Msg("branchTimestampCache found item, but result is empty") return nil } + log.Debug().Msg("branchTimestampCache found item, returning result") return result.(*branchTimestamp) } result := &branchTimestamp{ @@ -32,16 +36,20 @@ func GetBranchTimestamp(giteaClient *gitea.Client, owner, repo, branch string, b // Get default branch defaultBranch, err := giteaClient.GiteaGetRepoDefaultBranch(owner, repo) if err != nil { + log.Err(err).Msg("Could't fetch default branch from repository") _ = branchTimestampCache.Set(owner+"/"+repo+"/", nil, defaultBranchCacheTimeout) return nil } + log.Debug().Msg("Succesfully fetched default branch from Gitea") result.Branch = defaultBranch } timestamp, err := giteaClient.GiteaGetRepoBranchTimestamp(owner, repo, result.Branch) if err != nil { + log.Err(err).Msg("Could not get latest commit's timestamp from branch") return nil } + log.Debug().Msg("Succesfully fetched latest commit's timestamp from branch, adding to cache") result.Timestamp = timestamp _ = branchTimestampCache.Set(owner+"/"+repo+"/"+branch, result, branchExistenceCacheTimeout) return result