Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Utils;
using CommunityToolkit.Aspire.Hosting.GoFeatureFlag;
using Microsoft.Extensions.Logging;

namespace Aspire.Hosting;

Expand Down Expand Up @@ -55,11 +56,11 @@ public static IResourceBuilder<GoFeatureFlagResource> AddGoFeatureFlag(
return builder.AddResource(goFeatureFlagResource)
.WithImage(GoFeatureFlagContainerImageTags.Image, GoFeatureFlagContainerImageTags.Tag)
.WithImageRegistry(GoFeatureFlagContainerImageTags.Registry)
.WithHttpEndpoint(targetPort: GoFeatureFlagPort, port: port, name: GoFeatureFlagResource.PrimaryEndpointName)
.WithHttpEndpoint(targetPort: GoFeatureFlagPort, port: port,
name: GoFeatureFlagResource.PrimaryEndpointName)
.WithHttpHealthCheck("/health")
.WithEntrypoint("/go-feature-flag")
.WithArgs(args)
.WithOtlpExporter();
.WithArgs(args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we won't do OTEL wire-up initially?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I have an issue with the new tests. Some dependencies that are not registered, so I had to remove this to ensure my tests are passing. Also, I still have an issue with the collector so I suppose removing it seems better.

}

/// <summary>
Expand Down Expand Up @@ -120,4 +121,33 @@ public static IResourceBuilder<GoFeatureFlagResource> WithGoffBindMount(this IRe

return builder.WithBindMount(source, "/goff");
}

/// <summary>
/// Configures logging level for the GO Feature Flag container resource.
/// </summary>
/// <param name="builder">The resource builder.</param>
/// <param name="logLevel">The log level to set.</param>
/// <returns>The <see cref="IResourceBuilder{GoFeatureFlagResource}"/>.</returns>
/// <remarks>
/// The only supported <see cref="LogLevel"/> by GO Feature Flag are <see cref="LogLevel.Error"/>,
/// <see cref="LogLevel.Warning"/>, <see cref="LogLevel.Information"/> and <see cref="LogLevel.Debug"/>.
/// </remarks>
public static IResourceBuilder<GoFeatureFlagResource> WithLogLevel(
this IResourceBuilder<GoFeatureFlagResource> builder,
LogLevel logLevel
)
{
ArgumentNullException.ThrowIfNull(builder, nameof(builder));

string value = logLevel switch
{
LogLevel.Error => "ERROR",
LogLevel.Warning => "WARN",
LogLevel.Information => "INFO",
LogLevel.Debug => "DEBUG",
_ => throw new ArgumentOutOfRangeException(nameof(logLevel), "This log level is not supported by GO Feature Flag.")
};

return builder.WithEnvironment("LOGLEVEL", value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,30 @@ public static IResourceBuilder<SurrealDbServerResource> WithInitFiles(this IReso
context.EnvironmentVariables[ImportFileEnvVarName] = initFilePath;
});
}

/// <summary>
/// Configures logging level for the SurrealDB container resource.
/// </summary>
/// <param name="builder">The resource builder.</param>
/// <param name="logLevel">The log level to set.</param>
/// <returns>The <see cref="IResourceBuilder{SurrealDbServerResource}"/>.</returns>
public static IResourceBuilder<SurrealDbServerResource> WithLogLevel(
this IResourceBuilder<SurrealDbServerResource> builder,
LogLevel logLevel
)
{
ArgumentNullException.ThrowIfNull(builder, nameof(builder));

string value = logLevel switch
{
LogLevel.Critical => "full",
LogLevel.Information => "info",
LogLevel.Warning => "warn",
_ => logLevel.ToString().ToLowerInvariant()
};

return builder.WithEnvironment("SURREAL_LOG", value);
}

/// <summary>
/// Adds a Surrealist UI instance for SurrealDB to the application model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Net.Sockets;
using Aspire.Hosting;
using Microsoft.Extensions.Logging;

namespace CommunityToolkit.Aspire.Hosting.GoFeatureFlag.Tests;

Expand Down Expand Up @@ -89,4 +90,42 @@ public async Task GoFeatureFlagCreatesConnectionString()
Assert.Equal($"Endpoint=http://localhost:27020", connectionString);
Assert.Equal("Endpoint=http://{goff.bindings.http.host}:{goff.bindings.http.port}", connectionStringResource.ConnectionStringExpression.ValueExpression);
}

