Skip to content

Commit

Permalink
replication: change metrics API
Browse files Browse the repository at this point in the history
for additional info to be passed back.
  • Loading branch information
poornas committed May 26, 2023
1 parent 78f1dd8 commit da58094
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
36 changes: 36 additions & 0 deletions api-bucket-replication.go
Expand Up @@ -289,3 +289,39 @@ func (c *Client) GetBucketReplicationResyncStatus(ctx context.Context, bucketNam
}
return rinfo, nil
}

// GetBucketReplicationMetricsV2 fetches bucket replication status metrics
func (c *Client) GetBucketReplicationMetricsV2(ctx context.Context, bucketName string) (s replication.MetricsV2, err error) {
// Input validation.
if err := s3utils.CheckValidBucketName(bucketName); err != nil {
return s, err
}
// Get resources properly escaped and lined up before
// using them in http request.
urlValues := make(url.Values)
urlValues.Set("replication-metrics", "v2")

// Execute GET on bucket to get replication config.
resp, err := c.executeMethod(ctx, http.MethodGet, requestMetadata{
bucketName: bucketName,
queryValues: urlValues,
})

defer closeResponse(resp)
if err != nil {
return s, err
}

if resp.StatusCode != http.StatusOK {
return s, httpRespToErrorResponse(resp, bucketName, "")
}
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return s, err
}

if err := json.Unmarshal(respBytes, &s); err != nil {
return s, err
}
return s, nil
}
93 changes: 92 additions & 1 deletion pkg/replication/replication.go
Expand Up @@ -704,6 +704,8 @@ type TargetMetrics struct {
BandWidthLimitInBytesPerSecond int64 `json:"limitInBits"`
// Current bandwidth used in bytes/sec for this target
CurrentBandwidthInBytesPerSecond float64 `json:"currentBandwidth"`
// Completed count
ReplicatedCount uint64 `json:"replicationCount"`
}

// Metrics represents inline replication metrics for a bucket.
Expand All @@ -721,6 +723,10 @@ type Metrics struct {
PendingCount uint64 `json:"pendingReplicationCount"`
// Total number of failed operations including metadata updates across targets
FailedCount uint64 `json:"failedReplicationCount"`
// Total Replica counts
ReplicaCount int64 `json:"replicaCount,omitempty"`
// Total Replicated count
ReplicatedCount int64 `json:"replicationCount,omitempty"`
}

// ResyncTargetsInfo provides replication target information to resync replicated data.
Expand All @@ -742,9 +748,94 @@ type ResyncTarget struct {
FailedSize int64 `json:"failedReplicationSize,omitempty"`
// Total number of failed operations
FailedCount int64 `json:"failedReplicationCount,omitempty"`
// Total number of failed operations
// Total number of completed operations
ReplicatedCount int64 `json:"replicationCount,omitempty"`
// Last bucket/object replicated.
Bucket string `json:"bucket,omitempty"`
Object string `json:"object,omitempty"`
}

// ReplicationXferRate holds transfer rate info for uploads
type ReplicationXferRate struct {

Check failure on line 759 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

exported: type name will be used as replication.ReplicationXferRate by other packages, and that stutters; consider calling this XferRate (revive)

Check failure on line 759 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.20.x and ubuntu-latest

exported: type name will be used as replication.ReplicationXferRate by other packages, and that stutters; consider calling this XferRate (revive)
Avg float64 `json:"avg"`
Peak float64 `json:"peak"`
Curr float64 `json:"curr"`
}

