Skip to content

Commit

Permalink
Merge pull request #468 from SteeltoeOSS/updatesfrom2x
Browse files Browse the repository at this point in the history
Bring latest updates from 2x to 3x
  • Loading branch information
TimHess authored Oct 16, 2020
2 parents 3c05312 + 2990985 commit eb98ea3
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 44 deletions.
22 changes: 0 additions & 22 deletions DeterministicBuild.targets

This file was deleted.

4 changes: 0 additions & 4 deletions Directory.Build.targets

This file was deleted.

4 changes: 2 additions & 2 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<add key="OtelDev" value="https://www.myget.org/F/opentelemetry/api/v3/index.json"/>
<add key="DotnetCore" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />

<!-- for preview versions of Coverlet... use until next release after 1.3.0 hits nuget.org -->
<add key="coverletNightly" value="https://www.myget.org/F/coverlet-dev/api/v3/index.json" />
<!-- for preview versions of Coverlet... use until next release after 1.3.0 hits nuget.org -->
<add key="coverletNightly" value="https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json" />
</packageSources>
</configuration>
1 change: 0 additions & 1 deletion sharedproject.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugType>full</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="$(SourceLinkGitHubVersion)" PrivateAssets="All"/>
Expand Down
9 changes: 9 additions & 0 deletions src/Common/Common.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{CC77ED1F-B
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{473B575D-8871-4E77-9212-C2BBA20D702E}"
ProjectSection(SolutionItems) = preProject
..\..\.editorconfig = ..\..\.editorconfig
..\..\.gitattributes = ..\..\.gitattributes
..\..\.gitignore = ..\..\.gitignore
..\..\azure-pipelines.yml = ..\..\azure-pipelines.yml
..\..\codecov.yml = ..\..\codecov.yml
..\..\coverlet.runsettings = ..\..\coverlet.runsettings
..\..\DeterministicBuild.targets = ..\..\DeterministicBuild.targets
..\..\Directory.Build.targets = ..\..\Directory.Build.targets
..\..\nuget.config = ..\..\nuget.config
..\..\sharedproject.props = ..\..\sharedproject.props
..\..\sharedtest.props = ..\..\sharedtest.props
..\..\Steeltoe.ruleset = ..\..\Steeltoe.ruleset
..\..\stylecop.json = ..\..\stylecop.json
..\..\targetframework.props = ..\..\targetframework.props
..\..\versions.props = ..\..\versions.props
Expand Down
2 changes: 1 addition & 1 deletion src/Common/src/Common/Steeltoe.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(ExtensionsVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(ExtensionsVersion)" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(ExtensionsVersion)" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(DiagnosticSourceVersion)" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsVersion)" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="$(SystemReflectionVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
<ProjectReference Include="..\..\src\Common.Hosting\Steeltoe.Common.Hosting.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Common.Hosting\Steeltoe.Common.Hosting.csproj" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
<Import Project="..\..\..\..\versions.props" />
<Import Project="..\..\..\..\sharedtest.props" />

<ItemGroup>
<ProjectReference Include="..\..\src\Common.Net\Steeltoe.Common.Net.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Common.Net\Steeltoe.Common.Net.csproj" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Discovery/src/ClientBase/ConfigurationUrlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public static List<Uri> GetAspNetCoreUrls(this IConfiguration config)
foreach (var address in addresses)
{
if (!Uri.TryCreate(address, UriKind.Absolute, out var uri)
&& (address.Contains("*") || address.Contains("::")))
&& (address.Contains("*") || address.Contains("::") || address.Contains("+")))
{
Uri.TryCreate(address.Replace("*", WILDCARD_HOST).Replace("::", $"{WILDCARD_HOST}:"), UriKind.Absolute, out uri);
Uri.TryCreate(address.Replace("*", WILDCARD_HOST).Replace("::", $"{WILDCARD_HOST}:").Replace("+", $"{WILDCARD_HOST}:"), UriKind.Absolute, out uri);
}

uris.Add(uri);
Expand Down
27 changes: 27 additions & 0 deletions src/Discovery/test/Eureka.Test/EurekaInstanceOptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,32 @@ public void UpdateConfigurationFindsUrlsPicksHttps()
Assert.True(instOpts.SecurePortEnabled);
Assert.False(instOpts.NonSecurePortEnabled);
}

[Fact]
public void UpdateConfigurationHandlesPlus()
{
var config = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string>() { { "urls", "https://+;http://+" } }).Build();
var instOpts = new EurekaInstanceOptions();

instOpts.ApplyConfigUrls(config.GetAspNetCoreUrls(), ConfigurationUrlHelpers.WILDCARD_HOST);

Assert.Equal(80, instOpts.Port);
Assert.Equal(443, instOpts.SecurePort);
Assert.True(instOpts.SecurePortEnabled);
Assert.False(instOpts.NonSecurePortEnabled);
}

