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 v0.8.0 #3572

Merged
merged 7 commits into from
Jul 8, 2021
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
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ issues:
- text: "or a comment on this block"
linters:
- revive
# disabling to suppress deprecation warnings when updating OTLP to v0.8.0
# in support of breaking up the work into more manageable PRs
Comment on lines +137 to +138
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create an issue, or document this in #3534 that is left to deal with for later.

- path: pdata/metrics.go
linters:
- staticcheck
- path: pdata/metrics_test.go
linters:
- staticcheck

# The list of ids of default excludes to include or disable. By default it's empty.
# See the list of default excludes here https://golangci-lint.run/usage/configuration.
Expand Down
69 changes: 69 additions & 0 deletions cmd/pdatagen/internal/base_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ func (ms ${structName}) Set${fieldName}(v ${returnType}) {
(*ms.orig).${originFieldName} = v
}`

const accessorsPrimitiveAsDoubleTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return (*ms.orig).GetAsDouble()
}

// Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) Set${fieldName}(v ${returnType}) {
(*ms.orig).${originFieldName} = &${originFullName}_AsDouble{
AsDouble: v,
}
}`

const accessorsPrimitiveTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) {
ms := New${structName}()
assert.EqualValues(t, ${defaultVal}, ms.${fieldName}())
Expand Down Expand Up @@ -393,3 +405,60 @@ func (one oneofField) generateCopyToValue(sb *strings.Builder) {
}

var _ baseField = (*oneofField)(nil)

type primitiveAsDoubleField struct {
originFullName string
fieldName string
originFieldName string
returnType string
defaultVal string
testVal string
}

func (pf *primitiveAsDoubleField) generateAccessors(ms baseStruct, sb *strings.Builder) {
sb.WriteString(os.Expand(accessorsPrimitiveAsDoubleTemplate, func(name string) string {
switch name {
case "structName":
return ms.getName()
case "fieldName":
return pf.fieldName
case "lowerFieldName":
return strings.ToLower(pf.fieldName)
case "returnType":
return pf.returnType
case "originFieldName":
return pf.originFieldName
case "originFullName":
return pf.originFullName
default:
panic(name)
}
}))
}

func (pf *primitiveAsDoubleField) generateAccessorsTest(ms baseStruct, sb *strings.Builder) {
sb.WriteString(os.Expand(accessorsPrimitiveTestTemplate, func(name string) string {
switch name {
case "structName":
return ms.getName()
case "defaultVal":
return pf.defaultVal
case "fieldName":
return pf.fieldName
case "testValue":
return pf.testVal
default:
panic(name)
}
}))
}

func (pf *primitiveAsDoubleField) generateSetWithTestValue(sb *strings.Builder) {
sb.WriteString("\ttv.Set" + pf.fieldName + "(" + pf.testVal + ")")
}

func (pf *primitiveAsDoubleField) generateCopyToValue(sb *strings.Builder) {
sb.WriteString("\tdest.Set" + pf.fieldName + "(ms." + pf.fieldName + "())")
}

var _ baseField = (*primitiveField)(nil)
38 changes: 26 additions & 12 deletions cmd/pdatagen/internal/metrics_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var intGauge = &messageValueStruct{
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",
originFullName: "otlpmetrics.Gauge",
fields: []baseField{
&sliceField{
fieldName: "DataPoints",
Expand Down Expand Up @@ -171,7 +171,7 @@ var intSum = &messageValueStruct{
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",
originFullName: "otlpmetrics.Sum",
fields: []baseField{
aggregationTemporalityField,
isMonotonicField,
Expand Down Expand Up @@ -200,7 +200,7 @@ var intHistogram = &messageValueStruct{
var histogram = &messageValueStruct{
structName: "Histogram",
description: "// Histogram represents the type of a metric that is calculated by aggregating as a Histogram of all reported measurements over a time interval.",
originFullName: "otlpmetrics.DoubleHistogram",
originFullName: "otlpmetrics.Histogram",
fields: []baseField{
aggregationTemporalityField,
&sliceField{
Expand All @@ -214,7 +214,7 @@ var histogram = &messageValueStruct{
var summary = &messageValueStruct{
structName: "Summary",
description: "// Summary 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",
originFullName: "otlpmetrics.Summary",
fields: []baseField{
&sliceField{
fieldName: "DataPoints",
Expand Down Expand Up @@ -250,12 +250,19 @@ var doubleDataPointSlice = &sliceOfPtrs{
var doubleDataPoint = &messageValueStruct{
structName: "DoubleDataPoint",
description: "// DoubleDataPoint is a single data point in a timeseries that describes the time-varying value of a double metric.",
originFullName: "otlpmetrics.DoubleDataPoint",
originFullName: "otlpmetrics.NumberDataPoint",
fields: []baseField{
labelsField,
startTimeField,
timeField,
valueFloat64Field,
&primitiveAsDoubleField{
originFullName: "otlpmetrics.NumberDataPoint",
fieldName: "Value",
originFieldName: "Value",
returnType: "float64",
defaultVal: "float64(0.0)",
testVal: "float64(17.13)",
},
exemplarsField,
},
}
Expand Down Expand Up @@ -289,7 +296,7 @@ var histogramDataPointSlice = &sliceOfPtrs{
var histogramDataPoint = &messageValueStruct{
structName: "HistogramDataPoint",
description: "// HistogramDataPoint is a single data point in a timeseries that describes the time-varying values of a Histogram of values.",
originFullName: "otlpmetrics.DoubleHistogramDataPoint",
originFullName: "otlpmetrics.HistogramDataPoint",
fields: []baseField{
labelsField,
startTimeField,
Expand All @@ -310,7 +317,7 @@ var summaryDataPointSlice = &sliceOfPtrs{
var summaryDataPoint = &messageValueStruct{
structName: "SummaryDataPoint",
description: "// SummaryDataPoint is a single data point in a timeseries that describes the time-varying values of a Summary of double values.",
originFullName: "otlpmetrics.DoubleSummaryDataPoint",
originFullName: "otlpmetrics.SummaryDataPoint",
fields: []baseField{
labelsField,
startTimeField,
Expand All @@ -333,7 +340,7 @@ var quantileValuesSlice = &sliceOfPtrs{
var quantileValues = &messageValueStruct{
structName: "ValueAtQuantile",
description: "// ValueAtQuantile is a quantile value within a Summary data point.",
originFullName: "otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile",
originFullName: "otlpmetrics.SummaryDataPoint_ValueAtQuantile",
fields: []baseField{
quantileField,
valueFloat64Field,
Expand Down Expand Up @@ -363,7 +370,7 @@ var intExemplar = &messageValueStruct{
},
}

var exemplarSlice = &sliceOfValues{
var exemplarSlice = &sliceOfPtrs{
structName: "ExemplarSlice",
element: exemplar,
}
Expand All @@ -374,10 +381,17 @@ var exemplar = &messageValueStruct{
"// Exemplars also hold information about the environment when the measurement was recorded,\n" +
"// for example the span and trace ID of the active span when the exemplar was recorded.",

originFullName: "otlpmetrics.DoubleExemplar",
originFullName: "otlpmetrics.Exemplar",
fields: []baseField{
timeField,
valueFloat64Field,
&primitiveAsDoubleField{
originFullName: "otlpmetrics.Exemplar",
fieldName: "Value",
originFieldName: "Value",
returnType: "float64",
defaultVal: "float64(0.0)",
testVal: "float64(17.13)",
},
&sliceField{
fieldName: "FilteredLabels",
originFieldName: "FilteredLabels",
Expand Down
1 change: 1 addition & 0 deletions model/internal/data/protogen/common/v1/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions model/internal/data/protogen/logs/v1/logs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading