-
Notifications
You must be signed in to change notification settings - Fork 488
Add lookup for additional metadata from JS plugins #2099
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add lookup for additional metadata from JS plugins |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,16 @@ func (d *DashboardDelete) Call(ctx context.Context, vm *goja.Runtime) func(c goj | |
// This will never error since &key is a pointer to a type. | ||
_ = vm.ExportTo(obj, &key) | ||
|
||
if len(c.Arguments) > 1 { | ||
var metadata map[string]interface{} | ||
metadataObj := c.Argument(1).ToObject(vm) | ||
|
||
_ = vm.ExportTo(metadataObj, &metadata) | ||
for key, val := range metadata { | ||
ctx = context.WithValue(ctx, key, val) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the context passed in here has a long life and adding context here keep increasing the memory imprint of the context. While it doesn't impact the correctness of the functionality, its growth with every execution of this code is concerning to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example when i logged the context(I am passing datetime utc string from JS plugin in this example): It started off with: After a while the context grew:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this because we're iterating over all the keys of the metadata, but only deleting the last key? It was my impression that If it is a long-lived object, how does it behave when multiple calls specify different values for a given key? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should be using a different variable name than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because i'm reusing the variable for the new context. I'm experimenting with a new variable for each function call to avoid this. |
||
} | ||
} | ||
|
||
if err := d.storage.ObjectStore().Delete(ctx, key); err != nil { | ||
panic(panicMessage(vm, err, "")) | ||
} | ||
|
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 needed to keep the metadata argument optional. I don't have strong opinions about this so let me know if anybody prefers this to always be passed with calls to the data store.
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.
Javascript doesn't care one way or the other, so either way seems fine to me.
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 of a scenario where octant users decide to use the older plugins with new octant release. This will not introduce any breaking change in that case