-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate "Golden Data" trace spans #967
Merged
tigrannajaryan
merged 22 commits into
open-telemetry:master
from
kbrockhoff:golden-data-set-mgmt
May 26, 2020
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3f1997c
initial dev of golden data generators
kbrockhoff f39cd56
Merge branch 'master' into golden-data-set-mgmt
kbrockhoff 739a6d7
initial dev of golden data span generator
kbrockhoff ff928d5
initial dev of golden data span generator
kbrockhoff 1c08888
initial dev of golden data span generator
kbrockhoff 242404b
initial dev of golden data spans generator
kbrockhoff 57ef7e2
fix gosec issues
kbrockhoff 1297b4d
initial dev of resource spans generation
kbrockhoff f39b13f
fix some issues raised by PR reviewers
kbrockhoff 81ed6ac
fix issues raised by PR reviewers
kbrockhoff d6a1912
improve attribute constants naming
kbrockhoff da7aa25
introduce supplable random number generator
kbrockhoff 3083c1d
add max number of attributes test
kbrockhoff fd9cb75
Merge branch 'master' into golden-data-set-mgmt
kbrockhoff 78fe561
update to latest imports standard
kbrockhoff 6e0b5bb
Merge branch 'master' into golden-data-set-mgmt
kbrockhoff 432cb26
added documentation to public members
kbrockhoff 21642e6
Merge branch 'master' into golden-data-set-mgmt
kbrockhoff f54cf5c
Merge branch 'master' into golden-data-set-mgmt
kbrockhoff 6918bd0
Merge branch 'master' into golden-data-set-mgmt
kbrockhoff 88fd7ab
switch to structs for input values
kbrockhoff 5019ebb
changed span names to identity PICT inputs used in generation
kbrockhoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
initial dev of golden data span generator
- Loading branch information
commit 1c088886800db7b2c4b8c8e3023681684671dbe3
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,14 @@ const ( | |
SpanAttrInternal = "Internal" | ||
) | ||
|
||
const ( | ||
SpanChildCountNil = "Nil" | ||
SpanChildCountEmpty = "Empty" | ||
SpanChildCountOne = "One" | ||
SpanChildCountTwo = "Two" | ||
SpanChildCountEight = "Eight" | ||
) | ||
|
||
const ( | ||
SpanStatusNil = "Nil" | ||
SpanStatusOk = "Ok" | ||
|
@@ -127,7 +135,7 @@ func constructStatusMessageMap() map[string]string { | |
} | ||
|
||
func GenerateSpan(traceID []byte, tracestate string, parentID []byte, spanName string, kind string, spanTypeID string, | ||
statusStr string) *otlptrace.Span { | ||
eventCnt string, linkCnt string, statusStr string) *otlptrace.Span { | ||
endTime := time.Now().Add(-50 * time.Microsecond) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
return &otlptrace.Span{ | ||
TraceId: traceID, | ||
|
@@ -140,14 +148,23 @@ func GenerateSpan(traceID []byte, tracestate string, parentID []byte, spanName s | |
EndTimeUnixNano: uint64(endTime.UnixNano()), | ||
Attributes: generateSpanAttributes(spanTypeID), | ||
DroppedAttributesCount: 0, | ||
Events: nil, | ||
Events: generateSpanEvents(eventCnt), | ||
DroppedEventsCount: 0, | ||
Links: nil, | ||
Links: generateSpanLinks(linkCnt), | ||
DroppedLinksCount: 0, | ||
Status: generateStatus(statusStr), | ||
} | ||
} | ||
|
||
func generateTraceID() []byte { | ||
var r [16]byte | ||
_, err := rand.Read(r[:]) | ||
kbrockhoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
panic(err) | ||
} | ||
return r[:] | ||
} | ||
|
||
func generateSpanID() []byte { | ||
var r [8]byte | ||
_, err := rand.Read(r[:]) | ||
|
@@ -388,3 +405,77 @@ func generateInternalAttributes() map[string]interface{} { | |
attrMap[conventions.AttributeEnduserID] = "unittest" | ||
return attrMap | ||
} | ||
|
||
func generateSpanEvents(eventCnt string) []*otlptrace.Span_Event { | ||
if SpanChildCountNil == eventCnt { | ||
return nil | ||
} | ||
listSize := calculateListSize(eventCnt) | ||
eventList := make([]*otlptrace.Span_Event, listSize) | ||
for i := 0; i < listSize; i++ { | ||
eventList[i] = generateSpanEvent(i) | ||
} | ||
return eventList | ||
} | ||
|
||
func generateSpanLinks(linkCnt string) []*otlptrace.Span_Link { | ||
if SpanChildCountNil == linkCnt { | ||
return nil | ||
} | ||
listSize := calculateListSize(linkCnt) | ||
linkList := make([]*otlptrace.Span_Link, listSize) | ||
for i := 0; i < listSize; i++ { | ||
linkList[i] = generateSpanLink(i) | ||
} | ||
return linkList | ||
} | ||
|
||
func calculateListSize(listCnt string) int { | ||
if SpanChildCountOne == listCnt { | ||
return 1 | ||
} else if SpanChildCountTwo == listCnt { | ||
return 2 | ||
} else if SpanChildCountEight == listCnt { | ||
return 8 | ||
} else { | ||
return 0 | ||
} | ||
} | ||
|
||
func generateSpanEvent(index int) *otlptrace.Span_Event { | ||
t := time.Now().Add(-75 * time.Microsecond) | ||
return &otlptrace.Span_Event{ | ||
TimeUnixNano: uint64(t.UnixNano()), | ||
Name: "message", | ||
Attributes: generateEventAttributes(index), | ||
DroppedAttributesCount: 0, | ||
} | ||
} | ||
|
||
func generateEventAttributes(index int) []*otlpcommon.AttributeKeyValue { | ||
attrMap := make(map[string]interface{}) | ||
if index%2 == 0 { | ||
attrMap[conventions.AttributeMessageType] = "SENT" | ||
} else { | ||
attrMap[conventions.AttributeMessageType] = "RECEIVED" | ||
} | ||
attrMap[conventions.AttributeMessageID] = int64(index) | ||
attrMap[conventions.AttributeMessageCompressedSize] = int64(17 * index) | ||
attrMap[conventions.AttributeMessageUncompressedSize] = int64(24 * index) | ||
return convertMapToAttributeKeyValues(attrMap) | ||
} | ||
|
||
func generateSpanLink(index int) *otlptrace.Span_Link { | ||
return &otlptrace.Span_Link{ | ||
TraceId: generateTraceID(), | ||
SpanId: generateSpanID(), | ||
TraceState: "", | ||
Attributes: generateLinkAttributes(index), | ||
DroppedAttributesCount: 0, | ||
} | ||
} | ||
|
||
func generateLinkAttributes(index int) []*otlpcommon.AttributeKeyValue { | ||
attrMap := generateMessagingConsumerAttributes() | ||
return convertMapToAttributeKeyValues(attrMap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple more important case that would be useful to cover:
Type
value (out of enum bounds).