Skip to content

Commit

Permalink
add logging after all chunks were sent sucessfully
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene committed Dec 16, 2024
1 parent 1b0fc6b commit b4ad47b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
10 changes: 3 additions & 7 deletions proxy/config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ func (c *HTTPProxyConfig) fetchManifest(ctx context.Context, repo *remote.Reposi
return nil, fmt.Errorf("failed to resolve manifest for %s: %w", containerName, err)
}

log.Printf("Container %s:", containerName)
log.Printf("- Manifest size: %d bytes", descriptor.Size)
log.Printf("- Media type: %s", descriptor.MediaType)

reader, err := repo.Fetch(ctx, descriptor)
if err != nil {
return nil, fmt.Errorf("failed to fetch manifest for %s: %w", containerName, err)
Expand Down Expand Up @@ -136,9 +132,9 @@ func createChunks(data []byte, containerName string) []ChunkPayload {
dataSize := len(data)
totalChunks := (dataSize + chunkSize - 1) / chunkSize

log.Printf("Total data size: %d bytes (%.2f MB)", dataSize, float64(dataSize)/size)
log.Printf("Chunk size: %d bytes (500 KB)", chunkSize)
log.Printf("Total chunks: %d", totalChunks)
// log.Printf("Total data size: %d bytes (%.2f MB)", dataSize, float64(dataSize)/size)

Check failure on line 135 in proxy/config/http.go

View workflow job for this annotation

GitHub Actions / Lint and Build

commentedOutCode: may want to remove commented-out code (gocritic)
// log.Printf("Chunk size: %d bytes (500 KB)", chunkSize)
// log.Printf("Total chunks: %d", totalChunks)

chunks := make([]ChunkPayload, 0, totalChunks)
for i := range make([]struct{}, totalChunks) {
Expand Down
15 changes: 14 additions & 1 deletion proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func (s *ProxyService) StreamHTTP(ctx context.Context) error {
}

func (s *ProxyService) StreamMQTT(ctx context.Context) error {
containerChunks := make(map[string]int)

for {
select {
case <-ctx.Done():
Expand All @@ -87,9 +89,20 @@ func (s *ProxyService) StreamMQTT(ctx context.Context) error {

continue
}

s.logger.Info("published container chunk",
"chunk", chunk.ChunkIdx,
"chunk_name", chunk.AppName,
"chunk_no", chunk.ChunkIdx,
"total", chunk.TotalChunks)

containerChunks[chunk.AppName]++

if containerChunks[chunk.AppName] == chunk.TotalChunks {
s.logger.Info("successfully sent all chunks",
"container", chunk.AppName,
"total_chunks", chunk.TotalChunks)
delete(containerChunks, chunk.AppName)
}
}
}
}

0 comments on commit b4ad47b

Please sign in to comment.