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

Commit 876ca9d

Browse files
authored
[Orchestrator] Remove validation failure on timeout (#368)
1 parent 4ac9b7d commit 876ca9d

17 files changed

Lines changed: 425 additions & 152 deletions

src/NuGet.Services.Validation.Orchestrator/Configuration/ConfigurationValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ private void CheckPropertyValues()
6767
throw new ConfigurationErrorsException("Validation name cannot be empty");
6868
}
6969

70-
if (validationConfigurationItem.FailAfter == TimeSpan.Zero)
70+
if (validationConfigurationItem.TrackAfter == TimeSpan.Zero)
7171
{
72-
throw new ConfigurationErrorsException($"failAfter timeout must be set for validation {validationConfigurationItem.Name}");
72+
throw new ConfigurationErrorsException($"{nameof(validationConfigurationItem.TrackAfter)} must be set for validation {validationConfigurationItem.Name}");
7373
}
7474
}
7575
}

src/NuGet.Services.Validation.Orchestrator/Configuration/ValidationConfiguration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,15 @@ public class ValidationConfiguration
3939
/// this window.
4040
/// </summary>
4141
public TimeSpan NewValidationRequestDeduplicationWindow { get; set; }
42+
43+
/// <summary>
44+
/// The threshold until which an email will be sent out due to a validation set taking too long.
45+
/// </summary>
46+
public TimeSpan ValidationSetNotificationTimeout { get; set; }
47+
48+
/// <summary>
49+
/// The threshold until a validation set is no longer processed.
50+
/// </summary>
51+
public TimeSpan TimeoutValidationSetAfter { get; set; }
4252
}
4353
}

src/NuGet.Services.Validation.Orchestrator/Configuration/ValidationConfigurationItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class ValidationConfigurationItem
1717
public string Name { get; set; }
1818

1919
/// <summary>
20-
/// Timeout after which started validation is considered failed if it didn't produce any outcome
20+
/// Time after which a validation's processing time will be tracked. Use this to track validations that take too long.
2121
/// </summary>
22-
public TimeSpan FailAfter { get; set; }
22+
public TimeSpan TrackAfter { get; set; }
2323

2424
/// <summary>
2525
/// List of validation names that must finish before this validation can run

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public interface IMessageService
1010
void SendPackagePublishedMessage(Package package);
1111
void SendPackageValidationFailedMessage(Package package);
1212
void SendPackageSignedValidationFailedMessage(Package package);
13+
void SendPackageValidationTakingTooLongMessage(Package package);
1314
}
1415
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public interface IValidationStorageService
4545
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="validationResult"/> has status <see cref="ValidationStatus.NotStarted"/></exception>
4646
Task MarkValidationStartedAsync(PackageValidation packageValidation, IValidationResult validationResult);
4747

48+
/// <summary>
49+
/// Updates the <see cref="PackageValidationSet.Updated"/> to the current timestamp and persists changes.
50+
/// </summary>
51+
/// <param name="packageValidationSet">The validation set to update.</param>
52+
/// <returns>Task object tracking the async operation status.</returns>
53+
Task UpdateValidationSetAsync(PackageValidationSet packageValidationSet);
54+
4855
/// <summary>
4956
/// Updates the passed <see cref="PackageValidation"/> object with the result's validation status,
5057
/// updates the <see cref="PackageValidation.ValidationStatusTimestamp"/> property to the current

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,39 @@ public void SendPackagePublishedMessage(Package package)
4949
{
5050
package = package ?? throw new ArgumentNullException(nameof(package));
5151

52-
var galleryPackageUrl = string.Format(_emailConfiguration.PackageUrlTemplate, package.PackageRegistration.Id, package.NormalizedVersion);
53-
var packageSupportUrl = string.Format(_emailConfiguration.PackageSupportTemplate, package.PackageRegistration.Id, package.NormalizedVersion);
52+
var galleryPackageUrl = GalleryPackageUrl(package);
53+
var packageSupportUrl = PackageSupportUrl(package);
54+
5455
_coreMessageService.SendPackageAddedNotice(package, galleryPackageUrl, packageSupportUrl, _emailConfiguration.EmailSettingsUrl);
5556
}
5657

5758
public void SendPackageValidationFailedMessage(Package package)
5859
{
5960
package = package ?? throw new ArgumentNullException(nameof(package));
6061

61-
var galleryPackageUrl = string.Format(_emailConfiguration.PackageUrlTemplate, package.PackageRegistration.Id, package.NormalizedVersion);
62-
var packageSupportUrl = string.Format(_emailConfiguration.PackageSupportTemplate, package.PackageRegistration.Id, package.NormalizedVersion);
62+
var galleryPackageUrl = GalleryPackageUrl(package);
63+
var packageSupportUrl = PackageSupportUrl(package);
64+
6365
_coreMessageService.SendPackageValidationFailedNotice(package, galleryPackageUrl, packageSupportUrl);
6466
}
6567

