2022-07-12 16:38:26 +05:30
|
|
|
package logs
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"regexp"
|
|
|
|
|
|
2025-03-20 21:01:41 +05:30
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/constants"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/model"
|
|
|
|
|
v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"
|
2022-07-12 16:38:26 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ValidateUpdateFieldPayload(field *model.UpdateField) error {
|
|
|
|
|
if field.Name == "" {
|
|
|
|
|
return fmt.Errorf("name cannot be empty")
|
|
|
|
|
}
|
|
|
|
|
if field.Type == "" {
|
|
|
|
|
return fmt.Errorf("type cannot be empty")
|
|
|
|
|
}
|
|
|
|
|
if field.DataType == "" {
|
|
|
|
|
return fmt.Errorf("dataType cannot be empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
matched, err := regexp.MatchString(fmt.Sprintf("^(%s|%s|%s)$", constants.Static, constants.Attributes, constants.Resources), field.Type)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if !matched {
|
|
|
|
|
return fmt.Errorf("type %s not supported", field.Type)
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-22 16:49:40 +05:30
|
|
|
if field.IndexType != "" {
|
|
|
|
|
matched, err := regexp.MatchString(`^(minmax|set\([0-9]\)|bloom_filter\((0?.?[0-9]+|1)\)|tokenbf_v1\([0-9]+,[0-9]+,[0-9]+\)|ngrambf_v1\([0-9]+,[0-9]+,[0-9]+,[0-9]+\))$`, field.IndexType)
|
2022-07-12 16:38:26 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if !matched {
|
2022-07-22 16:49:40 +05:30
|
|
|
return fmt.Errorf("index type %s not supported", field.IndexType)
|
2022-07-12 16:38:26 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-12-19 11:52:20 +07:00
|
|
|
|
|
|
|
|
func ValidateUpdateFieldPayloadV2(field *model.UpdateField) error {
|
|
|
|
|
if field.Name == "" {
|
|
|
|
|
return fmt.Errorf("name cannot be empty")
|
|
|
|
|
}
|
|
|
|
|
if field.Type == "" {
|
|
|
|
|
return fmt.Errorf("type cannot be empty")
|
|
|
|
|
}
|
|
|
|
|
if field.DataType == "" {
|
|
|
|
|
return fmt.Errorf("dataType cannot be empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the logs api uses the old names i.e attributes and resources while traces use tag and attribute.
|
|
|
|
|
// update log api to use tag and attribute.
|
|
|
|
|
matched, err := regexp.MatchString(fmt.Sprintf("^(%s|%s)$", v3.AttributeKeyTypeTag, v3.AttributeKeyTypeResource), field.Type)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if !matched {
|
|
|
|
|
return fmt.Errorf("type %s not supported", field.Type)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if field.IndexType != "" {
|
|
|
|
|
matched, err := regexp.MatchString(`^(minmax|set\([0-9]\)|bloom_filter\((0?.?[0-9]+|1)\)|tokenbf_v1\([0-9]+,[0-9]+,[0-9]+\)|ngrambf_v1\([0-9]+,[0-9]+,[0-9]+,[0-9]+\))$`, field.IndexType)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if !matched {
|
|
|
|
|
return fmt.Errorf("index type %s not supported", field.IndexType)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|