-
Notifications
You must be signed in to change notification settings - Fork 3
feat: conditionally add actor headers #142
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
ssncferreira
left a comment
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.
Overall LGTM 👍 just some nits around header key/value sanitization. I know most of this is validated on the coder side, but since this is a library might be worth sanitizing or rejecting bad input.
| } | ||
|
|
||
| func ActorMetadataHeader(name string) string { | ||
| return fmt.Sprintf("%s-Metadata-%s", prefix, name) |
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.
nit: shouldn't we check if name != ""?
Otherwise, we could end with headers like X-AI-Bridge-Actor-Metadata-
|
|
||
| var opts []option.RequestOption | ||
| opts = append(opts, option.WithRequestTimeout(time.Second*600)) | ||
| if actor := aibcontext.ActorFromContext(r.Context()); actor != nil && i.cfg.SendActorHeaders { |
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.
minor nit: should we maybe check the cfg first, as in most cases this will be false?
| headers := make(map[string]string, len(actor.Metadata)+1) | ||
|
|
||
| // Add actor ID. | ||
| headers[ActorIDHeader()] = actor.ID |
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.
nit: can actor.ID be ""? Probably not, but be worth the check
|
|
||
| // Add headers for provided metadata. | ||
| for k, v := range actor.Metadata { | ||
| headers[ActorMetadataHeader(k)] = fmt.Sprintf("%v", v) |
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.
nit: we should probably be sanitizing the headers/vallues to make sure they don't have whitespaces or invalid characters
Closes #135
Introduces a new header (
X-AI-Bridge-Actor-Id) which will optionally be sent along with upstream requests with the actor's identity as the value.Any metadata includes in the
context.Actorstruct will also be added to the headers in the formatX-AI-Bridge-Actor-{Key}={Value}.When enabled in
coder/coder, two new headers will be added: