Skip to content

Commit

Permalink
Expose non-nullable metric types
Browse files Browse the repository at this point in the history
This is possible because:

* Gogo proto (and protobuf) will not unmarshal any nil element in a oneof;
* Set type will initialize the oneof wrapper as well as the element;

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Nov 23, 2020
1 parent 7874cd5 commit 28f9e43
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 434 deletions.
16 changes: 8 additions & 8 deletions cmd/pdatagen/internal/metrics_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var metric = &messagePtrStruct{
},
}

var intGauge = &messagePtrStruct{
var intGauge = &messageValueStruct{
structName: "IntGauge",
description: "// IntGauge represents the type of a int scalar metric that always exports the \"current value\" for every data point.",
originFullName: "otlpmetrics.IntGauge",
Expand All @@ -140,7 +140,7 @@ var intGauge = &messagePtrStruct{
},
}

var doubleGauge = &messagePtrStruct{
var doubleGauge = &messageValueStruct{
structName: "DoubleGauge",
description: "// DoubleGauge represents the type of a double scalar metric that always exports the \"current value\" for every data point.",
originFullName: "otlpmetrics.DoubleGauge",
Expand All @@ -153,7 +153,7 @@ var doubleGauge = &messagePtrStruct{
},
}

var intSum = &messagePtrStruct{
var intSum = &messageValueStruct{
structName: "IntSum",
description: "// IntSum represents the type of a numeric int scalar metric that is calculated as a sum of all reported measurements over a time interval.",
originFullName: "otlpmetrics.IntSum",
Expand All @@ -168,7 +168,7 @@ var intSum = &messagePtrStruct{
},
}

var doubleSum = &messagePtrStruct{
var doubleSum = &messageValueStruct{
structName: "DoubleSum",
description: "// DoubleSum represents the type of a numeric double scalar metric that is calculated as a sum of all reported measurements over a time interval.",
originFullName: "otlpmetrics.DoubleSum",
Expand All @@ -183,7 +183,7 @@ var doubleSum = &messagePtrStruct{
},
}

var intHistogram = &messagePtrStruct{
var intHistogram = &messageValueStruct{
structName: "IntHistogram",
description: "// IntHistogram represents the type of a metric that is calculated by aggregating as a Histogram of all reported double measurements over a time interval.",
originFullName: "otlpmetrics.IntHistogram",
Expand All @@ -197,7 +197,7 @@ var intHistogram = &messagePtrStruct{
},
}

var doubleHistogram = &messagePtrStruct{
var doubleHistogram = &messageValueStruct{
structName: "DoubleHistogram",
description: "// DoubleHistogram represents the type of a metric that is calculated by aggregating as a Histogram of all reported double measurements over a time interval.",
originFullName: "otlpmetrics.DoubleHistogram",
Expand All @@ -211,7 +211,7 @@ var doubleHistogram = &messagePtrStruct{
},
}

var doubleSummary = &messagePtrStruct{
var doubleSummary = &messageValueStruct{
structName: "DoubleSummary",
description: "// DoubleSummary represents the type of a metric that is calculated by aggregating as a Summary of all reported double measurements over a time interval.",
originFullName: "otlpmetrics.DoubleSummary",
Expand Down Expand Up @@ -488,6 +488,6 @@ var aggregationTemporalityField = &primitiveTypedField{
var oneofDataField = &oneofField{
copyFuncName: "copyData",
originFieldName: "Data",
testVal: "&otlpmetrics.Metric_IntGauge{}",
testVal: "&otlpmetrics.Metric_IntGauge{IntGauge: &otlpmetrics.IntGauge{}}",
fillTestName: "IntGauge",
}
7 changes: 4 additions & 3 deletions cmd/pdatagen/internal/trace_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package internal
var traceFile = &File{
Name: "trace",
imports: []string{
`"go.opentelemetry.io/collector/internal/data"`,
`otlpcommon "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/common/v1"`,
`otlptrace "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/trace/v1"`,
},
Expand Down Expand Up @@ -217,7 +218,7 @@ var traceIDField = &primitiveTypedField{
fieldName: "TraceID",
originFieldName: "TraceId",
returnType: "TraceID",
rawType: "otlpcommon.TraceID",
rawType: "data.TraceID",
defaultVal: "NewTraceID([16]byte{})",
testVal: "NewTraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1})",
}
Expand All @@ -226,7 +227,7 @@ var spanIDField = &primitiveTypedField{
fieldName: "SpanID",
originFieldName: "SpanId",
returnType: "SpanID",
rawType: "otlpcommon.SpanID",
rawType: "data.SpanID",
defaultVal: "NewSpanID([8]byte{})",
testVal: "NewSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8})",
}
Expand All @@ -235,7 +236,7 @@ var parentSpanIDField = &primitiveTypedField{
fieldName: "ParentSpanID",
originFieldName: "ParentSpanId",
returnType: "SpanID",
rawType: "otlpcommon.SpanID",
rawType: "data.SpanID",
defaultVal: "NewSpanID([8]byte{})",
testVal: "NewSpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1})",
}
Expand Down
Loading

0 comments on commit 28f9e43

Please sign in to comment.