type ReplQNodeStats struct {

Check failure on line 765 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

exported: exported type ReplQNodeStats should have comment or be unexported (revive)

Check failure on line 765 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.20.x and ubuntu-latest

exported: exported type ReplQNodeStats should have comment or be unexported (revive)
NodeName string `json:"nodename"`
ActiveWorkers int32 `json:"activeworkers"`
Lrg ReplicationXferRate `json:"lrg"`
Sml ReplicationXferRate `json:"sml"`
QueuedCount int32 `json:"totQueuedCount"`
QueuedBytes int64 `json:"totQueuedBytes"`
TotQueuedLrgCount int32 `json:"totQueuedLrgCount"`
TotQueuedLrgBytes int64 `json:"totQueuedLrgBytes"`
TotQueuedSmlCount int32 `json:"totQueuedSmlCount"`
TotQueuedSmlBytes int64 `json:"totQueuedSmlBytes"`
}
type ReplQueueStats struct {

Check failure on line 777 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

exported: exported type ReplQueueStats should have comment or be unexported (revive)

Check failure on line 777 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.20.x and ubuntu-latest

exported: exported type ReplQueueStats should have comment or be unexported (revive)
Nodes []ReplQNodeStats `json:"nodes"`
Uptime int64 `json:"uptime"`
}

func (q ReplQueueStats) Workers() int64 {

Check failure on line 782 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

exported: exported method ReplQueueStats.Workers should have comment or be unexported (revive)

Check failure on line 782 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.20.x and ubuntu-latest

exported: exported method ReplQueueStats.Workers should have comment or be unexported (revive)
var workers int64
for _, node := range q.Nodes {
workers += int64(node.ActiveWorkers)
}
return workers
}

type ReplQStats struct {

Check failure on line 790 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

exported: exported type ReplQStats should have comment or be unexported (revive)

Check failure on line 790 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.20.x and ubuntu-latest

exported: exported type ReplQStats should have comment or be unexported (revive)
Uptime int64 `json:"int64"`
Workers int64 `json:"workers"`
Lrg ReplicationXferRate `json:"lrg"`
Sml ReplicationXferRate `json:"sml"`
QueuedCount int32 `json:"totQueuedCount"`
QueuedBytes int64 `json:"totQueuedBytes"`
TotQueuedLrgCount int32 `json:"totQueuedLrgCount"`
TotQueuedLrgBytes int64 `json:"totQueuedLrgBytes"`
TotQueuedSmlCount int32 `json:"totQueuedSmlCount"`
TotQueuedSmlBytes int64 `json:"totQueuedSmlBytes"`
}

func (q ReplQueueStats) QStats() (r ReplQStats) {

Check failure on line 803 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

exported: exported method ReplQueueStats.QStats should have comment or be unexported (revive)

Check failure on line 803 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.20.x and ubuntu-latest

exported: exported method ReplQueueStats.QStats should have comment or be unexported (revive)
r.Uptime = q.Uptime
var lavg, lcurr, lpeak, savg, scurr, speak float64
for _, node := range q.Nodes {
r.Workers += int64(node.ActiveWorkers)
r.QueuedCount += node.QueuedCount
r.QueuedBytes += node.QueuedBytes
r.TotQueuedLrgCount += node.TotQueuedLrgCount
r.TotQueuedLrgBytes += node.TotQueuedLrgBytes
r.TotQueuedSmlCount += node.TotQueuedSmlCount
r.TotQueuedSmlBytes += node.TotQueuedSmlBytes
lavg += node.Lrg.Avg
lcurr += node.Lrg.Curr
if node.Lrg.Peak > lpeak {
lpeak = node.Lrg.Peak
}
savg += node.Sml.Avg
scurr += node.Sml.Curr
if node.Sml.Peak > speak {
speak = node.Sml.Peak
}
}
if len(q.Nodes) > 0 {
r.Lrg.Avg = lavg / float64(len(q.Nodes))
r.Lrg.Curr = lcurr / float64(len(q.Nodes))
r.Lrg.Peak = lpeak
r.Sml.Avg = savg / float64(len(q.Nodes))
r.Sml.Curr = scurr / float64(len(q.Nodes))
r.Sml.Peak = speak
}

return
}

type MetricsV2 struct {

Check failure on line 837 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

exported: exported type MetricsV2 should have comment or be unexported (revive)

Check failure on line 837 in pkg/replication/replication.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.20.x and ubuntu-latest

exported: exported type MetricsV2 should have comment or be unexported (revive)
History Metrics `json:"history"`
CurrentStats Metrics `json:"currStats"`
QueueStats ReplQueueStats `json:"queueStats"`
}

0 comments on commit da58094

Please sign in to comment.