Skip to content

feat: controller cash#173

Open
vovanbravin wants to merge 6 commits into
traffic_filteringfrom
controller_cash
Open

feat: controller cash#173
vovanbravin wants to merge 6 commits into
traffic_filteringfrom
controller_cash

Conversation

@vovanbravin

Copy link
Copy Markdown
Collaborator

No description provided.

@KonstantinKondratenko KonstantinKondratenko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Нужно исправлять, что я описал + не забывать про метрики -- задачку нужно будет на себя взять (я думаю, что идейно в другом PR лучше делать)

req.WorkerId, req.Type, req.Target)

categoryIDs, err := s.classifier.Check(req.Target, req.Type)
cashRequest, err := s.storage.GetRequestHash(ctx, req.Target)

@KonstantinKondratenko KonstantinKondratenko Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

почему кэш контракт нарушается, у нас же
message ClassifyRequest {
uint64 worker_id = 1;
string type = 2;
string target = 3;
}
тип и таргет -- а у вас только таргет

Причем ниже же categoryIDs, err = s.classifier.Check(req.Target, req.Type)

сделайте отдельную функцию по типу makeClassifyCacheKey, которая будет использоваться и в Save, и в Get

return err
}

return c.db.Set(ctx, key, data, 0).Err()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

почему нет TTL, у нас же нет концепции вечного кэша

TrustLevel: 0,
}, nil
categoryIDs, err = s.classifier.Check(req.Target, req.Type)
if err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

если я правильно понял логику, то все ошибки редиса классифицируются как промах кэша
правильно было бы разделить на

  • реальный промах
  • ошибка редиса

иначе мы будем некорректно интерпретировать результаты

}, nil
}

err = s.storage.SaveRequestHash(ctx, storage.RequestCash{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

если внешний провайдер временно будет недоступен, то мы в classifier.Check не кидаем ошибку наверх, а просто логируем ее и продолжаем -> что мы сохраняем в кэш?

Нам нужно разбирать ошибки по типам:

  • если ошибка внешних сервисов, то ничего не кэшируем
  • если результат unknown, то можно кэшировать на меньший TTL например
  • если нормальная классификация прошла, то кэшируем на нормальный ttl

Comment thread controller/.env
SERVER_PORT=50051
MAX_MESSAGE_SIZE=4194304 No newline at end of file
MAX_MESSAGE_SIZE=4194304
REDIS_PASSWORD=mysecretpassword

@KonstantinKondratenko KonstantinKondratenko Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

почему контроллер при обращаениях к БД не использует креды?
давайте их или уберем или будет нормальный запросы делать с кредами смысл делать креды а потом default on nopass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

я подумал, что убрать креды -- плохая мысль -- работаем по паролю но честно по паролю

echo "requirepass $REDIS_PASSWORD" >> /usr/local/etc/redis/redis.conf &&
echo "appendonly yes" >> /usr/local/etc/redis/redis.conf &&
echo "appendfsync everysec" >> /usr/local/etc/redis/redis.conf &&
echo "user default on nopass ~* +@all" > /usr/local/etc/redis/users.acl &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

почему?
Это опасно, если мы хотим, чтобы разработкой пользовались, нужно ее аккуратно писать, а не оставлять такие дыры.

и сразу нормальный контракт взаимодействия описать

build:
dockerfile: Dockerfile.controller
environment:
- REDIS_ADDR=redis:6379

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

а почему оно не в .env???
вынесите в .env файл

func init() {
err := gotenv.Load()
if err != nil {
log.Fatalf("Error to load env: %v", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

почему фатальная ошибка?
А если я передам переменные руками без .env файле
или какой-то хитрый оркестратор подсунет переменные и без env файла? Кажется что ломаться нам не стоит на данном этапе -- мб имеет смысл грохнуться с ошибкой когда какая-то жизненно важная переменная не задана, но тут излищне

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

а вообще нужн ли тут init?

redis, err := storage.NewRedisClient(ctx, config)

if err != nil {
log.Fatalf("Error to create redis storage: %v", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

почему фатально опять?
У вас же функция может прокинуть ошибку через error -- и должна по логике именно так и поступить, а сверху ее уже как-то обрабатывать

Comment on lines -7 to -9
data = [
"//internal/service/config",
],

Copy link
Copy Markdown
Member

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants