-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Update Analytics to use new API #6221
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
base: develop
Are you sure you want to change the base?
Changes from all commits
5ca12f4
5e5dfa1
b13ca87
876d97e
568e053
195cd47
363d3da
4ea383b
6bdd41c
f019339
95c13d7
7592ecf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,24 +24,6 @@ namespace Unity.MLAgents.Analytics | |
{ | ||
internal class InferenceAnalytics | ||
{ | ||
const string k_VendorKey = "unity.ml-agents"; | ||
const string k_EventName = "ml_agents_inferencemodelset"; | ||
const int k_EventVersion = 1; | ||
|
||
/// <summary> | ||
/// Whether or not we've registered this particular event yet | ||
/// </summary> | ||
static bool s_EventRegistered; | ||
|
||
/// <summary> | ||
/// Hourly limit for this event name | ||
/// </summary> | ||
const int k_MaxEventsPerHour = 1000; | ||
|
||
/// <summary> | ||
/// Maximum number of items in this event. | ||
/// </summary> | ||
const int k_MaxNumberOfElements = 1000; | ||
|
||
|
||
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS | ||
|
@@ -54,25 +36,17 @@ internal class InferenceAnalytics | |
static bool EnableAnalytics() | ||
{ | ||
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS | ||
if (s_EventRegistered) | ||
{ | ||
return true; | ||
} | ||
|
||
AnalyticsResult result = EditorAnalytics.RegisterEventWithLimit(k_EventName, k_MaxEventsPerHour, k_MaxNumberOfElements, k_VendorKey, k_EventVersion); | ||
if (result == AnalyticsResult.Ok) | ||
{ | ||
s_EventRegistered = true; | ||
} | ||
if (s_EventRegistered && s_SentModels == null) | ||
if (s_SentModels == null) | ||
{ | ||
s_SentModels = new HashSet<ModelAsset>(); | ||
} | ||
|
||
return true; | ||
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. EnableAnalytics() always returns true if the conditions apply, i.e. UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS. Is that OK? We don't RegisterEvent anymore in the new API. |
||
|
||
#else // no editor, no analytics | ||
s_EventRegistered = false; | ||
return false; | ||
#endif | ||
return s_EventRegistered; | ||
} | ||
|
||
public static bool IsAnalyticsEnabled() | ||
|
@@ -127,7 +101,7 @@ IList<IActuator> actuators | |
// Debug.Log(JsonUtility.ToJson(data, true)); | ||
if (AnalyticsUtils.s_SendEditorAnalytics) | ||
{ | ||
EditorAnalytics.SendEventWithLimit(k_EventName, data, k_EventVersion); | ||
EditorAnalytics.SendAnalytic(data); | ||
} | ||
#endif | ||
} | ||
|
@@ -156,7 +130,7 @@ IList<IActuator> actuators | |
var inferenceEvent = new InferenceEvent(); | ||
|
||
// Hash the behavior name so that there's no concern about PII or "secret" data being leaked. | ||
inferenceEvent.BehaviorName = AnalyticsUtils.Hash(k_VendorKey, behaviorName); | ||
inferenceEvent.BehaviorName = AnalyticsUtils.Hash(AnalyticsConstants.k_VendorKey, behaviorName); | ||
|
||
inferenceEvent.SentisModelVersion = sentisModelInfo.Version; | ||
inferenceEvent.SentisModelProducer = sentisModel.ProducerName; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,35 +23,9 @@ namespace Unity.MLAgents.Analytics | |
{ | ||
internal static class TrainingAnalytics | ||
{ | ||
const string k_VendorKey = "unity.ml-agents"; | ||
const string k_TrainingEnvironmentInitializedEventName = "ml_agents_training_environment_initialized"; | ||
const string k_TrainingBehaviorInitializedEventName = "ml_agents_training_behavior_initialized"; | ||
const string k_RemotePolicyInitializedEventName = "ml_agents_remote_policy_initialized"; | ||
|
||
private static readonly string[] s_EventNames = | ||
{ | ||
k_TrainingEnvironmentInitializedEventName, | ||
k_TrainingBehaviorInitializedEventName, | ||
k_RemotePolicyInitializedEventName | ||
}; | ||
|
||
/// <summary> | ||
/// Hourly limit for this event name | ||
/// </summary> | ||
const int k_MaxEventsPerHour = 1000; | ||
|
||
/// <summary> | ||
/// Maximum number of items in this event. | ||
/// </summary> | ||
const int k_MaxNumberOfElements = 1000; | ||
|
||
private static bool s_SentEnvironmentInitialized; | ||
|
||
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS | ||
/// <summary> | ||
/// Whether or not we've registered this particular event yet | ||
/// </summary> | ||
static bool s_EventsRegistered; | ||
|
||
/// <summary> | ||
/// Behaviors that we've already sent events for. | ||
|
@@ -69,19 +43,6 @@ internal static class TrainingAnalytics | |
internal static bool EnableAnalytics() | ||
{ | ||
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS | ||
if (s_EventsRegistered) | ||
{ | ||
return true; | ||
} | ||
foreach (var eventName in s_EventNames) | ||
{ | ||
AnalyticsResult result = EditorAnalytics.RegisterEventWithLimit(eventName, k_MaxEventsPerHour, k_MaxNumberOfElements, k_VendorKey); | ||
if (result != AnalyticsResult.Ok) | ||
{ | ||
return false; | ||
} | ||
} | ||
s_EventsRegistered = true; | ||
|
||
if (s_SentRemotePolicyInitialized == null) | ||
{ | ||
|
@@ -90,7 +51,7 @@ internal static bool EnableAnalytics() | |
s_TrainingSessionGuid = Guid.NewGuid(); | ||
} | ||
|
||
return s_EventsRegistered; | ||
return true; | ||
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. EnableAnalytics() always returns true if the conditions apply, i.e. UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS. Is that OK? We don't RegisterEvent anymore in the new API. |
||
#else | ||
return false; | ||
#endif // MLA_UNITY_ANALYTICS_MODULE | ||
|
@@ -137,12 +98,12 @@ public static void TrainingEnvironmentInitialized(TrainingEnvironmentInitialized | |
|
||
// Note - to debug, use JsonUtility.ToJson on the event. | ||
// Debug.Log( | ||
// $"Would send event {k_TrainingEnvironmentInitializedEventName} with body {JsonUtility.ToJson(tbiEvent, true)}" | ||
// $"Would send event ml_agents_training_environment_initialized with body {JsonUtility.ToJson(tbiEvent, true)}" | ||
// ); | ||
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE && ENABLE_CLOUD_SERVICES_ANALYTICS | ||
if (AnalyticsUtils.s_SendEditorAnalytics) | ||
{ | ||
EditorAnalytics.SendEventWithLimit(k_TrainingEnvironmentInitializedEventName, tbiEvent); | ||
EditorAnalytics.SendAnalytic(tbiEvent); | ||
} | ||
#endif | ||
} | ||
|
@@ -175,11 +136,11 @@ IList<IActuator> actuators | |
var data = GetEventForRemotePolicy(behaviorName, sensors, actionSpec, actuators); | ||
// Note - to debug, use JsonUtility.ToJson on the event. | ||
// Debug.Log( | ||
// $"Would send event {k_RemotePolicyInitializedEventName} with body {JsonUtility.ToJson(data, true)}" | ||
// $"Would send event ml_agents_remote_policy_initialized with body {JsonUtility.ToJson(data, true)}" | ||
// ); | ||
if (AnalyticsUtils.s_SendEditorAnalytics) | ||
{ | ||
EditorAnalytics.SendEventWithLimit(k_RemotePolicyInitializedEventName, data); | ||
EditorAnalytics.SendAnalytic(data); | ||
} | ||
#endif | ||
} | ||
|
@@ -203,7 +164,7 @@ internal static TrainingBehaviorInitializedEvent SanitizeTrainingBehaviorInitial | |
// Context: The config field was added at the same time as trainer side hashing, so messages including it should already be hashed. | ||
if (tbiEvent.Config.Length == 0 || tbiEvent.BehaviorName.Length != 64) | ||
{ | ||
tbiEvent.BehaviorName = AnalyticsUtils.Hash(k_VendorKey, tbiEvent.BehaviorName); | ||
tbiEvent.BehaviorName = AnalyticsUtils.Hash(AnalyticsConstants.k_VendorKey, tbiEvent.BehaviorName); | ||
} | ||
|
||
return tbiEvent; | ||
|
@@ -233,11 +194,11 @@ public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent | |
|
||
// Note - to debug, use JsonUtility.ToJson on the event. | ||
// Debug.Log( | ||
// $"Would send event {k_TrainingBehaviorInitializedEventName} with body {JsonUtility.ToJson(tbiEvent, true)}" | ||
// $"Would send event ml_agents_training_behavior_initialized with body {JsonUtility.ToJson(tbiEvent, true)}" | ||
// ); | ||
if (AnalyticsUtils.s_SendEditorAnalytics) | ||
{ | ||
EditorAnalytics.SendEventWithLimit(k_TrainingBehaviorInitializedEventName, tbiEvent); | ||
EditorAnalytics.SendAnalytic(tbiEvent); | ||
} | ||
#endif | ||
} | ||
|
@@ -252,7 +213,7 @@ IList<IActuator> actuators | |
var remotePolicyEvent = new RemotePolicyInitializedEvent(); | ||
|
||
// Hash the behavior name so that there's no concern about PII or "secret" data being leaked. | ||
remotePolicyEvent.BehaviorName = AnalyticsUtils.Hash(k_VendorKey, behaviorName); | ||
remotePolicyEvent.BehaviorName = AnalyticsUtils.Hash(AnalyticsConstants.k_VendorKey, behaviorName); | ||
|
||
remotePolicyEvent.TrainingSessionGuid = s_TrainingSessionGuid.ToString(); | ||
remotePolicyEvent.ActionSpec = EventActionSpec.FromActionSpec(actionSpec); | ||
|
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.
any objections to do a cleanup first? Anything else is using /tmp/.dotnet/shm?