logging: move rockskip service status to new log lib (#61210)

This commit is contained in:
William Bezuidenhout 2024-03-18 14:47:26 +02:00 committed by GitHub
parent 80aa3c4d13
commit c134ad7a1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 7 deletions

View File

@ -69,7 +69,7 @@ func NewService(
git: git,
fetcher: fetcher,
createParser: createParser,
status: NewStatus(),
status: NewStatus(logger),
repoUpdates: make(chan struct{}, 1),
maxRepos: maxRepos,
logQueries: logQueries,

View File

@ -10,8 +10,8 @@ import (
"time"
"github.com/dustin/go-humanize"
"github.com/inconshreveable/log15" //nolint:logging // TODO move all logging to sourcegraph/log
"github.com/sourcegraph/log"
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
)
@ -20,13 +20,15 @@ type RequestId = int
// ServiceStatus contains the status of all requests.
type ServiceStatus struct {
logger log.Logger
threadIdToThreadStatus map[RequestId]*ThreadStatus
nextThreadId RequestId
mu sync.Mutex
}
func NewStatus() *ServiceStatus {
func NewStatus(logger log.Logger) *ServiceStatus {
return &ServiceStatus{
logger: logger.Scoped("status"),
threadIdToThreadStatus: map[int]*ThreadStatus{},
nextThreadId: 0,
mu: sync.Mutex{},
@ -56,7 +58,7 @@ func (s *Service) HandleStatus(w http.ResponseWriter, r *http.Request) {
repositoryCount, _, err := basestore.ScanFirstInt(s.db.QueryContext(ctx, "SELECT COUNT(*) FROM rockskip_repos"))
if err != nil {
log15.Error("Failed to count repos", "error", err)
s.logger.Error("failed to count repos", log.Error(err))
w.WriteHeader(http.StatusInternalServerError)
return
}
@ -69,7 +71,7 @@ func (s *Service) HandleStatus(w http.ResponseWriter, r *http.Request) {
repoRows := []repoRow{}
repoSqlRows, err := s.db.QueryContext(ctx, "SELECT repo, last_accessed_at FROM rockskip_repos ORDER BY last_accessed_at DESC LIMIT 5")
if err != nil {
log15.Error("Failed to list repoRows", "error", err)
s.logger.Error("failed to list repoRows", log.Error(err))
w.WriteHeader(http.StatusInternalServerError)
return
}
@ -78,7 +80,7 @@ func (s *Service) HandleStatus(w http.ResponseWriter, r *http.Request) {
var repo string
var lastAccessedAt time.Time
if err := repoSqlRows.Scan(&repo, &lastAccessedAt); err != nil {
log15.Error("Failed to scan repo", "error", err)
s.logger.Error("failed to scan repo", log.Error(err))
w.WriteHeader(http.StatusInternalServerError)
return
}
@ -87,7 +89,7 @@ func (s *Service) HandleStatus(w http.ResponseWriter, r *http.Request) {
symbolsSize, _, err := basestore.ScanFirstString(s.db.QueryContext(ctx, "SELECT pg_size_pretty(pg_total_relation_size('rockskip_symbols'))"))
if err != nil {
log15.Error("Failed to get size of symbols table", "error", err)
s.logger.Error("failed to get size of symbols table", log.Error(err))
w.WriteHeader(http.StatusInternalServerError)
return
}