Skip to content

Conversation

@zeusongit
Copy link
Contributor

@zeusongit zeusongit commented Dec 4, 2023

Purpose

https://jira.autodesk.com/browse/DYN-6030

Add heartbeat ADP API to log active/idle user state.
This PR build will fail since we need the analytics PR first:https://git.autodesk.com/Dynamo/Analytics.NET/pull/70

Note: The Analytics method to track active/idle status will not trigger the API at each call, 
instead it will send out one call for every 4 minutes for each user and machine type activity. 
For example, if the method gets called 100 times in 8 minutes, then it will only trigger the 
HeartBeat API twice. This is to avoid sending out too many calls as the API expects a call 
every 5 minutes, to mark the user/machine active.

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB

Release Notes

  • Add active/idle state tracking for users

Reviewers

{
serviceInitialized.Wait();

lock (trackEventLockObj)
Copy link
Member

@mjkkirschner mjkkirschner Dec 5, 2023

Choose a reason for hiding this comment

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

hmm

@pinzart90 @BogdanZavu - What is this lock protecting?
ReportingAnalytics? Is that really going to be changing?

Because this task gets run when a user clicks the left mouse button it seems we're going to kick off a bunch of tasks that attempt to acquire this lock and wait for each other until these API calls return... is the lock really needed in this case?

Do we know how long these API calls take @zeusongit ?

Copy link
Contributor Author

@zeusongit zeusongit Dec 5, 2023

Choose a reason for hiding this comment

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

In debug build, it takes less than 1000 ticks (on average). First call was 3000, all proceeding calls were less than 500.

Copy link
Contributor

Choose a reason for hiding this comment

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

ReportingAnalytics? Is that really going to be changing? - mostlikely not but it is safer imo to have it like this. It does not buy us anything if it is outside, it will only exposes us to risk now and in the future if the implementation changes.

The lock is protecting from concurrent access into ADP api. In theory that is noted as being thread safe but there were reports with relatively simple use cases where surprisingly it is not. So to be on the safe side we have this lock.

using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Autodesk.ADPDesktopSDK;
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this namespace coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was coming from AdpSDKCSharpWrapper.dll

Copy link
Contributor

Choose a reason for hiding this comment

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

If we are ok with bleeding AdpSDKCSharpWrapper types directly in Dynamo, then makes me wonder why we need an entire Analytics project in between Dynamo and AdpSDKCSharpWrapper. Maybe it made sense when we had multiple analytics providers...but now.
I think it would make it somewhat simpler to consume if we referenced the binary directly in Dynamo and gave up on all the complicated logic of the Analytics.Core. Of course AdpSDKCSharpWrapper is an internal nuget package, so we would have to handle its distribution directly in Dynamo.

Of course if we think we might get into a situation with multiple analytics providers again, then I suggest we keep layer of separation intact

FYI @QilongTang @mjkkirschner

Copy link
Contributor

Choose a reason for hiding this comment

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

I see what was going on. When consuming the Analytics nuget pacakge, we now have access to the AdpSDKCSharpWrapper.dll at compile time
So any dev writing code could potentially access types directly from that assembly
There are ways to avoid this, like removing the adpsdk binrary from libs, and adding a build.props with a copy target.

@zeusongit zeusongit marked this pull request as ready for review December 6, 2023 17:45
@zeusongit zeusongit requested a review from QilongTang December 6, 2023 17:46
@BogdanZavu
Copy link
Contributor

Just curious overall why do we need to track this ? What are we looking for or what decision can we made based on this data to improve Dynamo ?

@QilongTang QilongTang added this to the 3.0 milestone Dec 7, 2023
public virtual IAnalyticsSession Session { get; private set; }

private DateTime LastMachineHBLogTime;
private DateTime LastUserHBLogTime;
Copy link
Member

@mjkkirschner mjkkirschner Dec 7, 2023

Choose a reason for hiding this comment

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

since I don't see these fields set anywhere initially, won't they always be null and no events will ever be sent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DateTime types are initiated with a default value just like booleans

Copy link
Member

Choose a reason for hiding this comment

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

ah it's a struct

Export
}

public enum HeartBeatType
Copy link
Member

Choose a reason for hiding this comment

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

