From b38c5943fd48e8afe32c29f76da3144fee9a625e Mon Sep 17 00:00:00 2001 From: Ron cohen Date: Tue, 17 Jul 2018 12:34:12 +0200 Subject: [PATCH] Separate "span" into its own package --- model/span/_meta/fields.yml | 59 ++++++++++++++++++ model/{transaction => span}/span.go | 2 +- model/{transaction => span}/span_context.go | 2 +- .../span_context_test.go | 2 +- model/{transaction => span}/span_test.go | 2 +- model/transaction/_meta/fields.yml | 61 ------------------- model/transaction/event.go | 13 ++-- model/transaction/event_test.go | 9 +-- model/transaction/payload.go | 3 +- model/transaction/payload_test.go | 5 +- .../transaction/package_tests/attrs_common.go | 1 + 11 files changed, 81 insertions(+), 78 deletions(-) create mode 100644 model/span/_meta/fields.yml rename model/{transaction => span}/span.go (99%) rename model/{transaction => span}/span_context.go (98%) rename model/{transaction => span}/span_context_test.go (99%) rename model/{transaction => span}/span_test.go (99%) diff --git a/model/span/_meta/fields.yml b/model/span/_meta/fields.yml new file mode 100644 index 0000000000..8e7e22a7e4 --- /dev/null +++ b/model/span/_meta/fields.yml @@ -0,0 +1,59 @@ +- key: apm-span + title: APM Span + description: Span-specific data for APM. + fields: + - name: view spans + format: url + label_template: "View Spans" + + - name: span + type: group + dynamic: false + fields: + + - name: id + type: long + description: > + A locally unique ID of the span. + + - name: name + type: keyword + count: 1 + description: > + Generic designation of a span in the scope of a transaction. + + - name: type + type: keyword + count: 1 + description: > + Keyword of specific relevance in the service's domain (eg: 'db.postgresql.query', 'template.erb', 'cache', etc). + + - name: start + type: group + description: + fields: + - name: us + type: long + count: 1 + description: > + Offset relative to the transaction's timestamp identifying the start of the span, in microseconds. + + - name: duration + type: group + description: + fields: + + - name: us + type: long + count: 1 + description: > + Duration of the span, in microseconds. + format: duration + input_format: microseconds + output_format: asMilliseconds + output_precision: 0 + + - name: parent + type: long + description: > + The locally unique ID of the parent of the span. diff --git a/model/transaction/span.go b/model/span/span.go similarity index 99% rename from model/transaction/span.go rename to model/span/span.go index 3698d1c94f..d7a968b81e 100644 --- a/model/transaction/span.go +++ b/model/span/span.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package transaction +package span import ( "errors" diff --git a/model/transaction/span_context.go b/model/span/span_context.go similarity index 98% rename from model/transaction/span_context.go rename to model/span/span_context.go index f7883a510a..7a0581d8d8 100644 --- a/model/transaction/span_context.go +++ b/model/span/span_context.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package transaction +package span import ( m "github.com/elastic/apm-server/model" diff --git a/model/transaction/span_context_test.go b/model/span/span_context_test.go similarity index 99% rename from model/transaction/span_context_test.go rename to model/span/span_context_test.go index d9d55c694b..902d1d363c 100644 --- a/model/transaction/span_context_test.go +++ b/model/span/span_context_test.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package transaction +package span import ( "fmt" diff --git a/model/transaction/span_test.go b/model/span/span_test.go similarity index 99% rename from model/transaction/span_test.go rename to model/span/span_test.go index 1efe07f73c..a4128fa37a 100644 --- a/model/transaction/span_test.go +++ b/model/span/span_test.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package transaction +package span import ( "errors" diff --git a/model/transaction/_meta/fields.yml b/model/transaction/_meta/fields.yml index e220712f41..ff5a7485b7 100644 --- a/model/transaction/_meta/fields.yml +++ b/model/transaction/_meta/fields.yml @@ -64,64 +64,3 @@ - name: total type: long description: The total amount of dropped spans for this transaction. - - -- key: apm-span - title: APM Span - description: Span-specific data for APM. - fields: - - name: view spans - format: url - label_template: "View Spans" - - - name: span - type: group - dynamic: false - fields: - - - name: id - type: long - description: > - A locally unique ID of the span. - - - name: name - type: keyword - count: 1 - description: > - Generic designation of a span in the scope of a transaction. - - - name: type - type: keyword - count: 1 - description: > - Keyword of specific relevance in the service's domain (eg: 'db.postgresql.query', 'template.erb', 'cache', etc). - - - name: start - type: group - description: - fields: - - name: us - type: long - count: 1 - description: > - Offset relative to the transaction's timestamp identifying the start of the span, in microseconds. - - - name: duration - type: group - description: - fields: - - - name: us - type: long - count: 1 - description: > - Duration of the span, in microseconds. - format: duration - input_format: microseconds - output_format: asMilliseconds - output_precision: 0 - - - name: parent - type: long - description: > - The locally unique ID of the parent of the span. diff --git a/model/transaction/event.go b/model/transaction/event.go index 22d5c0c998..30fa6351f1 100644 --- a/model/transaction/event.go +++ b/model/transaction/event.go @@ -21,6 +21,7 @@ import ( "errors" "time" + "github.com/elastic/apm-server/model/span" "github.com/elastic/apm-server/utility" "github.com/elastic/beats/libbeat/common" ) @@ -36,7 +37,7 @@ type Event struct { Marks common.MapStr Sampled *bool SpanCount SpanCount - Spans []*Span + Spans []*span.Span } type SpanCount struct { Dropped Dropped @@ -67,12 +68,12 @@ func DecodeEvent(input interface{}, err error) (*Event, error) { SpanCount: SpanCount{Dropped: Dropped{Total: decoder.IntPtr(raw, "total", "span_count", "dropped")}}, } err = decoder.Err - var span *Span + var sp *span.Span spans := decoder.InterfaceArr(raw, "spans") - e.Spans = make([]*Span, len(spans)) - for idx, sp := range spans { - span, err = DecodeSpan(sp, err) - e.Spans[idx] = span + e.Spans = make([]*span.Span, len(spans)) + for idx, rawSpan := range spans { + sp, err = span.DecodeSpan(rawSpan, err) + e.Spans[idx] = sp } return &e, err } diff --git a/model/transaction/event_test.go b/model/transaction/event_test.go index 4c02179328..ea329e38bf 100644 --- a/model/transaction/event_test.go +++ b/model/transaction/event_test.go @@ -26,6 +26,7 @@ import ( "time" + "github.com/elastic/apm-server/model/span" "github.com/elastic/beats/libbeat/common" ) @@ -60,7 +61,7 @@ func TestTransactionEventDecode(t *testing.T) { Duration: 0.0, Timestamp: time.Time{}, Context: nil, Marks: nil, Sampled: nil, SpanCount: SpanCount{Dropped: Dropped{Total: nil}}, - Spans: []*Span{}, + Spans: []*span.Span{}, }, }, { @@ -81,8 +82,8 @@ func TestTransactionEventDecode(t *testing.T) { Duration: duration, Timestamp: timestampParsed, Context: context, Marks: marks, Sampled: &sampled, SpanCount: SpanCount{Dropped: Dropped{Total: &dropped}}, - Spans: []*Span{ - &Span{Name: "span", Type: "db", Start: 1.2, Duration: 2.3}, + Spans: []*span.Span{ + &span.Span{Name: "span", Type: "db", Start: 1.2, Duration: 2.3}, }, }, }, @@ -125,7 +126,7 @@ func TestEventTransform(t *testing.T) { Timestamp: time.Now(), Duration: 65.98, Context: common.MapStr{"foo": "bar"}, - Spans: []*Span{}, + Spans: []*span.Span{}, Sampled: &sampled, SpanCount: SpanCount{Dropped: Dropped{Total: &dropped}}, }, diff --git a/model/transaction/payload.go b/model/transaction/payload.go index fc59c06053..696e37f987 100644 --- a/model/transaction/payload.go +++ b/model/transaction/payload.go @@ -23,6 +23,7 @@ import ( "github.com/elastic/apm-server/config" "github.com/elastic/apm-server/model" m "github.com/elastic/apm-server/model" + "github.com/elastic/apm-server/model/span" "github.com/elastic/apm-server/model/transaction/generated/schema" "github.com/elastic/apm-server/utility" "github.com/elastic/apm-server/validation" @@ -99,7 +100,7 @@ func (pa *Payload) Transform(conf config.Config) []beat.Event { logp.NewLogger("transaction").Debugf("Transform transaction events: events=%d, service=%s, agent=%s:%s", len(pa.Events), pa.Service.Name, pa.Service.Agent.Name, pa.Service.Agent.Version) context := m.NewContext(&pa.Service, pa.Process, pa.System, pa.User) - spanContext := NewSpanContext(&pa.Service) + spanContext := span.NewSpanContext(&pa.Service) var events []beat.Event for idx := 0; idx < len(pa.Events); idx++ { diff --git a/model/transaction/payload_test.go b/model/transaction/payload_test.go index 950377bd9e..ac54283770 100644 --- a/model/transaction/payload_test.go +++ b/model/transaction/payload_test.go @@ -28,6 +28,7 @@ import ( "github.com/elastic/apm-server/config" m "github.com/elastic/apm-server/model" + "github.com/elastic/apm-server/model/span" "github.com/elastic/beats/libbeat/common" ) @@ -95,7 +96,7 @@ func TestPayloadDecode(t *testing.T) { Type: "transaction", Timestamp: timestampParsed, Duration: 34.9, - Spans: []*Span{}, + Spans: []*span.Span{}, }, }, }, @@ -188,7 +189,7 @@ func TestPayloadTransform(t *testing.T) { }, }, } - spans := []*Span{{}} + spans := []*span.Span{{}} txValidWithSpan := Event{Timestamp: timestamp, Spans: spans} spanEs := common.MapStr{ "context": common.MapStr{ diff --git a/processor/transaction/package_tests/attrs_common.go b/processor/transaction/package_tests/attrs_common.go index 511fbe0174..9f3a009b5e 100644 --- a/processor/transaction/package_tests/attrs_common.go +++ b/processor/transaction/package_tests/attrs_common.go @@ -31,6 +31,7 @@ func procSetup() *tests.ProcessorSetup { Proc: transaction.Processor, FullPayloadPath: "../testdata/transaction/payload.json", TemplatePaths: []string{"../../../model/transaction/_meta/fields.yml", + "../../../model/span/_meta/fields.yml", "../../../_meta/fields.common.yml"}, Schema: schema.PayloadSchema, }