diff --git a/input/elasticapm/docs/spec/rumv3/transaction.json b/input/elasticapm/docs/spec/rumv3/transaction.json index a4c691f9..121d887f 100644 --- a/input/elasticapm/docs/spec/rumv3/transaction.json +++ b/input/elasticapm/docs/spec/rumv3/transaction.json @@ -379,7 +379,8 @@ "properties": { "count": { "description": "Count is the total number of of longtasks.", - "type": "integer" + "type": "integer", + "minimum": 0 }, "max": { "description": "Max longtask duration", diff --git a/input/elasticapm/docs/spec/v2/metricset.json b/input/elasticapm/docs/spec/v2/metricset.json index c2bfd19b..01760a1f 100644 --- a/input/elasticapm/docs/spec/v2/metricset.json +++ b/input/elasticapm/docs/spec/v2/metricset.json @@ -87,7 +87,8 @@ "array" ], "items": { - "type": "integer" + "type": "integer", + "minimum": 0 }, "minItems": 0 }, diff --git a/input/elasticapm/docs/spec/v2/transaction.json b/input/elasticapm/docs/spec/v2/transaction.json index 42bd9501..cdc6262f 100644 --- a/input/elasticapm/docs/spec/v2/transaction.json +++ b/input/elasticapm/docs/spec/v2/transaction.json @@ -759,7 +759,8 @@ "type": [ "null", "integer" - ] + ], + "minimum": 0 } } } @@ -835,7 +836,8 @@ "properties": { "count": { "description": "Count is the total number of of longtasks.", - "type": "integer" + "type": "integer", + "minimum": 0 }, "max": { "description": "Max longtask duration", diff --git a/input/elasticapm/internal/modeldecoder/rumv3/model.go b/input/elasticapm/internal/modeldecoder/rumv3/model.go index aff3d28d..2f9c4e27 100644 --- a/input/elasticapm/internal/modeldecoder/rumv3/model.go +++ b/input/elasticapm/internal/modeldecoder/rumv3/model.go @@ -622,7 +622,7 @@ type transactionUserExperience struct { type longtaskMetrics struct { // Count is the total number of of longtasks. - Count nullable.Int `json:"count" validate:"required"` + Count nullable.Int `json:"count" validate:"required,min=0"` // Max longtask duration Max nullable.Float64 `json:"max" validate:"required,min=0"` // Sum of longtask durations diff --git a/input/elasticapm/internal/modeldecoder/rumv3/model_generated.go b/input/elasticapm/internal/modeldecoder/rumv3/model_generated.go index 12e71fe6..50cb91b5 100644 --- a/input/elasticapm/internal/modeldecoder/rumv3/model_generated.go +++ b/input/elasticapm/internal/modeldecoder/rumv3/model_generated.go @@ -1674,6 +1674,9 @@ func (val *longtaskMetrics) validate() error { if !val.IsSet() { return nil } + if val.Count.IsSet() && val.Count.Val < 0 { + return fmt.Errorf("'count': validation rule 'min(0)' violated") + } if !val.Count.IsSet() { return fmt.Errorf("'count' required") } diff --git a/input/elasticapm/internal/modeldecoder/v2/model.go b/input/elasticapm/internal/modeldecoder/v2/model.go index f5078d9a..1e54abdb 100644 --- a/input/elasticapm/internal/modeldecoder/v2/model.go +++ b/input/elasticapm/internal/modeldecoder/v2/model.go @@ -680,7 +680,7 @@ type metricsetSampleValue struct { // If Counts is specified, then Values is expected to be // specified with the same number of elements, and with the // same order. - Counts []uint64 `json:"counts" validate:"requiredIfAny=values"` + Counts []uint64 `json:"counts" validate:"requiredIfAny=values,minVals=0"` // Value holds the value of a single metric sample. Value nullable.Float64 `json:"value"` } @@ -1117,7 +1117,7 @@ type transactionUserExperience struct { type longtaskMetrics struct { // Count is the total number of of longtasks. - Count nullable.Int `json:"count" validate:"required"` + Count nullable.Int `json:"count" validate:"required,min=0"` // Max longtask duration Max nullable.Float64 `json:"max" validate:"required,min=0"` // Sum of longtask durations @@ -1161,7 +1161,7 @@ type transactionDroppedSpansDuration struct { type transactionDroppedSpansDurationSum struct { // Us represents the summation of the span duration. - Us nullable.Int `json:"us"` + Us nullable.Int `json:"us" validate:"min=0"` } type spanLink struct { diff --git a/input/elasticapm/internal/modeldecoder/v2/model_generated.go b/input/elasticapm/internal/modeldecoder/v2/model_generated.go index 44dd6576..175fa2d8 100644 --- a/input/elasticapm/internal/modeldecoder/v2/model_generated.go +++ b/input/elasticapm/internal/modeldecoder/v2/model_generated.go @@ -1951,6 +1951,11 @@ func (val *metricsetSampleValue) validate() error { return fmt.Errorf("'values' required when 'counts' is set") } } + for _, elem := range val.Counts { + if elem < 0 { + return fmt.Errorf("'counts': validation rule 'minVals(0)' violated") + } + } if !(len(val.Counts) > 0) { if len(val.Values) > 0 { return fmt.Errorf("'counts' required when 'values' is set") @@ -2884,6 +2889,9 @@ func (val *transactionDroppedSpansDurationSum) validate() error { if !val.IsSet() { return nil } + if val.Us.IsSet() && val.Us.Val < 0 { + return fmt.Errorf("'us': validation rule 'min(0)' violated") + } return nil } @@ -2971,6 +2979,9 @@ func (val *longtaskMetrics) validate() error { if !val.IsSet() { return nil } + if val.Count.IsSet() && val.Count.Val < 0 { + return fmt.Errorf("'count': validation rule 'min(0)' violated") + } if !val.Count.IsSet() { return fmt.Errorf("'count' required") }