mirror of
https://github.com/temporalio/temporal.git
synced 2026-08-31 02:51:51 -07:00
## What changed? Add a top-level Visibility config in the server config file. Option to overwrite the default number of preallocated custom search attributes in the server config (`visibility.persistenceCustomSearchAttributes`). Register the preallocated custom search attributes when using custom Visibility store. The config can be changed at any point: increasing the number of custom search attributes will register additional custom search attributes in the cluster metadata; decreasing the number of custom search attributes is no-op. Replace struct validator library with `github.com/go-playground/validator`. ## Why? Be able to add more custom search attributes when using SQL Visibility store. ## How did you test it? - [x] built - [x] run locally and tested manually - [x] covered by existing tests - [x] added new unit test(s) - [ ] added new functional test(s) ## Potential risks
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
"gopkg.in/validator.v2"
|
|
)
|
|
|
|
func newValidator() *validator.Validator {
|
|
validate := validator.NewValidator()
|
|
_ = validate.SetValidationFunc("persistence_custom_search_attributes", validatePersistenceCustomSearchAttributes)
|
|
return validate
|
|
}
|
|
|
|
func validatePersistenceCustomSearchAttributes(v any, param string) error {
|
|
st := reflect.ValueOf(v)
|
|
switch st.Kind() {
|
|
case reflect.Map:
|
|
iter := st.MapRange()
|
|
for iter.Next() {
|
|
// key must be a string and a valid search attribute type
|
|
key := iter.Key()
|
|
if key.Kind() != reflect.String {
|
|
return validator.ErrUnsupported
|
|
}
|
|
if enumspb.IndexedValueType_shorthandValue[key.String()] == 0 {
|
|
return validator.ErrInvalid
|
|
}
|
|
// value must an integer and between 0 and 99
|
|
val := iter.Value()
|
|
var num int64
|
|
if val.CanInt() {
|
|
num = val.Int()
|
|
} else if val.CanUint() {
|
|
num = int64(val.Uint())
|
|
} else {
|
|
return validator.ErrUnsupported
|
|
}
|
|
if num < 0 || num > 99 {
|
|
return validator.ErrInvalid
|
|
}
|
|
}
|
|
|
|
default:
|
|
return validator.ErrUnsupported
|
|
}
|
|
return nil
|
|
}
|