Add number of versions in server info API (#14812)

The goal is to show the number of versions in the server info API.
This commit is contained in:
Anis Elleuch 2022-04-26 06:04:10 +01:00 committed by GitHub
parent f5d3313210
commit df50eda811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 7 deletions

View File

@ -1699,6 +1699,7 @@ func getServerInfo(ctx context.Context, r *http.Request) madmin.InfoMessage {
buckets := madmin.Buckets{} buckets := madmin.Buckets{}
objects := madmin.Objects{} objects := madmin.Objects{}
versions := madmin.Versions{}
usage := madmin.Usage{} usage := madmin.Usage{}
objectAPI := newObjectLayerFn() objectAPI := newObjectLayerFn()
@ -1710,6 +1711,7 @@ func getServerInfo(ctx context.Context, r *http.Request) madmin.InfoMessage {
if err == nil { if err == nil {
buckets = madmin.Buckets{Count: dataUsageInfo.BucketsCount} buckets = madmin.Buckets{Count: dataUsageInfo.BucketsCount}
objects = madmin.Objects{Count: dataUsageInfo.ObjectsTotalCount} objects = madmin.Objects{Count: dataUsageInfo.ObjectsTotalCount}
versions = madmin.Versions{Count: dataUsageInfo.VersionsTotalCount}
usage = madmin.Usage{Size: dataUsageInfo.ObjectsTotalSize} usage = madmin.Usage{Size: dataUsageInfo.ObjectsTotalSize}
} else { } else {
buckets = madmin.Buckets{Error: err.Error()} buckets = madmin.Buckets{Error: err.Error()}
@ -1758,6 +1760,7 @@ func getServerInfo(ctx context.Context, r *http.Request) madmin.InfoMessage {
DeploymentID: globalDeploymentID, DeploymentID: globalDeploymentID,
Buckets: buckets, Buckets: buckets,
Objects: objects, Objects: objects,
Versions: versions,
Usage: usage, Usage: usage,
Services: services, Services: services,
Backend: backend, Backend: backend,

View File

@ -537,6 +537,7 @@ func (d *dataUsageCache) dui(path string, buckets []BucketInfo) DataUsageInfo {
dui := DataUsageInfo{ dui := DataUsageInfo{
LastUpdate: d.Info.LastUpdate, LastUpdate: d.Info.LastUpdate,
ObjectsTotalCount: flat.Objects, ObjectsTotalCount: flat.Objects,
VersionsTotalCount: flat.Versions,
ObjectsTotalSize: uint64(flat.Size), ObjectsTotalSize: uint64(flat.Size),
BucketsCount: uint64(len(e.Children)), BucketsCount: uint64(len(e.Children)),
BucketsUsage: d.bucketsUsageInfo(buckets), BucketsUsage: d.bucketsUsageInfo(buckets),
@ -788,6 +789,7 @@ func (d *dataUsageCache) bucketsUsageInfo(buckets []BucketInfo) map[string]Bucke
flat := d.flatten(*e) flat := d.flatten(*e)
bui := BucketUsageInfo{ bui := BucketUsageInfo{
Size: uint64(flat.Size), Size: uint64(flat.Size),
VersionsCount: flat.Versions,
ObjectsCount: flat.Objects, ObjectsCount: flat.Objects,
ObjectSizesHistogram: flat.ObjSizes.toMap(), ObjectSizesHistogram: flat.ObjSizes.toMap(),
} }

View File

@ -60,6 +60,7 @@ type BucketUsageInfo struct {
ObjectsCount uint64 `json:"objectsCount"` ObjectsCount uint64 `json:"objectsCount"`
ObjectSizesHistogram map[string]uint64 `json:"objectsSizesHistogram"` ObjectSizesHistogram map[string]uint64 `json:"objectsSizesHistogram"`
VersionsCount uint64 `json:"versionsCount"`
ReplicaSize uint64 `json:"objectReplicaTotalSize"` ReplicaSize uint64 `json:"objectReplicaTotalSize"`
ReplicationInfo map[string]BucketTargetUsageInfo `json:"objectsReplicationInfo"` ReplicationInfo map[string]BucketTargetUsageInfo `json:"objectsReplicationInfo"`
} }
@ -73,6 +74,9 @@ type DataUsageInfo struct {
// Objects total count across all buckets // Objects total count across all buckets
ObjectsTotalCount uint64 `json:"objectsCount"` ObjectsTotalCount uint64 `json:"objectsCount"`
// Objects total count across all buckets
VersionsTotalCount uint64 `json:"versionsCount"`
// Objects total size across all buckets // Objects total size across all buckets
ObjectsTotalSize uint64 `json:"objectsTotalSize"` ObjectsTotalSize uint64 `json:"objectsTotalSize"`
ReplicationInfo map[string]BucketTargetUsageInfo `json:"objectsReplicationInfo"` ReplicationInfo map[string]BucketTargetUsageInfo `json:"objectsReplicationInfo"`

View File

@ -498,7 +498,7 @@ func (s *xlStorage) NSScanner(ctx context.Context, cache dataUsageCache, updates
atomic.AddUint64(&globalScannerStats.accTotalVersions, 1) atomic.AddUint64(&globalScannerStats.accTotalVersions, 1)
oi := version.ToObjectInfo(item.bucket, item.objectPath()) oi := version.ToObjectInfo(item.bucket, item.objectPath())
sz := item.applyActions(ctx, objAPI, oi, &sizeS) sz := item.applyActions(ctx, objAPI, oi, &sizeS)
if !oi.DeleteMarker && sz == oi.Size { if oi.VersionID != "" && sz == oi.Size {
sizeS.versions++ sizeS.versions++
} }
sizeS.totalSize += sz sizeS.totalSize += sz