Floating-point numbers in filter configuration does not get read correctly for dynamic modules and Go filters
- Dominant language
- C++
- Stars
- 28.9k
- Forks
- 5.6k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 430
Description
*Title*: Floating-point numbers in filter configuration does not get read correctly for dynamic modules and Go filters
*Description*:
Dynamic modules (or Go Filters) must use `type.googleapis.com/google.protobuf.Struct` when configuring a filter. Example:
```yaml
http_filters:
- name: myfilter
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_modules.v3.DynamicModuleFilter
dynamic_module_config:
name: composer
do_not_close: true
filter_config:
"@type": "type.googleapis.com/google.protobuf.Struct"
value:
body:
maxSize: 5000
filter_name: myfilter
```
The above config works only if `maxSize` is a integer type. However, the issue that I am observing here is that if `maxSize` is a floating-point number then Envoy will always read it as a string, see [here](https://github.com/envoyproxy/envoy/blob/main/source/common/protobuf/yaml_utility.cc#L75).
*Repro steps*:
Assuming that we have the following config structure for a dynamic module:
```go
type Config struct {
Body BodyConfig `json:"body"`
}
type BodyConfig struct {
MaxSize *uint64 `json:"maxSize"`
}
```
and our filter factory looks like this:
```go
func (p *filterConfigFactory) Create(handle shared.HttpFilterConfigHandle, unparsedConfig []byte) (shared.HttpFilterFactory, error) {
config := &Config{}
if err := json.Unmarshal(unparsedConfig, config); err != nil {
return nil, err
}
return &filterFactory{config: config}, nil
}
```
Then the following config cannot be parsed because Envoy sees `maxSize` as a string:
```yaml
http_filters:
- name: myfilter
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_modules.v3.DynamicModuleFilter
dynamic_module_config:
name: composer
do_not_close: true
filter_config:
"@type": "type.googleapis.com/google.protobuf.Struct"
value:
body:
maxSize: 5000.0
filter_name: myfilter
```
Contributor guide
Research direction
Start in source/common/protobuf/yaml_utility.cc around the linked conversion at line 75, then reproduce the provided Struct configuration with maxSize: 5000.0 for a dynamic module or Go filter. Trace where the floating-point value becomes a string and find the relevant protobuf/YAML tests; done means floating-point Struct values remain numeric and the repro configuration parses successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100