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

Commit eafa854

Browse files
committed
Integrate orchestrator telemetry with Application Insights (#319)
Address NuGet/NuGetGallery#4652
1 parent 52fc47a commit eafa854

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

src/NuGet.Services.Validation.Orchestrator/Job.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Autofac;
1111
using Autofac.Core;
1212
using Autofac.Extensions.DependencyInjection;
13+
using Microsoft.ApplicationInsights;
1314
using Microsoft.Extensions.Configuration;
1415
using Microsoft.Extensions.DependencyInjection;
1516
using Microsoft.Extensions.Logging;
@@ -22,6 +23,7 @@
2223
using NuGet.Jobs.Validation.PackageSigning.Storage;
2324
using NuGet.Services.Configuration;
2425
using NuGet.Services.KeyVault;
26+
using NuGet.Services.Logging;
2527
using NuGet.Services.ServiceBus;
2628
using NuGet.Services.Validation.Orchestrator.Telemetry;
2729
using NuGet.Services.Validation.PackageCertificates;
@@ -209,6 +211,7 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo
209211
services.AddTransient<ICoreMessageService, CoreMessageService>();
210212
services.AddTransient<IMessageService, MessageService>();
211213
services.AddTransient<ITelemetryService, TelemetryService>();
214+
services.AddSingleton(new TelemetryClient());
212215
}
213216

214217
private static IServiceProvider CreateProvider(IServiceCollection services)

src/NuGet.Services.Validation.Orchestrator/Telemetry/TelemetryService.cs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,138 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
6+
using Microsoft.ApplicationInsights;
57
using NuGetGallery;
68

79
namespace NuGet.Services.Validation.Orchestrator.Telemetry
810
{
911
public class TelemetryService : ITelemetryService
1012
{
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+
1139
public void TrackDurationToValidationSetCreation(TimeSpan duration)
1240
{
41+
_telemetryClient.TrackMetric(
42+
DurationToValidationSetCreationSeconds,
43+
duration.TotalSeconds);
1344
}
1445

1546
public void TrackPackageStatusChange(PackageStatus fromStatus, PackageStatus toStatus)
1647
{
48+
_telemetryClient.TrackMetric(
49+
PackageStatusChange,
50+
1,
51+
new Dictionary<string, string>
52+
{
53+
{ FromStatus, fromStatus.ToString() },
54+
{ ToStatus, toStatus.ToString() },
55+
});
1756
}
1857

1958
public void TrackTotalValidationDuration(TimeSpan duration, bool isSuccess)
2059
{
60+
_telemetryClient.TrackMetric(
61+
TotalValidationDurationSeconds,
62+
duration.TotalSeconds,
63+
new Dictionary<string, string>
64+
{
65+
{ IsSuccess, isSuccess.ToString() },
66+
});
2167
}
2268

2369
public void TrackValidationIssue(string validatorType, ValidationIssueCode code)
2470
{
71+
_telemetryClient.TrackMetric(
72+
ValidationIssue,
73+
1,
74+
new Dictionary<string, string>
75+
{
76+
{ ValidatorType, validatorType },
77+
{ IssueCode, code.ToString() },
78+
});
2579
}
2680

2781
public void TrackValidationIssueCount(int count, string validatorType, bool isSuccess)
2882
{
83+
_telemetryClient.TrackMetric(
84+
ValidationIssueCount,
85+
count,
86+
new Dictionary<string, string>
87+
{
88+
{ ValidatorType, validatorType },
89+
{ IsSuccess, isSuccess.ToString() },
90+
});
2991
}
3092

3193
public void TrackValidatorTimeout(string validatorType)
3294
{
95+
_telemetryClient.TrackMetric(
96+
ValidatorTimeout,
97+
1,
98+
new Dictionary<string, string>
99+
{
100+
{ ValidatorType, validatorType },
101+
});
33102
}
34103

35104
public void TrackValidatorDuration(TimeSpan duration, string validatorType, bool isSuccess)
36105
{
106+
_telemetryClient.TrackMetric(
107+
ValidatorDurationSeconds,
108+
duration.TotalSeconds,
109+
new Dictionary<string, string>
110+
{
111+
{ ValidatorType, validatorType },
112+
{ IsSuccess, isSuccess.ToString() },
113+
});
37114
}
38115

39116
public void TrackValidatorStarted(string validatorType)
40117
{
118+
_telemetryClient.TrackMetric(
119+
ValidatorStarted,
120+
1,
121+
new Dictionary<string, string>
122+
{
123+
{ ValidatorType, validatorType },
124+
});
41125
}
42126

43127
public void TrackClientValidationIssue(string validatorType, string clientCode)
44128
{
129+
_telemetryClient.TrackMetric(
130+
ClientValidationIssue,
131+
1,
132+
new Dictionary<string, string>
133+
{
134+
{ ValidatorType, validatorType },
135+
{ ClientCode, clientCode },
136+
});
45137
}
46138
}
47139
}

0 commit comments

Comments
 (0)