-
Notifications
You must be signed in to change notification settings - Fork 459
fix: Report messages properly that are locally executed as 0 bytes #1162
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
Conversation
var bytesReported = m_NetworkManager.LocalClientId == clientId | ||
? 0 | ||
: stream.Length; | ||
|
||
if (SceneEventData.SceneEventType == SceneEventData.SceneEventTypes.S2C_Sync) | ||
{ | ||
// For this event the server may be sending scene event data about multiple scenes, so we need | ||
// to track a metric for each one. | ||
foreach (var sceneIndex in SceneEventData.ScenesToSynchronize) | ||
{ | ||
m_NetworkManager.NetworkMetrics.TrackSceneEventReceived( | ||
clientId, (uint)SceneEventData.SceneEventType, ScenesInBuild[(int)sceneIndex], stream.Length); | ||
clientId, (uint)SceneEventData.SceneEventType, ScenesInBuild[(int)sceneIndex], bytesReported); | ||
} | ||
} | ||
else | ||
{ | ||
// For all other scene event types, we are only dealing with one scene at a time, so we can read it | ||
// from the SceneEventData directly. | ||
m_NetworkManager.NetworkMetrics.TrackSceneEventReceived( | ||
clientId, (uint)SceneEventData.SceneEventType, ScenesInBuild[(int)SceneEventData.SceneIndex], stream.Length); | ||
clientId, (uint)SceneEventData.SceneEventType, ScenesInBuild[(int)SceneEventData.SceneIndex], bytesReported); |
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.
I think this is getting refactored in Josie's PR FYI
Tests are failing with latest commit. Although I'm a little concerned that it's just the NetworkVariableDelta tests that are failing, not the others. These tests were supposed to validate byte counts. |
f711f88
to
021d8a0
Compare
021d8a0
to
a02dfee
Compare
} | ||
|
||
var bytesReported = NetworkManager.LocalClientId == clientId | ||
? 0 |
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.
nit: a comment explaining why we return 0 here might be useful (like "not a failure but success with 0") — also applies to other 0 returning ternaries below.
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.
🚀
eea5634
to
5c5647c
Compare
var bytesReported = m_NetworkManager.LocalClientId == clientId | ||
? 0 | ||
: size; |
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.
Late feedback on this part, but I wonder if it makes sense to add an internal utility function to network manager? Something like m_NetworkManager.GetBytesForMetricReporting(clientId, size);
.
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.
I mean at that point it could be part of the BufferSizeCapture utility class
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.
Maybe, I don't know if BufferSizeCapture should know anything about client ids though. this eval only work if you know networkManager.LocalClientId
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 is one statement. I don't see too huge of a reason to refactor a single statement into a function
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.
I mainly proposed this because you're using the same pattern a bunch of times across the codebase, so it is a bit of a code smell. I agree that for such a small expression it's not a big deal
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.
Yeah, I agree with Beck. I know it's just one statement, but anywhere these functions are used without this statement will be a bug that's inconsistent with the others, so I think there should be a function that can be called that takes care of this ternary as well
42e1133
to
46a8a76
Compare
var bytesReported = NetworkManager.LocalClientId == client.Key | ||
? 0 | ||
: messageSize; | ||
NetworkManager.NetworkMetrics.TrackRpcSent( | ||
client.Key, | ||
NetworkObjectId, | ||
rpcMethodName, | ||
__getTypeName(), | ||
bytesReported); |
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 pattern of computing bytesReported
is repeated so often that personally I think it should be extracted out to other function(s) before merging. As is this is a little fragile, because any of these Track
functions called without the ternary will be result in bugs as their behavior will be inconsistent with the rest. I think this work could be done in the NetworkMetrics
Track functions themselves, so that at least all of this is taken care of in one file if it can't be done in a single function.
using NUnit.Framework; | ||
using Unity.Multiplayer.Tools.MetricTypes; | ||
using Unity.Netcode.RuntimeTests.Metrics.Utility; | ||
using Unity.Netcode.RuntimeTests.Metrics.Utlity; |
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.
Shouldn't this be removed now too?
I think there's still a few missing test updates - it looks like the test pattern worked for the ones you added which is great, but you've modified more cases than the tests you've updated and I think it's important that the change in behavior is verified for all the cases. For example, the Object Destroy case was updated to report 0 for local execution but the test wasn't updated to verify it. I think it should be as simple as applying your new method to those tests though |
|
Oh, sorry about that. Somehow I missed it! |
…ty-Technologies/com.unity.multiplayer.mlapi into sam/feature/client-network-transform * 'sam/feature/client-network-transform' of github.com:Unity-Technologies/com.unity.multiplayer.mlapi: fix: Report messages properly that are locally executed as 0 bytes (#1162)
…transform-teleport * sam/feature/client-network-transform: adding some tests todo all current tests pass fixed tests, interpolation was depending on network manager singleton, this didn't do well in multiinstance tests removing useless comments removing useless sample, adding delta input per Matt's design missing private adding compression, owner check, dirty check adding input based transform sample fixing CI issues test: build multiprocesstestplayer and add it to project tests job (#1174) reenabling net transform tests fix: Report messages properly that are locally executed as 0 bytes (#1162)
…nity-Technologies#1162) * fix: Report messages properly that are locally executed as 0 bytes * Fix: we can run tests from internal classes * fix: whitespace * chore: Fixing namespace
No description provided.