Skip to content

Commit

Permalink
fixed unmarshalling for streaming aggregation match field.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amper committed Aug 29, 2023
1 parent 8f741e7 commit 06fabb7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions api/v1beta1/additional.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1beta1

import (
"encoding/json"
"fmt"
"path"
"reflect"
Expand Down Expand Up @@ -526,3 +527,29 @@ func (m *Match) UnmarshalYAML(unmarshal func(interface{}) error) error {
}}
}
}

func (m *Match) UnmarshalJSON(data []byte) error {
var raw any
if err := json.Unmarshal(data, &raw); err != nil {
return fmt.Errorf("cannot unmarshal match: %w", err)
}
rawType := reflect.TypeOf(raw)
switch rawType.Kind() {
case reflect.String:
var match string
if err := json.Unmarshal(data, &match); err != nil {
return err
}
*m = []string{match}
return nil
case reflect.Slice, reflect.Array:
var match []string
if err := json.Unmarshal(data, &match); err != nil {
return err
}
*m = match
return nil
default:
return &json.UnmarshalTypeError{Value: string(data), Type: rawType}
}
}
2 changes: 1 addition & 1 deletion docs/CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Fixes

- TODO
- [vmagent](https://docs.victoriametrics.com/operator/api.html#vmagent): fix unmarshalling for streaming aggregation `match` field.

### Features

Expand Down

0 comments on commit 06fabb7

Please sign in to comment.