|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using Microsoft.ApplicationInsights; |
5 | 7 | using NuGetGallery; |
6 | 8 |
|
7 | 9 | namespace NuGet.Services.Validation.Orchestrator.Telemetry |
8 | 10 | { |
9 | 11 | public class TelemetryService : ITelemetryService |
10 | 12 | { |
| 13 | + private const string Prefix = "Orchestrator."; |
| 14 | + |
| 15 | + private const string DurationToValidationSetCreationSeconds = Prefix + "DurationToValidationSetCreationSeconds"; |
| 16 | + private const string PackageStatusChange = Prefix + "PackageStatusChange"; |
| 17 | + private const string TotalValidationDurationSeconds = Prefix + "TotalValidationDurationSeconds"; |
| 18 | + private const string ValidationIssue = Prefix + "ValidationIssue"; |
| 19 | + private const string ValidationIssueCount = Prefix + "ValidationIssueCount"; |
| 20 | + private const string ValidatorTimeout = Prefix + "ValidatorTimeout"; |
| 21 | + private const string ValidatorDurationSeconds = Prefix + "ValidatorDurationSeconds"; |
| 22 | + private const string ValidatorStarted = Prefix + "ValidatorStarted"; |
| 23 | + private const string ClientValidationIssue = Prefix + "ClientValidationIssue"; |
| 24 | + |
| 25 | + private const string FromStatus = "FromStatus"; |
| 26 | + private const string ToStatus = "ToStatus"; |
| 27 | + private const string IsSuccess = "IsSuccess"; |
| 28 | + private const string ValidatorType = "ValidatorType"; |
| 29 | + private const string IssueCode = "IssueCode"; |
| 30 | + private const string ClientCode = "ClientCode"; |
| 31 | + |
| 32 | + private readonly TelemetryClient _telemetryClient; |
| 33 | + |
| 34 | + public TelemetryService(TelemetryClient telemetryClient) |
| 35 | + { |
| 36 | + _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); |
| 37 | + } |
| 38 | + |
11 | 39 | public void TrackDurationToValidationSetCreation(TimeSpan duration) |
12 | 40 | { |
| 41 | + _telemetryClient.TrackMetric( |
| 42 | + DurationToValidationSetCreationSeconds, |
| 43 | + duration.TotalSeconds); |
13 | 44 | } |
14 | 45 |
|
15 | 46 | public void TrackPackageStatusChange(PackageStatus fromStatus, PackageStatus toStatus) |
16 | 47 | { |
| 48 | + _telemetryClient.TrackMetric( |
| 49 | + PackageStatusChange, |
| 50 | + 1, |
| 51 | + new Dictionary<string, string> |
| 52 | + { |
| 53 | + { FromStatus, fromStatus.ToString() }, |
| 54 | + { ToStatus, toStatus.ToString() }, |
| 55 | + }); |
17 | 56 | } |
18 | 57 |
|
19 | 58 | public void TrackTotalValidationDuration(TimeSpan duration, bool isSuccess) |
20 | 59 | { |
| 60 | + _telemetryClient.TrackMetric( |
| 61 | + TotalValidationDurationSeconds, |
| 62 | + duration.TotalSeconds, |
| 63 | + new Dictionary<string, string> |
| 64 | + { |
| 65 | + { IsSuccess, isSuccess.ToString() }, |
| 66 | + }); |
21 | 67 | } |
22 | 68 |
|
23 | 69 | public void TrackValidationIssue(string validatorType, ValidationIssueCode code) |
24 | 70 | { |
| 71 | + _telemetryClient.TrackMetric( |
| 72 | + ValidationIssue, |
| 73 | + 1, |
| 74 | + new Dictionary<string, string> |
| 75 | + { |
| 76 | + { ValidatorType, validatorType }, |
| 77 | + { IssueCode, code.ToString() }, |
| 78 | + }); |
25 | 79 | } |
26 | 80 |
|
27 | 81 | public void TrackValidationIssueCount(int count, string validatorType, bool isSuccess) |
28 | 82 | { |
| 83 | + _telemetryClient.TrackMetric( |
| 84 | + ValidationIssueCount, |
| 85 | + count, |
| 86 | + new Dictionary<string, string> |
| 87 | + { |
| 88 | + { ValidatorType, validatorType }, |
| 89 | + { IsSuccess, isSuccess.ToString() }, |
| 90 | + }); |
29 | 91 | } |
30 | 92 |
|
31 | 93 | public void TrackValidatorTimeout(string validatorType) |
32 | 94 | { |
| 95 | + _telemetryClient.TrackMetric( |
| 96 | + ValidatorTimeout, |
| 97 | + 1, |
| 98 | + new Dictionary<string, string> |
| 99 | + { |
| 100 | + { ValidatorType, validatorType }, |
| 101 | + }); |
33 | 102 | } |
34 | 103 |
|
35 | 104 | public void TrackValidatorDuration(TimeSpan duration, string validatorType, bool isSuccess) |
36 | 105 | { |
| 106 | + _telemetryClient.TrackMetric( |
| 107 | + ValidatorDurationSeconds, |
| 108 | + duration.TotalSeconds, |
| 109 | + new Dictionary<string, string> |
| 110 | + { |
| 111 | + { ValidatorType, validatorType }, |
| 112 | + { IsSuccess, isSuccess.ToString() }, |
| 113 | + }); |
37 | 114 | } |
38 | 115 |
|
39 | 116 | public void TrackValidatorStarted(string validatorType) |
40 | 117 | { |
| 118 | + _telemetryClient.TrackMetric( |
| 119 | + ValidatorStarted, |
| 120 | + 1, |
| 121 | + new Dictionary<string, string> |
| 122 | + { |
| 123 | + { ValidatorType, validatorType }, |
| 124 | + }); |
41 | 125 | } |
42 | 126 |
|
43 | 127 | public void TrackClientValidationIssue(string validatorType, string clientCode) |
44 | 128 | { |
| 129 | + _telemetryClient.TrackMetric( |
| 130 | + ClientValidationIssue, |
| 131 | + 1, |
| 132 | + new Dictionary<string, string> |
| 133 | + { |
| 134 | + { ValidatorType, validatorType }, |
| 135 | + { ClientCode, clientCode }, |
| 136 | + }); |
45 | 137 | } |
46 | 138 | } |
47 | 139 | } |
0 commit comments