Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notifier): add ability to scale webhook and script #961

Closed
wants to merge 22 commits into from

Conversation

almostinf
Copy link
Member

Add ability to scale webhook and script

For scaling webhooks and scripts, I used the name field, by which I distinguish between different senders of the same type. In addition, I fixed a problem with metrics registry when adding several senders of the same type

IMPORTANT, the name field in the senders config must match the type field in the api config if you want multiple senders of the same type, if you don't need to add multiple senders of the same type, the name field is optional

Relates #821

@almostinf almostinf requested a review from a team as a code owner November 9, 2023 17:50
@codecov-commenter
Copy link

codecov-commenter commented Nov 9, 2023

Codecov Report

Attention: 40 lines in your changes are missing coverage. Please review.

Comparison is base (0633491) 68.20% compared to head (3ee4a1d) 68.31%.
Report is 1 commits behind head on master.

❗ Current head 3ee4a1d differs from pull request most recent head 4c5c480. Consider uploading reports for the commit 4c5c480 to get more accurate results

Files Patch % Lines
notifier/registrator.go 50.00% 24 Missing and 1 partial ⚠️
senders/script/script.go 53.33% 6 Missing and 1 partial ⚠️
notifier/notifier.go 82.35% 2 Missing and 1 partial ⚠️
senders/webhook/request.go 66.66% 2 Missing and 1 partial ⚠️
senders/webhook/webhook.go 91.30% 1 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #961      +/-   ##
==========================================
+ Coverage   68.20%   68.31%   +0.10%     
==========================================
  Files         208      208              
  Lines       11731    11768      +37     
==========================================
+ Hits         8001     8039      +38     
  Misses       3251     3251              
+ Partials      479      478       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

notifier/notifier_test.go Outdated Show resolved Hide resolved
notifier/registrator.go Outdated Show resolved Hide resolved
@almostinf almostinf requested a review from Tetrergeru November 27, 2023 08:43
@almostinf
Copy link
Member Author

/build

Copy link

Build and push Docker images with tag: feat-add-ability-to-scale-senders.2023-11-28.991ac7d

2 similar comments
Copy link

Build and push Docker images with tag: feat-add-ability-to-scale-senders.2023-11-28.991ac7d

Copy link

Build and push Docker images with tag: feat-add-ability-to-scale-senders.2023-11-28.991ac7d

notifier/notifier.go Outdated Show resolved Hide resolved
@almostinf almostinf requested a review from kissken December 4, 2023 08:25
metrics *metrics.NotifierMetrics
metricSourceProvider *metricSource.SourceProvider
imageStores map[string]moira.ImageStore
sendersNameToType map[string]string
Copy link
Member

Choose a reason for hiding this comment

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

это для меня пометочка: смотрю зачем он остался...

Copy link
Member

@kissken kissken Dec 7, 2023

Choose a reason for hiding this comment

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

это тоже мне, если нужно, то зачем такой тип поля, кажется, можно иначе
и перенести ближе к сендерам - по смыслу, чтоб не разносить

Copy link
Member Author

Choose a reason for hiding this comment

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

Кажется, по смыслу оно не зависит от каждого конкретного сендера, а нужно именно для нотифаера. Поле маппит имя типа контакта = имени сендера на тип сендера, а если поле с именем не указано, как сейчас для почти всех сендеров, то маппит тип контакта = типу сендера на тип сендера

Таким образом, если хочется несколько сендеров одного типа, то достаточно добавить поле name и смотреть, чтобы оно совпадало с типом контакта

Copy link
Member Author

Choose a reason for hiding this comment

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

вот в этом Issue пользователь как раз написал, что такой вариант нужен и я как раз такой и сделал

if sender.url == moira.VariableContactValue {
sender.log.Warning().
String("potentially_dangerous_url", sender.url).
func (client *webhookClient) buildRequest(events moira.NotificationEvents, contact moira.ContactData, trigger moira.TriggerData, plots [][]byte, throttled bool) (*http.Request, error) {
Copy link
Member

Choose a reason for hiding this comment

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

не поняла, почему сендер поменялся на вебхук-клиент...

Copy link
Member Author

Choose a reason for hiding this comment

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

У нас есть 1 структура для вебхука, если мы хотим иметь несколько хуков, то я внутри этой структуры сендера сделал мапку, внутри которой будут поддерживаться несколько клиентов, а тип для функции сменился, потому что в каждом клиенте своя специфичная информация, которая нужна для построения запроса

@@ -21,10 +21,107 @@ import (
const (
testUser = "testUser"
Copy link
Member

Choose a reason for hiding this comment

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

давай тут сразу сделаем идентично
а то и верблюды и змеи :)

Copy link
Member Author

@almostinf almostinf Dec 7, 2023

Choose a reason for hiding this comment

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

Давай я в целом уберу лишние изменения в файлах, которые на будущее были сделаны. Чтобы проще было ориентироваться

}
}

// Send is realization of StandardNotifier Send functionality
func (notifier *StandardNotifier) Send(pkg *NotificationPackage, waitGroup *sync.WaitGroup) {
ch, found := notifier.senders[pkg.Contact.Type]
if !found {
senderType, ok := notifier.sendersNameToType[pkg.Contact.Type]
Copy link
Member

Choose a reason for hiding this comment

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

pkg.Contact.Type - это на самом деле уникальный идентификатор?

Copy link
Member

Choose a reason for hiding this comment

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

не поняла, как мы ловко определим тут, что это нужная нам почта/вебхук/и тд

Copy link
Member

Choose a reason for hiding this comment

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

pkg.Contact.Type - у всех же будет лежать как лежал старое значение

Copy link
Member Author

Choose a reason for hiding this comment

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

Да, будет лежать старое значение и все будет норм работать, тк будет матчиться тип сендера на тип контакта, а если пользователи захотят добавить несколько сендеров одного типа, то необходимо различать по полю name, которое должно будет совпадать с типом контакта

Copy link
Member

Choose a reason for hiding this comment

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

кажется, что-то непрозрачное
у меня была одна почта
потом появилась вторая

я первую назову: Старая почта, а новую - Новая почта

@@ -126,7 +143,7 @@ func (notifier *StandardNotifier) Send(pkg *NotificationPackage, waitGroup *sync
// GetSenders get hash of registered notifier senders
func (notifier *StandardNotifier) GetSenders() map[string]bool {
Copy link
Member

Choose a reason for hiding this comment

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

map[string]bool
😭

@almostinf almostinf closed this Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants