-
Notifications
You must be signed in to change notification settings - Fork 120
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(router): template expressions for access logs #1612
base: main
Are you sure you want to change the base?
feat(router): template expressions for access logs #1612
Conversation
…ssion # Conflicts: # router-tests/telemetry/telemetry_test.go
…he authentication code has been executed, and the other expressions as soon as possible
…s checks also auth usage in functions arguments
…tes-by-expression' into ale/eng-6258-custom-otel-attributes-by-expression
…s checks also auth usage in functions arguments
Router image scan passed✅ No security vulnerabilities found in image:
|
51ab90c
to
58d494e
Compare
func (c *requestContext) ResolveAnyExpressionWithWrappedError(expression *vm.Program) (any, error) { | ||
// If an error exists already, wrap it and resolve the expression with the copied context | ||
currExprContext := c.expressionContext.Request | ||
if currExprContext.Error != nil { | ||
copyExprContext := expr.Context{ | ||
Request: expr.Request{ | ||
Auth: currExprContext.Auth, | ||
URL: currExprContext.URL, | ||
Header: currExprContext.Header, | ||
Error: &ExprWrapError{currExprContext.Error}, | ||
}, | ||
} | ||
return expr.ResolveAnyExpression(expression, copyExprContext) | ||
} | ||
return expr.ResolveAnyExpression(expression, c.expressionContext) | ||
} |
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 suggest flipping the if
conditional here and returning early in the simple case, to reduce nesting.
func (c *requestContext) ResolveAnyExpression(expression *vm.Program) (any, error) { | ||
return expr.ResolveAnyExpression(expression, c.expressionContext) | ||
} |
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 function seems unused?
} | ||
|
||
func GetAccessLogConfigExpressions(attributes []config.CustomAttribute) ([]ExpressionAttribute, error) { | ||
exprSlice := make([]ExpressionAttribute, 0) |
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.
exprSlice := make([]ExpressionAttribute, 0) | |
exprSlice := make([]ExpressionAttribute, 0, len(attributes)) |
func CleanupExpressionAttributes(attributes []config.CustomAttribute) []config.CustomAttribute { | ||
filtered := make([]config.CustomAttribute, 0, len(attributes)) | ||
|
||
for _, elem := range attributes { | ||
if elem.ValueFrom == nil || elem.ValueFrom.Expression == "" { | ||
filtered = append(filtered, elem) | ||
} | ||
} | ||
|
||
return filtered | ||
} |
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 function is untested in access_log_expression_test.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.
Looks like the changeset is a bit borked by GitHub, maybe try rebasing?
Motivation and Context
The goal is to extend the router to allow defining custom access log attributes by template expressions.
In order to do this the PR adds an "expression" field which can be set to process any log messages based on these exprlang expressions
However on top of this, the PR also goes ahead and adds the request
error
to theexpressionContext
.This means that the user could now use expressions for access logs
This task was also previously mentioned in the PR: #1545 which was opened from a fork of mine, moved this to a branch in the repo so CI checks can run.
Checklist