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

Commit

Permalink
compute and display duration of log segments
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel committed May 30, 2023
1 parent 86c0c4b commit cdeaf21
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Examples:
Start: 3h ago, Mon, 29 May 2023 23:00:41 UTC
Records: 27 (1 batch)
---
SEGMENT RECORDS BATCHES SIZE UNCOMPRESSED SIZE COMPRESSED SIZE COMPRESSION RATIO CREATED
0 27 1 1.68 KiB 3.88 KiB 1.62 KiB 58.27% 4h ago
SEGMENT RECORDS BATCHES SIZE UNCOMPRESSED SIZE COMPRESSED SIZE COMPRESSION RATIO
0 27 1 1.68 KiB 3.88 KiB 1.62 KiB 58.27%
Options:
-h, --help Show this usage information
Expand Down Expand Up @@ -440,7 +440,7 @@ type recordBatch struct {
Duration human.Duration `json:"-" yaml:"-" text:"DURATION"`
UncompressedSize human.Bytes `json:"uncompressedSize" yaml:"uncompressedSize" text:"UNCOMPRESSED SIZE"`
CompressedSize human.Bytes `json:"compressedSize" yaml:"compressedSize" text:"COMPRESSED SIZE"`
CompressionRatio human.Ratio `json:"copmressionRatio" yaml:"compressionRatio" text:"COMPRESSION RATIO"`
CompressionRatio human.Ratio `json:"-" yaml:"-" text:"COMPRESSION RATIO"`
Compression string `json:"compression" yaml:"compression" text:"COMPRESSION"`
}

Expand All @@ -453,7 +453,7 @@ type logSegment struct {
UncompressedSize human.Bytes `json:"-" yaml:"-" text:"UNCOMPRESSED SIZE"`
CompressedSize human.Bytes `json:"-" yaml:"-" text:"COMPRESSED SIZE"`
CompressionRatio human.Ratio `json:"-" yaml:"-" text:"COMPRESSION RATIO"`
CreatedAt human.Time `json:"createdAt" yaml:"createdAt" text:"CREATED"`
CreatedAt human.Time `json:"createdAt" yaml:"createdAt" text:"-"`
RecordBatches []recordBatch `json:"recordBatches" yaml:"recordBatches" text:"-"`
}

Expand Down Expand Up @@ -557,6 +557,7 @@ func describeLog(ctx context.Context, reg *timemachine.Registry, id string) (any
CreatedAt: human.Time(seg.CreatedAt),
}

lastTime := time.Time(logSegment.CreatedAt)
for {
b, err := logReader.ReadRecordBatch()
if err != nil {
Expand All @@ -567,34 +568,37 @@ func describeLog(ctx context.Context, reg *timemachine.Registry, id string) (any
u := human.Ratio(logSegment.UncompressedSize)
logSegment.CompressionRatio = 1 - c/u
logSegment.NumBatches = len(logSegment.RecordBatches)
logSegment.Duration = human.Duration(lastTime.Sub(time.Time(logSegment.CreatedAt)))
logch <- logSegment
}
break
}

var (
numRecords = b.NumRecords()
firstOffset = b.FirstOffset()
firstTimestamp = b.FirstTimestamp()
lastTimestamp = b.LastTimestamp()
duration = human.Duration(lastTimestamp.Sub(firstTimestamp))
uncompressedSize = human.Bytes(b.UncompressedSize())
compressedSize = human.Bytes(b.CompressedSize())
compression = b.Compression()
)

lastTime = lastTimestamp
logSegment.NumRecords += numRecords
logSegment.Duration += duration
logSegment.CompressedSize += compressedSize
logSegment.UncompressedSize += uncompressedSize
logSegment.RecordBatches = append(logSegment.RecordBatches, recordBatch{
NumRecords: numRecords,
FirstOffset: b.FirstOffset(),
FirstOffset: firstOffset,
FirstTimestamp: human.Time(firstTimestamp),
LastTimestamp: human.Time(lastTimestamp),
Duration: duration,
UncompressedSize: uncompressedSize,
CompressedSize: compressedSize,
CompressionRatio: 1 - human.Ratio(compressedSize)/human.Ratio(uncompressedSize),
Compression: b.Compression().String(),
Compression: compression.String(),
})
}
}(seg)
Expand Down

0 comments on commit cdeaf21

Please sign in to comment.