8000 feat(repositories): add cache size in mon/status by sguiheux · Pull Request #6288 · ovh/cds · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(repositories): add cache size in mon/status #6288

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

Merged
merged 1 commit into from
Sep 26, 2022
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
1 change: 1 addition & 0 deletions cli/cdsctl/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func adminCommands() []*cobra.Command {
adminDatabase(),
adminServices(),
adminCdn(),
adminRepositories(),
adminHooks(),
adminIntegrationModels(),
adminMaintenance(),
Expand Down
37 changes: 37 additions & 0 deletions cli/cdsctl/admin_repositories.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"github.com/spf13/cobra"

"github.com/ovh/cds/cli"
"github.com/ovh/cds/sdk"
)

var adminRepositoriesCmd = cli.Command{
Name: "repositories",
Short: "Manage CDS repositories uService",
}

func adminRepositories() *cobra.Command {
return cli.NewCommand(adminRepositoriesCmd, nil, []*cobra.Command{
cli.NewListCommand(adminRepositorisStatusCmd, adminRepositorisStatusRun, nil),
})
}

func adminRepositorisStatusRun(_ cli.Values) (cli.ListResult, error) {
services, err := client.ServicesByType(sdk.TypeRepositories)
if err != nil {
return nil, err
}
status := sdk.MonitoringStatus{}
for _, srv := range services {
status.Lines = append(status.Lines, srv.MonitoringStatus.Lines...)
}
return cli.AsListResult(status.Lines), nil
}

var adminRepositorisStatusCmd = cli.Command{
Name: "status",
Short: "display the status of repositories",
Example: "cdsctl admin repositories status",
}
29 changes: 29 additions & 0 deletions engine/repositories/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/rockbears/log"

Expand Down Expand Up @@ -42,3 +43,31 @@ func (s *Service) cleanFS(ctx context.Context, r *sdk.OperationRepo) error {
log.Info(ctx, "cleaning operation basedir: %v", r.Basedir)
return sdk.WithStack(os.RemoveAll(r.Basedir))
}

func (s *Service) computeCacheSize(ctx context.Context) error {
tick := time.NewTicker(5 * time.Minute)

defer tick.Stop()
for {
select {
case <-tick.C:
var size int64
err := filepath.Walk(s.Cfg.Basedir, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
size += info.Size()
}
return err
})
if err != nil {
log.ErrorWithStackTrace(ctx, sdk.WrapError(err, "unable to compute size"))
continue
}
s.cacheSize = size
case <-ctx.Done():
return ctx.Err()
}
}
}
19 changes: 13 additions & 6 deletions engine/repositories/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,25 @@ func (s *Service) Serve(c context.Context) error {
}

log.Info(ctx, "Initializing processor...")
go func() {
s.GoRoutines.RunWithRestart(ctx, "processor", func(ctx context.Context) {
if err := s.processor(ctx); err != nil {
log.Info(ctx, "Shutdown processor")
log.ErrorWithStackTrace(ctx, err)
}
}()
})

log.Info(ctx, "Initializing vacuumCleaner...")
go func() {
s.GoRoutines.RunWithRestart(ctx, "vacuumCleaner", func(ctx context.Context) {
if err := s.vacuumCleaner(ctx); err != nil {
log.Info(ctx, "Shutdown vacuumCleaner")
log.ErrorWithStackTrace(ctx, err)
}
}()
})

log.Info(ctx, "Initializing cache size...")
s.GoRoutines.RunWithRestart(ctx, "computeCacheSize", func(ctx context.Context) {
if err := s.computeCacheSize(ctx); err != nil {
log.ErrorWithStackTrace(ctx, err)
}
})

//Gracefully shutdown the http server
go func() {
Expand Down
7 changes: 7 additions & 0 deletions engine/repositories/repositories_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"bytes"
"context"
"fmt"
"io"
"net/http"
"strings"
Expand Down Expand Up @@ -133,6 +134,12 @@ func (s *Service) getOperationsHandler() service.Handler {
// Status returns sdk.MonitoringStatus, implements interface service.Service
func (s *Service) Status(ctx context.Context) *sdk.MonitoringStatus {
m := s.NewMonitoringStatus()

m.Lines = append(m.Lines, sdk.MonitoringStatusLine{
Component: "Cache size",
Value: fmt.Sprintf("%d octets", s.cacheSize),
Status: sdk.MonitoringStatusOK,
})
return m
}

Expand Down
9 changes: 5 additions & 4 deletions engine/repositories/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
// Service is the repostories service
type Service struct {
service.Common
Cfg Configuration
Router *api.Router
Cache cache.Store
dao dao
Cfg Configuration
Router *api.Router
Cache cache.Store
dao dao
cacheSize int64
}

// Configuration is the vcs configuration structure
Expand Down
0