Skip to content

Commit

Permalink
Deprecate NumberDataPoint/Exemplar Val suffix methods (#6134)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan <[email protected]>

Signed-off-by: Bogdan <[email protected]>
  • Loading branch information
bogdandrutu authored Sep 23, 2022
1 parent d9a847e commit 44ce8e3
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 88 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
- Deprecate `pcommon.NewValueBytesEmpty` in favor of `pcommon.NewValueBytes` that now has the same signature. (#6105)
- Deprecate `pmetric.MetricDataType` and related constants in favor of `pmetric.MetricType`. (#6127)
- Deprecate `pmetric.Metric.DataType()` in favor of `pmetric.Metric.Type()`. (#6127)
- Deprecate `pmetric.NumberDataPoint.[Set]?[Int|Double]Val()` in favor of `pmetric.NumberDataPoint.[Set]?[Int|Double]Value()`. (#6134)
- Deprecate `pmetric.Exemplar.[Set]?[Int|Double]Val()` in favor of `pmetric.Exemplar.[Set]?[Int|Double]Value()`. (#6134)

### 💡 Enhancements 💡

Expand Down
4 changes: 2 additions & 2 deletions exporter/loggingexporter/internal/otlptext/databuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func (b *dataBuffer) logNumberDataPoints(ps pmetric.NumberDataPointSlice) {
b.logEntry("Timestamp: %s", p.Timestamp())
switch p.ValueType() {
case pmetric.NumberDataPointValueTypeInt:
b.logEntry("Value: %d", p.IntVal())
b.logEntry("Value: %d", p.IntValue())
case pmetric.NumberDataPointValueTypeDouble:
b.logEntry("Value: %f", p.DoubleVal())
b.logEntry("Value: %f", p.DoubleValue())
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions internal/testdata/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ func initGaugeIntMetric(im pmetric.Metric) {
initMetricAttributes1(idp0.Attributes())
idp0.SetStartTimestamp(metricStartTimestamp)
idp0.SetTimestamp(metricTimestamp)
idp0.SetIntVal(123)
idp0.SetIntValue(123)
idp1 := idps.AppendEmpty()
initMetricAttributes2(idp1.Attributes())
idp1.SetStartTimestamp(metricStartTimestamp)
idp1.SetTimestamp(metricTimestamp)
idp1.SetIntVal(456)
idp1.SetIntValue(456)
}

func initGaugeDoubleMetric(im pmetric.Metric) {
Expand All @@ -137,12 +137,12 @@ func initGaugeDoubleMetric(im pmetric.Metric) {
initMetricAttributes12(idp0.Attributes())
idp0.SetStartTimestamp(metricStartTimestamp)
idp0.SetTimestamp(metricTimestamp)
idp0.SetDoubleVal(1.23)
idp0.SetDoubleValue(1.23)
idp1 := idps.AppendEmpty()
initMetricAttributes13(idp1.Attributes())
idp1.SetStartTimestamp(metricStartTimestamp)
idp1.SetTimestamp(metricTimestamp)
idp1.SetDoubleVal(4.56)
idp1.SetDoubleValue(4.56)
}

func initSumIntMetric(im pmetric.Metric) {
Expand All @@ -153,12 +153,12 @@ func initSumIntMetric(im pmetric.Metric) {
initMetricAttributes1(idp0.Attributes())
idp0.SetStartTimestamp(metricStartTimestamp)
idp0.SetTimestamp(metricTimestamp)
idp0.SetIntVal(123)
idp0.SetIntValue(123)
idp1 := idps.AppendEmpty()
initMetricAttributes2(idp1.Attributes())
idp1.SetStartTimestamp(metricStartTimestamp)
idp1.SetTimestamp(metricTimestamp)
idp1.SetIntVal(456)
idp1.SetIntValue(456)
}

func initSumDoubleMetric(dm pmetric.Metric) {
Expand All @@ -169,13 +169,13 @@ func initSumDoubleMetric(dm pmetric.Metric) {
initMetricAttributes12(ddp0.Attributes())
ddp0.SetStartTimestamp(metricStartTimestamp)
ddp0.SetTimestamp(metricTimestamp)
ddp0.SetDoubleVal(1.23)
ddp0.SetDoubleValue(1.23)

ddp1 := ddps.AppendEmpty()
initMetricAttributes13(ddp1.Attributes())
ddp1.SetStartTimestamp(metricStartTimestamp)
ddp1.SetTimestamp(metricTimestamp)
ddp1.SetDoubleVal(4.56)
ddp1.SetDoubleValue(4.56)
}

func initHistogramMetric(hm pmetric.Metric) {
Expand All @@ -200,7 +200,7 @@ func initHistogramMetric(hm pmetric.Metric) {
hdp1.BucketCounts().FromRaw([]uint64{0, 1})
exemplar := hdp1.Exemplars().AppendEmpty()
exemplar.SetTimestamp(metricExemplarTimestamp)
exemplar.SetDoubleVal(15)
exemplar.SetDoubleValue(15)
initMetricExemplarAttributes(exemplar.FilteredAttributes())
hdp1.ExplicitBounds().FromRaw([]float64{1})
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func initExponentialHistogramMetric(hm pmetric.Metric) {

exemplar := hdp1.Exemplars().AppendEmpty()
exemplar.SetTimestamp(metricExemplarTimestamp)
exemplar.SetDoubleVal(15)
exemplar.SetDoubleValue(15)
initMetricExemplarAttributes(exemplar.FilteredAttributes())
}

Expand Down
40 changes: 23 additions & 17 deletions pdata/internal/cmd/pdatagen/internal/base_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,23 @@ func Test${structName}_CopyTo_${fieldName}(t *testing.T) {
const copyToValueOneOfMessageTemplate = ` case ${typeName}:
ms.${fieldName}().CopyTo(dest.SetEmpty${fieldName}())`

const accessorsOneOfPrimitiveTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
const accessorsOneOfPrimitiveTemplate = `// ${accessorFieldName} returns the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) ${accessorFieldName}() ${returnType} {
return ms.getOrig().Get${originFieldName}()
}
// Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) Set${fieldName}(v ${returnType}) {
// Set${accessorFieldName} replaces the ${lowerFieldName} associated with this ${structName}.
func (ms ${structName}) Set${accessorFieldName}(v ${returnType}) {
ms.getOrig().${originOneOfFieldName} = &${originStructType}{
${originFieldName}: v,
}
}`

const accessorsOneOfPrimitiveTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) {
const accessorsOneOfPrimitiveTestTemplate = `func Test${structName}_${accessorFieldName}(t *testing.T) {
ms := New${structName}()
assert.Equal(t, ${defaultVal}, ms.${fieldName}())
ms.Set${fieldName}(${testValue})
assert.Equal(t, ${testValue}, ms.${fieldName}())
assert.Equal(t, ${defaultVal}, ms.${accessorFieldName}())
ms.Set${accessorFieldName}(${testValue})
assert.Equal(t, ${testValue}, ms.${accessorFieldName}())
assert.Equal(t, ${typeName}, ms.${originOneOfTypeFuncName}())
}`

Expand Down Expand Up @@ -603,7 +603,6 @@ type oneOfValue interface {

type oneOfPrimitiveValue struct {
fieldName string
fieldType string
defaultVal string
testVal string
returnType string
Expand All @@ -615,8 +614,8 @@ func (opv *oneOfPrimitiveValue) generateAccessors(ms baseStruct, of *oneOfField,
switch name {
case "structName":
return ms.getName()
case "fieldName":
return opv.fieldName
case "accessorFieldName":
return opv.accessorFieldName(of)
case "lowerFieldName":
return strings.ToLower(opv.fieldName)
case "returnType":
Expand All @@ -643,33 +642,40 @@ func (opv *oneOfPrimitiveValue) generateTests(ms baseStruct, of *oneOfField, sb
return opv.defaultVal
case "packageName":
return ""
case "fieldName":
return opv.fieldName
case "accessorFieldName":
return opv.accessorFieldName(of)
case "testValue":
return opv.testVal
case "originOneOfTypeFuncName":
return of.typeFuncName()
case "typeName":
return of.typeName + opv.fieldType
return of.typeName + opv.fieldName
default:
panic(name)
}
}))
sb.WriteString("\n")
}

func (opv *oneOfPrimitiveValue) accessorFieldName(of *oneOfField) string {
if of.omitOriginFieldNameInNames {
return opv.fieldName
}
return opv.fieldName + of.originFieldName
}

func (opv *oneOfPrimitiveValue) generateSetWithTestValue(of *oneOfField, sb *strings.Builder) {
sb.WriteString("\ttv.orig." + of.originFieldName + " = &" + of.originTypePrefix + opv.originFieldName + "{" + opv.originFieldName + ":" + opv.testVal + "}")
}

func (opv *oneOfPrimitiveValue) generateCopyToValue(of *oneOfField, sb *strings.Builder) {
sb.WriteString("\tcase " + of.typeName + opv.fieldType + ":\n")
sb.WriteString("\tdest.Set" + opv.fieldName + "(ms." + opv.fieldName + "())\n")
sb.WriteString("\tcase " + of.typeName + opv.fieldName + ":\n")
sb.WriteString("\tdest.Set" + opv.accessorFieldName(of) + "(ms." + opv.accessorFieldName(of) + "())\n")
}

func (opv *oneOfPrimitiveValue) generateTypeSwitchCase(of *oneOfField, sb *strings.Builder) {
sb.WriteString("\tcase *" + of.originTypePrefix + opv.originFieldName + ":\n")
sb.WriteString("\t\treturn " + of.typeName + opv.fieldType + "\n")
sb.WriteString("\t\treturn " + of.typeName + opv.fieldName + "\n")
}

var _ oneOfValue = (*oneOfPrimitiveValue)(nil)
Expand Down
12 changes: 4 additions & 8 deletions pdata/internal/cmd/pdatagen/internal/metrics_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,14 @@ var numberDataPoint = &messageValueStruct{
testValueIdx: 0, // Double
values: []oneOfValue{
&oneOfPrimitiveValue{
fieldName: "DoubleVal",
fieldType: "Double",
fieldName: "Double",
originFieldName: "AsDouble",
returnType: "float64",
defaultVal: "float64(0.0)",
testVal: "float64(17.13)",
},
&oneOfPrimitiveValue{
fieldName: "IntVal",
fieldType: "Int",
fieldName: "Int",
originFieldName: "AsInt",
returnType: "int64",
defaultVal: "int64(0)",
Expand Down Expand Up @@ -464,20 +462,18 @@ var exemplar = &messageValueStruct{
testValueIdx: 1, // Int
values: []oneOfValue{
&oneOfPrimitiveValue{
fieldName: "DoubleVal",
fieldName: "Double",
originFieldName: "AsDouble",
returnType: "float64",
defaultVal: "float64(0.0)",
testVal: "float64(17.13)",
fieldType: "Double",
},
&oneOfPrimitiveValue{
fieldName: "IntVal",
fieldName: "Int",
originFieldName: "AsInt",
returnType: "int64",
defaultVal: "int64(0)",
testVal: "int64(17)",
fieldType: "Int",
},
},
},
Expand Down
40 changes: 20 additions & 20 deletions pdata/pmetric/generated_metrics.go

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

32 changes: 16 additions & 16 deletions pdata/pmetric/generated_metrics_test.go

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

Loading

0 comments on commit 44ce8e3

Please sign in to comment.