Skip to content

Commit

Permalink
Define supported Kafka versions (#3316)
Browse files Browse the repository at this point in the history
  • Loading branch information
RassK authored Mar 26, 2024
1 parent 67a7726 commit dca75ff
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 84 deletions.
4 changes: 2 additions & 2 deletions build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ DotNetRestoreSettings Restore(DotNetRestoreSettings s) =>
.SetPlatform(Platform)
.When(!string.IsNullOrEmpty(NuGetPackagesDirectory), o => o.SetPackageDirectory(NuGetPackagesDirectory));

if (LibraryVersion.Versions.TryGetValue(project.Name, out var libraryVersions))
if (LibraryVersion.TryGetVersions(project.Name, Platform, out var libraryVersions))
{
DotNetRestore(s =>
Restore(s)
.CombineWithBuildInfos(libraryVersions));
.CombineWithBuildInfos(libraryVersions));
}
else
{
Expand Down
19 changes: 19 additions & 0 deletions build/LibraryVersions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Models;
using Nuke.Common.Tools.MSBuild;

public static partial class LibraryVersion
{
public static bool TryGetVersions(string applicationName, MSBuildTargetPlatform platform, out IReadOnlyCollection<PackageBuildInfo> libraryVersions)
{
var result = Versions.TryGetValue(applicationName, out libraryVersions);
if (result)
{
libraryVersions = libraryVersions
.Where(x =>
x.SupportedPlatforms.Contains(platform.ToString(), StringComparer.OrdinalIgnoreCase))
.ToList();
}

return result;
}
}
13 changes: 8 additions & 5 deletions build/LibraryVersions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

using Models;

public static class LibraryVersion
public static partial class LibraryVersion
{
public static IReadOnlyDictionary<string, IReadOnlyCollection<PackageBuildInfo>> Versions = new Dictionary<string, IReadOnlyCollection<PackageBuildInfo>>
{
Expand All @@ -38,7 +38,7 @@ public static class LibraryVersion
{
new("6.0.27"),
new("7.0.16"),
new("8.0.2", new string[] {"net8.0"}),
new("8.0.2", supportedFrameworks: new string[] {"net8.0"}),
}
},
{
Expand All @@ -47,15 +47,15 @@ public static class LibraryVersion
{
new("6.0.2"),
new("7.0.0"),
new("8.0.0", new string[] {"net8.0"}),
new("8.0.0", supportedFrameworks: new string[] {"net8.0"}),
}
},
{
"TestApplication.GraphQL",
new List<PackageBuildInfo>
{
new("7.5.0", Array.Empty<string>(), new() {{"GraphQLMicrosoftDI","7.5.0"},{"GraphQLServerTransportsAspNetCore","7.5.0"},{"GraphQLServerUIPlayground","7.5.0"}}),
new("7.8.0", Array.Empty<string>(), new() {{"GraphQLMicrosoftDI","7.8.0"},{"GraphQLServerTransportsAspNetCore","7.7.1"},{"GraphQLServerUIPlayground","7.7.1"}}),
new("7.5.0", additionalMetaData: new() {{"GraphQLMicrosoftDI","7.5.0"},{"GraphQLServerTransportsAspNetCore","7.5.0"},{"GraphQLServerUIPlayground","7.5.0"}}),
new("7.8.0", additionalMetaData: new() {{"GraphQLMicrosoftDI","7.8.0"},{"GraphQLServerTransportsAspNetCore","7.7.1"},{"GraphQLServerUIPlayground","7.7.1"}}),
}
},
{
Expand Down Expand Up @@ -162,6 +162,9 @@ public static class LibraryVersion
"TestApplication.Kafka",
new List<PackageBuildInfo>
{
new("1.4.0", supportedPlatforms: new string[] {"x64"}),
new("1.6.2"),
new("1.8.2"),
new("2.3.0"),
}
},
Expand Down
17 changes: 6 additions & 11 deletions build/Models/PackageBuildInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ namespace Models;

public class PackageBuildInfo
{
public PackageBuildInfo(string libraryVersion) : this(libraryVersion, Array.Empty<string>())
{
}

public PackageBuildInfo(string libraryVersion, string[] supportedFrameworks) : this(libraryVersion, supportedFrameworks, new Dictionary<string, string>())
{
}

public PackageBuildInfo(string libraryVersion, string[] supportedFrameworks, Dictionary<string, string> additionalMetaData)
public PackageBuildInfo(string libraryVersion, string[] supportedFrameworks = null, string[] supportedPlatforms = null, Dictionary<string, string> additionalMetaData = null)
{
LibraryVersion = libraryVersion;
SupportedFrameworks = supportedFrameworks;
AdditionalMetaData = additionalMetaData;
SupportedFrameworks = supportedFrameworks ?? Array.Empty<string>();
SupportedPlatforms = supportedPlatforms ?? Array.Empty<string>();
AdditionalMetaData = additionalMetaData ?? new Dictionary<string, string>();
}

public string LibraryVersion { get; }

public string[] SupportedFrameworks { get; }

public string[] SupportedPlatforms { get; }

public Dictionary<string, string> AdditionalMetaData { get; }
}
56 changes: 30 additions & 26 deletions docs/config.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion test/IntegrationTests/Helpers/EnvironmentTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class EnvironmentTools
public const string ProfilerClsId = "{918728DD-259F-4A6A-AC2B-B85E1B658318}";
public const string DotNetFramework = ".NETFramework";
public const string CoreFramework = ".NETCoreApp";

private static readonly Lazy<string> SolutionDirectory = new(() =>
{
var startDirectory = Environment.CurrentDirectory;
Expand Down Expand Up @@ -89,7 +90,7 @@ public static bool IsMacOS()

public static string GetPlatform()
{
return RuntimeInformation.ProcessArchitecture.ToString();
return RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
}

public static bool IsX64()
Expand Down
14 changes: 7 additions & 7 deletions test/IntegrationTests/KafkaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public KafkaTests(ITestOutputHelper testOutputHelper)
[Theory]
[Trait("Category", "EndToEnd")]
[Trait("Containers", "Linux")]
[MemberData(nameof(LibraryVersion.Kafka), MemberType = typeof(LibraryVersion))]
[MemberData(nameof(LibraryVersion.GetPlatformVersions), nameof(LibraryVersion.Kafka), MemberType = typeof(LibraryVersion))]
public void SubmitsTraces(string packageVersion)
{
var topicName = $"test-topic-{packageVersion}";
Expand All @@ -56,17 +56,17 @@ public void SubmitsTraces(string packageVersion)
collector.Expect(KafkaInstrumentationScopeName, span => span.Kind == Span.Types.SpanKind.Producer && ValidateProduceExceptionSpan(span, topicName), "Failed Produce attempt without delivery handler set.");
collector.Expect(KafkaInstrumentationScopeName, span => span.Kind == Span.Types.SpanKind.Producer && ValidateResultProcessingProduceExceptionSpan(span, topicName), "Failed ProduceAsync attempt.");

if (packageVersion == string.Empty || Version.Parse(packageVersion) >= new Version(2, 3, 0))
{
// Failed consume attempt.
collector.Expect(KafkaInstrumentationScopeName, span => span.Kind == Span.Types.SpanKind.Consumer && ValidateConsumeExceptionSpan(span, topicName), "Failed Consume attempt.");
}
else
if (packageVersion != string.Empty && Version.Parse(packageVersion) == new Version(1, 4, 0))
{
// For 1.4.0 null is returned when attempting to read from non-existent topic,
// and no exception is thrown.
collector.Expect(KafkaInstrumentationScopeName, span => span.Kind == Span.Types.SpanKind.Consumer && ValidateEmptyReadConsumerSpan(span, topicName), "Successful Consume attempt that returned no message.");
}
else
{
// Failed consume attempt.
collector.Expect(KafkaInstrumentationScopeName, span => span.Kind == Span.Types.SpanKind.Consumer && ValidateConsumeExceptionSpan(span, topicName), "Failed Consume attempt.");
}

// Successful produce attempts after topic was created with admin client.
collector.Expect(KafkaInstrumentationScopeName, span => span.Kind == Span.Types.SpanKind.Producer && ValidateProducerSpan(span, topicName, 0), "Successful ProduceAsync attempt.");
Expand Down
25 changes: 25 additions & 0 deletions test/IntegrationTests/LibraryVersions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using IntegrationTests.Helpers;

namespace IntegrationTests;

/// <summary>
/// Logic partial of LibraryVersion
/// </summary>
public static partial class LibraryVersion
{
public static IEnumerable<object[]> GetPlatformVersions(string integrationName)
{
var anyPlatformVersions = LookupMap[integrationName];
var platformKey = $"{integrationName}_{EnvironmentTools.GetPlatform()}";

if (LookupMap.TryGetValue(platformKey, out var platformVersions))
{
return anyPlatformVersions.Concat(platformVersions);
}

return anyPlatformVersions;
}
}
34 changes: 33 additions & 1 deletion test/IntegrationTests/LibraryVersions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace IntegrationTests;

public static class LibraryVersion
public static partial class LibraryVersion
{
public static readonly IReadOnlyCollection<object[]> Azure = new List<object[]>
{
Expand Down Expand Up @@ -182,7 +182,39 @@ public static class LibraryVersion
#if DEFAULT_TEST_PACKAGE_VERSIONS
new object[] { string.Empty }
#else
new object[] { "1.6.2" },
new object[] { "1.8.2" },
new object[] { "2.3.0" },
#endif
};
public static readonly IReadOnlyCollection<object[]> Kafka_x64 = new List<object[]>
{
#if DEFAULT_TEST_PACKAGE_VERSIONS
new object[] { string.Empty }
#else
new object[] { "1.4.0" },
#endif
};
public static readonly IReadOnlyDictionary<string, IReadOnlyCollection<object[]>> LookupMap = new Dictionary<string, IReadOnlyCollection<object[]>>
{
{ "Azure", Azure },
{ "Elasticsearch", Elasticsearch },
{ "EntityFrameworkCore", EntityFrameworkCore },
{ "EntityFrameworkCorePomeloMySql", EntityFrameworkCorePomeloMySql },
{ "GraphQL", GraphQL },
{ "GrpcNetClient", GrpcNetClient },
{ "MassTransit", MassTransit },
{ "SqlClientMicrosoft", SqlClientMicrosoft },
{ "SqlClientSystem", SqlClientSystem },
{ "MongoDB", MongoDB },
{ "MySqlConnector", MySqlConnector },
{ "MySqlData", MySqlData },
{ "Npgsql", Npgsql },
{ "NServiceBus", NServiceBus },
{ "Quartz", Quartz },
{ "StackExchangeRedis", StackExchangeRedis },
{ "WCFCoreClient", WCFCoreClient },
{ "Kafka", Kafka },
{ "Kafka_x64", Kafka_x64 },
};
}
39 changes: 28 additions & 11 deletions tools/LibraryVersionsGenerator/BuildFileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,18 @@ public override CSharpFileBuilder BeginTestPackage(string testApplicationName, s
return this;
}

public override CSharpFileBuilder AddVersion(string version, string[] supportedFrameworks)
public override CSharpFileBuilder AddVersion(string version, string[] supportedFrameworks, string[] supportedPlatforms)
{
if (supportedFrameworks.Length > 0)
{
Builder.AppendLine($" new(\"{version}\", {SerializeArray(supportedFrameworks)}),");
}
else
{
Builder.AppendLine($" new(\"{version}\"),");
}
AddVersion(version, supportedFrameworks, supportedPlatforms, appendEnd: true);

return this;
}

public override CSharpFileBuilder AddVersionWithDependencies(string version, Dictionary<string, string> dependencies, string[] supportedFrameworks)
public override CSharpFileBuilder AddVersionWithDependencies(string version, Dictionary<string, string> dependencies, string[] supportedFrameworks, string[] supportedPlatforms)
{
Builder.AppendLine($" new(\"{version}\", {SerializeArray(supportedFrameworks)}, {SerializeDictionary(dependencies)}),");
AddVersion(version, supportedFrameworks, supportedPlatforms, appendEnd: false);

Builder.AppendLine($", additionalMetaData: {SerializeDictionary(dependencies)}),");
return this;
}

Expand Down Expand Up @@ -111,4 +106,26 @@ private static string SerializeArray(string[] array)

return arraySb.ToString();
}

private CSharpFileBuilder AddVersion(string version, string[] supportedFrameworks, string[] supportedPlatforms, bool appendEnd)
{
Builder.Append($" new(\"{version}\"");

if (supportedFrameworks.Length > 0)
{
Builder.Append($", supportedFrameworks: {SerializeArray(supportedFrameworks)}");
}

if (supportedPlatforms.Length > 0)
{
Builder.Append($", supportedPlatforms: {SerializeArray(supportedPlatforms)}");
}

if (appendEnd)
{
Builder.AppendLine($"),");
}

return this;
}
}
6 changes: 3 additions & 3 deletions tools/LibraryVersionsGenerator/CSharpFileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public virtual CSharpFileBuilder BeginClass(string classNamespace, string classN
Builder.AppendLine();
}

Builder.AppendLine(@"public static class LibraryVersion
Builder.AppendLine(@"public static partial class LibraryVersion
{");

return this;
Expand All @@ -64,9 +64,9 @@ public virtual CSharpFileBuilder EndClass()

public abstract CSharpFileBuilder BeginTestPackage(string testApplicationName, string integrationName);

public abstract CSharpFileBuilder AddVersion(string version, string[] supportedFrameworks);
public abstract CSharpFileBuilder AddVersion(string version, string[] supportedFrameworks, string[] supportedPlatforms);

public abstract CSharpFileBuilder AddVersionWithDependencies(string version, Dictionary<string, string> dependencies, string[] supportedFrameworks);
public abstract CSharpFileBuilder AddVersionWithDependencies(string version, Dictionary<string, string> dependencies, string[] supportedFrameworks, string[] supportedPlatforms);

public abstract CSharpFileBuilder EndTestPackage();

Expand Down
9 changes: 6 additions & 3 deletions tools/LibraryVersionsGenerator/Models/PackageVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ namespace LibraryVersionsGenerator.Models;

internal class PackageVersion
{
public PackageVersion(string version, params string[] supportedFrameworks)
public PackageVersion(string version, string[]? supportedFrameworks = null, string[]? supportedPlatforms = null)
{
Version = version;
SupportedFrameworks = supportedFrameworks;
SupportedFrameworks = supportedFrameworks ?? Array.Empty<string>();
SupportedPlatforms = supportedPlatforms ?? Array.Empty<string>();
}

public string Version { get; init; }

public string[] SupportedFrameworks { get; set; }
public string[] SupportedFrameworks { get; init; }

public string[] SupportedPlatforms { get; init; }
}
13 changes: 7 additions & 6 deletions tools/LibraryVersionsGenerator/PackageVersionDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ internal static class PackageVersionDefinitions
{
new("6.0.27"),
new("7.0.16"),
new("8.0.2", "net8.0"),
new("*", "net8.0")
new("8.0.2", supportedFrameworks: new[] { "net8.0" }),
new("*", supportedFrameworks: new[] { "net8.0" })
}
},
new()
Expand All @@ -54,8 +54,8 @@ internal static class PackageVersionDefinitions
{
new("6.0.2"),
new("7.0.0"),
new("8.0.0", "net8.0"),
new("*", "net8.0")
new("8.0.0", supportedFrameworks: new[] { "net8.0" }),
new("*", supportedFrameworks: new[] { "net8.0" })
}
},
new()
Expand Down Expand Up @@ -216,8 +216,9 @@ internal static class PackageVersionDefinitions
TestApplicationName = "TestApplication.Kafka",
Versions = new List<PackageVersion>
{
// TODO: Temporarily disable version 1.4.0, Doesn't support ARM64
// new("1.4.0"),
new("1.4.0", supportedPlatforms: new[] { "x64" }),
new("1.6.2"), // First version that supports both arm64 and x64
new("1.8.2"), // 1.8.0-1.8.1 are known to have issues with arm64
new("*")
}
}
Expand Down
Loading

0 comments on commit dca75ff

Please sign in to comment.