Skip to content

Commit

Permalink
mapi: Simplify push status
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Nov 14, 2022
1 parent dfeb437 commit a62a21d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
13 changes: 6 additions & 7 deletions internal/app/mistapiconnector/mistapiconnector_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ type (
profile string
pushStartEmitted bool
pushStopped bool
metrics *pushMetrics
}

pushMetrics struct {
pushedBytes int64
pushedMediaTime time.Duration
metrics *data.MultistreamMetrics
}

streamInfo struct {
Expand Down Expand Up @@ -841,7 +836,11 @@ func (mc *mac) startMultistream(wildcardPlaybackID, playbackID string, info *str
}

info.mu.Lock()
info.pushStatus[pushURL] = &pushStatus{target: target, profile: targetRef.Profile}
info.pushStatus[pushURL] = &pushStatus{
target: target,
profile: targetRef.Profile,
metrics: &data.MultistreamMetrics{},
}
info.mu.Unlock()

err = mc.mapi.StartPush(wildcardPlaybackID, pushURL)
Expand Down
20 changes: 7 additions & 13 deletions internal/app/mistapiconnector/stats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,16 @@ func createMetricsEvent(nodeID, region string, info *streamInfo, metrics *stream
Bytes: push.Stats.Bytes,
MediaTimeMs: push.Stats.MediaTime,
}
mediaTime := time.Duration(metrics.MediaTimeMs) * time.Millisecond
if pushInfo.metrics == nil {
pushInfo.metrics = &pushMetrics{
pushedBytes: push.Stats.Bytes,
pushedMediaTime: mediaTime,
if last := pushInfo.metrics; last != nil {
if metrics.Bytes > last.Bytes {
census.IncMultistreamBytes(metrics.Bytes-last.Bytes, info.stream.PlaybackID) // manifestID === playbackID
}
} else {
if metrics.Bytes > pushInfo.metrics.pushedBytes {
census.IncMultistreamBytes(metrics.Bytes-pushInfo.metrics.pushedBytes, info.stream.PlaybackID) // manifestID === playbackID
pushInfo.metrics.pushedBytes = metrics.Bytes
}
if mediaTime > pushInfo.metrics.pushedMediaTime {
census.IncMultistreamTime(mediaTime-pushInfo.metrics.pushedMediaTime, info.stream.PlaybackID)
pushInfo.metrics.pushedMediaTime = mediaTime
if metrics.MediaTimeMs > last.MediaTimeMs {
diff := time.Duration(metrics.MediaTimeMs-last.MediaTimeMs) * time.Millisecond
census.IncMultistreamTime(diff, info.stream.PlaybackID)
}
}
pushInfo.metrics = metrics
}
multistream[i] = &data.MultistreamTargetMetrics{
Target: pushToMultistreamTargetInfo(pushInfo),
Expand Down

0 comments on commit a62a21d

Please sign in to comment.