does this need to be public?

Copy link
Member

Choose a reason for hiding this comment

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

I guess it does if the method is public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@mjkkirschner
Copy link
Member

Just curious overall why do we need to track this ? What are we looking for or what decision can we made based on this data to improve Dynamo ?

I'm curious about the premise of using this data as well because I feel that impacts what "active" means.
Is a graph executing for 30 minutes active? the user will not be clicking during this time.

@zeusongit
Copy link
Contributor Author

Just curious overall why do we need to track this ? What are we looking for or what decision can we made based on this data to improve Dynamo ?

I'm curious about the premise of using this data as well because I feel that impacts what "active" means. Is a graph executing for 30 minutes active? the user will not be clicking during this time.

@mjkkirschner There is a separate identifier for when the machine is active/idle, it will log exactly the cases you mentioned, i.e the machine is active but the user is or maybe idle.
We do not have a comprehensive implementation of this at the moment, but it should be the next step, that is when a graph is running for like 30 minutes, we should send a heart beat every 5 minutes to indicate that the machine is active, currently we are sending one beat per machine execution, so if the execution takes longer than 5 minutes we may still have a single heartbeat log indicating that the machine was active for 5 minutes, but we will improve that.

@zeusongit
Copy link
Contributor Author

Re-triggered the Analytics build, after the nugets are generated build should pass.

@github-actions
Copy link

github-actions bot commented Dec 7, 2023

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net8.0

@github-actions
Copy link

github-actions bot commented Dec 7, 2023

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net6.0

/// as the API expects a call every 5 minutes, to mark the user/machine active.
/// </summary>
/// <param name="activityType">Value must be either Machine or User. If no value is provided the API will default to user activity type.</param>
public void TrackActivityStatus(string activityType)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we expect this API to be used by externally ?
shouldn;t this be internal to dynamo ?

Copy link
Contributor Author

@zeusongit zeusongit Dec 11, 2023

Choose a reason for hiding this comment

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

@mjkkirschner
Copy link
Member

@zeusongit I think you should add a test to ensure your code does what you think it does and that the behavior does not change.

@zeusongit
Copy link
Contributor Author

@zeusongit I think you should add a test to ensure your code does what you think it does and that the behavior does not change.

@mjkkirschner I can add track activity status to the current analytics test, but I don't think the current Moq implementation of the Analytics will be able to completely test the functionality of this method, for e.g how to test that it will send off 1 log for each activity type in a 4 minute period.

@mjkkirschner
Copy link
Member

@zeusongit I think you should add a test to ensure your code does what you think it does and that the behavior does not change.

@mjkkirschner I can add track activity status to the current analytics test, but I don't think the current Moq implementation of the Analytics will be able to completely test the functionality of this method, for e.g how to test that it will send off 1 log for each activity type in a 4 minute period.

you should make your code testable - you can have the timeout be a parameter and set it lower for the test.

@github-actions
Copy link

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net8.0

@github-actions
Copy link

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net6.0

@github-actions
Copy link

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net6.0

@github-actions
Copy link

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net8.0

@zeusongit
Copy link
Contributor Author

@zeusongit I think you should add a test to ensure your code does what you think it does and that the behavior does not change.

@mjkkirschner I can add track activity status to the current analytics test, but I don't think the current Moq implementation of the Analytics will be able to completely test the functionality of this method, for e.g how to test that it will send off 1 log for each activity type in a 4 minute period.

you should make your code testable - you can have the timeout be a parameter and set it lower for the test.

@mjkkirschner parametrization is not a problem here, the problem is to track if the ADP service actually recorded the log, verifying the Moq instance for invocation will not record the desired result. After discussion with the team we have decided to go forward with the current state, and file a separate task to improve the machine active/idle time tracking in the future release.

@zeusongit zeusongit merged commit cfad5a1 into DynamoDS:master Dec 13, 2023
zeusongit added a commit to zeusongit/Dynamo that referenced this pull request Dec 13, 2023
* Fix PostDiff job

* log heartbeat

* Optimize logging and add mouse and key press events log

* Update DynamoAnalyticsClient.cs

* add machine tracking status

* comments

* Update Analytics nuget

* add to test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants