Skip to content

Commit

Permalink
fix Availability, less BuildInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHess committed Aug 20, 2020
1 parent c6d4f3f commit f3db544
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Hosting;
using Steeltoe.Management.Endpoint;
using Steeltoe.Management.Endpoint.CloudFoundry;
using Steeltoe.Management.Endpoint.Health;
using System;

namespace Steeltoe.Management.CloudFoundry
Expand All @@ -31,6 +32,8 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
endpoints.Map<CloudFoundryEndpoint>();
endpoints.MapAllActuators(MediaTypeVersion);
});

HealthStartupFilter.InitializeAvailability(app.ApplicationServices);
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using Steeltoe.Management.Info;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;

Expand All @@ -21,8 +22,18 @@ public BuildInfoContributor()

public void Contribute(IInfoBuilder builder)
{
builder.WithInfo("applicationVersionInfo", _applicationInfo);
builder.WithInfo("steeltoeVersionInfo", _steeltoeInfo);
builder.WithInfo("applicationVersionInfo", GetImportantDetails(_applicationInfo));
builder.WithInfo("steeltoeVersionInfo", GetImportantDetails(_steeltoeInfo));
}

private Dictionary<string, string> GetImportantDetails(FileVersionInfo info)
{
return new Dictionary<string, string>
{
{ "ProductName", info.ProductName },
{ "FileVersion", info.FileVersion },
{ "ProductVersion", info.ProductVersion }
};
}
}
}
3 changes: 3 additions & 0 deletions src/Management/src/EndpointCore/AllActuatorsStartupFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Steeltoe.Management.Endpoint.Health;
using System;

namespace Steeltoe.Management.Endpoint
Expand All @@ -28,6 +29,8 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
var builder = endpoints.MapAllActuators();
_configureConventions?.Invoke(builder);
});

HealthStartupFilter.InitializeAvailability(app.ApplicationServices);
};
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/Management/src/EndpointCore/Health/HealthStartupFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ namespace Steeltoe.Management.Endpoint.Health
{
public class HealthStartupFilter : IStartupFilter
{
public static void InitializeAvailability(IServiceProvider serviceProvider)
{
var lifetime = serviceProvider.GetService<IHostApplicationLifetime>();
var availability = serviceProvider.GetService<ApplicationAvailability>();
lifetime.ApplicationStarted.Register(() =>
{
availability.SetAvailabilityState(availability.LivenessKey, LivenessState.Correct, "ApplicationStarted");
availability.SetAvailabilityState(availability.ReadinessKey, ReadinessState.AcceptingTraffic, "ApplicationStarted");
});
lifetime.ApplicationStopping.Register(() => availability.SetAvailabilityState(availability.ReadinessKey, ReadinessState.RefusingTraffic, "ApplicationStopping"));
}

public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
{
return app =>
Expand All @@ -23,14 +35,7 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
endpoints.Map<HealthEndpointCore>();
});

var lifetime = app.ApplicationServices.GetService<IHostApplicationLifetime>();
var availability = app.ApplicationServices.GetService<ApplicationAvailability>();
lifetime.ApplicationStarted.Register(() =>
{
availability.SetAvailabilityState(availability.LivenessKey, LivenessState.Correct, "ApplicationStarted");
availability.SetAvailabilityState(availability.ReadinessKey, ReadinessState.AcceptingTraffic, "ApplicationStarted");
});
lifetime.ApplicationStopping.Register(() => availability.SetAvailabilityState(availability.ReadinessKey, ReadinessState.RefusingTraffic, "ApplicationStopping"));
InitializeAvailability(app.ApplicationServices);
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Steeltoe.Management.Endpoint;
using Steeltoe.Management.Endpoint.Health;
using System;

namespace Steeltoe.Management.Kubernetes
Expand All @@ -27,6 +28,7 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
{
endpoints.MapAllActuators(MediaTypeVersion);
});
HealthStartupFilter.InitializeAvailability(app.ApplicationServices);
};
}
}
Expand Down

0 comments on commit f3db544

Please sign in to comment.