Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
chore: add new call to block/image endpoint with cache support to ide…
Browse files Browse the repository at this point in the history
…ntify the volumes

Signed-off-by: Javier <sjavierlopez@gmail.com>
  • Loading branch information
Javlopez authored and galexrt committed Nov 6, 2023
1 parent e505c6c commit 2cb301e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
9 changes: 4 additions & 5 deletions internal/ceph/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *Service) GetHealthFull(ctx context.Context) (*HealthStatus, error) {
return &healthStatus, nil
}

func (s *Service) GetBlockImage(ctx context.Context) (*BlockImageResponse, error) {
func (s *Service) GetBlockImage(ctx context.Context) ([]BlockImage, error) {
if err := s.apiClient.Auth(ctx); err != nil {
s.logger.Error(ErrorUnableToAuthenticate.Error(), zap.Error(err))
return nil, ErrorUnableToAuthenticate
Expand All @@ -81,11 +81,10 @@ func (s *Service) GetBlockImage(ctx context.Context) (*BlockImageResponse, error
return nil, ErrorUnableToConnectWithApi
}

var bir BlockImageResponse
if err := json.NewDecoder(resp.Body).Decode(&bir); err != nil {
var blockImage []BlockImage
if err := json.NewDecoder(resp.Body).Decode(&blockImage); err != nil {
s.logger.Error("error decoding response", zap.Error(err))
return nil, fmt.Errorf("error decoding response %w", err)
}

return &bir, nil
return blockImage, nil
}
10 changes: 3 additions & 7 deletions internal/ceph/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,12 @@ func (hs *HealthStatus) ObjectSize() int64 {
return int64(size)
}

type BlockImageResponse struct {
BlockImages []BlockImage
}

type BlockImage struct {
BlockImageValue BlockImageValue `json:"value"`
PoolName string `json:"pool_name"`
BlockImageValue []BlockImageValue `json:"value"`
PoolName string `json:"pool_name"`
}

type BlockImageValue []struct {
type BlockImageValue struct {
Size int `json:"size"`
ObjSize int `json:"obj_size"`
NumObjs int `json:"num_objs"`
Expand Down
16 changes: 15 additions & 1 deletion pkg/ceph/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Cache struct {
ceph *ceph.Service

healthStatus cache.CacheEntry[*ceph.HealthStatus]
rbdImages cache.CacheEntry[[]ceph.BlockImage]
}

type Params struct {
Expand Down Expand Up @@ -105,6 +106,15 @@ func (c *Cache) run(ctx context.Context) error {
errs = multierr.Append(errs, err)
return
}

blockImages, err := c.ceph.GetBlockImage(ctx)
if err != nil {
c.logger.Error("failed to update block image cache", zap.Error(err))
errs = multierr.Append(errs, err)
return
}

c.rbdImages.Set(blockImages)
c.healthStatus.Set(healthStatus)
}()

Expand All @@ -113,6 +123,10 @@ func (c *Cache) run(ctx context.Context) error {
return errs
}

func (c *Cache) GetHealthFull(ctx context.Context) (*ceph.HealthStatus, bool) {
func (c *Cache) GetHealthFull(_ context.Context) (*ceph.HealthStatus, bool) {
return c.healthStatus.Get()
}

func (c *Cache) GetBlockImages(_ context.Context) ([]ceph.BlockImage, bool) {
return c.rbdImages.Get()
}
9 changes: 3 additions & 6 deletions server/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ func (s *Server) GetClusterStats(ctx context.Context, req *connect.Request[stats
activeAndCleanPGs += pool.PgStatus.ActiveClean
}

//blockImages, err := s.ceph(ctx).GetBlockImage()
//if err != {
// return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("error caused by %w", err))
// }
// volumes = len(blockImages)
blockImages, _ := s.ceph.GetBlockImages(ctx)
volumes := len(blockImages)

now := time.Now()

Expand Down Expand Up @@ -147,7 +144,7 @@ func (s *Server) GetClusterStats(ctx context.Context, req *connect.Request[stats
},
},
Data: &statsv1.Data{
Volumes: int32(1), // TODO still figuring out https://linear.app/koorinc/issue/KSD-290/
Volumes: int32(volumes),
Pools: &statsv1.Pools{
Pools: int32(poolCount),
Pgs: &statsv1.PGs{
Expand Down

0 comments on commit 2cb301e

Please sign in to comment.