[Theory]
[InlineData(LogLevel.Debug, "DEBUG")]
[InlineData(LogLevel.Information, "INFO")]
[InlineData(LogLevel.Warning, "WARN")]
[InlineData(LogLevel.Error, "ERROR")]
public async Task AddSurrealServerContainerWithLogLevel(LogLevel logLevel, string? expected)
{
var appBuilder = DistributedApplication.CreateBuilder();

var goff = appBuilder
.AddGoFeatureFlag("goff")
.WithLogLevel(logLevel);

using var app = appBuilder.Build();

var config = await goff.Resource.GetEnvironmentVariableValuesAsync();

bool hasValue = config.TryGetValue("LOGLEVEL", out var value);

Assert.True(hasValue);
Assert.Equal(expected, value);
}

[Theory]
[InlineData(LogLevel.Trace)]
[InlineData(LogLevel.Critical)]
[InlineData(LogLevel.None)]
public void AddSurrealServerContainerWithLogLevelThrowsOnUnsupportedLogLevel(LogLevel logLevel)
{
var appBuilder = DistributedApplication.CreateBuilder();

var func = () => appBuilder
.AddGoFeatureFlag("goff")
.WithLogLevel(logLevel);

Assert.Throws<ArgumentOutOfRangeException>(func);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting;
using Microsoft.Extensions.Logging;

namespace CommunityToolkit.Aspire.Hosting.GoFeatureFlag.Tests;

Expand Down Expand Up @@ -79,4 +80,17 @@ public void CtorGoFeatureFlagResourceShouldThrowWhenNameIsNull()
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}

[Fact]
public void WithLogLevelShouldThrowWhenBuilderIsNull()
{
IResourceBuilder<GoFeatureFlagResource> builder = null!;

#pragma warning disable CTASPIRE002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var action = () => builder.WithLogLevel(LogLevel.Trace);
#pragma warning restore CTASPIRE002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Aspire.Hosting;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.Logging;
using System.Net.Sockets;

namespace CommunityToolkit.Aspire.Hosting.SurrealDb.Tests;
Expand Down Expand Up @@ -180,4 +181,30 @@ public void CanAddDatabasesWithTheSameNameOnMultipleServers()
Assert.Equal("{ns1.connectionString};Database=imports", db1.Resource.ConnectionStringExpression.ValueExpression);
Assert.Equal("{ns2.connectionString};Database=imports", db2.Resource.ConnectionStringExpression.ValueExpression);
}

[Theory]
[InlineData(LogLevel.Trace, "trace")]
[InlineData(LogLevel.Debug, "debug")]
[InlineData(LogLevel.Information, "info")]
[InlineData(LogLevel.Warning, "warn")]
[InlineData(LogLevel.Error, "error")]
[InlineData(LogLevel.Critical, "full")]
[InlineData(LogLevel.None, "none")]
public async Task AddSurrealServerContainerWithLogLevel(LogLevel logLevel, string expected)
{
var appBuilder = DistributedApplication.CreateBuilder();

var surrealServer = appBuilder
.AddSurrealServer("surreal")
.WithLogLevel(logLevel);

using var app = appBuilder.Build();

var config = await surrealServer.Resource.GetEnvironmentVariableValuesAsync();

bool hasValue = config.TryGetValue("SURREAL_LOG", out var value);

Assert.True(hasValue);
Assert.Equal(expected, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Aspire.Hosting;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.Logging;

namespace CommunityToolkit.Aspire.Hosting.SurrealDb.Tests;

Expand Down Expand Up @@ -121,7 +122,6 @@ public void WithDataBindMountShouldThrowWhenSourceIsNull()
Assert.Equal(nameof(source), exception.ParamName);
}


[Fact(Skip = "Feature is unstable and blocking the release")]
public void WithInitFilesShouldThrowWhenBuilderIsNull()
{
Expand Down Expand Up @@ -154,6 +154,19 @@ public void WithInitFilesShouldThrowWhenSourceIsNullOrEmpty(bool isNull)
: Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(source), exception.ParamName);
}

[Fact]
public void WithLogLevelShouldThrowWhenBuilderIsNull()
{
IResourceBuilder<SurrealDbServerResource> builder = null!;

#pragma warning disable CTASPIRE002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var action = () => builder.WithLogLevel(LogLevel.Trace);
#pragma warning restore CTASPIRE002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}

[Fact]
public void WithSurrealistShouldThrowWhenBuilderIsNull()
Expand Down
Loading