Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Renaming metrics to indicate the user interaction that caused them #719

Merged
merged 20 commits into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
61e0227
Renaming metrics values
StanleyGoldman May 7, 2018
3e2db8e
Making names more uniform
StanleyGoldman May 7, 2018
145a816
Renaming Initialized to ProjectsInitialized
StanleyGoldman May 7, 2018
baaab02
Adding metric for git lfs lock/unlock operations
StanleyGoldman May 7, 2018
d14c123
Merge remote-tracking branch 'remotes/origin/master' into fixes/metri…
StanleyGoldman May 7, 2018
13400e6
Merge remote-tracking branch 'remotes/origin/more-serialization-magic…
StanleyGoldman May 7, 2018
bf89a53
Merge more-serialization-magic into fixes/metrics-rename
shana May 8, 2018
d7198ba
Add metrics tests and move some code around so it's simpler to mock
shana May 8, 2018
c4beef8
Doh
shana May 8, 2018
ab5df1e
Always use DateTimeOffset for serialization
shana May 8, 2018
6ba2185
Add test for serializing/deserializing metrics from disk
shana May 8, 2018
a0bcffe
Merge more-serialization-magic into fixes/metrics-rename
shana May 8, 2018
1c27f01
Merge master into fixes/metrics-rename
shana May 8, 2018
1b48431
Add branch methods to Repository and fix handler hookups
shana May 8, 2018
c22472d
Do not call GitClient directly
shana May 8, 2018
9372ce7
This doesn't need to be in the UI thread
shana May 8, 2018
835baa3
Make sure things are called at the end of tasks
shana May 8, 2018
2d049ac
Merge master into fixes/metrics-rename
shana May 8, 2018
106dee9
Tweak the metrics names some more
shana May 8, 2018
6c1afe3
Adding metrics for publishing and opening the command line
StanleyGoldman May 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion script
6 changes: 2 additions & 4 deletions src/GitHub.Api/Application/ApplicationManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public ITask InitializeRepository()
})
.ThenInUI(() =>
{
TaskManager.Run(UsageTracker.IncrementNumberOfProjectsInitialized);
TaskManager.Run(UsageTracker.IncrementProjectsInitialized);
InitializeUI();
});
return task;
Expand All @@ -191,8 +191,6 @@ protected void SetupMetrics(string unityVersion, bool firstRun, Guid instanceId)
{
//Logger.Trace("Setup metrics");

var usagePath = Environment.UserCachePath.Combine(Constants.UsageFile);

string userId = null;
if (UserSettings.Exists(Constants.GuidKey))
{
Expand All @@ -212,7 +210,7 @@ protected void SetupMetrics(string unityVersion, bool firstRun, Guid instanceId)
Environment.NodeJsExecutablePath,
Environment.OctorunScriptPath);

UsageTracker = new UsageTracker(metricsService, UserSettings, usagePath, userId, unityVersion, instanceId.ToString());
UsageTracker = new UsageTracker(metricsService, UserSettings, Environment, userId, unityVersion, instanceId.ToString());

if (firstRun)
{
Expand Down
3 changes: 3 additions & 0 deletions src/GitHub.Api/Git/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,8 @@ public interface IRepository : IEquatable<IRepository>, IDisposable
ITask RemoteAdd(string remote, string url);
ITask RemoteRemove(string remote);
ITask Push(string remote);
ITask DeleteBranch(string branch, bool force);
ITask CreateBranch(string branch, string baseBranch);
ITask SwitchBranch(string branch);
}
}
3 changes: 3 additions & 0 deletions src/GitHub.Api/Git/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public ITask SetupRemote(string remote, string remoteUrl)
public ITask DiscardChanges(GitStatusEntry[] gitStatusEntry) => repositoryManager.DiscardChanges(gitStatusEntry);
public ITask RemoteAdd(string remote, string url) => repositoryManager.RemoteAdd(remote, url);
public ITask RemoteRemove(string remote) => repositoryManager.RemoteRemove(remote);
public ITask DeleteBranch(string branch, bool force) => repositoryManager.DeleteBranch(branch, force);
public ITask CreateBranch(string branch, string baseBranch) => repositoryManager.CreateBranch(branch, baseBranch);
public ITask SwitchBranch(string branch) => repositoryManager.SwitchBranch(branch);

public void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEvent cacheUpdateEvent) => cacheContainer.CheckAndRaiseEventsIfCacheNewer(cacheType, cacheUpdateEvent);

Expand Down
48 changes: 33 additions & 15 deletions src/GitHub.Api/Git/RepositoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,14 @@ public ITask DiscardChanges(GitStatusEntry[] gitStatusEntries)

if (itemsToRevert.Any())
{
task.Then(GitClient.Discard(itemsToRevert));
var next = GitClient.Discard(itemsToRevert);
HookupHandlers(next, true);
task.OnEnd -= HookupEndHandlerWithWatcher;
task.Then(next);
}
}
, () => gitStatusEntries);


return HookupHandlers(task, true);
}

Expand Down Expand Up @@ -459,21 +461,37 @@ private ITask HookupHandlers(ITask task, bool filesystemChangesExpected)
}
};

task.Finally(success =>
if (filesystemChangesExpected)
task.OnEnd += HookupEndHandlerWithWatcher;
else
task.OnEnd += HookupEndHandlerWithoutWatcher;
return task;
}

private void HookupEndHandlerWithWatcher(ITask task, bool success, Exception ex)
{
HookupEndHandler(task, true);
}

private void HookupEndHandlerWithoutWatcher(ITask task, bool success, Exception ex)
{
HookupEndHandler(task, false);
}

private void HookupEndHandler(ITask task, bool filesystemChangesExpected)
{
var isExclusive = task.IsChainExclusive();
if (filesystemChangesExpected)
{
if (filesystemChangesExpected)
{
//Logger.Trace("Ended Operation - Enable Watcher");
watcher.Start();
}
//Logger.Trace("Ended Operation - Enable Watcher");
watcher.Start();
}

if (isExclusive)
{
//Logger.Trace("Ended Operation - Clearing Busy Flag");
IsBusy = false;
}
});
return task;
if (isExclusive)
{
//Logger.Trace("Ended Operation - Clearing Busy Flag");
IsBusy = false;
}
}

private string GetCurrentHead()
Expand Down
42 changes: 15 additions & 27 deletions src/GitHub.Api/Metrics/IUsageTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,20 @@ public interface IUsageTracker
{
bool Enabled { get; set; }
void IncrementNumberOfStartups();
void IncrementNumberOfCommits();
void IncrementNumberOfFetches();
void IncrementNumberOfPushes();
void IncrementNumberOfPulls();
void IncrementNumberOfAuthentications();
void IncrementNumberOfProjectsInitialized();
void IncrementNumberOfLocalBranchCreations();
void IncrementNumberOfLocalBranchDeletions();
void IncrementNumberOfLocalBranchCheckouts();
void IncrementNumberOfRemoteBranchCheckouts();
}

class NullUsageTracker : IUsageTracker
{
public bool Enabled { get; set; }
public void IncrementNumberOfStartups() { }
public void IncrementNumberOfCommits() { }
public void IncrementNumberOfFetches() { }
public void IncrementNumberOfPushes() { }
public void IncrementNumberOfPulls() { }
public void IncrementNumberOfAuthentications() { }
public void IncrementNumberOfProjectsInitialized() { }
public void IncrementNumberOfLocalBranchCreations() { }
public void IncrementNumberOfLocalBranchDeletions() { }
public void IncrementNumberOfLocalBranchCheckouts() { }
public void IncrementNumberOfRemoteBranchCheckouts() { }
public void SetMetricsService(IMetricsService instance) { }
void IncrementChangesViewButtonCommit();
void IncrementHistoryViewToolbarFetch();
void IncrementHistoryViewToolbarPush();
void IncrementHistoryViewToolbarPull();
void IncrementAuthenticationViewButtonAuthentication();
void IncrementProjectsInitialized();
void IncrementBranchesViewButtonCreateBranch();
void IncrementBranchesViewButtonDeleteBranch();
void IncrementBranchesViewButtonCheckoutLocalBranch();
void IncrementBranchesViewButtonCheckoutRemoteBranch();
void IncrementSettingsViewButtonLfsUnlock();
void IncrementUnityProjectViewContextLfsLock();
void IncrementUnityProjectViewContextLfsUnlock();
void IncrementPublishViewButtonPublish();
void IncrementApplicationMenuMenuItemCommandLine();
}
}
40 changes: 26 additions & 14 deletions src/GitHub.Api/Metrics/UsageModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using GitHub.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace GitHub.Unity
{
Expand All @@ -15,7 +17,7 @@ public class Usage
public class Dimensions
{
public string Guid { get; set; }
public DateTime Date { get; set; }
public DateTimeOffset Date { get; set; }
public string AppVersion { get; set; }
public string UnityVersion { get; set; }
public string Lang { get; set; }
Expand All @@ -25,16 +27,21 @@ public class Dimensions
public class Measures
{
public int NumberOfStartups { get; set; }
public int Commits { get; set; }
public int Fetches { get; set; }
public int Pushes { get; set; }
public int Pulls { get; set; }
public int ProjectsInitialized { get; set; }
public int Authentications { get; set; }
public int LocalBranchCreations { get; set; }
public int LocalBranchDeletion { get; set; }
public int LocalBranchCheckouts { get; set; }
public int RemoteBranchCheckouts { get; set; }
public int ChangesViewButtonCommit { get; set; }
public int HistoryViewToolbarFetch { get; set; }
public int HistoryViewToolbarPush { get; set; }
public int HistoryViewToolbarPull { get; set; }
public int AuthenticationViewButtonAuthentication { get; set; }
public int BranchesViewButtonCreateBranch { get; set; }
public int BranchesViewButtonDeleteBranch { get; set; }
public int BranchesViewButtonCheckoutLocalBranch { get; set; }
public int BranchesViewButtonCheckoutRemoteBranch { get; set; }
public int SettingsViewButtonLfsUnlock { get; set; }
public int UnityProjectViewContextLfsLock { get; set; }
public int UnityProjectViewContextLfsUnlock { get; set; }
public int PublishViewButtonPublish { get; set; }
public int ApplicationMenuMenuItemCommandLine { get; set; }
}

class UsageModel
Expand All @@ -49,7 +56,7 @@ public Usage GetCurrentUsage(string appVersion, string unityVersion, string inst
Guard.ArgumentNotNullOrWhiteSpace(appVersion, "appVersion");
Guard.ArgumentNotNullOrWhiteSpace(unityVersion, "unityVersion");

var date = DateTime.UtcNow.Date;
var now = DateTimeOffset.Now;
if (currentUsage == null)
{
currentUsage = Reports
Expand All @@ -62,7 +69,7 @@ public Usage GetCurrentUsage(string appVersion, string unityVersion, string inst
{
InstanceId = instanceId,
Dimensions = {
Date = date,
Date = now,
Guid = Guid,
AppVersion = appVersion,
UnityVersion = unityVersion,
Expand All @@ -89,7 +96,12 @@ public void RemoveReports(DateTime beforeDate)

class UsageStore
{
public DateTimeOffset LastUpdated { get; set; } = DateTimeOffset.UtcNow;
public DateTimeOffset LastUpdated { get; set; } = DateTimeOffset.Now;
public UsageModel Model { get; set; } = new UsageModel();

public Measures GetCurrentMeasures(string appVersion, string unityVersion, string instanceId)
{
return Model.GetCurrentUsage(appVersion, unityVersion, instanceId).Measures;
}
}
}
Loading