Skip to content

Commit

Permalink
Update timestamp in JSON Spec for edge-case (elastic#77)
Browse files Browse the repository at this point in the history
Also brings back logging in case we missed other issues.
  • Loading branch information
roncohen authored and ruflin committed Aug 21, 2017
1 parent cd5a0e4 commit 449df0f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/spec/errors/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"timestamp": {
"type": "string",
"description": "Recorded time of the error, UTC based and formatted as YYYY-MM-DDTHH:mm:ss.sssZ",
"pattern": "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,6})?Z"
"pattern": "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,6})?Z$"
}
},
"required": ["timestamp"],
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/transactions/transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"timestamp": {
"type": "string",
"description": "Recorded time of the transaction, UTC based and formatted as YYYY-MM-DDTHH:mm:ss.sssZ",
"pattern": "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,6})?Z"
"pattern": "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,6})?Z$"
},
"traces": {
"type": ["array", "null"],
Expand Down
2 changes: 1 addition & 1 deletion processor/error/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ var errorSchema = `{
"timestamp": {
"type": "string",
"description": "Recorded time of the error, UTC based and formatted as YYYY-MM-DDTHH:mm:ss.sssZ",
"pattern": "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,6})?Z"
"pattern": "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,6})?Z$"
}
},
"required": ["timestamp"],
Expand Down
8 changes: 6 additions & 2 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package processor
import (
"io"

"github.com/elastic/beats/libbeat/logp"

m "github.com/elastic/apm-server/processor/model"
"github.com/elastic/apm-server/utility"
"github.com/elastic/beats/libbeat/beat"
Expand All @@ -29,8 +31,10 @@ func CreateDoc(strTime string, docMappings []m.DocMapping) beat.Event {
}
}

// This assumes JSON Spec has already validated the timestamp to be the correct format.
timestamp, _ := utility.ParseTime(strTime)
timestamp, err := utility.ParseTime(strTime)
if err != nil {
logp.Err("Unable to parse timestamp %s: %s", strTime, err)
}

return beat.Event{
Fields: doc,
Expand Down
2 changes: 1 addition & 1 deletion processor/transaction/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ var transactionSchema = `{
"timestamp": {
"type": "string",
"description": "Recorded time of the transaction, UTC based and formatted as YYYY-MM-DDTHH:mm:ss.sssZ",
"pattern": "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,6})?Z"
"pattern": "^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(\\.\\d{1,6})?Z$"
},
"traces": {
"type": ["array", "null"],
Expand Down
7 changes: 7 additions & 0 deletions tests/data/invalid/error/invalid_timestamp5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "85915e55-b43f-4340-a8e0-df1906ecbfa9",
"timestamp": "2017-05-30T18:53:27ZNOTCORRECT",
"exception": {
"message": ""
}
}
8 changes: 8 additions & 0 deletions tests/data/invalid/transaction/invalid_timestamp5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "85915e55-b43f-4340-a8e0-df1906ecbfa9",
"name": "GET /api/types",
"type": "request",
"duration": 2.0,
"timestamp": "2017-05-30T18:53:27ZNOTCORRECT",
"traces": []
}
2 changes: 2 additions & 0 deletions tests/json_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestTransactionSchema(t *testing.T) {
{File: "invalid_timestamp2.json", Error: "[#/properties/timestamp/pattern] does not match pattern"},
{File: "invalid_timestamp3.json", Error: "[#/properties/timestamp/pattern] does not match pattern"},
{File: "invalid_timestamp4.json", Error: "[#/properties/timestamp/pattern] does not match pattern"},
{File: "invalid_timestamp5.json", Error: "[#/properties/timestamp/pattern] does not match pattern"},
}
testDataAgainstSchema(t, testData, "transactions/transaction", "transaction", `"$ref": "../docs/spec/transactions/`)
}
Expand All @@ -121,6 +122,7 @@ func TestErrorSchema(t *testing.T) {
{File: "invalid_timestamp2.json", Error: "[#/properties/timestamp/pattern] does not match pattern"},
{File: "invalid_timestamp3.json", Error: "[#/properties/timestamp/pattern] does not match pattern"},
{File: "invalid_timestamp4.json", Error: "[#/properties/timestamp/pattern] does not match pattern"},
{File: "invalid_timestamp5.json", Error: "[#/properties/timestamp/pattern] does not match pattern"},
{File: "no_log_message.json", Error: "missing properties: \"message\""},
{File: "no_exception_message.json", Error: "missing properties: \"message\""},
{File: "no_log_or_exception.json", Error: "missing properties: \"exception\""},
Expand Down

0 comments on commit 449df0f

Please sign in to comment.