diff --git a/pkg/handlers/custom_metrics.go b/pkg/handlers/custom_metrics.go index 4f658ae7a2..64ad490260 100644 --- a/pkg/handlers/custom_metrics.go +++ b/pkg/handlers/custom_metrics.go @@ -79,6 +79,10 @@ func validateCustomMetricsData(data ApplicationMetricsData) error { for key, val := range data { valType := reflect.TypeOf(val) + if valType == nil { + return errors.Errorf("%s value is nil, only scalar values are allowed", key) + } + switch valType.Kind() { case reflect.Slice: return errors.Errorf("%s value is an array, only scalar values are allowed", key) diff --git a/pkg/handlers/custom_metrics_test.go b/pkg/handlers/custom_metrics_test.go index 8e0b3bda1b..d588738764 100644 --- a/pkg/handlers/custom_metrics_test.go +++ b/pkg/handlers/custom_metrics_test.go @@ -53,6 +53,14 @@ func Test_validateCustomMetricsData(t *testing.T) { }, wantErr: true, }, + { + name: "nil value", + data: ApplicationMetricsData{ + "key1": nil, + "key2": 4, + }, + wantErr: true, + }, } for _, test := range tests {