Skip to content

Ле Лок Тхо 6513 Лаб. 2#80

Open
lelocthoVN wants to merge 5 commits intoitsecd:mainfrom
lelocthoVN:lab-2
Open

Ле Лок Тхо 6513 Лаб. 2#80
lelocthoVN wants to merge 5 commits intoitsecd:mainfrom
lelocthoVN:lab-2

Conversation

@lelocthoVN
Copy link
Copy Markdown

ФИО: Ле Лок Тхо
Номер группы: 6513
Номер лабораторной: 2
Номер варианта:
Краткое описание предметной области: Транспортное средство
Краткое описание добавленных фич: Добавил балансировщик нагрузки ocelot с алгоритмом Weighted Random

@github-actions github-actions bot added In progress Код в процессе проверки Lab 2 Лабораторная №2. Балансировка нагрузки labels Mar 31, 2026
@github-actions github-actions bot requested a review from alxmcs March 31, 2026 23:02
Comment on lines +9 to +18
builder.Services.AddCors(options =>
{
options.AddPolicy("ClientCors", policy =>
{
policy
.AllowAnyOrigin()
.WithMethods("GET")
.WithHeaders("Content-Type");
});
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

cors в сервисе уже не нужен, так как он перестает общаться с клиентов в браузере напрямую

Comment on lines +98 to +116
foreach (var item in configuration.GetSection("WeightedRandom:Replicas").GetChildren())
{
var endpoint = item.Key;
var separatorIndex = endpoint.LastIndexOf(':');

if (separatorIndex <= 0 || separatorIndex >= endpoint.Length - 1)
continue;

var host = endpoint[..separatorIndex].Trim().ToLowerInvariant();
var portText = endpoint[(separatorIndex + 1)..].Trim();

if (!int.TryParse(portText, out var port))
continue;
if (!int.TryParse(item.Value, out var weight))
continue;

result[(host, port)] = Math.Max(weight, 1);
}
return result;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Какой-то жуткий способ чтения настроек

Я бы предложил воспользоваться IOptions и смаппить все в экземпляры класса
Либо configuration.GetSection("WeightedRandom:Replicas").GetChildren().ToDictionary(*тут linq-выражение*)

Comment on lines +33 to +38
app.MapGet("/", () => Results.Ok(new
{
service = "Vehicle.Gateway",
status = "ok",
message = "Gateway is running"
}));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

У тебя есть встроенный healtcheck от aspire для этого

configuration,
discoveryProvider.GetAsync);
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Добавить сюда корс

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

In progress Код в процессе проверки Lab 2 Лабораторная №2. Балансировка нагрузки

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants