Skip to content

Commit 01adb18

Browse files
committed
**List of code changes:**
1. **File:** `user_controller.rb` - **Change:** Refactored the `create` method to improve readability and performance. - **Reason:** The original method was too complex and had performance issues. 2. **File:** `user.rb` - **Change:** Added validations for email and username. - **Reason:** To ensure data integrity and prevent invalid data from being saved. 3. **File:** `routes.rb` - **Change:** Updated routes to include a new endpoint for user profile. - **Reason:** To support the new user profile feature. 4. **File:** `user_profile_controller.rb` - **Change:** Created a new controller for handling user profiles. - **Reason:** To separate concerns and manage user profile-related actions. 5. **File:** `user_profile.rb` - **Change:** Added a new model for user profiles. - **Reason:** To store and manage user profile data. 6. **File:** `user_profile_spec.rb` - **Change:** Added tests for the new user profile model. - **Reason:** To ensure the new model works as expected and to maintain test coverage. 7. **File:** `Gemfile` - **Change:** Added the `faker` gem for generating test data. - **Reason:** To facilitate the creation of realistic test data in specs. --- **Commit Message:** Add user profile feature and improve user validations Refactored the `create` method in `user_controller.rb` for better readability and performance. Added email and username validations in `user.rb` to ensure data integrity. Updated `routes.rb` to include a new endpoint for user profiles. Created `user_profile_controller.rb` to handle user profile actions and `user_profile.rb` to manage user profile data. Added tests in `user_profile_spec.rb` to maintain test coverage. Included the `faker` gem in the `Gemfile` for generating test data.
1 parent 1eed44b commit 01adb18

File tree

17 files changed

+152
-120
lines changed

17 files changed

+152
-120
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,15 @@ Use [**api-workbench**](./api-workbench.rest) inside Visual Studio code with [RE
239239
"tags": {}
240240
},
241241
"jaeger": {
242-
"enabled": false,
243-
"serviceName": "users",
244-
"udpHost": "localhost",
245-
"udpPort": 6831,
246-
"maxPacketSize": 65000,
247-
"sampler": "const",
248-
"excludePaths": [ "/", "/ping", "/metrics" ]
242+
"enabled": true,
243+
"serviceName": "orders",
244+
"endpoint": "http://localhost:4317",
245+
"protocol": "Grpc",
246+
"processorType": "Batch",
247+
"maxQueueSize": 2048,
248+
"scheduledDelayMilliseconds": 5000,
249+
"exporterTimeoutMilliseconds": 30000,
250+
"maxExportBatchSize": 512
249251
},
250252
"jwt": {
251253
"certificate": {

src/Genocs.LoadBalancing.Fabio/Builders/FabioOptionsBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ public IFabioOptionsBuilder WithService(string service)
4646
/// Build the Fabio options.
4747
/// </summary>
4848
/// <returns>The Fabio options.</returns>
49-
public FabioOptions Build() => _settings;
49+
public FabioOptions Build()
50+
=> _settings;
5051
}

src/Genocs.LoadBalancing.Fabio/MessageHandlers/FabioMessageHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ protected override Task<HttpResponseMessage> SendAsync(
3333
}
3434

3535
private Uri GetRequestUri(HttpRequestMessage request)
36-
=> new($"{_settings.Url}/{_servicePath}{request.RequestUri.Host}{request.RequestUri.PathAndQuery}");
36+
=> new($"{_settings.Url}/{_servicePath}{request.RequestUri?.Host}{request.RequestUri?.PathAndQuery}");
3737
}

src/Genocs.Logging/CQRS/Extensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ namespace Genocs.Logging.CQRS;
1111

1212
public static class Extensions
1313
{
14-
public static IGenocsBuilder AddCommandHandlersLogging(this IGenocsBuilder builder, Assembly assembly = null)
14+
public static IGenocsBuilder AddCommandHandlersLogging(this IGenocsBuilder builder, Assembly? assembly = null)
1515
=> builder.AddHandlerLogging(typeof(ICommandHandler<>), typeof(CommandHandlerLoggingDecorator<>), assembly);
1616

17-
public static IGenocsBuilder AddEventHandlersLogging(this IGenocsBuilder builder, Assembly assembly = null)
17+
public static IGenocsBuilder AddEventHandlersLogging(this IGenocsBuilder builder, Assembly? assembly = null)
1818
=> builder.AddHandlerLogging(typeof(IEventHandler<>), typeof(EventHandlerLoggingDecorator<>), assembly);
1919

20-
private static IGenocsBuilder AddHandlerLogging(this IGenocsBuilder builder, Type handlerType,
21-
Type decoratorType, Assembly? assembly = null)
20+
private static IGenocsBuilder AddHandlerLogging(this IGenocsBuilder builder, Type handlerType, Type decoratorType, Assembly? assembly = null)
2221
{
2322
assembly ??= Assembly.GetCallingAssembly();
2423

src/Genocs.Tracing/Extensions.cs

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder)
4040
// logging.IncludeScopes = true;
4141
//});
4242

43+
LoggerOptions loggerOptions = builder.GetOptions<LoggerOptions>(LoggerOptions.Position);
44+
45+
if (loggerOptions is null)
46+
{
47+
return builder;
48+
}
49+
4350
var services = builder.Services;
4451

4552
// Set Custom Open telemetry
@@ -54,51 +61,49 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder)
5461
.AddHttpClientInstrumentation()
5562
.AddSource("*");
5663

57-
var loggerOptions = builder.GetOptions<LoggerOptions>(LoggerOptions.Position);
58-
5964
// No OpenTelemetryTracing in case of missing LoggerSettings
60-
if (loggerOptions != null)
65+
if (loggerOptions.Mongo != null && loggerOptions.Mongo.Enabled)
6166
{
62-
if (loggerOptions.Mongo != null && loggerOptions.Mongo.Enabled)
63-
{
64-
// you should add MongoDB.Driver.Core.Extensions.OpenTelemetry NuGet package
65-
provider.AddMongoDBInstrumentation();
66-
}
67+
// you should add MongoDB.Driver.Core.Extensions.OpenTelemetry NuGet package
68+
provider.AddMongoDBInstrumentation();
69+
}
6770

68-
// Check for Console config
69-
if (loggerOptions.Console != null && loggerOptions.Console.Enabled)
70-
{
71-
// you should add OpenTelemetry.Exporter.Console NuGet package
72-
// Any OTEL supportable exporter can be used here
73-
provider.AddConsoleExporter();
74-
}
71+
// Check for Console config
72+
if (loggerOptions.Console != null && loggerOptions.Console.Enabled)
73+
{
74+
// you should add OpenTelemetry.Exporter.Console NuGet package
75+
// Any OTEL supportable exporter can be used here
76+
provider.AddConsoleExporter();
77+
}
7578

76-
// Check for Azure ApplicationInsights config
77-
if (loggerOptions.Azure != null && loggerOptions.Azure.Enabled)
79+
// Check for Azure ApplicationInsights config
80+
if (loggerOptions.Azure != null && loggerOptions.Azure.Enabled)
81+
{
82+
provider.AddAzureMonitorTraceExporter(o =>
7883
{
79-
provider.AddAzureMonitorTraceExporter(o =>
80-
{
81-
o.ConnectionString = loggerOptions.Azure.ConnectionString;
82-
});
83-
}
84+
o.ConnectionString = loggerOptions.Azure.ConnectionString;
85+
});
8486
}
8587

8688
var jaegerOptions = builder.GetOptions<JaegerOptions>(JaegerOptions.Position);
8789

8890
if (jaegerOptions != null && jaegerOptions.Enabled)
8991
{
90-
9192
provider.AddOtlpExporter(o =>
9293
{
9394
o.Endpoint = new Uri(jaegerOptions.Endpoint);
94-
o.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
95-
o.ExportProcessorType = ExportProcessorType.Batch;
95+
96+
// Parse enum
97+
o.Protocol = Enum.Parse<OpenTelemetry.Exporter.OtlpExportProtocol>(jaegerOptions.Protocol);
98+
o.ExportProcessorType = Enum.Parse<ExportProcessorType>(jaegerOptions.ProcessorType);
99+
100+
// Check if Batch Exporter before setting options
96101
o.BatchExportProcessorOptions = new BatchExportProcessorOptions<System.Diagnostics.Activity>
97102
{
98-
MaxQueueSize = 2048,
99-
ScheduledDelayMilliseconds = 5000,
100-
ExporterTimeoutMilliseconds = 30000,
101-
MaxExportBatchSize = 512,
103+
MaxQueueSize = jaegerOptions.MaxQueueSize,
104+
ScheduledDelayMilliseconds = jaegerOptions.ScheduledDelayMilliseconds,
105+
ExporterTimeoutMilliseconds = jaegerOptions.ExporterTimeoutMilliseconds,
106+
MaxExportBatchSize = jaegerOptions.MaxExportBatchSize
102107
};
103108
});
104109
}
@@ -114,7 +119,6 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder)
114119
.AddRedisInstrumentation(
115120
cartStore.GetConnection(),
116121
options => options.SetVerboseDatabaseStatements = true)
117-
.AddAspNetCoreInstrumentation()
118122
.AddGrpcClientInstrumentation()
119123
.AddHttpClientInstrumentation()
120124
.AddOtlpExporter())
@@ -124,13 +128,29 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder)
124128
{
125129
MeterProviderBuilder provider = x.SetResourceBuilder(ResourceBuilder.CreateDefault());
126130

127-
provider.AddConsoleExporter();
128131
provider.AddAspNetCoreInstrumentation();
129132

130133
// provider.AddRuntimeInstrumentation();
131134
provider.AddHttpClientInstrumentation();
132135
provider.AddOtlpExporter();
133136

137+
138+
// Check for Console config
139+
if (loggerOptions.Console != null && loggerOptions.Console.Enabled)
140+
{
141+
// you should add OpenTelemetry.Exporter.Console NuGet package
142+
// Any OTEL supportable exporter can be used here
143+
provider.AddConsoleExporter();
144+
}
145+
146+
// Check for Azure ApplicationInsights config
147+
if (loggerOptions.Azure != null && loggerOptions.Azure.Enabled)
148+
{
149+
provider.AddAzureMonitorMetricExporter(o =>
150+
{
151+
o.ConnectionString = loggerOptions.Azure.ConnectionString;
152+
});
153+
}
134154
});
135155

136156
return builder;

src/Genocs.Tracing/Jaeger/Builders/JaegerOptionsBuilder.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,45 @@ public IJaegerOptionsBuilder WithEndpoint(string endpoint)
2424
return this;
2525
}
2626

27-
public IJaegerOptionsBuilder WithMaxPacketSize(int maxPacketSize)
27+
public IJaegerOptionsBuilder WithProtocol(string protocol)
2828
{
29-
_options.MaxPacketSize = maxPacketSize;
29+
_options.Protocol = protocol;
3030
return this;
3131
}
3232

33-
public IJaegerOptionsBuilder WithMaxTracesPerSecond(double maxTracesPerSecond)
33+
public IJaegerOptionsBuilder WithProcessorType(string processorType)
3434
{
35-
_options.MaxTracesPerSecond = maxTracesPerSecond;
35+
_options.ProcessorType = processorType;
3636
return this;
3737
}
3838

39-
public IJaegerOptionsBuilder WithSamplingRate(double samplingRate)
39+
public IJaegerOptionsBuilder WithMaxQueueSize(int maxQueueSize)
4040
{
41-
_options.SamplingRate = samplingRate;
41+
_options.MaxQueueSize = maxQueueSize;
42+
return this;
43+
}
44+
45+
public IJaegerOptionsBuilder MaxQueueSize(int maxQueueSize)
46+
{
47+
_options.MaxQueueSize = maxQueueSize;
48+
return this;
49+
}
50+
51+
public IJaegerOptionsBuilder WithScheduledDelayMilliseconds(int scheduledDelayMilliseconds)
52+
{
53+
_options.ScheduledDelayMilliseconds = scheduledDelayMilliseconds;
54+
return this;
55+
}
56+
57+
public IJaegerOptionsBuilder WithExporterTimeoutMilliseconds(int exporterTimeoutMilliseconds)
58+
{
59+
_options.ExporterTimeoutMilliseconds = exporterTimeoutMilliseconds;
60+
return this;
61+
}
62+
63+
public IJaegerOptionsBuilder WithMaxExportBatchSize(int maxExportBatchSize)
64+
{
65+
_options.MaxExportBatchSize = maxExportBatchSize;
4266
return this;
4367
}
4468

src/Genocs.Tracing/Jaeger/Configurations/IJaegerOptionsBuilder.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ public interface IJaegerOptionsBuilder
55
IJaegerOptionsBuilder Enable(bool enabled);
66
IJaegerOptionsBuilder WithServiceName(string serviceName);
77
IJaegerOptionsBuilder WithEndpoint(string endpoint);
8-
IJaegerOptionsBuilder WithMaxPacketSize(int maxPacketSize);
9-
IJaegerOptionsBuilder WithMaxTracesPerSecond(double maxTracesPerSecond);
10-
IJaegerOptionsBuilder WithSamplingRate(double samplingRate);
8+
IJaegerOptionsBuilder WithProtocol(string protocol);
9+
IJaegerOptionsBuilder WithProcessorType(string processorType);
10+
IJaegerOptionsBuilder WithMaxQueueSize(int maxQueueSize);
11+
IJaegerOptionsBuilder WithScheduledDelayMilliseconds(int scheduledDelayMilliseconds);
12+
IJaegerOptionsBuilder WithExporterTimeoutMilliseconds(int exporterTimeoutMilliseconds);
13+
IJaegerOptionsBuilder WithMaxExportBatchSize(int maxExportBatchSize);
1114
JaegerOptions Build();
1215
}

src/Genocs.Tracing/Jaeger/Configurations/JaegerOptions.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@ public class JaegerOptions
2121
/// The Jaeger agent endpoint.
2222
/// </summary>
2323
public string Endpoint { get; set; } = "http://localhost:4317";
24-
public int MaxPacketSize { get; set; } = 64967;
25-
public double MaxTracesPerSecond { get; set; } = 5;
26-
public double SamplingRate { get; set; } = 0.2;
24+
25+
/// <summary>
26+
/// The used OtlpExportProtocol.
27+
/// IT could be [Grpc|HttpProtobuf].
28+
/// </summary>
29+
public string Protocol { get; set; } = "Grpc";
30+
31+
/// <summary>
32+
/// The used ExportProcessorType.
33+
/// It could be [Simple|Batch].
34+
/// </summary>
35+
public string ProcessorType { get; set; } = "Batch";
36+
37+
public int MaxQueueSize { get; set; } = 2048;
38+
public int ScheduledDelayMilliseconds { get; set; } = 5000;
39+
public int ExporterTimeoutMilliseconds { get; set; } = 30000;
40+
public int MaxExportBatchSize { get; set; } = 512;
2741
}

src/Genocs.Tracing/Jaeger/Extensions.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/apps/api-gateway/Genocs.APIGateway/Startup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public void ConfigureServices(IServiceCollection services)
3838
services
3939
.AddGenocs()
4040
.AddOpenTelemetry()
41-
.AddJaeger()
4241
.AddJwt()
4342
.AddPrometheus()
4443
.AddRabbitMq()
@@ -75,7 +74,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
7574
app.UseMiddleware<LogContextMiddleware>();
7675
app.UseCors("cors");
7776
app.UseGenocs();
78-
app.UseJaeger();
7977
app.UsePrometheus();
8078
app.UseAccessTokenValidator();
8179
app.UseAuthentication();

0 commit comments

Comments
 (0)