Skip to content
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-59996] Make stats and client logs more easily accessible through slash commands #840

Merged
merged 7 commits into from
Aug 13, 2024

Conversation

streamer45
Copy link
Collaborator

Summary

PR fixes an issue with the /call stats command not working on the Desktop app. This bug has existed since we introduced the global widget, which is a different window and requires special handling in order to communicate any data back to the center channel (main app).

Here, we are using a trick that doesn't require touching the Desktop. We use the localStorage, which is shared between all the windows. This is a temporary solution while we work on a better path forward (MM-60028).

While we are here, I also wanted to address another significant limitation concerning Call logs. On Desktop, these would disappear along with the widget window as soon as the call dropped, making it almost impossible to debug network issues.

To address this, PR implements a convenient storage-backed /call logs command that returns the client logs for the last call session without requiring users to go through multiple hops (i.e., the console) in order to access them (see screenshot).

Screenshot

calls_logs

Ticket Link

https://mattermost.atlassian.net/browse/MM-59996
https://mattermost.atlassian.net/browse/MM-59995

@streamer45 streamer45 added 2: Dev Review Requires review by a core committer 3: Security Review labels Aug 7, 2024
@streamer45 streamer45 added this to the v1.0.0 🚀 / MM 10.0 milestone Aug 7, 2024
@streamer45 streamer45 self-assigned this Aug 7, 2024
Comment on lines 493 to 494
const storage = window.desktop ? localStorage : sessionStorage;
storage.setItem(STORAGE_CALLS_CLIENT_STATS_KEY, JSON.stringify(stats));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to overcomplicate it by adding listeners, so the stats are saved when the client disconnects (user leaves call) and can be retrieved after that.

This slightly differs from Web browser behavior, where stats can be fetched at any time during or after a call, but the simple fix is enough to cover the customer's use case (troubleshooting).

@@ -245,6 +264,17 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
return resp, nil
}

if subCmd == logsCommandTrigger {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if subCmd == subCommandCXyz { ... } format in this function is getting kind of long.
Either in this PR or another can we shorten it?

Maybe something like the following (or a switch):

if subCmd == subCommandXyz {
return subCommandXyzHelper()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, having a long function that reads simply top-to-bottom can be easier and quicker to read and understand, compared to having to jump back and forth to/from functions. So there's an argument for keeping it simple, too. :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpoile single responsibility principle + easier to write tests for / understand the code coverage, especially if you use an IDE tool that shows highlights for code coverage.

I'm fine with leaving it as is if nobody else thinks it's an issue, but it's definitely a code smell.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is I can make this change if you all want in another ticket.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enzowritescode I added a wrapping utility to clean it up a little. Let me know if that works.

webapp/src/client.ts Outdated Show resolved Hide resolved
Copy link
Member

@cpoile cpoile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Nice simple solution to a tough problem.

@@ -245,6 +264,17 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
return resp, nil
}

if subCmd == logsCommandTrigger {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, having a long function that reads simply top-to-bottom can be easier and quicker to read and understand, compared to having to jump back and forth to/from functions. So there's an argument for keeping it simple, too. :)

@@ -99,8 +104,8 @@ export default class CallsClient extends EventEmitter {
};
}

const defaultInputID = window.localStorage.getItem('calls_default_audio_input');
const defaultOutputID = window.localStorage.getItem('calls_default_audio_output');
const defaultInputID = window.localStorage.getItem(STORAGE_CALLS_DEFAULT_AUDIO_INPUT_KEY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

import {pluginId} from './manifest';

let clientLogs = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ js

@streamer45 streamer45 added 3: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer 3: Security Review labels Aug 13, 2024
@streamer45 streamer45 merged commit 8687852 into main Aug 13, 2024
19 checks passed
@streamer45 streamer45 deleted the MM-59996 branch August 13, 2024 09:45
streamer45 added a commit that referenced this pull request Sep 17, 2024
…slash commands (#840)

* Make stats and client logs more easily accessible through slash commands

* Util function

* Command response wrapper

* Fix e2e

* Revert "Fix e2e"

This reverts commit 7710471.

* Use Playbooks v2
streamer45 added a commit that referenced this pull request Sep 18, 2024
* [MM-59996] Make stats and client logs more easily accessible through slash commands (#840)

* Make stats and client logs more easily accessible through slash commands

* Util function

* Command response wrapper

* Fix e2e

* Revert "Fix e2e"

This reverts commit 7710471.

* Use Playbooks v2

* Fix e2e tests pipeline (#859)

* update e2e test pipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants