Skip to content

Conversation

imkonsowa
Copy link
Contributor

@imkonsowa imkonsowa commented Jul 11, 2025

What problem are we solving?

  • Async http webhook calls
  • Queue params customization
  • Events and path prefixes filters

How are we solving the problem?

  • Use buffered watermill in memory pubsub
  • Apply filters before publishing events

How is the PR tested?

  • Manual and unit testing

Checks

  • I have added unit tests if possible.
  • I will add related wiki document changes and link to this PR after merging.

@imkonsowa imkonsowa marked this pull request as draft July 11, 2025 05:26
@chrislusf chrislusf requested a review from Copilot July 14, 2025 13:43
Copilot

This comment was marked as outdated.

@imkonsowa imkonsowa marked this pull request as ready for review July 15, 2025 04:23
@chrislusf chrislusf requested a review from Copilot July 15, 2025 04:48
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors webhook notifications to use an in-memory Watermill pub/sub queue, adds configurable filters for event types and path prefixes, and updates the HTTP client to support timeouts.

  • Introduce Queue backed by Watermill GoChannel and retry/poison-queue middleware
  • Apply event-type and path-prefix filters before publishing to the queue
  • Update HTTP client to accept structured webhookMessage and enforce request timeouts

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
weed/notification/webhook/webhook_queue_test.go Added comprehensive tests for config validation, serialization, queue init/send, retry, and filters
weed/notification/webhook/webhook_queue.go Implemented Queue using Watermill, middleware setup, handler, and dead-letter logging
weed/notification/webhook/types.go Defined config defaults/validation, webhookMessage, and event type detection
weed/notification/webhook/http_test.go Updated HTTP client tests to use newWebhookMessage and assert event_type metadata
weed/notification/webhook/http.go Changed sendMessage signature, added JSON payload, timeout handling, and removed raw proto import
weed/notification/webhook/filter.go & filter_test.go Added filter logic and tests for event types and path prefixes
Comments suppressed due to low confidence (3)

weed/notification/webhook/http.go:52

  • Add a Content-Type header for JSON payloads before sending the request, e.g., req.Header.Set("Content-Type", "application/json").
	if h.token != "" {

weed/notification/webhook/webhook_queue.go:1

  • [nitpick] Add GoDoc comments to exported types and methods (e.g., Queue, SendMessage, Initialize, handleWebhook) to improve code navigation and documentation.
package webhook

weed/notification/webhook/webhook_queue.go:60

  • Guard against uninitialized w.queueChannel or w.client to prevent panics if Initialize was not called.
	return w.queueChannel.Publish(pubSubTopicName, wMsg)

defer cancel()
req = req.WithContext(ctx)
}

resp, err := util_http.Do(req)
if err != nil {
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

Check resp.StatusCode for non-2xx responses and return an error, and ensure resp.Body.Close() is called to avoid leaking connections.

Suggested change
if err != nil {
if err != nil {
if resp != nil {
resp.Body.Close()
}

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not helpful.

Copy link
Collaborator

Choose a reason for hiding this comment

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

need to consume the response body. otherwise, the http connection reusing would not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chrislusf thanks, closed it in case of error as suggested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

close it is not enough. need to read all remaining body content.

for {
select {
case msg := <-ch:
glog.Errorf("received dead letter message: %v", msg)
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

[nitpick] Log more context for dead-lettered messages, such as msg.Metadata or string(msg.Payload), rather than the raw message object.

Suggested change
glog.Errorf("received dead letter message: %v", msg)
glog.Errorf("received dead letter message: metadata=%v, payload=%s", msg.Metadata, string(msg.Payload))

Copilot uses AI. Check for mistakes.

@chrislusf chrislusf merged commit d78aa3d into seaweedfs:master Jul 15, 2025
16 checks passed
@imkonsowa imkonsowa deleted the feature/webhook-notifications-enhancements branch July 15, 2025 17:52
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.

2 participants