Merge pull request #131 from SteeltoeOSS/actuators_dynamic_loggers_3.0
Update actuators to use webhost extensions and update dynamic logging…
This commit is contained in:
Коммит
c1d2ff20b4
|
@ -10,5 +10,5 @@ obj
|
|||
|
||||
# ignore Rider state
|
||||
Steeltoe.Initializr.sln.DotSettings.user
|
||||
/.idea/
|
||||
**/.idea/*
|
||||
Steeltoe.Initializr.sln.DotSettings.user
|
||||
|
|
2
src/Steeltoe.Initializr.TemplateEngine/.idea/.idea.Steeltoe.Initializr.TemplateEngine.dir/.idea/.gitignore
поставляемый
Normal file
2
src/Steeltoe.Initializr.TemplateEngine/.idea/.idea.Steeltoe.Initializr.TemplateEngine.dir/.idea/.gitignore
поставляемый
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Default ignored files
|
||||
/workspace.xml
|
|
@ -108,6 +108,12 @@
|
|||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add Dockerfile",
|
||||
"friendlyName": "Dockerfile"
|
||||
},
|
||||
{
|
||||
"Name": "DistributedTracing",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add Distributed Tracing",
|
||||
"friendlyName": "Distributed Tracing"
|
||||
}
|
||||
],
|
||||
"CalculatedParams": [
|
||||
|
|
|
@ -3,15 +3,31 @@ using Microsoft.AspNetCore.Hosting;
|
|||
{{#AzureSpringCloud}}
|
||||
using Microsoft.Azure.SpringCloud.Client;
|
||||
{{/AzureSpringCloud}}
|
||||
{{#ActuatorsOrDynamicLogger}}
|
||||
{{#DynamicSerilog}}
|
||||
using Steeltoe.Extensions.Logging.DynamicSerilog;
|
||||
{{/ActuatorsOrDynamicLogger}}
|
||||
{{/DynamicSerilog}}
|
||||
{{#DynamicLogger}}
|
||||
using Steeltoe.Extensions.Logging;
|
||||
{{/DynamicLogger}}
|
||||
{{#CloudFoundry}}
|
||||
using Steeltoe.Common.Hosting;
|
||||
{{^ConfigServer}}
|
||||
{{^ConfigServer}}
|
||||
using Steeltoe.Extensions.Configuration.CloudFoundry;
|
||||
{{/ConfigServer}}
|
||||
{{/ConfigServer}}
|
||||
{{#Actuators}}
|
||||
using Steeltoe.Management.CloudFoundry;
|
||||
{{/Actuators}}
|
||||
{{/CloudFoundry}}
|
||||
{{^CloudFoundry}}
|
||||
{{#Actuators}}
|
||||
using Steeltoe.Management.Endpoint;
|
||||
{{/Actuators}}
|
||||
{{/CloudFoundry}}
|
||||
{{^Actuators}}
|
||||
{{#DynamicLogger}}
|
||||
using Steeltoe.Management.Endpoint;
|
||||
{{/DynamicLogger}}
|
||||
{{/Actuators}}
|
||||
{{#ConfigServer}}
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
{{/ConfigServer}}
|
||||
|
@ -42,10 +58,18 @@ namespace {{ProjectNameSpace}}
|
|||
.UseDefaultServiceProvider(configure => configure.ValidateScopes = false)
|
||||
{{#CloudFoundry}}
|
||||
.UseCloudHosting() //Enable listening on a Env provided port
|
||||
{{#Actuators}}
|
||||
.AddCloudFoundryActuators()
|
||||
{{/Actuators}}
|
||||
{{^ConfigServer}}
|
||||
.AddCloudFoundryConfiguration() //Add cloudfoundry environment variables as a configuration source
|
||||
{{/ConfigServer}}
|
||||
{{/CloudFoundry}}
|
||||
{{^CloudFoundry}}
|
||||
{{#Actuators}}
|
||||
.AddAllActuators()
|
||||
{{/Actuators}}
|
||||
{{/CloudFoundry}}
|
||||
{{#ConfigServer}}
|
||||
.AddConfigServer()
|
||||
{{/ConfigServer}}
|
||||
|
@ -58,9 +82,16 @@ namespace {{ProjectNameSpace}}
|
|||
{{#AzureSpringCloud}}
|
||||
.UseAzureSpringCloudService()
|
||||
{{/AzureSpringCloud}}
|
||||
{{#ActuatorsOrDynamicLogger}}
|
||||
.ConfigureLogging((context, builder) => builder.AddSerilogDynamicConsole())
|
||||
{{/ActuatorsOrDynamicLogger}}
|
||||
|
||||
{{#DynamicSerilog}}
|
||||
.ConfigureLogging((context, loggingBuilder) => loggingBuilder.AddSerilogDynamicConsole())
|
||||
{{/DynamicSerilog}}
|
||||
{{#DynamicLogger}}
|
||||
{{^ActuatorsOrCloudFoundry}}
|
||||
.AddLoggersActuator()
|
||||
.ConfigureLogging((context, loggingBuilder) => loggingBuilder.AddDynamicConsole())
|
||||
{{/ActuatorsOrCloudFoundry}}
|
||||
{{/DynamicLogger}}
|
||||
.UseStartup<Startup>();
|
||||
return builder;
|
||||
}
|
||||
|
|
|
@ -59,14 +59,20 @@
|
|||
<PackageReference Include="Steeltoe.Extensions.Configuration.PlaceholderCore" Version="{{SteeltoeVersion}}" />
|
||||
{{/PlaceholderConfig}}
|
||||
{{#ActuatorsOrCloudFoundry}}
|
||||
<PackageReference Include="Steeltoe.Extensions.Logging.DynamicSerilogCore" Version="{{SteeltoeVersion}}" />
|
||||
<PackageReference Include="Steeltoe.Extensions.Logging.DynamicLogger" Version="{{SteeltoeVersion}}" />
|
||||
{{/ActuatorsOrCloudFoundry}}
|
||||
{{#DynamicLogger}}
|
||||
<PackageReference Include="Steeltoe.Extensions.Logging.DynamicSerilogCore" Version="{{SteeltoeVersion}}" />
|
||||
<PackageReference Include="Steeltoe.Extensions.Logging.DynamicLogger" Version="{{SteeltoeVersion}}" />
|
||||
{{^Actuators}}
|
||||
<PackageReference Include="Steeltoe.Management.EndpointCore" Version="{{SteeltoeVersion}}" />
|
||||
{{/Actuators}}
|
||||
{{/DynamicLogger}}
|
||||
{{#ActuatorsOrCloudFoundry}}
|
||||
{{#Actuators}}
|
||||
<PackageReference Include="Steeltoe.Management.EndpointCore" Version="{{SteeltoeVersion}}" />
|
||||
{{/Actuators}}
|
||||
{{#CloudFoundry}}
|
||||
<PackageReference Include="Steeltoe.Management.CloudFoundryCore" Version="{{SteeltoeVersion}}" />
|
||||
{{/ActuatorsOrCloudFoundry}}
|
||||
{{/CloudFoundry}}
|
||||
{{#ConfigServer}}
|
||||
<PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="{{SteeltoeVersion}}" />
|
||||
{{/ConfigServer}}
|
||||
|
|
|
@ -33,9 +33,6 @@ using Steeltoe.Connector.SqlServer.EFCore;
|
|||
{{#Discovery}}
|
||||
using Steeltoe.Discovery.Client;
|
||||
{{/Discovery}}
|
||||
{{#Actuators}}
|
||||
using Steeltoe.Management.CloudFoundry;
|
||||
{{/Actuators}}
|
||||
{{#RequiresHttps}}
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
{{/RequiresHttps}}
|
||||
|
@ -51,7 +48,9 @@ using Microsoft.AspNetCore.Authentication.AzureADB2C.UI;
|
|||
{{#CircuitBreaker}}
|
||||
using Steeltoe.CircuitBreaker.Hystrix;
|
||||
{{/CircuitBreaker}}
|
||||
|
||||
{{#DistributedTracing}}
|
||||
using Steeltoe.Management.Tracing;
|
||||
{{/DistributedTracing}}
|
||||
namespace {{ProjectNameSpace}}
|
||||
{
|
||||
public class Startup
|
||||
|
@ -77,9 +76,6 @@ namespace {{ProjectNameSpace}}
|
|||
{{#MySql}}
|
||||
services.AddMySqlConnection(Configuration);
|
||||
{{/MySql}}
|
||||
{{#Actuators}}
|
||||
services.AddCloudFoundryActuators(Configuration);
|
||||
{{/Actuators}}
|
||||
{{#Discovery}}
|
||||
services.AddDiscoveryClient(Configuration);
|
||||
{{/ Discovery}}
|
||||
|
@ -108,6 +104,9 @@ namespace {{ProjectNameSpace}}
|
|||
// Add Context and use Postgres as provider ... provider will be configured from VCAP_ info
|
||||
// services.AddDbContext<MyDbContext>(options => options.UseNpgsql(Configuration));
|
||||
{{/PostgresEFCore}}
|
||||
{{#DistributedTracing}}
|
||||
services.AddDistributedTracing(Configuration, builder => builder.UseZipkinWithTraceOptions(services));
|
||||
{{/DistributedTracing}}
|
||||
services.AddControllers();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,12 +31,14 @@ namespace Steeltoe.Initializr.TemplateEngine.Test
|
|||
{
|
||||
IConfigurationRoot configuration = TestHelper.GetConfiguration();
|
||||
var implementation = new MustacheTemplateService(configuration, new LoggerFactory().CreateLogger<MustacheTemplateService>());
|
||||
_data = new []
|
||||
|
||||
_data = new[]
|
||||
{
|
||||
new object[] { implementation, Constants.Steeltoe24, Constants.NetCoreApp21, Constants.WebApi},
|
||||
new object[] { implementation, Constants.Steeltoe24, Constants.NetCoreApp31, Constants.WebApi},
|
||||
new object[] { implementation, Constants.Steeltoe30, Constants.NetCoreApp31, Constants.WebApi},
|
||||
new object[] {implementation, Constants.Steeltoe24, Constants.NetCoreApp21, Constants.WebApi},
|
||||
new object[] {implementation, Constants.Steeltoe24, Constants.NetCoreApp31, Constants.WebApi},
|
||||
new object[] {implementation, Constants.Steeltoe30, Constants.NetCoreApp31, Constants.WebApi},
|
||||
}.ToList();
|
||||
|
||||
}
|
||||
|
||||
public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator();
|
||||
|
|
|
@ -71,6 +71,15 @@ namespace Steeltoe.Initializr.TemplateEngine.Test
|
|||
Template = template,
|
||||
});
|
||||
|
||||
if (steeltoe.Equals("3.0.0"))
|
||||
{
|
||||
var programFileContents = files.Find(x => x.Key == "Program.cs").Value;
|
||||
Assert.Contains("using Steeltoe.Management.Endpoint;", programFileContents);
|
||||
Assert.Contains(".AddAllActuators()", programFileContents);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
string startUpContents = files.Find(x => x.Key == "Startup.cs").Value;
|
||||
|
||||
Assert.Contains("using Steeltoe.Management.CloudFoundry;", startUpContents);
|
||||
|
@ -79,9 +88,46 @@ namespace Steeltoe.Initializr.TemplateEngine.Test
|
|||
Assert.Contains("using Steeltoe.Management.Endpoint;", startUpContents);
|
||||
Assert.Contains("using Steeltoe.Management.Hypermedia;", startUpContents);
|
||||
}
|
||||
|
||||
Assert.Contains("services.AddCloudFoundryActuators(Configuration);", startUpContents);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[ClassData(typeof(AllImplementationsAndTemplates))]
|
||||
public async Task CreateTemplate_cfActuators(ITemplateService templateService, string steeltoe,
|
||||
string framework, string template)
|
||||
{
|
||||
var files = await templateService.GenerateProjectFiles(new GeneratorModel()
|
||||
{
|
||||
Dependencies = "Actuators,CloudFoundry",
|
||||
ProjectName = "testProject",
|
||||
SteeltoeVersion = steeltoe,
|
||||
TargetFramework = framework,
|
||||
Template = template,
|
||||
});
|
||||
|
||||
if (steeltoe.Equals("3.0.0"))
|
||||
{
|
||||
var programFile = files.Find(x => x.Key == "Program.cs").Value;
|
||||
Assert.Contains("using Steeltoe.Management.CloudFoundry;", programFile);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var startUpContents = files.Find(x => x.Key == "Startup.cs").Value;
|
||||
|
||||
Assert.Contains("using Steeltoe.Management.CloudFoundry;", startUpContents);
|
||||
if (!framework.Equals("netcoreapp3.1"))
|
||||
{
|
||||
Assert.Contains("using Steeltoe.Management.Endpoint;", startUpContents);
|
||||
Assert.Contains("using Steeltoe.Management.Hypermedia;", startUpContents);
|
||||
}
|
||||
|
||||
Assert.Contains("services.AddCloudFoundryActuators", startUpContents);
|
||||
}
|
||||
}
|
||||
[Theory]
|
||||
[ClassData(typeof(AllImplementationsAndTemplates))]
|
||||
public async Task CreateTemplate_react(ITemplateService templateService, string steeltoe, string framework, string template)
|
||||
|
@ -130,7 +176,16 @@ namespace Steeltoe.Initializr.TemplateEngine.Test
|
|||
});
|
||||
|
||||
string startUpContents = files.Find(x => x.Key == "Startup.cs").Value;
|
||||
if (steeltoe != "3.0.0")
|
||||
{
|
||||
Assert.Contains("services.AddCloudFoundryActuators(Configuration);", startUpContents);
|
||||
}
|
||||
else
|
||||
{
|
||||
string programFile = files.Find(x => x.Key == "Program.cs").Value;
|
||||
Assert.Contains("AddAllActuators", programFile);
|
||||
}
|
||||
|
||||
Assert.Contains("using Steeltoe.CircuitBreaker.Hystrix;", startUpContents);
|
||||
|
||||
Assert.Contains(files, file => file.Key.EndsWith("MyCircuitBreakerCommand.cs"));
|
||||
|
@ -551,20 +606,17 @@ using System.Threading;", valuesController);
|
|||
Template = template,
|
||||
});
|
||||
|
||||
string fileContents = files.Find(x => x.Key == "testProject.csproj").Value;
|
||||
string programFileContents = files.Find(x => x.Key == "Program.cs").Value;
|
||||
if (steeltoe.Equals(Constants.Steeltoe30))
|
||||
{
|
||||
Assert.Contains(@"<PackageReference Include=""Steeltoe.Extensions.Logging.DynamicSerilogCore"" Version=", fileContents);
|
||||
Assert.Contains(@"using Steeltoe.Extensions.Logging.DynamicSerilog", programFileContents);
|
||||
Assert.Contains(@"ConfigureLogging((context, builder) => builder.AddSerilogDynamicConsole())", programFileContents);
|
||||
}
|
||||
else
|
||||
{
|
||||
var fileContents = files.Find(x => x.Key == "testProject.csproj").Value;
|
||||
var programFileContents = files.Find(x => x.Key == "Program.cs").Value;
|
||||
|
||||
Assert.Contains(@"<PackageReference Include=""Steeltoe.Extensions.Logging.DynamicLogger"" Version=", fileContents);
|
||||
Assert.Contains(@"using Steeltoe.Extensions.Logging;", programFileContents);
|
||||
Assert.Contains(@"loggingBuilder.AddConfiguration(hostingContext.Configuration.GetSection(""Logging""));", programFileContents);
|
||||
Assert.Contains(@"loggingBuilder.AddDynamicConsole();", programFileContents);
|
||||
Assert.Contains(@"loggingBuilder.AddDynamicConsole()", programFileContents);
|
||||
if (!steeltoe.Equals(Constants.Steeltoe30))
|
||||
{
|
||||
Assert.Contains(
|
||||
@"loggingBuilder.AddConfiguration(hostingContext.Configuration.GetSection(""Logging""));",
|
||||
programFileContents);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -596,56 +648,7 @@ using System.Threading;", valuesController);
|
|||
Assert.Contains(".AddCloudFoundry", programFileContents);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[ClassData(typeof(AllImplementationsAndTemplates))]
|
||||
public async Task CreateTemplate_actuators_v22(ITemplateService templateService, string steeltoe, string framework, string template)
|
||||
{
|
||||
var files = await templateService.GenerateProjectFiles(new GeneratorModel()
|
||||
{
|
||||
Dependencies = "Actuators",
|
||||
SteeltoeVersion = steeltoe,
|
||||
TargetFramework = framework,
|
||||
Template = template,
|
||||
});
|
||||
|
||||
var startUpContents = files.Find(x => x.Key == "Startup.cs").Value;
|
||||
|
||||
Assert.Contains("services.AddCloudFoundryActuators(Configuration);", startUpContents);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[ClassData(typeof(AllImplementationsAndTemplates))]
|
||||
public async Task CreateTemplate_actuators_23(ITemplateService templateService, string steeltoe, string framework, string template)
|
||||
{
|
||||
var files = await templateService.GenerateProjectFiles(new GeneratorModel()
|
||||
{
|
||||
Dependencies = "Actuators",
|
||||
SteeltoeVersion = steeltoe,
|
||||
TargetFramework = framework,
|
||||
Template = template,
|
||||
});
|
||||
|
||||
var startUpContents = files.Find(x => x.Key == "Startup.cs").Value;
|
||||
|
||||
Assert.Contains("services.AddCloudFoundryActuators(Configuration);", startUpContents);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[ClassData(typeof(AllImplementationsAndTemplates))]
|
||||
public async Task CreateTemplate_actuators_24(ITemplateService templateService, string steeltoe, string framework, string template)
|
||||
{
|
||||
var files = await templateService.GenerateProjectFiles(new GeneratorModel()
|
||||
{
|
||||
Dependencies = "Actuators",
|
||||
SteeltoeVersion = steeltoe,
|
||||
TargetFramework = framework,
|
||||
Template = template,
|
||||
});
|
||||
|
||||
var startUpContents = files.Find(x => x.Key == "Startup.cs").Value;
|
||||
|
||||
Assert.Contains("services.AddCloudFoundryActuators(Configuration);", startUpContents);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[ClassData(typeof(AllImplementationsAndTemplateNames))]
|
||||
|
|
Загрузка…
Ссылка в новой задаче