[Fact]
public void UpdateConfigurationUsesDefaultsWhenNoUrl()
{
var config = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string>() { }).Build();
var instOpts = new EurekaInstanceOptions();

instOpts.ApplyConfigUrls(config.GetAspNetCoreUrls(), ConfigurationUrlHelpers.WILDCARD_HOST);

Assert.Equal(80, instOpts.Port);
Assert.False(instOpts.SecurePortEnabled);
Assert.True(instOpts.NonSecurePortEnabled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(LoggingVersion)" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(DiagnosticSourceVersion)" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public Links Invoke(string baseUrl)
{
if (!links._links.ContainsKey(opt.Id))
{
links._links.Add(opt.Id, new Link(baseUrl + "/" + opt.Path));
var linkPath = $"{baseUrl.TrimEnd('/')}/{opt.Path}";
links._links.Add(opt.Id, new Link(linkPath));
}
else if (links._links.ContainsKey(opt.Id))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected internal async Task HandleLoggersRequestAsync(HttpContext context)
}
else
{
paths.Add($"{_mgmtOptions.Path}/{_endpoint.Path}");
paths.Add($"{_mgmtOptions.Path}/{_endpoint.Path}".Replace("//", "/"));
}

foreach (var path in paths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected internal string GetMetricName(HttpRequest request)
return GetMetricName(request, _endpoint.Path);
}

var path = $"{_mgmtOptions.Path}/{_endpoint.Id}";
var path = $"{_mgmtOptions.Path}/{_endpoint.Id}".Replace("//", "/");
var metricName = GetMetricName(request, path);

return metricName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ public async void HypermediaEndpointMiddleware_ServiceContractNotBroken()
Assert.Equal("{\"type\":\"steeltoe\",\"_links\":{\"info\":{\"href\":\"http://localhost/actuator/info\",\"templated\":false},\"self\":{\"href\":\"http://localhost/actuator\",\"templated\":false}}}", json);
}

[Fact]
public async void HypermediaEndpointMiddleware_Returns_Expected_When_ManagementPath_Is_Slash()
{
var settings = new Dictionary<string, string>(appSettings);
appSettings.Add("Management:Endpoints:Path", "/");

// arrange a server and client
var builder = new WebHostBuilder()
.UseStartup<Startup>()
.ConfigureAppConfiguration((builderContext, config) => config.AddInMemoryCollection(appSettings));

using var server = new TestServer(builder);
var client = server.CreateClient();

// send the request
var result = await client.GetAsync("http://localhost/");
var json = await result.Content.ReadAsStringAsync();

// assert
Assert.Equal("{\"type\":\"steeltoe\",\"_links\":{\"info\":{\"href\":\"http://localhost/info\",\"templated\":false},\"self\":{\"href\":\"http://localhost/\",\"templated\":false}}}", json);
}

[Fact]
public void RoutesByPathAndVerb()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,32 @@ public async void LoggersActuator_AcceptsPost()
Assert.Equal("ERROR", parsedObject.GetProperty("loggers").GetProperty("Default").GetProperty("effectiveLevel").GetString());
}

