Skip to content

Commit 617fe10

Browse files
committed
server: Gather transcode health info in broadcast
- Include both orch eth address and transcoder URI - transcodeAttemptInfo as an out parameter of transcodeSegment - named returns+defer trick to avoid repetitions of time&error setting
1 parent 226447a commit 617fe10

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

server/broadcast.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"time"
1818

1919
ethcommon "github.com/ethereum/go-ethereum/common"
20+
"github.com/ethereum/go-ethereum/common/hexutil"
2021
"github.com/golang/glog"
2122

2223
"github.com/livepeer/go-livepeer/common"
@@ -469,10 +470,21 @@ func processSegment(cxn *rtmpConnection, seg *stream.HLSSegment) ([]string, erro
469470
sv = verification.NewSegmentVerifier(Policy)
470471
}
471472

473+
var (
474+
attempts []transcodeAttemptInfo
475+
urls []string
476+
)
477+
defer func() {
478+
// TODO: Send saved attempts somewhere. Or better yet, avoid this defer and
479+
// refactor the retry loop below to send the attempts after looping.
480+
}()
472481
for i := 0; i < MaxAttempts; i++ {
473-
// if fails, retry; rudimentary
474-
var urls []string
475-
if urls, err = transcodeSegment(cxn, seg, name, sv); err == nil {
482+
// if transcodeSegment fails, retry; rudimentary
483+
info := transcodeAttemptInfo{}
484+
urls, err = transcodeSegment(cxn, seg, name, sv, &info)
485+
attempts = append(attempts, info)
486+
487+
if err == nil {
476488
return urls, nil
477489
}
478490

@@ -495,8 +507,24 @@ func processSegment(cxn *rtmpConnection, seg *stream.HLSSegment) ([]string, erro
495507
return nil, err
496508
}
497509

510+
// TODO: Declare this somewhere else, probably with func that sends to queue.
511+
type orchShortInfo struct {
512+
Address string
513+
TranscoderUri string
514+
}
515+
516+
type transcodeAttemptInfo struct {
517+
Orchestrator orchShortInfo
518+
LatencyMs int64
519+
Error error
520+
}
521+
498522
func transcodeSegment(cxn *rtmpConnection, seg *stream.HLSSegment, name string,
499-
verifier *verification.SegmentVerifier) ([]string, error) {
523+
verifier *verification.SegmentVerifier, info *transcodeAttemptInfo) (urls []string, err error) {
524+
defer func(startTime time.Time) {
525+
info.LatencyMs = time.Since(startTime).Milliseconds()
526+
info.Error = err
527+
}(time.Now())
500528

501529
nonce := cxn.nonce
502530
cpl := cxn.pl
@@ -513,6 +541,10 @@ func transcodeSegment(cxn *rtmpConnection, seg *stream.HLSSegment, name string,
513541
// similar to the orchestrator's RemoteTranscoderFatalError
514542
return nil, nil
515543
}
544+
info.Orchestrator = orchShortInfo{
545+
TranscoderUri: sess.OrchestratorInfo.Transcoder,
546+
Address: hexutil.Encode(sess.OrchestratorInfo.Address),
547+
}
516548

517549
glog.Infof("Trying to transcode segment manifestID=%v nonce=%d seqNo=%d", cxn.mid, nonce, seg.SeqNo)
518550
if monitor.Enabled {

0 commit comments

Comments
 (0)