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

Named arguments in eskip #3037

Open
boopathi opened this issue Apr 23, 2024 · 2 comments
Open

Named arguments in eskip #3037

boopathi opened this issue Apr 23, 2024 · 2 comments

Comments

@boopathi
Copy link
Member

Is your feature request related to a problem? Please describe.
The eskip file format includes only positional arguments. The eskip file format is used in places such as configuration files, web based editors, editors like vscode, and so on. It is often unintuitive to edit a filter / predicate arguments as we constantly refer to the documentation of the filter in different places - skipper docs for internal ones, other docs for custom ones. Matching filter signature manually is often painful, especially if there are multiple arguments.

Adding editor support (to show filter signature inline) to all places where eskip file format is used is complex and sometimes impossible (for example yaml configuration files). Instead, it would be beneficial to add named arguments to the eskip language directly.

Describe the solution you would like
Support for named arguments syntax in predicates and filters. For example,

Path("foo")
  -> customFilter(a = 1, b = "str")
  -> otherFilter(foo = "bar", bar = "baz")

This way, we also eliminate the order in which the arguments appear.

Would you like to work on it?
Yes if I find time

@AlexanderYastrebov
Copy link
Member

Hello, for custom filters you may use flow style yaml and parse arguments yourself, see example #3020

jwtMetrics("{issuers: ['https://example.com', 'https://example.org'], optOutAnnotations: [oauth.disabled]}")

Of course this will not enable editor support.
Maybe for editor support we can prepare machine-readable format of https://github.com/zalando/skipper/blob/master/docs/reference/filters.md

@AlexanderYastrebov
Copy link
Member

For named arguments we would need to support another style of filter constructor

skipper/filters/filters.go

Lines 180 to 190 in 708e97a

// Spec objects are specifications for filters. When initializing the routes,
// the Filter instances are created using the Spec objects found in the
// registry.
type Spec interface {
// Name gives the name of the Spec. It is used to identify filters in a route definition.
Name() string
// CreateFilter creates a Filter instance. Called with the parameters in the route
// definition while initializing a route.
CreateFilter(config []interface{}) (Filter, error)
}

as well as maybe change eskip Predicate/Filter interfaces

skipper/eskip/eskip.go

Lines 233 to 262 in 708e97a

// A Predicate object represents a parsed, in-memory, route matching predicate
// that is defined by extensions.
type Predicate struct {
// The name of the custom predicate as referenced
// in the route definition. E.g. 'Foo'.
Name string `json:"name"`
// The arguments of the predicate as defined in the
// route definition. The arguments can be of type
// float64 or string (string for both strings and
// regular expressions).
Args []interface{} `json:"args"`
}
func (p *Predicate) String() string {
return fmt.Sprintf("%s(%s)", p.Name, argsString(p.Args))
}
// A Filter object represents a parsed, in-memory filter expression.
type Filter struct {
// name of the filter specification
Name string `json:"name"`
// filter args applied within a particular route
Args []interface{} `json:"args"`
}
func (f *Filter) String() string {
return fmt.Sprintf("%s(%s)", f.Name, argsString(f.Args))
}

Before we invest into this we need to understand how named arguments will help with outlined usecases, specifically given that

Adding editor support (to show filter signature inline) to all places where eskip file format is used is complex and sometimes impossible (for example yaml configuration files). Instead, it would be beneficial to add named arguments to the eskip language directly.

I think one would need to consult documentation anyway for parameter names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants