-
Notifications
You must be signed in to change notification settings - Fork 739
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
fix: Concurrent access to trigger connection maps #2814
Conversation
feat: add all sprig functions to templates (argoproj#2768)
…safe maps - HTTP client - CustomTrigger client - Kafka client - Pulsar client - NATS client - Lambda client - OpenWhisk client - Eventbus client - Servicebus client Signed-off-by: gokulav137 <gokulav999@gmail.com>
Signed-off-by: gokulav137 <gokulav999@gmail.com>
Signed-off-by: gokulav137 <gokulav999@gmail.com>
@@ -51,25 +52,25 @@ type SensorContext struct { | |||
hostname string | |||
|
|||
// httpClients holds the reference to HTTP clients for HTTP triggers. | |||
httpClients map[string]*http.Client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define a generic struct in the utilities like below?
type StringKeyedMap[T any] struct {
items map[string]T
lock *sync.RWMutex
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I'll make the changes. Thanks.
- Add StringKeyedMap, Concurrent Safe String keyed map; using generics - Replace concurrent safe connection map structs with StringKeyedMap Signed-off-by: gokulav137 <52277763+gokulav137@users.noreply.github.com>
common/util.go
Outdated
@@ -475,3 +476,35 @@ func StructToMap(obj interface{}, output map[string]interface{}) error { | |||
|
|||
return json.Unmarshal(data, &output) // Convert to a map | |||
} | |||
|
|||
// Concurrent Safe String keyed map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving it to a dedicated file would be better, all the rest looks good to me. Thanks again!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick feedback.😄Where do you think this would fit. Kinda puzzled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking same package but, in a concurrent.go file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same package, string_keyed_map.go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking along the lines any common concurrent safe implementations required moving forward could be placed in concurrent.go
. If this doesn't track, I will change the filename. Let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is even bigger...
It is good to use straightforward file names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh big as in vague. concur_safe_type.go
? Sorry if I'm dragging this naming out 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its just that the other files in common/
are json.go
, retry.go
, string.go
, time.go
etc are generic names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal opinions:
- The package structure in Argo Events (including file names) should be refactored;
- Those file names (json.go, string.go ...) are kind of simple, because they provide that particular file name related utility functions (not struct functions), and maybe there's no better names to describe it - you can imagine we could name them something like
json_util.go
orstring_util.go
, that wouldn't make too much difference. But it's for sure it does not make much sense to separate them into different files. - If it's util structs (like the one you added), there is already a clear boundary (the struct itself), putting them in separated files and naming them as straightforward as possible might be better, so that ppl clearly know what they are about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes a lot of sense. Thanks for clarifying!
Will rename the file to string_keyed_map.go
Signed-off-by: gokulav137 <52277763+gokulav137@users.noreply.github.com>
Signed-off-by: gokulav137 <52277763+gokulav137@users.noreply.github.com>
…from eventhubs to eventhub Signed-off-by: gokulav137 <52277763+gokulav137@users.noreply.github.com>
2b8f2fb
to
ed62a55
Compare
common/concurrent.go
Outdated
lock *sync.RWMutex | ||
} | ||
|
||
func NewStringKeyedMap[T any]() *StringKeyedMap[T] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to return a pointer, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I'll make it return by value.
Signed-off-by: gokulav137 <52277763+gokulav137@users.noreply.github.com>
…rgo-events into concurrent-safe-map
Signed-off-by: gokulav137 <52277763+gokulav137@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Fixes #2660
Refactor connection maps for trigger clients from map to concurrent safe map.
Checklist: