Skip to content

Commit

Permalink
Generate "Golden Data" trace spans (#967)
Browse files Browse the repository at this point in the history
1. PICT tool input files for trace data and resulting output files from running pict from the command line. These are in `internal/goldendataset/testdata`. See: [Pairwise Independent Combinatorial Testing](https://github.com/microsoft/pict)
2. Generator for fully-populated OLTP ResourceSpans from PICT output files.

This has all the intended functionality for this PR. It has no impact on other functionality so there should be no problem in merging to master. I will follow up with other PRs to complete full "Golden Dataset" testing functionality.

**Link to tracking Issue:** #652 

**Testing:** Unit tests exist for all functionality which has been coded so far

**Documentation:** None yet. Will do so after golden dataset generation coding is complete.
  • Loading branch information
kbrockhoff authored May 26, 2020
1 parent 14ae217 commit ffd4838
Show file tree
Hide file tree
Showing 17 changed files with 1,660 additions and 27 deletions.
105 changes: 105 additions & 0 deletions internal/goldendataset/generator_commons.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2020, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package goldendataset

import (
"encoding/csv"
"io"
"os"
"path/filepath"

otlpcommon "github.com/open-telemetry/opentelemetry-proto/gen/go/common/v1"
"github.com/spf13/cast"
)

func convertMapToAttributeKeyValues(attrsMap map[string]interface{}) []*otlpcommon.AttributeKeyValue {
if attrsMap == nil {
return nil
}
attrList := make([]*otlpcommon.AttributeKeyValue, len(attrsMap))
index := 0
for key, value := range attrsMap {
attrList[index] = constructAttributeKeyValue(key, value)
index++
}
return attrList
}

func constructAttributeKeyValue(key string, value interface{}) *otlpcommon.AttributeKeyValue {
var attr otlpcommon.AttributeKeyValue
switch val := value.(type) {
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
attr = otlpcommon.AttributeKeyValue{
Key: key,
Type: otlpcommon.AttributeKeyValue_INT,
IntValue: cast.ToInt64(val),
}
case float32, float64:
attr = otlpcommon.AttributeKeyValue{
Key: key,
Type: otlpcommon.AttributeKeyValue_DOUBLE,
DoubleValue: cast.ToFloat64(val),
}
case bool:
attr = otlpcommon.AttributeKeyValue{
Key: key,
Type: otlpcommon.AttributeKeyValue_BOOL,
BoolValue: cast.ToBool(val),
}
default:
attr = otlpcommon.AttributeKeyValue{
Key: key,
Type: otlpcommon.AttributeKeyValue_STRING,
StringValue: val.(string),
}
}
return &attr
}

func loadPictOutputFile(fileName string) ([][]string, error) {
file, err := os.Open(filepath.Clean(fileName))
if err != nil {
return nil, err
}
defer func() {
cerr := file.Close()
if err == nil {
err = cerr
}
}()

reader := csv.NewReader(file)
reader.Comma = '\t'

return reader.ReadAll()
}

func generateTraceID(random io.Reader) []byte {
var r [16]byte
_, err := random.Read(r[:])
if err != nil {
panic(err)
}
return r[:]
}

func generateSpanID(random io.Reader) []byte {
var r [8]byte
_, err := random.Read(r[:])
if err != nil {
panic(err)
}
return r[:]
}
184 changes: 184 additions & 0 deletions internal/goldendataset/pict_tracing_input_defs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Copyright 2020, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package goldendataset

//// Start of PICT inputs for generating golden dataset ResourceSpans (pict_input_traces.txt) ////

// Input columns in pict_input_traces.txt
const (
TracesColumnResource = 0
TracesColumnInstrumentationLibrary = 1
TracesColumnSpans = 2
)

// Enumerates the supported types of resource instances that can be generated.
type PICTInputResource string

const (
ResourceNil PICTInputResource = "Nil"
ResourceEmpty PICTInputResource = "Empty"
ResourceVMOnPrem PICTInputResource = "VMOnPrem"
ResourceVMCloud PICTInputResource = "VMCloud"
ResourceK8sOnPrem PICTInputResource = "K8sOnPrem"
ResourceK8sCloud PICTInputResource = "K8sCloud"
ResourceFaas PICTInputResource = "Faas"
)

// Enumerates the number and kind of instrumentation library instances that can be generated.
type PICTInputInstrumentationLibrary string

const (
LibraryNone PICTInputInstrumentationLibrary = "None"
LibraryOne PICTInputInstrumentationLibrary = "One"
LibraryTwo PICTInputInstrumentationLibrary = "Two"
)

// Enumerates the relative sizes of tracing spans that can be attached to an instrumentation library span instance.
type PICTInputSpans string

const (
LibrarySpansNone PICTInputSpans = "None"
LibrarySpansOne PICTInputSpans = "One"
LibrarySpansSeveral PICTInputSpans = "Several"
LibrarySpansAll PICTInputSpans = "All"
)

// PICTTracingInputs defines one pairwise combination of ResourceSpans variations
type PICTTracingInputs struct {
// Specifies the category of attributes to populate the Resource field with
Resource PICTInputResource
// Specifies the number and library categories to populte the InstrumentationLibrarySpans field with
InstrumentationLibrary PICTInputInstrumentationLibrary
// Specifies the relative number of spans to populate the InstrumentationLibrarySpans' Spans field with
Spans PICTInputSpans
}

//// Start of PICT inputs for generating golden dataset Spans (pict_input_spans.txt) ////

// Input columns in pict_input_spans.txt
const (
SpansColumnParent = 0
SpansColumnTracestate = 1
SpansColumnKind = 2
SpansColumnAttributes = 3
SpansColumnEvents = 4
SpansColumnLinks = 5
SpansColumnStatus = 6
)

// Enumerates the parent/child types of spans that can be generated.
type PICTInputParent string

const (
SpanParentRoot PICTInputParent = "Root"
SpanParentChild PICTInputParent = "Child"
)

// Enumerates the categories of tracestate values that can be generated for a span.
type PICTInputTracestate string

const (
TraceStateEmpty PICTInputTracestate = "Empty"
TraceStateOne PICTInputTracestate = "One"
TraceStateFour PICTInputTracestate = "Four"
)

// Enumerates the span kind values that can be set for a span.
type PICTInputKind string

const (
SpanKindUnspecified PICTInputKind = "Unspecified"
SpanKindInternal PICTInputKind = "Internal"
SpanKindServer PICTInputKind = "Server"
SpanKindClient PICTInputKind = "Client"
SpanKindProducer PICTInputKind = "Producer"
SpanKindConsumer PICTInputKind = "Consumer"
)

// Enumerates the categories of representative attributes a generated span can be populated with.
type PICTInputAttributes string

const (
SpanAttrNil PICTInputAttributes = "Nil"
SpanAttrEmpty PICTInputAttributes = "Empty"
SpanAttrDatabaseSQL PICTInputAttributes = "DatabaseSQL"
SpanAttrDatabaseNoSQL PICTInputAttributes = "DatabaseNoSQL"
SpanAttrFaaSDatasource PICTInputAttributes = "FaaSDatasource"
SpanAttrFaaSHTTP PICTInputAttributes = "FaaSHTTP"
SpanAttrFaaSPubSub PICTInputAttributes = "FaaSPubSub"
SpanAttrFaaSTimer PICTInputAttributes = "FaaSTimer"
SpanAttrFaaSOther PICTInputAttributes = "FaaSOther"
SpanAttrHTTPClient PICTInputAttributes = "HTTPClient"
SpanAttrHTTPServer PICTInputAttributes = "HTTPServer"
SpanAttrMessagingProducer PICTInputAttributes = "MessagingProducer"
SpanAttrMessagingConsumer PICTInputAttributes = "MessagingConsumer"
SpanAttrGRPCClient PICTInputAttributes = "gRPCClient"
SpanAttrGRPCServer PICTInputAttributes = "gRPCServer"
SpanAttrInternal PICTInputAttributes = "Internal"
SpanAttrMaxCount PICTInputAttributes = "MaxCount"
)

// Enumerates the categories of events and/or links a generated span can be populated with.
type PICTInputSpanChild string

const (
SpanChildCountNil PICTInputSpanChild = "Nil"
SpanChildCountEmpty PICTInputSpanChild = "Empty"
SpanChildCountOne PICTInputSpanChild = "One"
SpanChildCountTwo PICTInputSpanChild = "Two"
SpanChildCountEight PICTInputSpanChild = "Eight"
)

// Enumerates the status values a generated span can be populated with.
type PICTInputStatus string

const (
SpanStatusNil PICTInputStatus = "Nil"
SpanStatusOk PICTInputStatus = "Ok"
SpanStatusCancelled PICTInputStatus = "Cancelled"
SpanStatusUnknownError PICTInputStatus = "UnknownError"
SpanStatusInvalidArgument PICTInputStatus = "InvalidArgument"
SpanStatusDeadlineExceeded PICTInputStatus = "DeadlineExceeded"
SpanStatusNotFound PICTInputStatus = "NotFound"
SpanStatusAlreadyExists PICTInputStatus = "AlreadyExists"
SpanStatusPermissionDenied PICTInputStatus = "PermissionDenied"
SpanStatusResourceExhausted PICTInputStatus = "ResourceExhausted"
SpanStatusFailedPrecondition PICTInputStatus = "FailedPrecondition"
SpanStatusAborted PICTInputStatus = "Aborted"
SpanStatusOutOfRange PICTInputStatus = "OutOfRange"
SpanStatusUnimplemented PICTInputStatus = "Unimplemented"
SpanStatusInternalError PICTInputStatus = "InternalError"
SpanStatusUnavailable PICTInputStatus = "Unavailable"
SpanStatusDataLoss PICTInputStatus = "DataLoss"
SpanStatusUnauthenticated PICTInputStatus = "Unauthenticated"
)

// PICTSpanInputs defines one pairwise combination of Span variations
type PICTSpanInputs struct {
// Specifies whether the ParentSpanId field should be populated or not
Parent PICTInputParent
// Specifies the category of contents to populate the TraceState field with
Tracestate PICTInputTracestate
// Specifies the value to populate the Kind field with
Kind PICTInputKind
// Specifies the category of values to populate the Attributes field with
Attributes PICTInputAttributes
// Specifies the category of contents to populate the Events field with
Events PICTInputSpanChild
// Specifies the category of contents to populate the Links field with
Links PICTInputSpanChild
// Specifies the value to populate the Status field with
Status PICTInputStatus
}
Loading

0 comments on commit ffd4838

Please sign in to comment.