-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MM-62410] Automatically cleanup stale calls in RTCD enabled deployments #940
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 132 additions & 1 deletion
133
.../mocks/github.com/mattermost/mattermost-plugin-calls/server/interfaces/mock_RTCDClient.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"fmt" | ||
"math/rand" | ||
"net" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"strings" | ||
|
@@ -21,6 +22,7 @@ import ( | |
"github.com/mattermost/mattermost-plugin-calls/server/db" | ||
"github.com/mattermost/mattermost-plugin-calls/server/interfaces" | ||
"github.com/mattermost/mattermost-plugin-calls/server/license" | ||
"github.com/mattermost/mattermost-plugin-calls/server/public" | ||
|
||
rtcd "github.com/mattermost/rtcd/service" | ||
"github.com/mattermost/rtcd/service/random" | ||
|
@@ -706,3 +708,54 @@ func (h *rtcdHost) isFlagged() bool { | |
defer h.mut.RUnlock() | ||
return h.flagged | ||
} | ||
|
||
// hasCallEnded checks if the call has ended by querying the RTCD host assigned to the call. | ||
// Since this method is used to clean up the call state, it's important to be as conservative as possible | ||
// and only return true if we are absolutely sure the call has ended. | ||
func (m *rtcdClientManager) hasCallEnded(call *public.Call) bool { | ||
m.ctx.LogDebug("RTCD host is set in call, checking...", "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
host := m.getHost(call.Props.RTCDHost) | ||
if host != nil { | ||
m.ctx.LogDebug("RTCD host found", "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
|
||
// Version compatibility check. We need to be talking to RTCD v1.0.0 or higher to be able to call GetSessions. | ||
info, err := host.client.GetVersionInfo() | ||
if err != nil { | ||
m.ctx.LogDebug("failed to get version info", "err", err.Error(), "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
return false | ||
} | ||
|
||
// Always support dev builds. | ||
if info.BuildVersion == "" || info.BuildVersion == "master" || strings.HasPrefix(info.BuildVersion, "dev") { | ||
m.ctx.LogDebug("skipping version compatibility check", "buildVersion", info.BuildVersion, "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
} else if err := checkMinVersion("v1.0.0", info.BuildVersion); err != nil { | ||
m.ctx.LogDebug("RTCD host version is not compatible", "err", err.Error(), "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
return false | ||
} | ||
|
||
cfgs, code, err := host.client.GetSessions(call.ID) | ||
if err != nil { | ||
m.ctx.LogDebug("failed to get sessions for call", "err", err.Error(), "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
} | ||
|
||
if code != http.StatusOK && code != http.StatusNotFound { | ||
m.ctx.LogDebug("unexpected status code from RTCD", "code", code, "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
// The request above could fail for various reasons, in which case we can't assume the call has ended. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, this confirms the default behavior. Maybe add this comment to the above as well? (would just save some cognitive overhead) |
||
return false | ||
} | ||
|
||
if len(cfgs) > 0 { | ||
// The call is ongoing so we skip state cleanup. | ||
m.ctx.LogDebug("call is still ongoing", "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
return false | ||
} | ||
|
||
// no call ongoing | ||
m.ctx.LogDebug("call was not found", "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
} else { | ||
// If the host is not found we can assume the RTCD node is gone for good so there's no way a call would be ongoing. | ||
m.ctx.LogDebug("RTCD host not found", "callID", call.ID, "rtcdHost", call.Props.RTCDHost) | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This defaults to call is still running if there's a problem getting the version info -- will that cause trouble? Should we return the err and have logic for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A stuck call is strictly better than killing a live call, so unless we get a guarantee from the RTCD side that the call has ended, we err on the side of caution.