Skip to content
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

Update OTLP to latest version #1384

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ALL_SRC := $(shell find . -name '*.go' \
-not -path '*/third_party/*' \
-not -path '*/internal/data/opentelemetry-proto/*' \
-not -path '*/internal/data/opentelemetry-proto-gen/*' \
-not -path '*/internal/data/logsproto/*' \
-not -path './.circleci/scripts/reportgenerator/*' \
-type f | sort)

Expand Down Expand Up @@ -126,7 +125,7 @@ lint: lint-static-check

.PHONY: impi
impi:
@$(IMPI) --local go.opentelemetry.io/collector --scheme stdThirdPartyLocal --skip internal/data/opentelemetry-proto --skip internal/data/logsproto ./...
@$(IMPI) --local go.opentelemetry.io/collector --scheme stdThirdPartyLocal --skip internal/data/opentelemetry-proto ./...

.PHONY: fmt
fmt:
Expand Down Expand Up @@ -219,12 +218,6 @@ OPENTELEMETRY_PROTO_SRC_DIR=internal/data/opentelemetry-proto
# Find all .proto files.
OPENTELEMETRY_PROTO_FILES := $(subst $(OPENTELEMETRY_PROTO_SRC_DIR)/,,$(wildcard $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/*/v1/*.proto $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/collector/*/v1/*.proto))

# The source directory for experimental Log ProtoBufs.
LOGS_PROTO_SRC_DIR=internal/data/logsproto

# Find Log .proto files.
LOGS_PROTO_FILES := $(subst $(LOGS_PROTO_SRC_DIR)/,,$(wildcard $(LOGS_PROTO_SRC_DIR)/*/v1/*.proto $(LOGS_PROTO_SRC_DIR)/collector/*/v1/*.proto))

# Target directory to write generated files to.
PROTO_TARGET_GEN_DIR=internal/data/opentelemetry-proto-gen

Expand Down Expand Up @@ -260,20 +253,13 @@ genproto_sub:
@echo Modify them in the intermediate directory.
$(foreach file,$(OPENTELEMETRY_PROTO_FILES),$(call exec-command,sed 's+github.com/open-telemetry/opentelemetry-proto/gen/go/+go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/+g' $(OPENTELEMETRY_PROTO_SRC_DIR)/$(file) > $(PROTO_INTERMEDIATE_DIR)/$(file)))

@echo Generate Go code from Logs .proto files in intermediate directory.
$(foreach file,$(LOGS_PROTO_FILES),$(call exec-command,cd $(LOGS_PROTO_SRC_DIR) && protoc --gogofaster_out=plugins=grpc:./ -I./ -I$(PWD)/$(PROTO_INTERMEDIATE_DIR) $(file)))

@echo Move generated code to target directory.
mkdir -p $(PROTO_TARGET_GEN_DIR)
cp -R $(LOGS_PROTO_SRC_DIR)/$(PROTO_PACKAGE)/* $(PROTO_TARGET_GEN_DIR)/
rm -rf $(LOGS_PROTO_SRC_DIR)/go.opentelemetry.io

@echo Generate Go code from .proto files in intermediate directory.
$(foreach file,$(OPENTELEMETRY_PROTO_FILES),$(call exec-command,cd $(PROTO_INTERMEDIATE_DIR) && protoc --gogofaster_out=plugins=grpc:./ -I./ $(file)))

@echo Generate gRPC gateway code.
cd $(PROTO_INTERMEDIATE_DIR) && protoc --grpc-gateway_out=logtostderr=true,grpc_api_configuration=opentelemetry/proto/collector/trace/v1/trace_service_http.yaml:./ opentelemetry/proto/collector/trace/v1/trace_service.proto
cd $(PROTO_INTERMEDIATE_DIR) && protoc --grpc-gateway_out=logtostderr=true,grpc_api_configuration=opentelemetry/proto/collector/metrics/v1/metrics_service_http.yaml:./ opentelemetry/proto/collector/metrics/v1/metrics_service.proto
cd $(PROTO_INTERMEDIATE_DIR) && protoc --grpc-gateway_out=logtostderr=true,grpc_api_configuration=opentelemetry/proto/collector/logs/v1/logs_service_http.yaml:./ opentelemetry/proto/collector/logs/v1/logs_service.proto

@echo Move generated code to target directory.
mkdir -p $(PROTO_TARGET_GEN_DIR)
Expand Down
5 changes: 5 additions & 0 deletions cmd/pdatagen/internal/common_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ var nameField = &primitiveField{
defaultVal: `""`,
testVal: `"test_name"`,
}

var anyValue = &messageStruct{
structName: "AttributeValue",
originFullName: "otlpcommon.AnyValue",
}
57 changes: 39 additions & 18 deletions cmd/pdatagen/internal/log_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ package internal
var logFile = &File{
Name: "log",
imports: []string{
`logsproto "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"`,
`otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"`,
},
testImports: []string{
`"testing"`,
``,
`"github.com/stretchr/testify/assert"`,
``,
`logsproto "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"`,
`otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"`,
},
structs: []baseStruct{
resourceLogsSlice,
resourceLogs,
instrumentationLibraryLogsSlice,
instrumentationLibraryLogs,
logSlice,
logRecord,
},
Expand All @@ -42,9 +44,28 @@ var resourceLogsSlice = &sliceStruct{
var resourceLogs = &messageStruct{
structName: "ResourceLogs",
description: "// ResourceLogs is a collection of logs from a Resource.",
originFullName: "logsproto.ResourceLogs",
originFullName: "otlplogs.ResourceLogs",
fields: []baseField{
resourceField,
&sliceField{
fieldMame: "InstrumentationLibraryLogs",
originFieldName: "InstrumentationLibraryLogs",
returnSlice: instrumentationLibraryLogsSlice,
},
},
}

var instrumentationLibraryLogsSlice = &sliceStruct{
structName: "InstrumentationLibraryLogsSlice",
element: instrumentationLibraryLogs,
}

var instrumentationLibraryLogs = &messageStruct{
structName: "InstrumentationLibraryLogs",
description: "// InstrumentationLibraryLogs is a collection of logs from a LibraryInstrumentation.",
originFullName: "otlplogs.InstrumentationLibraryLogs",
fields: []baseField{
instrumentationLibraryField,
&sliceField{
fieldMame: "Logs",
originFieldName: "Logs",
Expand All @@ -61,11 +82,11 @@ var logSlice = &sliceStruct{
var logRecord = &messageStruct{
structName: "LogRecord",
description: "// LogRecord are experimental implementation of OpenTelemetry Log Data Model.\n",
originFullName: "logsproto.LogRecord",
originFullName: "otlplogs.LogRecord",
fields: []baseField{
&primitiveTypedField{
fieldMame: "Timestamp",
originFieldName: "TimestampUnixNano",
originFieldName: "TimeUnixNano",
returnType: "TimestampUnixNano",
rawType: "uint64",
defaultVal: "TimestampUnixNano(0)",
Expand All @@ -91,26 +112,26 @@ var logRecord = &messageStruct{
&primitiveTypedField{
fieldMame: "SeverityNumber",
originFieldName: "SeverityNumber",
returnType: "logsproto.SeverityNumber",
rawType: "logsproto.SeverityNumber",
defaultVal: `logsproto.SeverityNumber_UNDEFINED_SEVERITY_NUMBER`,
testVal: `logsproto.SeverityNumber_INFO`,
returnType: "otlplogs.SeverityNumber",
rawType: "otlplogs.SeverityNumber",
defaultVal: `otlplogs.SeverityNumber_UNDEFINED_SEVERITY_NUMBER`,
testVal: `otlplogs.SeverityNumber_INFO`,
},
&primitiveField{
fieldMame: "ShortName",
originFieldName: "ShortName",
fieldMame: "Name",
originFieldName: "Name",
returnType: "string",
defaultVal: `""`,
testVal: `"test_name"`,
},
&primitiveField{
fieldMame: "Body",
originFieldName: "Body",
returnType: "string",
defaultVal: `""`,
testVal: `"test log message"`,
},
bodyField,
attributes,
droppedAttributesCount,
},
}

var bodyField = &messageField{
fieldName: "Body",
originFieldName: "Body",
returnMessage: anyValue,
}
20 changes: 20 additions & 0 deletions consumer/pdata/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ type AttributeValue struct {
orig **otlpcommon.AnyValue
}

func newAttributeValue(orig **otlpcommon.AnyValue) AttributeValue {
return AttributeValue{orig}
}

// NewAttributeValueNull creates a new AttributeValue with a null value.
func NewAttributeValueNull() AttributeValue {
orig := &otlpcommon.AnyValue{}
Expand Down Expand Up @@ -141,6 +145,15 @@ func NewAttributeValueSlice(len int) []AttributeValue {
return wrappers
}

func (a AttributeValue) InitEmpty() {
*a.orig = &otlpcommon.AnyValue{}
}

// IsNil returns true if the underlying data are nil.
func (a AttributeValue) IsNil() bool {
return *a.orig == nil
}

// Type returns the type of the value for this AttributeValue.
// Calling this function on zero-initialized AttributeValue will cause a panic.
func (a AttributeValue) Type() AttributeValueType {
Expand Down Expand Up @@ -296,6 +309,13 @@ func (a AttributeValue) copyTo(dest *otlpcommon.AnyValue) {
}
}

func (a AttributeValue) CopyTo(dest AttributeValue) {
if *a.orig != nil && dest.IsNil() {
dest.InitEmpty()
}
a.copyTo(*dest.orig)
}

// Equal checks for equality, it returns true if the objects are equal otherwise false.
func (a AttributeValue) Equal(av AttributeValue) bool {
if (*a.orig) == nil || (*a.orig).Value == nil {
Expand Down
10 changes: 10 additions & 0 deletions consumer/pdata/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,16 @@ func BenchmarkStringMap_RangeOverMap(b *testing.B) {
}
}

func fillTestAttributeValue(dest AttributeValue) {
dest.SetStringVal("v")
}

func generateTestAttributeValue() AttributeValue {
av := NewAttributeValueNull()
fillTestAttributeValue(av)
return av
}

func generateTestStringMap() StringMap {
sm := NewStringMap()
fillTestStringMap(sm)
Expand Down
Loading