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(webhooks): Refonte V2 Webhooks #1595

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

agourdel
Copy link
Contributor

@agourdel agourdel commented Jul 4, 2024

ENG-989

@agourdel agourdel requested a review from a team as a code owner July 4, 2024 13:25
Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

139 files out of 198 files are above the max files limit of 50. Please upgrade to Pro plan to get higher limits.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.


func SetNextRetry(a *Attempt) {
now := time.Now()
a.NextTry = now.Add(time.Duration(1<<a.NbTry) * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe set a max ? After some try, the delay will be very long.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, maybe, we should allow to not have a max number of attempts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Effectivement mais deux écoles :
On peut dire que comme le nombre de tentative max est géré par l'application, (par un paramètre) forcément le temps d'attente maximum entre deux attempts sera borné.
Ou rajouter ici un max delay.

MAIS, je sens venir gros comme une maison que le max delay choisi sera jamais le bon....

if len(r.URL.Query()) == 0 {
return str
}
return fmt.Sprintf("%s?%s", str, r.URL.Query().Encode())
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for query params. Worse then :D
You should use resource attributes to store those kind of data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is code coming from V1.
I just used it as if because I Thought it was legacy.

Copy link
Contributor

Choose a reason for hiding this comment

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

As i remember, i've done the same on membership, r.URL.Path return the templated string "/test/{id}". It can be easily checked with Jeager

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolve

return serverParams
},

func(db *bun.DB) *storage.PostgresStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

In Go, you can use directly some things like fx.Provide(storage.NewPostgresStoreProvider) instead of wrapping the call.

func (*noCopy) Unlock() {}

type Queue struct {
noCopy noCopy
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you doing that? I'm curious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean the Queue struct ?
Or the noCopy ?

}

if idx == 0 {
*s.Val = (*s.Val)[1:]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will fail if the array has a size of 1 (I have a doubt)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact it works with Size == 1 but it failed with Size == 0
But Size == 0 is not a possible case here.

package shared

type SharedMapArr[T any] struct {
Shared[map[string]*SharedArr[T]]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not against generalizing some kind of utility around object sharing, but this start to sound like very specific to a specific use case ^^

Copy link

gitguardian bot commented Jul 5, 2024

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
Once a secret has been leaked into a git repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

BeforeEach(func() {
time.Sleep(1*time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid this in tests. Tests should not depend on time.

E.G You could implement a Ticker with manual declencher

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is orchestration tests, I need let the caches of the worker and collector runner refresh.
Whether with a sleep() or a ticker, I have to wait at least one second to be able to trigger the rest.
(And ticker is wrapper for timer by the way, with a sleep() inside)

So I think I do not understand how to do it without wait.

// Import the postgres driver.
_ "github.com/lib/pq"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this will have an impact on other modules ? Does Ledger need PQ maybe ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, All the integrations tests (for each modules) are working.
I don't remember why I had to delete this line, because it goes back a long way (I discussed with Gfyrag about it)
But I think I was able to delete it because it's not used.

@@ -0,0 +1,186 @@
package webhookcollector
Copy link
Contributor

Choose a reason for hiding this comment

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

Questions here for the team:
Is it better to have internals related to each command in their own internal sub package in the cmd directory instead of here ?

That way, each command only have access to its internal codes and not the other ones ?

@@ -0,0 +1,392 @@
package controllers
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is a bit long and difficult to read or find the endpoint we want, I would have separate the different endpoints into different files, what do you think ?

})
})
defaultServer.handler.Group(func(r chi.Router) {
r.Get(HealthcheckRoute, func(_ http.ResponseWriter, r *http.Request) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Healtcheck should not be under authentication and otel I think


func RegisterV2AttemptControllers(serverHttp serverInterfaces.IHTTPServer, database storeInterface.IStoreProvider) {

serverHttp.Register(string(r.V2GetWaitingAttempts.Method), r.V2GetWaitingAttempts.Url, func(w http.ResponseWriter, r *http.Request) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, having endpoints function registered in another function makes everything hard to read, but to discuss with the team

@@ -0,0 +1 @@
package telemetry
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing code ?


func fillDBWithData(db storage.PostgresStore, nbHooks int, nbAttempts int) error {

// hooks := make([]*commons.Hook, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Dead code

@@ -0,0 +1,228 @@
package webhookcontroller
Copy link
Contributor

Choose a reason for hiding this comment

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

Question for the team: in every other services, we putted test files in the same package than the actual code ? Do we want to enforce this rule ?

for _, log := range logs {
event, err := commons.Event{}.FromPayload(log.Payload)
if err != nil {
//TODO(LOG) QUOI FAIRE ?
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can log it, and maybe we can add some opentelemetry metrics to add alarms ?

)

func DecodeJSONBody(r *http.Request, v any) error {
data, err := io.ReadAll(r.Body)
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick opti, you can use json.NewDecoder(r.Body).Decode, instead of io.readall and unmarshall. It has its own buffering and for big body, it's actually better in performances than to raed everything at once in memory

@paul-nicolas
Copy link
Contributor

Should we also add some code in the operator to deploy webhooks ?

$ref: '#/components/schemas/V2HookBodyParams'
required: true
responses:
"200":
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe 201 when creating something ?

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.

None yet

4 participants