Skip to content

Commit

Permalink
fix: TOOLS-2979 logging levels to have case insensitive compare
Browse files Browse the repository at this point in the history
  • Loading branch information
a-spiker committed Oct 28, 2024
1 parent f890f3a commit 134b6df
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ func diffFlatMaps(m1 map[string]any, m2 map[string]any) []string {
continue
}

// #TOOLS-2979 if part of logging section and is valid logging enum when compared "info" == "INFO"
if strings.HasPrefix(k, "logging.") && isValidLoggingEnumCompare(v1, v2) {
continue
}

if !reflect.DeepEqual(v1, v2) {
res = append(res, fmt.Sprintf("%s:\n\t<: %v\n\t>: %v\n", k, v1, v2))
}
Expand Down
43 changes: 43 additions & 0 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,55 @@ const (
metaKeyAsadmVersion = "asadm-version"
)

// LoggingEnum is a map of valid logging levels - collated from schema
var LoggingEnum = map[string]bool{
"critical": true,
"warning": true,
"info": true,
"debug": true,
"detail": true,
}

type metaDataArgs struct {
src []byte
aerospikeVersion string
asconfigVersion string
}

func isValidLoggingEnumCompare(s1 any, s2 any) bool {
// convert to string
str1, ok := toString(s1)
if !ok {
return false
}
str2, ok := toString(s2)
if !ok {
return false
}
// convert to lower case
str1Lower := strings.ToLower(str1)
str2Lower := strings.ToLower(str2)

// check if the strings are valid logging levels
if _, ok := LoggingEnum[str1Lower]; !ok {
return false
}
if _, ok := LoggingEnum[str2Lower]; !ok {
return false
}

// compare the strings
if str1Lower == str2Lower {
return true
}
return false
}

func toString(value interface{}) (string, bool) {
str, ok := value.(string)
return str, ok
}

func genMetaDataText(src []byte, msg []byte, mdata map[string]string) ([]byte, error) {

metaHeader := "# *** Aerospike Metadata Generated by Asconfig ***"
Expand Down

0 comments on commit 134b6df

Please sign in to comment.