Skip to content

Commit 4073331

Browse files
committed
docs/spec: require duration >= 0 (#3721)
* docs/spec: require duration >= 0 * Fix NOTICE.txt * Update changelog
1 parent 99d8eff commit 4073331

11 files changed

Lines changed: 96 additions & 55 deletions

File tree

NOTICE.txt

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -239,34 +239,6 @@ Contents of "NOTICE":
239239
See the License for the specific language governing permissions and
240240
Limitations under the License.
241241

242-
--------------------------------------------------------------------
243-
Dependency: github.com/codahale/hdrhistogram
244-
Revision: 3a0bb77429bd
245-
License type (autodetected): MIT
246-
Contents of "LICENSE":
247-
248-
The MIT License (MIT)
249-
250-
Copyright (c) 2014 Coda Hale
251-
252-
Permission is hereby granted, free of charge, to any person obtaining a copy
253-
of this software and associated documentation files (the "Software"), to deal
254-
in the Software without restriction, including without limitation the rights
255-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
256-
copies of the Software, and to permit persons to whom the Software is
257-
furnished to do so, subject to the following conditions:
258-
259-
The above copyright notice and this permission notice shall be included in
260-
all copies or substantial portions of the Software.
261-
262-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
263-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
264-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
265-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
266-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
267-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
268-
THE SOFTWARE.
269-
270242
--------------------------------------------------------------------
271243
Dependency: github.com/containerd/containerd
272244
Version: v1.3.3
@@ -575,6 +547,35 @@ Version: v8.0.0
575547
Revision: aff00e5adfde
576548
License type (autodetected): Apache-2.0
577549

550+
--------------------------------------------------------------------
551+
Dependency: github.com/elastic/go-hdrhistogram
552+
Version: v0.1.0
553+
License type (autodetected): MIT
554+
Contents of "LICENSE":
555+
556+
The MIT License (MIT)
557+
558+
Copyright (c) 2014 Coda Hale
559+
Copyright (c) 2020 Elasticsearch BV
560+
561+
Permission is hereby granted, free of charge, to any person obtaining a copy
562+
of this software and associated documentation files (the "Software"), to deal
563+
in the Software without restriction, including without limitation the rights
564+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
565+
copies of the Software, and to permit persons to whom the Software is
566+
furnished to do so, subject to the following conditions:
567+
568+
The above copyright notice and this permission notice shall be included in
569+
all copies or substantial portions of the Software.
570+
571+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
572+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
573+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
574+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
575+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
576+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
577+
THE SOFTWARE.
578+
578579
--------------------------------------------------------------------
579580
Dependency: github.com/elastic/go-lumber
580581
Version: v0.1.0

docs/spec/spans/rum_v3_span.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@
188188
},
189189
"d": {
190190
"type": "number",
191-
"description": "Duration of the span in milliseconds"
191+
"description": "Duration of the span in milliseconds",
192+
"minimum": 0
192193
},
193194
"n": {
194195
"type": "string",

docs/spec/spans/span.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@
195195
},
196196
"duration": {
197197
"type": "number",
198-
"description": "Duration of the span in milliseconds"
198+
"description": "Duration of the span in milliseconds",
199+
"minimum": 0
199200
},
200201
"name": {
201202
"type": "string",

docs/spec/transactions/rum_v3_transaction.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
},
6969
"d": {
7070
"type": "number",
71-
"description": "How long the transaction took to complete, in ms with 3 decimal points"
71+
"description": "How long the transaction took to complete, in ms with 3 decimal points",
72+
"minimum": 0
7273
},
7374
"rt": {
7475
"type": [

docs/spec/transactions/transaction.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
},
4545
"duration": {
4646
"type": "number",
47-
"description": "How long the transaction took to complete, in ms with 3 decimal points"
47+
"description": "How long the transaction took to complete, in ms with 3 decimal points",
48+
"minimum": 0
4849
},
4950
"result": {
5051
"type": ["string", "null"],

model/modeldecoder/span_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,21 +270,31 @@ func TestDecodeSpanInvalid(t *testing.T) {
270270

271271
for name, test := range map[string]struct {
272272
input map[string]interface{}
273+
err string
273274
}{
274275
"transaction id wrong type": {
275276
input: map[string]interface{}{"transaction_id": 123},
277+
err: `type.*expected string or null, but got number`,
276278
},
277279
"no trace_id": {
278280
input: map[string]interface{}{"trace_id": nil},
281+
err: `missing properties: "trace_id"`,
279282
},
280283
"no id": {
281284
input: map[string]interface{}{"id": nil},
285+
err: `missing properties: "id"`,
282286
},
283287
"no parent_id": {
284288
input: map[string]interface{}{"parent_id": nil},
289+
err: `missing properties: "parent_id"`,
285290
},
286291
"invalid stacktrace": {
287292
input: map[string]interface{}{"stacktrace": []interface{}{"foo"}},
293+
err: `stacktrace.*expected object, but got string`,
294+
},
295+
"negative duration": {
296+
input: map[string]interface{}{"duration": -1.0},
297+
err: "duration.*must be >= 0 but found -1",
288298
},
289299
} {
290300
t.Run(name, func(t *testing.T) {
@@ -301,7 +311,7 @@ func TestDecodeSpanInvalid(t *testing.T) {
301311
}
302312
err := DecodeSpan(Input{Raw: input}, &model.Batch{})
303313
require.Error(t, err)
304-
t.Logf("%s", err)
314+
assert.Regexp(t, test.err, err.Error())
305315
})
306316
}
307317
}

model/modeldecoder/transaction_test.go

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,51 @@ var fullTransactionInput = map[string]interface{}{
9393
},
9494
}
9595

96-
func TestTransactionEventDecodeFailure(t *testing.T) {
96+
func TestDecodeTransactionInvalid(t *testing.T) {
97+
err := DecodeTransaction(Input{Raw: nil}, &model.Batch{})
98+
require.EqualError(t, err, "failed to validate transaction: error validating JSON: input missing")
99+
100+
err = DecodeTransaction(Input{Raw: ""}, &model.Batch{})
101+
require.EqualError(t, err, "failed to validate transaction: error validating JSON: invalid input type")
102+
103+
baseInput := map[string]interface{}{
104+
"type": "type",
105+
"trace_id": "trace_id",
106+
"id": "id",
107+
"duration": 123,
108+
"span_count": map[string]interface{}{"dropped": 1.0, "started": 2.0},
109+
}
110+
97111
for name, test := range map[string]struct {
98-
input interface{}
112+
input map[string]interface{}
99113
err string
100-
e *model.Transaction
101114
}{
102-
"no input": {input: nil, err: "failed to validate transaction: error validating JSON: input missing", e: nil},
103-
"invalid type": {input: "", err: "failed to validate transaction: error validating JSON: invalid input type", e: nil},
104-
"cannot fetch field": {input: map[string]interface{}{}, err: "failed to validate transaction: error validating JSON: (.|\n)*missing properties:(.|\n)*", e: nil},
115+
"missing trace_id": {
116+
input: map[string]interface{}{"trace_id": nil},
117+
err: "missing properties: \"trace_id\"",
118+
},
119+
"negative duration": {
120+
input: map[string]interface{}{"duration": -1.0},
121+
err: "duration.*must be >= 0 but found -1",
122+
},
105123
} {
106124
t.Run(name, func(t *testing.T) {
107-
batch := &model.Batch{}
108-
err := DecodeTransaction(Input{Raw: test.input}, batch)
109-
if test.err != "" {
110-
assert.Regexp(t, test.err, err.Error())
111-
} else {
112-
assert.NoError(t, err)
125+
input := make(map[string]interface{})
126+
for k, v := range baseInput {
127+
input[k] = v
113128
}
114-
if test.e != nil {
115-
event := batch.Transactions[0]
116-
assert.Equal(t, test.e, event)
117-
} else {
118-
assert.Nil(t, batch.Transactions)
129+
for k, v := range test.input {
130+
if v == nil {
131+
delete(input, k)
132+
} else {
133+
input[k] = v
134+
}
119135
}
136+
var batch model.Batch
137+
err := DecodeTransaction(Input{Raw: input}, &batch)
138+
assert.Error(t, err)
139+
assert.Regexp(t, test.err, err.Error())
140+
assert.Zero(t, batch)
120141
})
121142
}
122143
}

model/span/generated/schema/rum_v3_span.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ const RUMV3Schema = `{
217217
},
218218
"d": {
219219
"type": "number",
220-
"description": "Duration of the span in milliseconds"
220+
"description": "Duration of the span in milliseconds",
221+
"minimum": 0
221222
},
222223
"n": {
223224
"type": "string",

model/span/generated/schema/span.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ const ModelSchema = `{
323323
},
324324
"duration": {
325325
"type": "number",
326-
"description": "Duration of the span in milliseconds"
326+
"description": "Duration of the span in milliseconds",
327+
"minimum": 0
327328
},
328329
"name": {
329330
"type": "string",

model/transaction/generated/schema/rum_v3_transaction.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ const RUMV3Schema = `{
256256
},
257257
"d": {
258258
"type": "number",
259-
"description": "Duration of the span in milliseconds"
259+
"description": "Duration of the span in milliseconds",
260+
"minimum": 0
260261
},
261262
"n": {
262263
"type": "string",
@@ -838,7 +839,8 @@ const RUMV3Schema = `{
838839
},
839840
"d": {
840841
"type": "number",
841-
"description": "How long the transaction took to complete, in ms with 3 decimal points"
842+
"description": "How long the transaction took to complete, in ms with 3 decimal points",
843+
"minimum": 0
842844
},
843845
"rt": {
844846
"type": [

0 commit comments

Comments
 (0)