Skip to content

Commit

Permalink
Merge pull request #99 from replicatedhq/divolgin/sc-89026/custom-met…
Browse files Browse the repository at this point in the history
…rics-sending-null-as-a-metric-value

Don't panic on nil values
  • Loading branch information
divolgin authored Oct 6, 2023
2 parents e054c63 + 6df8e95 commit 098f98d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/handlers/custom_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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)
Expand Down
8 changes: 8 additions & 0 deletions pkg/handlers/custom_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func Test_validateCustomMetricsData(t *testing.T) {
},
wantErr: true,
},
{
name: "nil value",
data: ApplicationMetricsData{
"key1": nil,
"key2": 4,
},
wantErr: true,
},
}

for _, test := range tests {
Expand Down

0 comments on commit 098f98d

Please sign in to comment.