From 8c1b3e96c4d5bb879b7ee8d02012231934357911 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Fri, 2 Jun 2017 16:57:47 -0400 Subject: [PATCH] Do not omit empty arrays in JSON --- model/converter/json/fixtures/ui_01.json | 23 ++++++++++++++++++----- model/json/fixture.json | 20 +++++++++++++++----- model/json/model.go | 14 +++++++------- model/json/model_test.go | 5 ++++- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/model/converter/json/fixtures/ui_01.json b/model/converter/json/fixtures/ui_01.json index 27a5028715c..91829c7587c 100644 --- a/model/converter/json/fixtures/ui_01.json +++ b/model/converter/json/fixtures/ui_01.json @@ -5,8 +5,10 @@ "traceID": "1", "spanID": "2", "operationName": "test-general-conversion", + "references": [], "startTime": 1485467191639875, "duration": 5, + "tags": [], "logs": [ { "timestamp": 1485467191639875, @@ -29,12 +31,14 @@ ] } ], - "processID": "p1" + "processID": "p1", + "warnings": null }, { "traceID": "1", "spanID": "2", "operationName": "some-operation", + "references": [], "startTime": 1485467191639875, "duration": 5, "tags": [ @@ -64,7 +68,9 @@ "value": "AAAwOQ==" } ], - "processID": "p1" + "logs": [], + "processID": "p1", + "warnings": null }, { "traceID": "1", @@ -79,7 +85,10 @@ ], "startTime": 1485467191639875, "duration": 5, - "processID": "p2" + "tags": [], + "logs": [], + "processID": "p2", + "warnings": null }, { "traceID": "1", @@ -104,6 +113,8 @@ ], "startTime": 1485467191639875, "duration": 5, + "tags": [], + "logs": [], "processID": "p2", "warnings": [ "some span warning" @@ -112,10 +123,12 @@ ], "processes": { "p1": { - "serviceName": "service-x" + "serviceName": "service-x", + "tags": [] }, "p2": { - "serviceName": "service-y" + "serviceName": "service-y", + "tags": [] } }, "warnings": [ diff --git a/model/json/fixture.json b/model/json/fixture.json index e344bdf9c05..29c27c8131f 100644 --- a/model/json/fixture.json +++ b/model/json/fixture.json @@ -5,9 +5,13 @@ "traceID": "abc0", "spanID": "abc0", "operationName": "root-span", + "references": null, "startTime": 1000, "duration": 500, - "processID": "p1" + "tags": null, + "logs": null, + "processID": "p1", + "warnings": null }, { "traceID": "abc0", @@ -56,7 +60,8 @@ ] } ], - "processID": "p2" + "processID": "p2", + "warnings": null }, { "traceID": "abc0", @@ -71,12 +76,16 @@ ], "startTime": 1000, "duration": 500, - "processID": "p2" + "tags": null, + "logs": null, + "processID": "p2", + "warnings": null } ], "processes": { "p1": { - "serviceName": "service_1" + "serviceName": "service_1", + "tags": null }, "p2": { "serviceName": "service_2", @@ -88,5 +97,6 @@ } ] } - } + }, + "warnings": null } diff --git a/model/json/model.go b/model/json/model.go index b700dd3d69d..bd93c136b79 100644 --- a/model/json/model.go +++ b/model/json/model.go @@ -63,7 +63,7 @@ type Trace struct { TraceID TraceID `json:"traceID"` Spans []Span `json:"spans"` Processes map[ProcessID]Process `json:"processes"` - Warnings []string `json:"warnings,omitempty"` + Warnings []string `json:"warnings"` } // Span is a span denoting a piece of work in some infrastructure @@ -72,13 +72,13 @@ type Span struct { SpanID SpanID `json:"spanID"` Flags uint32 `json:"flags,omitempty"` OperationName string `json:"operationName"` - References []Reference `json:"references,omitempty"` + References []Reference `json:"references"` StartTime uint64 `json:"startTime"` // microseconds since Unix epoch Duration uint64 `json:"duration"` // microseconds - Tags []KeyValue `json:"tags,omitempty"` - Logs []Log `json:"logs,omitempty"` + Tags []KeyValue `json:"tags"` + Logs []Log `json:"logs"` ProcessID ProcessID `json:"processID"` - Warnings []string `json:"warnings,omitempty"` + Warnings []string `json:"warnings"` } // Reference is a reference from one span to another @@ -91,13 +91,13 @@ type Reference struct { // Process is the process emitting a set of spans type Process struct { ServiceName string `json:"serviceName"` - Tags []KeyValue `json:"tags,omitempty"` + Tags []KeyValue `json:"tags"` } // Log is a log emitted in a span type Log struct { Timestamp uint64 `json:"timestamp"` - Fields []KeyValue `json:"fields,omitempty"` + Fields []KeyValue `json:"fields"` } // KeyValue is a a key-value pair with typed value. diff --git a/model/json/model_test.go b/model/json/model_test.go index 03eeb6728b1..fc8046b4ef4 100644 --- a/model/json/model_test.go +++ b/model/json/model_test.go @@ -46,7 +46,10 @@ func TestModel(t *testing.T) { err = encoder.Encode(&trace) require.NoError(t, err) - assert.Equal(t, string(in), string(out.Bytes())) + if !assert.Equal(t, string(in), string(out.Bytes())) { + err := ioutil.WriteFile("fixture-actual.json", out.Bytes(), 0644) + assert.NoError(t, err) + } } func TestFromFileErrors(t *testing.T) {