6668
public void SendPackageSignedValidationFailedMessage(Package package)
6769
{
6870
package = package ?? throw new ArgumentNullException(nameof(package));
6971

70-
var galleryPackageUrl = string.Format(_emailConfiguration.PackageUrlTemplate, package.PackageRegistration.Id, package.NormalizedVersion);
72+
var galleryPackageUrl = GalleryPackageUrl(package);
73+
7174
_coreMessageService.SendSignedPackageNotAllowedNotice(package, galleryPackageUrl, _emailConfiguration.AnnouncementsUrl, _emailConfiguration.TwitterUrl);
7275
}
76+
77+
public void SendPackageValidationTakingTooLongMessage(Package package)
78+
{
79+
package = package ?? throw new ArgumentNullException(nameof(package));
80+
81+
_coreMessageService.SendValidationTakingTooLongNotice(package, GalleryPackageUrl(package));
82+
}
83+
84+
private string GalleryPackageUrl(Package package) => string.Format(_emailConfiguration.PackageUrlTemplate, package.PackageRegistration.Id, package.NormalizedVersion);
85+
private string PackageSupportUrl(Package package) => string.Format(_emailConfiguration.PackageSupportTemplate, package.PackageRegistration.Id, package.NormalizedVersion);
7386
}
7487
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ public interface ITelemetryService
3434
void TrackTotalValidationDuration(TimeSpan duration, bool isSuccess);
3535

3636
/// <summary>
37-
/// A counter metric emitted when a validator fails due to the <see cref="ValidationConfigurationItem.FailAfter"/>
37+
/// A counter metric emitted when a notification is sent because a validation set takes too long.
38+
/// </summary>
39+
void TrackSentValidationTakingTooLongMessage(string packageId, string normalizedVersion, Guid validationTrackingId);
40+
41+
/// <summary>
42+
/// A counter metric emitted when a validation set times out.
43+
/// </summary>
44+
void TrackValidationSetTimeout(string packageId, string normalizedVersion, Guid validationTrackingId);
45+
46+
/// <summary>
47+
/// A counter metric emitted when a validation is past its validator's <see cref="ValidationConfigurationItem.TrackAfter"/>
3848
/// configuration.
3949
/// </summary>
4050
/// <param name="validatorType">The validator type (name).</param>

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class TelemetryService : ITelemetryService
1515
private const string DurationToValidationSetCreationSeconds = Prefix + "DurationToValidationSetCreationSeconds";
1616
private const string PackageStatusChange = Prefix + "PackageStatusChange";
1717
private const string TotalValidationDurationSeconds = Prefix + "TotalValidationDurationSeconds";
18+
private const string SentValidationTakingTooLongMessage = Prefix + "SentValidationTakingTooLongMessage";
19+
private const string ValidationSetTimeout = Prefix + "TotalValidationDurationSeconds";
1820
private const string ValidationIssue = Prefix + "ValidationIssue";
1921
private const string ValidationIssueCount = Prefix + "ValidationIssueCount";
2022
private const string ValidatorTimeout = Prefix + "ValidatorTimeout";
@@ -90,6 +92,28 @@ public void TrackTotalValidationDuration(TimeSpan duration, bool isSuccess)
9092
});
9193
}
9294

95+
public void TrackSentValidationTakingTooLongMessage(string packageId, string normalizedVersion, Guid validationTrackingId)
96+
=> _telemetryClient.TrackMetric(
97+
SentValidationTakingTooLongMessage,
98+
1,
99+
new Dictionary<string, string>
100+
{
101+
{ PackageId, packageId },
102+
{ NormalizedVersion, normalizedVersion },
103+
{ ValidationTrackingId, validationTrackingId.ToString() },
104+
});
105+
106+
public void TrackValidationSetTimeout(string packageId, string normalizedVersion, Guid validationTrackingId)
107+
=> _telemetryClient.TrackMetric(
108+
ValidationSetTimeout,
109+
1,
110+
new Dictionary<string, string>
111+
{
112+
{ PackageId, packageId },
113+
{ NormalizedVersion, normalizedVersion },
114+
{ ValidationTrackingId, validationTrackingId.ToString() },
115+
});
116+
93117
public void TrackValidationIssue(string validatorType, ValidationIssueCode code)
94118
{
95119
_telemetryClient.TrackMetric(

0 commit comments

Comments
 (0)