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

Commit ee4fac7

Browse files
author
Scott Bommarito
authored
Merge pull request #508 from NuGet/dev
[ReleasePrep][2018.07.31]RI of dev into master
2 parents 01298d9 + 006cdef commit ee4fac7

23 files changed

Lines changed: 612 additions & 80 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace NuGet.Services.Revalidate
5+
{
6+
public class HealthConfiguration
7+
{
8+
/// <summary>
9+
/// The name of the Azure Blob Storage container that stores status information.
10+
/// </summary>
11+
public string ContainerName { get; set; }
12+
13+
/// <summary>
14+
/// The name of the Azure Blob Storage blob that stores status information.
15+
/// </summary>
16+
public string StatusBlobName { get; set; }
17+
18+
/// <summary>
19+
/// The path to the component that the revalidation job will monitor. The revalidation job will
20+
/// pause if this component isn't healthy.
21+
/// </summary>
22+
public string ComponentPath { get; set; }
23+
}
24+
}

src/NuGet.Services.Revalidate/Configuration/RevalidationConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class RevalidationConfiguration
3535
/// </summary>
3636
public InitializationConfiguration Initialization { get; set; }
3737

38+
/// <summary>
39+
/// The configurations used to determine the health of the ingestion pipeline.
40+
/// </summary>
41+
public HealthConfiguration Health { get; set; }
42+
3843
/// <summary>
3944
/// The configurations used by the in-memory queue of revalidations to start.
4045
/// </summary>

src/NuGet.Services.Revalidate/Job.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ protected override void ConfigureJobServices(IServiceCollection services, IConfi
9696
services.Configure<RevalidationConfiguration>(configurationRoot.GetSection(JobConfigurationSectionName));
9797
services.AddSingleton(provider => provider.GetRequiredService<IOptionsSnapshot<RevalidationConfiguration>>().Value);
9898
services.AddSingleton(provider => provider.GetRequiredService<IOptionsSnapshot<RevalidationConfiguration>>().Value.Initialization);
99+
services.AddSingleton(provider => provider.GetRequiredService<IOptionsSnapshot<RevalidationConfiguration>>().Value.Health);
99100
services.AddSingleton(provider => provider.GetRequiredService<IOptionsSnapshot<RevalidationConfiguration>>().Value.Queue);
100101

101102
services.AddScoped<IGalleryContext>(provider =>

src/NuGet.Services.Revalidate/NuGet.Services.Revalidate.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<Reference Include="System.Xml" />
4444
</ItemGroup>
4545
<ItemGroup>
46+
<Compile Include="Configuration\HealthConfiguration.cs" />
4647
<Compile Include="Configuration\InitializationConfiguration.cs" />
4748
<Compile Include="Configuration\RevalidationQueueConfiguration.cs" />
4849
<Compile Include="Extensions\IEnumerableExtensions.cs" />
@@ -103,6 +104,9 @@
103104
</ProjectReference>
104105
</ItemGroup>
105106
<ItemGroup>
107+
<PackageReference Include="NuGet.Services.Status">
108+
<Version>2.27.0</Version>
109+
</PackageReference>
106110
<PackageReference Include="NuGet.Services.Storage">
107111
<Version>2.27.0</Version>
108112
</PackageReference>
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,52 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
5+
using System.IO;
46
using System.Threading.Tasks;
7+
using Microsoft.Extensions.Logging;
8+
using Newtonsoft.Json;
9+
using NuGet.Services.Status;
10+
using NuGetGallery;
511

612
namespace NuGet.Services.Revalidate
713
{
814
public class HealthService : IHealthService
915
{
10-
public Task<bool> IsHealthyAsync()
16+
private readonly ICoreFileStorageService _storage;
17+
private readonly HealthConfiguration _config;
18+
private readonly ILogger<HealthService> _logger;
19+
20+
public HealthService(
21+
ICoreFileStorageService storage,
22+
HealthConfiguration config,
23+
ILogger<HealthService> logger)
24+
{
25+
_storage = storage ?? throw new ArgumentNullException(nameof(storage));
26+
_config = config ?? throw new ArgumentNullException(nameof(config));
27+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
28+
}
29+
30+
public async Task<bool> IsHealthyAsync()
1131
{
12-
// TODO:
13-
// We are software gods that never make mistakes.
14-
return Task.FromResult(true);
32+
using (var stream = await _storage.GetFileAsync(_config.ContainerName, _config.StatusBlobName))
33+
using (var reader = new StreamReader(stream))
34+
{
35+
var json = await reader.ReadToEndAsync();
36+
var status = JsonConvert.DeserializeObject<ServiceStatus>(json);
37+
var component = status.ServiceRootComponent.GetByPath(_config.ComponentPath);
38+
39+
if (component == null)
40+
{
41+
_logger.LogError(
42+
"Assuming that the service is unhealthy as the component path {ComponentPath} could not be found",
43+
_config.ComponentPath);
44+
45+
return false;
46+
}
47+
48+
return component.Status == ComponentStatus.Up;
49+
}
1550
}
1651
}
17-
}
52+
}

src/NuGet.Services.Revalidate/Settings/dev.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
"SleepDurationBetweenBatches": "00:00:01"
1111
},
1212

13+
"Health": {
14+
"ContainerName": "status",
15+
"StatusBlobName": "status.json",
16+
"ComponentPath": "NuGet/Package Publishing"
17+
},
18+
1319
"MinPackageEventRate": 120,
1420
"MaxPackageEventRate": 500,
1521

src/NuGet.Services.Revalidate/Settings/int.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
"SleepDurationBetweenBatches": "00:00:30"
1111
},
1212

13+
"Health": {
14+
"ContainerName": "status",
15+
"StatusBlobName": "status.json",
16+
"ComponentPath": "NuGet/Package Publishing"
17+
},
18+
1319
"MinPackageEventRate": 120,
1420
"MaxPackageEventRate": 500,
1521

src/NuGet.Services.Revalidate/Settings/prod.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
"SleepDurationBetweenBatches": "00:00:30"
1111
},
1212

13+
"Health": {
14+
"ContainerName": "status",
15+
"StatusBlobName": "status.json",
16+
"ComponentPath": "NuGet/Package Publishing"
17+
},
18+
1319
"MinPackageEventRate": 120,
1420
"MaxPackageEventRate": 500,
1521

src/StatusAggregator/MessageUpdater.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public async Task CreateMessageForEventStart(EventEntity eventEntity, DateTime c
6060
}
6161
}
6262

63-
private const string _messageForEventStartTemplate = "<b>{0} is {1}.</b> You may encounter issues {2}.";
63+
private const string _messageForEventStartTemplate = "**{0} is {1}.** You may encounter issues {2}.";
6464

6565
private bool TryGetContentsForMessageForEventStart(EventEntity eventEntity, out string contents)
6666
{
@@ -102,7 +102,7 @@ private Task CreateMessage(EventEntity eventEntity, DateTime time, string conten
102102
return _table.InsertOrReplaceAsync(messageEntity);
103103
}
104104

105-
private const string _messageForEventEndTemplate = "<b>{0} is no longer {1}.</b> You should no longer encounter any issues {2}. Thank you for your patience.";
105+
private const string _messageForEventEndTemplate = "**{0} is no longer {1}.** You should no longer encounter any issues {2}. Thank you for your patience.";
106106

107107
private bool TryGetContentsForMessageForEventEnd(EventEntity eventEntity, out string contents)
108108
{

src/Validation.Common.Job/LoggerDiagnosticsSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private static IDictionary<string, string> GetProperties(
9191

9292
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
9393
{
94-
_logger.Log<TState>(logLevel, eventId, state, exception, formatter);
94+
_logger.Log(logLevel, eventId, state, exception, formatter);
9595
}
9696

9797
public bool IsEnabled(LogLevel logLevel)
@@ -101,7 +101,7 @@ public bool IsEnabled(LogLevel logLevel)
101101

102102
public IDisposable BeginScope<TState>(TState state)
103103
{
104-
return _logger.BeginScope<TState>(state);
104+
return _logger.BeginScope(state);
105105
}
106106

107107
/// <summary>

0 commit comments

Comments
 (0)