-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gh-1150] Re-add feature tracking as server-side metrics
- Loading branch information
Showing
43 changed files
with
1,148 additions
and
971 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using SharpLab.Server.Monitoring; | ||
|
||
namespace SharpLab.Server.Caching; | ||
|
||
public class CachingTracker : ICachingTracker { | ||
private readonly IMetricMonitor _cacheableRequestCountMonitor; | ||
private readonly IMetricMonitor _noCacheRequestCountMonitor; | ||
private readonly IMetricMonitor _blobUploadRequestCountMonitor; | ||
private readonly IMetricMonitor _blobUploadErrorCountMonitor; | ||
|
||
public CachingTracker(MetricMonitorFactory createMonitor) { | ||
_cacheableRequestCountMonitor = createMonitor("caching", "Caching: Cacheable Requests"); | ||
_noCacheRequestCountMonitor = createMonitor("caching", "Caching: No-Cache Requests"); | ||
_blobUploadRequestCountMonitor = createMonitor("caching", "Caching: Blob Upload Requests"); | ||
_blobUploadErrorCountMonitor = createMonitor("caching", "Caching: Blob Upload Errors"); | ||
} | ||
|
||
public void TrackCacheableRequest() => _cacheableRequestCountMonitor.Track(1); | ||
public void TrackNoCacheRequest() => _noCacheRequestCountMonitor.Track(1); | ||
public void TrackBlobUploadRequest() => _blobUploadRequestCountMonitor.Track(1); | ||
public void TrackBlobUploadError() => _blobUploadErrorCountMonitor.Track(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SharpLab.Server.Caching; | ||
|
||
public interface ICachingTracker { | ||
void TrackBlobUploadError(); | ||
void TrackBlobUploadRequest(); | ||
void TrackCacheableRequest(); | ||
void TrackNoCacheRequest(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using SharpLab.Server.Monitoring; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace SharpLab.Server.Common; | ||
|
||
public class FeatureTracker : IFeatureTracker { | ||
private readonly IMetricMonitor _branchMonitor; | ||
private readonly IReadOnlyDictionary<string, IMetricMonitor> _languageMetricMonitors; | ||
private readonly IReadOnlyDictionary<string, IMetricMonitor> _targetMetricMonitors; | ||
private readonly IMetricMonitor _optimizeDebugMonitor; | ||
private readonly IMetricMonitor _optimizeReleaseMonitor; | ||
|
||
public FeatureTracker(MetricMonitorFactory createMonitor, string webAppName) { | ||
_branchMonitor = createMonitor("feature", $"Branch: {webAppName}"); | ||
_languageMetricMonitors = LanguageNames.All.ToDictionary( | ||
name => name, | ||
name => createMonitor("feature", $"Language: {name}") | ||
); | ||
_targetMetricMonitors = TargetNames.All.ToDictionary( | ||
name => name, | ||
name => createMonitor("feature", $"Target: {name}") | ||
); | ||
|
||
_optimizeDebugMonitor = createMonitor("feature", "Optimize: Debug"); | ||
_optimizeReleaseMonitor = createMonitor("feature", "Optimize: Release"); | ||
} | ||
|
||
public void TrackBranch() { | ||
_branchMonitor.Track(1); | ||
} | ||
|
||
public void TrackLanguage(string languageName) { | ||
if (_languageMetricMonitors.TryGetValue(languageName, out var metricMonitor)) | ||
metricMonitor.Track(1); | ||
} | ||
|
||
public void TrackTarget(string targetName) { | ||
if (_targetMetricMonitors.TryGetValue(targetName, out var metricMonitor)) | ||
metricMonitor.Track(1); | ||
} | ||
|
||
public void TrackOptimize(string? optimize) { | ||
var monitor = optimize switch { | ||
Optimize.Debug => _optimizeDebugMonitor, | ||
Optimize.Release => _optimizeReleaseMonitor, | ||
_ => null | ||
}; | ||
monitor?.Track(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SharpLab.Server.Common; | ||
|
||
public interface IFeatureTracker { | ||
void TrackBranch(); | ||
void TrackLanguage(string languageName); | ||
void TrackTarget(string targetName); | ||
void TrackOptimize(string? optimize); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
using System.Collections.Immutable; | ||
using CodeAnalysis = Microsoft.CodeAnalysis; | ||
|
||
namespace SharpLab.Server.Common { | ||
public class LanguageNames { | ||
public const string CSharp = CodeAnalysis.LanguageNames.CSharp; | ||
public const string VisualBasic = CodeAnalysis.LanguageNames.VisualBasic; | ||
public const string FSharp = CodeAnalysis.LanguageNames.FSharp; | ||
public const string IL = "IL"; | ||
} | ||
namespace SharpLab.Server.Common; | ||
public class LanguageNames { | ||
public const string CSharp = CodeAnalysis.LanguageNames.CSharp; | ||
public const string VisualBasic = CodeAnalysis.LanguageNames.VisualBasic; | ||
public const string FSharp = CodeAnalysis.LanguageNames.FSharp; | ||
public const string IL = "IL"; | ||
|
||
|
||
public static readonly ImmutableArray<string> All = [ | ||
CSharp, VisualBasic, FSharp, IL | ||
]; | ||
} |
Oops, something went wrong.