Skip to content

Земель Алексей Лаб. 2 Группа 6511#103

Open
AlexeyZemel wants to merge 13 commits intoitsecd:mainfrom
AlexeyZemel:main
Open

Земель Алексей Лаб. 2 Группа 6511#103
AlexeyZemel wants to merge 13 commits intoitsecd:mainfrom
AlexeyZemel:main

Conversation

@AlexeyZemel
Copy link
Copy Markdown

ФИО: Земель Алексей
Номер группы: 6511
Номер лабораторной: 2
Номер варианта: 7
Краткое описание предметной области: Программный проект
Краткое описание добавленных фич: Реализована репликация сервиса генерации, апи гейтвей на основе Ocelot и и балансировщик нагрузки Weighted Random

@github-actions github-actions bot added In progress Код в процессе проверки Lab 2 Лабораторная №2. Балансировка нагрузки labels Apr 13, 2026
@github-actions github-actions bot requested a review from danlla April 13, 2026 11:51
Copy link
Copy Markdown

@danlla danlla left a comment

Choose a reason for hiding this comment

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

  • Readme не обновлено до 2 лабы

<UnorderedListItem><Link To="https://puginarug.com/">Ссылка на форк</Link></UnorderedListItem>
<UnorderedListItem>Номер <Strong>№2 "«Балансировка нагрузки» - Реализация апи гейтвея, настройка его работы"</Strong></UnorderedListItem>
<UnorderedListItem>Вариант <Strong>№7 "Weighted Random"</Strong></UnorderedListItem>
<UnorderedListItem>Выполнена <Strong>Земель Алексеем 6511</Strong> </UnorderedListItem>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Либо Выполнил, либо поменять склонение

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

у меня фамилия не склоняется(

@@ -0,0 +1,100 @@
using Microsoft.AspNetCore.Http;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cleanup

namespace ProjectApp.Gateway.LoadBalancing;

/// <summary>
/// ������������� �������� � ���������� ����������� ���������� ������ (Weighted Random)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Нужно поправить кодировку

/// <summary>
/// ���������� �������������� �������� � ���������� ��������� �������������� ��������
/// </summary>
private sealed class WeightedRandomLoadBalancer(IReadOnlyList<DownstreamHostAndPort> downstreamAddresses, IReadOnlyList<double> configuredWeights) : ILoadBalancer
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Выделить этот класс в отдельный файл

/// <summary>
/// ����������� ���������������� ����: �������� �� � ����� 1, ��������� ������������
/// </summary>
private static IReadOnlyList<double> NormalizeWeights(IReadOnlyList<double> configuredWeights, int replicasCount)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Если из этого метода возвращается только double[], то лучше этот тип в возвращаемое значение и прописать, тогда не будет лишних кастов типов


if (configuredWeights.Count != replicasCount || configuredWeights.Any(x => x <= 0d))
{
return Enumerable.Repeat(1d / replicasCount, replicasCount).ToArray();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return [.. Enumerable.Repeat(1d / replicasCount, replicasCount)];

Ниже аналогично

Comment on lines +29 to +37
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Нужно настроить cors так, чтобы в разрешенных origins были только origins клиента

Comment on lines +6 to +7
var builder = WebApplication.CreateBuilder(args);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не хватает builder.AddServiceDefaults();

Comment thread ProjectApp.Api/Program.cs Outdated
Comment on lines +17 to +25
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.WithOrigins(allowedOrigins)
.WithMethods("GET")
.WithHeaders("Content-Type");
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Отсюда cors можно убрать, теперь клиент взаимодействует с gateway

Comment thread ProjectApp.AppHost/Program.cs Outdated

var api = builder.AddProject<Projects.ProjectApp_Api>("projectapp-api")
.WithReference(redis)
.WithReplicas(5)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Идея правильная, но полноценно это работает в новом .net10 и aspire
Если посмотреть, то в gateway приходит всего один адрес, из-за этого неправильно настраиваются веса

Скорее всего проще будет просто заменить вызов этого метода на ручное создание 5 реплик в цикле

@AlexeyZemel AlexeyZemel requested a review from danlla April 15, 2026 11:40
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