alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

chore: remove trivago

Open SoloJacobs opened this issue 1 month ago • 0 comments

This dependency is unmaintained and has recently been archived. The function we used is equivalent to:

import "reflect"

func TryConvertToMarshalMap(value any) any {
        valueMeta := reflect.ValueOf(value)
        switch valueMeta.Kind() {
        case reflect.Array, reflect.Slice:
                arrayLen := valueMeta.Len()
                converted := make([]any, arrayLen)
                for i := range arrayLen {
                        converted[i] = TryConvertToMarshalMap(valueMeta.Index(i).Interface())
                }
                return converted

        case reflect.Map:
                converted := make(map[string]any)
                keys := valueMeta.MapKeys()

                for _, keyMeta := range keys {
                        strKey, isString := keyMeta.Interface().(string)
                        if !isString {
                                continue
                        }
                        val := valueMeta.MapIndex(keyMeta).Interface()
                        converted[strKey] = TryConvertToMarshalMap(val)
                }
                return converted

        default:
                return value

        }
}

So, all it does is replace map types with map[string]any and skip keys, which are not of type string. However, DeepCopyWithTemplate already does this with the only difference being that it passes len(keys) as a capacity.

Moreover, ConvertToMarshalMap does not return an error, if one passes an object of type map. So, the extra error check was redundant as well.

In other words, omitting this function call does not affect behaviour.

The new extension of the unit test passes with and without the removal of trivago.

The PR here is related, but seems address additional issues: https://github.com/prometheus/alertmanager/pull/4083

SoloJacobs avatar Nov 22 '25 20:11 SoloJacobs