feat: add metrics, observability, test fixtures, and scaling playbook artifacts
CD / deploy (push) Successful in 57s
CI / test (push) Failing after 1m29s
CI / docker (push) Skipped

This commit is contained in:
zwitschi committed 2026-08-10 00:23:50 +02:00
1 parent 926a663c23
commit f9aba11b90
32 files changed
+1788 -124

No files matched your search

+36 -6
View File
@@ -28,6 +28,9 @@ type VideoFile struct {
var (
r2Client *s3.Client
putObject = func(client *s3.Client, input *s3.PutObjectInput) (*s3.PutObjectOutput, error) {
return client.PutObject(context.TODO(), input)
}
bucket = os.Getenv("R2_BUCKET_NAME")
playoutMode = "starting" // "live", "slate", "degraded"
restartCount = 0
@@ -39,6 +42,9 @@ var (
const (
maxRestartsPerMinute = 5
slateManifestName = "playlist.m3u8"
// Cache-Control header values for R2 uploads.
segmentCacheControl = "public, max-age=31536000, immutable"
manifestCacheControl = "public, max-age=2"
)
// initR2Client initializes the R2 (S3-compatible) client
@@ -203,7 +209,7 @@ func validateKeyframeInterval(videoPath string) error {
"-v", "quiet",
"-select_streams", "v:0",
"-show_frames",
"-show_entries", "frame=key_frame,pkt_pts_time",
"-show_entries", "frame=key_frame,best_effort_timestamp_time,pkt_pts_time",
"-of", "csv=p=0",
videoPath)
output, err := cmd.Output()
@@ -223,8 +229,16 @@ func validateKeyframeInterval(videoPath string) error {
if len(parts) < 2 || parts[0] != "1" {
continue
}
pts, err := strconv.ParseFloat(strings.TrimSpace(parts[1]), 64)
if err != nil {
var pts float64
var found bool
for _, raw := range parts[1:] {
if value, err := strconv.ParseFloat(strings.TrimSpace(raw), 64); err == nil {
pts = value
found = true
break
}
}
if !found {
continue
}
keyframes = append(keyframes, kfEntry{pts})
@@ -284,7 +298,11 @@ func ValidatePlaylist(playlistPath string) ([]VideoFile, error) {
return videos, nil
}
// SyncToR2 uploads a file to R2 and returns the key
// SyncToR2 uploads a file to R2 and returns the key.
// Cache-Control is set automatically based on file extension:
// - .m4s, .ts, .mp4, .m4a -> immutable (1 year)
// - .m3u8 -> short-lived (2s, live manifest)
// - everything else -> no cache header
func SyncToR2(localPath, r2Key string) error {
if r2Client == nil {
if err := initR2Client(); err != nil {
@@ -298,11 +316,23 @@ func SyncToR2(localPath, r2Key string) error {
}
defer file.Close()
_, err = r2Client.PutObject(context.TODO(), &s3.PutObjectInput{
input := &s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(r2Key),
Body: file,
})
}
ext := strings.ToLower(filepath.Ext(r2Key))
switch ext {
case ".m4s", ".ts", ".mp4", ".m4a":
input.CacheControl = aws.String(segmentCacheControl)
input.ContentType = aws.String("video/MP2T")
case ".m3u8":
input.CacheControl = aws.String(manifestCacheControl)
input.ContentType = aws.String("application/vnd.apple.mpegurl")
}
_, err = putObject(r2Client, input)
return err
}