Skip to content

Commit

Permalink
[v2] accept unix epoch timestamps in microseconds (elastic#1413)
Browse files Browse the repository at this point in the history
* makes "start" optional if "timestamp" is given for v2
* if "timestamp" is not given, it is set to the sum of req-time + start if data arrives through v2
* adds `timestamp.us` (long) to span, transaction and error documents for v2
  • Loading branch information
roncohen authored and Ron cohen committed Oct 15, 2018
1 parent 8802c48 commit 83ffefc
Show file tree
Hide file tree
Showing 70 changed files with 2,252 additions and 1,793 deletions.
10 changes: 10 additions & 0 deletions _meta/fields.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
type: keyword
description: Processor event.

- name: timestamp
type: group
description:
fields:
- name: us
type: long
count: 1
description: >
Timestamp of the event in microseconds since Unix epoch.
- name: context
type: group
description: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"errors": [
{
"document": "{ \"transaction\": { \"id\": 12345, \"trace_id\": \"0123456789abcdef0123456789abcdef\", \"parent_id\": \"abcdefabcdef01234567\", \"type\": \"request\", \"duration\": 32.592981, \"span_count\": { \"started\": 21 } } } ",
"message": "Problem validating JSON document against schema: I[#] S[#] doesn't validate with \"transaction#\"\n I[#] S[#/allOf/1] allOf failed\n I[#/id] S[#/allOf/1/properties/id/type] expected string, but got number"
"message": "Problem validating JSON document against schema: I[#] S[#] doesn't validate with \"transaction#\"\n I[#] S[#/allOf/2] allOf failed\n I[#/id] S[#/allOf/2/properties/id/type] expected string, but got number"
}
]
}
16 changes: 16 additions & 0 deletions docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ type: keyword
Processor event.
--
[float]
== timestamp fields
None
*`timestamp.us`*::
+
--
type: long
Timestamp of the event in microseconds since Unix epoch.
--
[float]
Expand Down
8 changes: 1 addition & 7 deletions docs/spec/errors/common_error.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "docs/spec/errors/error.json",
"$id": "docs/spec/errors/common_error.json",
"type": "object",
"description": "Data captured by an agent representing an event occurring in a monitored service",
"properties": {
Expand Down Expand Up @@ -86,12 +86,6 @@
}
},
"required": ["message"]
},
"timestamp": {
"type": ["string","null"],
"format": "date-time",
"pattern": "Z$",
"description": "Recorded time of the error, UTC based and formatted as YYYY-MM-DDTHH:mm:ss.sssZ"
}
},
"anyOf": [
Expand Down
3 changes: 2 additions & 1 deletion docs/spec/errors/v1_error.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"description": "Data captured by an agent representing an event occurring in a monitored service",
"allOf": [

{ "$ref": "common_error.json" },
{ "$ref": "common_error.json" },
{ "$ref": "../timestamp_rfc3339.json" },
{
"properties": {
"id": {
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/errors/v2_error.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"allOf": [

{ "$ref": "common_error.json" },
{ "$ref": "../timestamp_epoch.json" },
{
"properties": {
"id": {
Expand Down Expand Up @@ -36,7 +37,6 @@
"then": { "required": ["parent_id"], "properties": {"parent_id": { "type": "string" }}} },
{ "if": {"required": ["parent_id"], "properties": {"parent_id": { "type": "string" }}},
"then": { "required": ["transaction_id"], "properties": {"transaction_id": { "type": "string" }}} }

]
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$id": "docs/spec/metricsets/metricset.json",
"$id": "docs/spec/metricsets/common_metricset.json",
"type": "object",
"description": "Metric data captured by an APM agent",
"properties": {
Expand All @@ -24,13 +24,7 @@
}
},
"additionalProperties": false
},
"timestamp": {
"type": "string",
"format": "date-time",
"pattern": "Z$",
"description": "Recorded time of the metric, UTC based and formatted as YYYY-MM-DDTHH:mm:ss.sssZ"
}
},
"required": ["samples", "timestamp"]
"required": ["samples"]
}
2 changes: 1 addition & 1 deletion docs/spec/metricsets/payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"metrics": {
"type": "array",
"items": {
"$ref": "metricset.json"
"$ref": "v1_metricset.json"
},
"minItems": 1
},
Expand Down
12 changes: 12 additions & 0 deletions docs/spec/metricsets/v1_metricset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$id": "docs/spec/metricsets/v1_metricset.json",
"type": "object",
"description": "Data captured by an agent representing an event occurring in a monitored service",
"allOf": [

{ "$ref": "common_metricset.json" },
{ "$ref": "../timestamp_rfc3339.json" },
{"required": ["timestamp"], "properties": {"timestamp": { "type": "string" }}}

]
}
11 changes: 11 additions & 0 deletions docs/spec/metricsets/v2_metricset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$id": "docs/spec/metricsets/v2_metricset.json",
"type": "object",
"description": "Data captured by an agent representing an event occurring in a monitored service",
"allOf": [

{ "$ref": "common_metricset.json" },
{ "$ref": "../timestamp_epoch.json"},
{"required": ["timestamp"], "properties": {"timestamp": { "type": "integer" }}}
]
}
6 changes: 1 addition & 5 deletions docs/spec/spans/common_span.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,11 @@
},
"minItems": 0
},
"start": {
"type": "number",
"description": "Offset relative to the transaction's timestamp identifying the start of the span, in milliseconds"
},
"type": {
"type": "string",
"description": "Keyword of specific relevance in the service's domain (eg: 'db.postgresql.query', 'template.erb', etc)",
"maxLength": 1024
}
},
"required": ["duration", "name", "start", "type"]
"required": ["duration", "name", "type"]
}
5 changes: 5 additions & 0 deletions docs/spec/spans/v1_span.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
"parent": {
"type": ["integer", "null"],
"description": "The ID of the parent of the span."
},
"start": {
"type": "number",
"description": "Offset relative to the transaction's timestamp identifying the start of the span, in milliseconds"
}
},
"required": ["start"],
"dependencies": {
"parent": {
"required": ["id"]
Expand Down
16 changes: 10 additions & 6 deletions docs/spec/spans/v2_span.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"type": "object",
"$ref": "common_span.json",
"allOf": [
{ "$ref": "common_span.json" },
{ "$ref": "common_span.json" },
{ "$ref": "../timestamp_epoch.json" },
{
"properties": {
"id": {
Expand All @@ -26,14 +27,17 @@
"type": "string",
"maxLength": 1024
},
"timestamp": {
"description": "Recorded time of the span, UTC based and formatted as YYYY-MM-DDTHH:mm:ss.sssZ",
"type": ["string", "null"],
"pattern": "Z$",
"format": "date-time"
"start": {
"type": ["number", "null"],
"description": "Offset relative to the transaction's timestamp identifying the start of the span, in milliseconds"
}
},
"required": ["id", "transaction_id", "trace_id", "parent_id"]
},
{ "anyOf":[
{"required": ["timestamp"], "properties": {"timestamp": { "type": "integer" }}},
{"required": ["start"], "properties": {"start": { "type": "number" }}}
]
}
]
}
12 changes: 12 additions & 0 deletions docs/spec/timestamp_epoch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$id": "doc/spec/timestamp_epoch.json",
"title": "Timestamp Epoch",
"description": "Object with 'timestamp' property.",
"type": ["object"],
"properties": {
"timestamp": {
"description": "Recorded time of the event, UTC based and formatted as microseconds since Unix epoch",
"type": ["integer", "null"]
}
}
}
14 changes: 14 additions & 0 deletions docs/spec/timestamp_rfc3339.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$id": "doc/spec/timestamp_epoch.json",
"title": "Timestamp Epoch",
"description": "Object with 'timestamp' property.",
"type": ["object"],
"properties": {
"timestamp": {
"type": ["string", "null"],
"pattern": "Z$",
"format": "date-time",
"description": "Recorded time of the transaction, UTC based and formatted as YYYY-MM-DDTHH:mm:ss.sssZ"
}
}
}
6 changes: 0 additions & 6 deletions docs/spec/transactions/common_transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
"description": "The result of the transaction. For HTTP-related transactions, this should be the status code formatted like 'HTTP 2xx'.",
"maxLength": 1024
},
"timestamp": {
"type": ["string", "null"],
"pattern": "Z$",
"format": "date-time",
"description": "Recorded time of the transaction, UTC based and formatted as YYYY-MM-DDTHH:mm:ss.sssZ"
},
"type": {
"type": "string",
"description": "Keyword of specific relevance in the service's domain (eg: 'request', 'backgroundjob', etc)",
Expand Down
1 change: 1 addition & 0 deletions docs/spec/transactions/v1_transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"description": "Data captured by an agent representing an event occurring in a monitored service",
"allOf": [
{ "$ref": "common_transaction.json" },
{ "$ref": "../timestamp_rfc3339.json" },
{
"properties": {
"id": {
Expand Down
3 changes: 2 additions & 1 deletion docs/spec/transactions/v2_transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"type": "object",
"description": "Data captured by an agent representing an event occurring in a monitored service",
"allOf": [
{ "$ref": "common_transaction.json" },
{ "$ref": "common_transaction.json" },
{ "$ref": "../timestamp_epoch.json" },
{
"properties": {
"id": {
Expand Down
Loading

0 comments on commit 83ffefc

Please sign in to comment.