Skip to content

Commit 90f8ae3

Browse files
committed
Some Aspire progress
1 parent 1ca2296 commit 90f8ae3

File tree

10 files changed

+297
-367
lines changed

10 files changed

+297
-367
lines changed

src/Exceptionless.AppHost/ElasticsearchExtensions.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,23 @@ namespace Aspire.Hosting;
1111
public static class ElasticsearchBuilderExtensions
1212
{
1313
/// <summary>
14-
/// Adds a Elasticsearch container to the application model. The default image is "docker.elastic.co/elasticsearch/elasticsearch" and tag is "latest". This version the package defaults to the 8.12.2 tag of the redis container image
14+
/// Adds a Elasticsearch container to the application model. The default image is "docker.elastic.co/elasticsearch/elasticsearch" and tag is "latest". This version the package defaults to the 8.12.2 tag of the Elasticsearch container image
1515
/// </summary>
1616
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param>
1717
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param>
1818
/// <param name="port">The host port to bind the underlying container to.</param>
1919
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
2020
public static IResourceBuilder<ElasticsearchResource> AddElasticsearch(this IDistributedApplicationBuilder builder, string name, int? port = null)
2121
{
22-
var redis = new ElasticsearchResource(name);
23-
return builder.AddResource(redis)
24-
.WithHttpEndpoint(containerPort: 9200)
25-
.WithAnnotation(new ContainerImageAnnotation { Image = "docker.elastic.co/elasticsearch/elasticsearch", Tag = "8.12.2" })
26-
.WithEnvironment("discovery.type", "single-node")
27-
//.WithEnvironment("network.host", "0.0.0.0")
28-
.WithEnvironment("XPACK_SECURITY_ENABLED", "false")
29-
.WithEnvironment("action.destructive_requires_name", "false")
30-
.WithEnvironment("ES_JAVA_OPTS", "-Xms1g -Xmx1g")
31-
.PublishAsContainer();
22+
var elasticsearch = new ElasticsearchResource(name);
23+
return builder.AddResource(elasticsearch)
24+
.WithHttpEndpoint(containerPort: 9200, hostPort: port, name: "http")
25+
.WithAnnotation(new ContainerImageAnnotation { Image = "docker.elastic.co/elasticsearch/elasticsearch", Tag = "8.12.2" })
26+
.WithEnvironment("discovery.type", "single-node")
27+
.WithEnvironment("xpack.security.enabled", "false")
28+
.WithEnvironment("action.destructive_requires_name", "false")
29+
.WithEnvironment("ES_JAVA_OPTS", "-Xms1g -Xmx1g")
30+
.PublishAsConnectionString();
3231
}
3332

3433
/// <summary>
@@ -78,14 +77,14 @@ public string? ConnectionStringExpression
7877
return connectionStringAnnotation.Resource.ConnectionStringExpression;
7978
}
8079

81-
return $"{{{Name}.bindings.tcp.host}}:{{{Name}.bindings.tcp.port}}";
80+
return $"http://{{{Name}.bindings.tcp.host}}:{{{Name}.bindings.tcp.port}}";
8281
}
8382
}
8483

8584
/// <summary>
8685
/// Gets the connection string for the Elasticsearch server.
8786
/// </summary>
88-
/// <returns>A connection string for the redis server in the form "host:port".</returns>
87+
/// <returns>A connection string for the Elasticsearch server in the form "host:port".</returns>
8988
public string? GetConnectionString()
9089
{
9190
if (this.TryGetLastAnnotation<ConnectionStringRedirectAnnotation>(out var connectionStringAnnotation))
@@ -100,7 +99,7 @@ public string? ConnectionStringExpression
10099

101100
// We should only have one endpoint for Elasticsearch for local scenarios.
102101
var endpoint = allocatedEndpoints.Single();
103-
return endpoint.EndPointString;
102+
return $"http://{endpoint.EndPointString}";
104103
}
105104
}
106105

src/Exceptionless.AppHost/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var builder = DistributedApplication.CreateBuilder(args);
22

3-
var elastic = builder.AddElasticsearch("Elastic")
3+
var elastic = builder.AddElasticsearch("Elasticsearch")
44
.WithKibana();
55

66
var cache = builder.AddRedis("Redis")

src/Exceptionless.Core/Configuration/AppOptions.cs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,8 @@ public static AppOptions ReadFromConfiguration(IConfiguration config)
114114
options.EnableRepositoryNotifications = config.GetValue(nameof(options.EnableRepositoryNotifications), true);
115115
options.EnableWebSockets = config.GetValue(nameof(options.EnableWebSockets), true);
116116

117-
try
118-
{
119-
var versionInfo = FileVersionInfo.GetVersionInfo(typeof(AppOptions).Assembly.Location);
120-
options.Version = versionInfo?.FileVersion;
121-
options.InformationalVersion = versionInfo?.ProductVersion;
122-
}
123-
catch { }
117+
options.Version = GetVersion();
118+
options.InformationalVersion = GetInformationalVersion();
124119

125120
options.CacheOptions = CacheOptions.ReadFromConfiguration(config, options);
126121
options.MessageBusOptions = MessageBusOptions.ReadFromConfiguration(config, options);
@@ -135,6 +130,40 @@ public static AppOptions ReadFromConfiguration(IConfiguration config)
135130

136131
return options;
137132
}
133+
134+
private static string? _informationalVersion = null;
135+
private static string? _version = null;
136+
137+
private static void GetVersionInternal()
138+
{
139+
try
140+
{
141+
var versionInfo = FileVersionInfo.GetVersionInfo(typeof(AppOptions).Assembly.Location);
142+
_version = versionInfo?.FileVersion;
143+
_informationalVersion = versionInfo?.ProductVersion;
144+
}
145+
catch { }
146+
}
147+
148+
public static string GetVersion()
149+
{
150+
if (_version != null)
151+
return _version;
152+
153+
GetVersionInternal();
154+
155+
return _version ?? string.Empty;
156+
}
157+
158+
public static string GetInformationalVersion()
159+
{
160+
if (_informationalVersion != null)
161+
return _informationalVersion;
162+
163+
GetVersionInternal();
164+
165+
return _informationalVersion ?? string.Empty;
166+
}
138167
}
139168

140169
public enum AppMode

src/Exceptionless.Core/Utility/AppDiagnostics.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public static class AppDiagnostics
99
{
1010
internal static readonly AssemblyName AssemblyName = typeof(AppDiagnostics).Assembly.GetName();
1111
internal static readonly string? AssemblyVersion = typeof(AppDiagnostics).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? AssemblyName.Version?.ToString();
12-
internal static readonly ActivitySource ActivitySource = new(AssemblyName.Name ?? "Exceptionless", AssemblyVersion);
13-
internal static readonly Meter Meter = new("Exceptionless", AssemblyVersion);
12+
public static readonly ActivitySource ActivitySource = new(AssemblyName.Name ?? "Exceptionless", AssemblyVersion);
13+
public static readonly Meter Meter = new("Exceptionless", AssemblyVersion);
1414
private static readonly string _metricsPrefix = "ex.";
1515

1616
private static readonly ConcurrentDictionary<string, Counter<int>> _counters = new();

src/Exceptionless.Job/Exceptionless.Job.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<Compile Include="..\Exceptionless.Web\ApmExtensions.cs" Link="ApmExtensions.cs" />
31+
<Compile Include="..\Exceptionless.Web\ServiceDefaults.cs" Link="ServiceDefaults.cs" />
3232
</ItemGroup>
3333
</Project>

src/Exceptionless.Job/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static IHostBuilder CreateHostBuilder(string[] args)
4949
.SetBasePath(Directory.GetCurrentDirectory())
5050
.AddYamlFile("appsettings.yml", optional: true, reloadOnChange: true)
5151
.AddYamlFile($"appsettings.{environment}.yml", optional: true, reloadOnChange: true)
52+
.AddEnvironmentVariables()
5253
.AddEnvironmentVariables("EX_")
5354
.AddEnvironmentVariables("ASPNETCORE_")
5455
.AddCommandLine(args)
@@ -60,7 +61,7 @@ public static IHostBuilder CreateHostBuilder(string[] args)
6061
.ForContext<Program>();
6162

6263
var options = AppOptions.ReadFromConfiguration(config);
63-
var apmConfig = new ApmConfig(config, $"job-{jobOptions.JobName.ToLowerUnderscoredWords('-')}", options.InformationalVersion, options.CacheOptions.Provider == "redis");
64+
var otelConfig = new OpenTelemetryConfig(config, $"job-{jobOptions.JobName.ToLowerUnderscoredWords('-')}", options.CacheOptions.Provider == "redis");
6465

6566
var configDictionary = config.ToDictionary("Serilog");
6667
Log.Information("Bootstrapping Exceptionless {JobName} job(s) in {AppMode} mode ({InformationalVersion}) on {MachineName} with settings {@Settings}", jobOptions.JobName ?? "All", environment, options.InformationalVersion, Environment.MachineName, configDictionary);
@@ -100,8 +101,7 @@ public static IHostBuilder CreateHostBuilder(string[] args)
100101
if (!String.IsNullOrEmpty(options.ExceptionlessApiKey) && !String.IsNullOrEmpty(options.ExceptionlessServerUrl))
101102
app.UseExceptionless(ExceptionlessClient.Default);
102103

103-
if (apmConfig.EnableMetrics)
104-
app.UseOpenTelemetryPrometheusScrapingEndpoint();
104+
app.UseOpenTelemetryPrometheusScrapingEndpoint();
105105

106106
app.UseHealthChecks("/health", new HealthCheckOptions
107107
{
@@ -128,7 +128,7 @@ public static IHostBuilder CreateHostBuilder(string[] args)
128128
Bootstrapper.RegisterServices(services, options);
129129
Insulation.Bootstrapper.RegisterServices(services, options, true);
130130
})
131-
.AddApm(apmConfig);
131+
.AddServiceDefaults(otelConfig);
132132

133133
return builder;
134134
}

0 commit comments

Comments
 (0)