Skip to content

chore: remove trivago#4763

Merged
SuperQ merged 2 commits intoprometheus:mainfrom
SoloJacobs:remove-trivago
Dec 5, 2025
Merged

chore: remove trivago#4763
SuperQ merged 2 commits intoprometheus:mainfrom
SoloJacobs:remove-trivago

Conversation

@SoloJacobs
Copy link
Contributor

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: #4083

This ensures we don't have a regression in this area.

Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
This dependency is unmaintained and has recently been archived. The
function we used is equivalent to:

```go
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.

Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
@SuperQ SuperQ merged commit dbf48e2 into prometheus:main Dec 5, 2025
7 checks passed
@SoloJacobs SoloJacobs deleted the remove-trivago branch December 5, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants