Skip to content

Commit 757bf85

Browse files
askptCopilotaaronpowell
authored
Add flagd Aspire hosting (#827)
* Add flagd hosting integration with configuration and tests Signed-off-by: André Silva <[email protected]> * Update Flagd container image tag to v0.12.9 Signed-off-by: André Silva <[email protected]> * Moved Fladg example project and configuration files Signed-off-by: André Silva <[email protected]> * Refactor Flagd resource configuration and add health check support Signed-off-by: André Silva <[email protected]> * Refactor AddFlagd method calls to use named parameters for clarity Signed-off-by: André Silva <[email protected]> * Update AddFlagd method to use a default port value instead of nullable Signed-off-by: André Silva <[email protected]> * Update README.md to clarify usage and configuration for AddFlagd method Signed-off-by: André Silva <[email protected]> * Enhance AddFlagd method to validate port range and update container image version in tests Signed-off-by: André Silva <[email protected]> * Add examples folder to solution structure Signed-off-by: André Silva <[email protected]> * Add OpenFeature Flagd provider and configuration flags Signed-off-by: André Silva <[email protected]> * Update AddFlagd method documentation to specify the expected flag configuration file name Signed-off-by: André Silva <[email protected]> * Fix AddFlagd method to correctly set target port for HTTP endpoint Signed-off-by: André Silva <[email protected]> * Update README to correct flag configuration file path and enhance usage examples Signed-off-by: André Silva <[email protected]> * Refactor AddFlagd method to accept optional port parameter and update related tests Signed-off-by: André Silva <[email protected]> * Refactor AddFlagd method to use constant for target port in HTTP endpoint Signed-off-by: André Silva <[email protected]> * Refactor logging configuration in AddFlagd method to use default logging level and update related tests Signed-off-by: André Silva <[email protected]> * Add tests for flagd provider and assert expected values Signed-off-by: GitHub <[email protected]> * Add health check endpoint to Flagd resource and builder Signed-off-by: GitHub <[email protected]> * Add OFREP endpoint support to Flagd resource and builder Signed-off-by: André Silva <[email protected]> * Refactor AddFlagd method to use WithBindFileSync for flag configuration Signed-off-by: André Silva <[email protected]> * Fix documentation for AddFlagd method to include remarks about sync source configuration Signed-off-by: André Silva <[email protected]> * Update AddFlagdTests and AppHostTests to improve resource handling and endpoint validation Signed-off-by: André Silva <[email protected]> * Add support for OpenFeature.Providers.Ofrep and update related configurations Signed-off-by: André Silva <[email protected]> * Fix Ofrep evaluation test by updating connection string retrieval and removing skip attribute Signed-off-by: André Silva <[email protected]> * Update README to reflect changes in AddFlagd usage with WithBindFileSync method Signed-off-by: André Silva <[email protected]> * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Clarify logging and port customization in README Updated README to clarify logging configuration and port customization for flagd. * Add Hosting.Flagd.Tests to integration test matrix Signed-off-by: André Silva <[email protected]> * Add WithLoglevel method to configure logging level for flagd Signed-off-by: André Silva <[email protected]> * Add tests for WithLoglevel method to validate environment variable addition and error handling Signed-off-by: André Silva <[email protected]> * Refactor logging configuration: replace WithLogging method with WithLogLevel for improved clarity and functionality Signed-off-by: André Silva <[email protected]> --------- Signed-off-by: André Silva <[email protected]> Signed-off-by: GitHub <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Aaron Powell <[email protected]>
1 parent c485c8a commit 757bf85

File tree

17 files changed

+776
-0
lines changed

17 files changed

+776
-0
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
Hosting.DbGate.Tests,
3030
Hosting.Deno.Tests,
3131
Hosting.EventStore.Tests,
32+
Hosting.Flagd.Tests,
3233
Hosting.GoFeatureFlag.Tests,
3334
Hosting.Golang.Tests,
3435
Hosting.Java.Tests,

CommunityToolkit.Aspire.slnx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<Project Path="examples/eventstore/CommunityToolkit.Aspire.Hosting.EventStore.AppHost/CommunityToolkit.Aspire.Hosting.EventStore.AppHost.csproj" />
3636
<Project Path="examples/eventstore/CommunityToolkit.Aspire.Hosting.EventStore.ServiceDefaults/CommunityToolkit.Aspire.Hosting.EventStore.ServiceDefaults.csproj" />
3737
</Folder>
38+
<Folder Name="/examples/flagd/">
39+
<Project Path="examples/flagd/CommunityToolkit.Aspire.Hosting.Flagd.AppHost/CommunityToolkit.Aspire.Hosting.Flagd.AppHost.csproj" />
40+
</Folder>
3841
<Folder Name="/examples/goff/">
3942
<Project Path="examples/goff/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.ApiService/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.ApiService.csproj" />
4043
<Project Path="examples/goff/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.AppHost/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.AppHost.csproj" />
@@ -166,6 +169,7 @@
166169
<Project Path="src/CommunityToolkit.Aspire.Hosting.DbGate/CommunityToolkit.Aspire.Hosting.DbGate.csproj" />
167170
<Project Path="src/CommunityToolkit.Aspire.Hosting.Deno/CommunityToolkit.Aspire.Hosting.Deno.csproj" />
168171
<Project Path="src/CommunityToolkit.Aspire.Hosting.EventStore/CommunityToolkit.Aspire.Hosting.EventStore.csproj" />
172+
<Project Path="src/CommunityToolkit.Aspire.Hosting.Flagd/CommunityToolkit.Aspire.Hosting.Flagd.csproj" />
169173
<Project Path="src/CommunityToolkit.Aspire.Hosting.GoFeatureFlag/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.csproj" />
170174
<Project Path="src/CommunityToolkit.Aspire.Hosting.Golang/CommunityToolkit.Aspire.Hosting.Golang.csproj" />
171175
<Project Path="src/CommunityToolkit.Aspire.Hosting.Java/CommunityToolkit.Aspire.Hosting.Java.csproj" />
@@ -217,6 +221,7 @@
217221
<Project Path="tests/CommunityToolkit.Aspire.Hosting.DbGate.Tests/CommunityToolkit.Aspire.Hosting.DbGate.Tests.csproj" />
218222
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Deno.Tests/CommunityToolkit.Aspire.Hosting.Deno.Tests.csproj" />
219223
<Project Path="tests/CommunityToolkit.Aspire.Hosting.EventStore.Tests/CommunityToolkit.Aspire.Hosting.EventStore.Tests.csproj" />
224+
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Flagd.Tests/CommunityToolkit.Aspire.Hosting.Flagd.Tests.csproj" />
220225
<Project Path="tests/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.Tests/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.Tests.csproj" />
221226
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Golang.Tests/CommunityToolkit.Aspire.Hosting.Golang.Tests.csproj" />
222227
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Java.Tests/CommunityToolkit.Aspire.Hosting.Java.Tests.csproj" />

Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696
<PackageVersion Include="Aspire.Hosting.Testing" Version="$(AspireVersion)" />
9797
<PackageVersion Include="Bogus" Version="35.6.3" />
9898
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
99+
<PackageVersion Include="OpenFeature.Contrib.Providers.Flagd" Version="0.3.3" />
100+
<PackageVersion Include="OpenFeature.Providers.Ofrep" Version="0.1.2" />
99101
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.6.0" />
100102
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
101103
<PackageVersion Include="xunit" Version="2.9.3" />

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This repository contains the source code for the .NET Aspire Community Toolkit,
2929
| - **Learn More**: [`Hosting.Python.Extensions`][python-ext-integration-docs] <br /> - Stable 📦: [![CommunityToolkit.Aspire.Python.Extensions][python-ext-shields]][python-ext-nuget] <br /> - Preview 📦: [![CommunityToolkit.Aspire.Hosting.Python.Extensions][python-ext-shields-preview]][python-ext-nuget-preview] | An integration that contains some additional extensions for running python applications |
3030
| - **Learn More**: [`Hosting.EventStore`][eventstore-integration-docs] <br /> - Stable 📦: [![CommunityToolkit.Aspire.Hosting.EventStore][eventstore-shields]][eventstore-nuget] <br /> - Preview 📦: [![CommunityToolkit.Aspire.Hosting.EventStore][eventstore-shields-preview]][eventstore-nuget-preview] | An Aspire hosting integration leveraging the [EventStore](https://eventstore.com) container. |
3131
| - **Learn More**: [`EventStore`][eventstore-integration-docs] <br /> - Stable 📦: [![CommunityToolkit.Aspire.EventStore][eventstore-client-shields]][eventstore-client-nuget] <br /> - Preview 📦: [![CommunityToolkit.Aspire.EventStore][eventstore-client-shields-preview]][eventstore-client-nuget-preview] | An Aspire client integration for the [EventStore](https://github.com/EventStore/EventStore-Client-Dotnet) package. |
32+
| - **Learn More**: [`Hosting.Flagd`][flagd-integration-docs] <br /> - Stable 📦: [![CommunityToolkit.Aspire.Hosting.Flagd][flagd-shields]][flagd-nuget] <br /> - Preview 📦: [![CommunityToolkit.Aspire.Hosting.Flagd][flagd-shields-preview]][flagd-nuget-preview] | A .NET Aspire hosting integration for [flagd](https://flagd.dev), a feature flag evaluation engine. |
3233
| - **Learn More**: [`Hosting.ActiveMQ`][activemq-integration-docs] <br /> - Stable 📦: [![CommunityToolkit.Aspire.Hosting.ActiveMQ][activemq-shields]][activemq-nuget] <br /> - Preview 📦: [![CommunityToolkit.Aspire.Hosting.ActiveMQ][activemq-shields-preview]][activemq-nuget-preview] | An Aspire hosting integration leveraging the [ActiveMq](https://activemq.apache.org) container. |
3334
| - **Learn More**: [`Hosting.Sqlite`][sqlite-integration-docs] <br /> - Stable 📦: [![CommunityToolkit.Aspire.Hosting.Sqlite][sqlite-shields]][sqlite-hosting-nuget] <br /> - Preview 📦: [![CommunityToolkit.Aspire.Hosting.Sqlite][sqlite-shields-preview]][sqlite-hosting-nuget-preview] | An Aspire hosting integration to setup a SQLite database with optional SQLite Web as a dev UI. |
3435
| - **Learn More**: [`Microsoft.Data.Sqlite`][sqlite-integration-docs] <br /> - Stable 📦: [![CommunityToolkit.Aspire.Microsoft.Data.Sqlite][sqlite-shields]][sqlite-nuget] <br /> - Preview 📦: [![CommunityToolkit.Aspire.Microsoft.Data.Sqlite][sqlite-shields-preview]][sqlite-nuget-preview] | An Aspire client integration for the Microsoft.Data.Sqlite NuGet package. |
@@ -163,6 +164,11 @@ This project is supported by the [.NET Foundation](https://dotnetfoundation.org)
163164
[eventstore-client-nuget]: https://nuget.org/packages/CommunityToolkit.Aspire.EventStore/
164165
[eventstore-client-shields-preview]: https://img.shields.io/nuget/vpre/CommunityToolkit.Aspire.EventStore?label=nuget%20(preview)
165166
[eventstore-client-nuget-preview]: https://nuget.org/packages/CommunityToolkit.Aspire.EventStore/absoluteLatest
167+
[flagd-integration-docs]: https://learn.microsoft.com/dotnet/aspire/community-toolkit/hosting-flagd
168+
[flagd-shields]: https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Hosting.Flagd
169+
[flagd-nuget]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.Flagd/
170+
[flagd-shields-preview]: https://img.shields.io/nuget/vpre/CommunityToolkit.Aspire.Hosting.Flagd?label=nuget%20(preview)
171+
[flagd-nuget-preview]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.Flagd/absoluteLatest
166172
[activemq-integration-docs]: https://learn.microsoft.com/dotnet/aspire/community-toolkit/hosting-activemq
167173
[activemq-shields]: https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Hosting.ActiveMQ
168174
[activemq-nuget]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.ActiveMQ/
@@ -268,3 +274,4 @@ This project is supported by the [.NET Foundation](https://dotnetfoundation.org)
268274
[surrealdb-client-nuget]: https://nuget.org/packages/CommunityToolkit.Aspire.SurrealDb/
269275
[surrealdb-client-shields-preview]: https://img.shields.io/nuget/vpre/CommunityToolkit.Aspire.SurrealDb?label=nuget%20(preview)
270276
[surrealdb-client-nuget-preview]: https://nuget.org/packages/CommunityToolkit.Aspire.SurrealDb/absoluteLatest
277+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)" />
4+
5+
<PropertyGroup>
6+
<OutputType>Exe</OutputType>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<IsAspireHost>true</IsAspireHost>
10+
<UserSecretsId>6445164b-1ed4-461b-baa5-86790b0c158d</UserSecretsId>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Aspire.Hosting.AppHost" />
15+
<PackageReference Include="OpenFeature.Contrib.Providers.Flagd" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="../../../src/CommunityToolkit.Aspire.Hosting.Flagd/CommunityToolkit.Aspire.Hosting.Flagd.csproj" IsAspireProjectResource="false" />
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using OpenFeature.Contrib.Providers.Flagd;
2+
3+
var builder = DistributedApplication.CreateBuilder(args);
4+
5+
// Add flagd with local flag configuration file
6+
var flagd = builder
7+
.AddFlagd("flagd")
8+
.WithBindFileSync("./flags/")
9+
.WithLogLevel(Microsoft.Extensions.Logging.LogLevel.Debug);
10+
11+
builder.Build().Run();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17255;http://localhost:15238",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21210",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22287"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15238",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19230",
25+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20107"
26+
}
27+
}
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$schema": "https://flagd.dev/schema/v0/flags.json",
3+
"flags": {
4+
"welcome-banner": {
5+
"state": "ENABLED",
6+
"variants": {
7+
"on": true,
8+
"off": false
9+
},
10+
"defaultVariant": "on"
11+
},
12+
"background-color": {
13+
"state": "ENABLED",
14+
"variants": {
15+
"red": "#FF0000",
16+
"blue": "#0000FF",
17+
"green": "#00FF00",
18+
"yellow": "#FFFF00"
19+
},
20+
"defaultVariant": "red",
21+
"targeting": {
22+
"if": [
23+
{
24+
"===": [
25+
{
26+
"var": "company"
27+
},
28+
"aspire"
29+
]
30+
},
31+
"blue"
32+
]
33+
}
34+
},
35+
"api-version": {
36+
"state": "ENABLED",
37+
"variants": {
38+
"v1": "1.0",
39+
"v2": "2.0",
40+
"v3": "3.0"
41+
},
42+
"defaultVariant": "v1"
43+
}
44+
}
45+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<AdditionalPackageTags>hosting flagd feature-flags openfeature</AdditionalPackageTags>
5+
<Description>flagd is a feature flag evaluation engine. Think of it as a ready-made, open source, OpenFeature-compliant feature flag backend system.</Description>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Aspire.Hosting" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<InternalsVisibleTo Include="CommunityToolkit.Aspire.Hosting.Flagd.Tests"></InternalsVisibleTo>
14+
</ItemGroup>
15+
16+
</Project>

0 commit comments

Comments
 (0)