[Fact]
public async void LoggersActuator_AcceptsPost_When_ManagementPath_Is_Slash()
{
var appSettings = new Dictionary<string, string>(AppSettings);
appSettings["management:endpoints:path"] = "/";
appSettings.Add("Management:Endpoints:Actuator:Exposure:Include:0", "*");

var builder = new WebHostBuilder()
.UseStartup<Startup>()
.ConfigureAppConfiguration((builderContext, config) => config.AddInMemoryCollection(appSettings))
.ConfigureLogging((context, loggingBuilder) =>
{
loggingBuilder.AddConfiguration(context.Configuration.GetSection("Logging"));
loggingBuilder.AddDynamicConsole();
});

using var server = new TestServer(builder);
var client = server.CreateClient();
HttpContent content = new StringContent("{\"configuredLevel\":\"ERROR\"}");
var changeResult = await client.PostAsync("http://localhost/loggers/Default", content);
Assert.Equal(HttpStatusCode.OK, changeResult.StatusCode);

var parsedObject = await client.GetFromJsonAsync<JsonElement>("http://localhost/loggers");
Assert.Equal("ERROR", parsedObject.GetProperty("loggers").GetProperty("Default").GetProperty("effectiveLevel").GetString());
}

[Fact]
public async void LoggersActuator_UpdateNameSpace_UpdatesChildren()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xunit;

namespace Steeltoe.Management.Endpoint.Metrics.Test
Expand Down Expand Up @@ -88,6 +89,28 @@ public void GetMetricName_ReturnsExpected()
Assert.Null(middle.GetMetricName(context3.Request));
}

[Fact]
public void GetMetricName_ReturnsExpected_When_ManagementPath_Is_Slash()
{
var opts = new MetricsEndpointOptions();
var mopts = new ActuatorManagementOptions();
mopts.Path = "/";

mopts.EndpointOptions.Add(opts);

var ep = new MetricsEndpoint(opts, new SteeltoeExporter());
var middle = new MetricsEndpointMiddleware(null, ep, mopts);

var context1 = CreateRequest("GET", "/metrics");
Assert.Null(middle.GetMetricName(context1.Request));

var context2 = CreateRequest("GET", "/metrics/Foo.Bar.Class");
Assert.Equal("Foo.Bar.Class", middle.GetMetricName(context2.Request));

var context3 = CreateRequest("GET", "/metrics", "?tag=key:value&tag=key1:value1");
Assert.Null(middle.GetMetricName(context3.Request));
}

[Fact]
public async void HandleMetricsRequestAsync_GetMetricsNames_ReturnsExpected()
{
Expand Down
5 changes: 2 additions & 3 deletions versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<PropertyGroup>
<CoreFxVersion>4.4.0</CoreFxVersion>
<CSharpVersion>4.5.0</CSharpVersion>
<DiagnosticSourceVersion>4.4.1</DiagnosticSourceVersion>
<DriveInfoVersion>4.3.1</DriveInfoVersion>
<EFCoreVersion>2.0.0</EFCoreVersion>
<EFCoreTestVersion>2.1.2</EFCoreTestVersion>
Expand All @@ -15,7 +14,7 @@
<JwtTokensVersion>5.2.2</JwtTokensVersion>
<SymReaderVersion>1.2.0</SymReaderVersion>
<SymReaderPortableVersion>1.4.0</SymReaderPortableVersion>
<SystemDiagnosticsVersion>4.6.0</SystemDiagnosticsVersion>
<SystemDiagnosticsVersion>4.7.1</SystemDiagnosticsVersion>
<SystemJsonVersion>4.6.0</SystemJsonVersion>
<SystemReflectionVersion>4.6.0</SystemReflectionVersion>
<TelemetryCorrelationVersion>1.0.0</TelemetryCorrelationVersion>
Expand All @@ -37,7 +36,7 @@
<AutofacVersion>4.6.1</AutofacVersion>
<BouncyCastleVersion>1.8.4</BouncyCastleVersion>
<ConsulVersion>0.7.2.6</ConsulVersion>
<CoverletVersion>1.3.1-preview.27.gdd2237a3be</CoverletVersion>
<CoverletVersion>3.0.0-preview.1</CoverletVersion>
<HdrHistogramVersion>2.0.0</HdrHistogramVersion>
<HttpExtensionsVersion>2.1.0</HttpExtensionsVersion>
<DiagnosticsExtensionsVersion>2.2.5</DiagnosticsExtensionsVersion>
Expand Down

0 comments on commit eb98ea3

Please sign in to comment.