Replace MetricDataType with MetricType (#6127)
* Dreprecate old APIs, add new APIs without "Data" Updates https://github.com/open-telemetry/opentelemetry-collector/issues/6081 Signed-off-by: Bogdan <bogdandrutu@gmail.com> Signed-off-by: Bogdan <bogdandrutu@gmail.com>
This commit is contained in:
parent
a9f666f944
commit
937d1e6d25
|
|
@ -27,6 +27,8 @@
|
||||||
- Deprecate `pmetric.OptionalType`, unused enum type. (#6096)
|
- Deprecate `pmetric.OptionalType`, unused enum type. (#6096)
|
||||||
- Deprecate `ptrace.Span[Link]?.TraceStateStruct` in favor of `ptrace.Span[Link]?.TraceState` (#6085)
|
- Deprecate `ptrace.Span[Link]?.TraceStateStruct` in favor of `ptrace.Span[Link]?.TraceState` (#6085)
|
||||||
- Deprecate `pcommon.NewValueBytesEmpty` in favor of `pcommon.NewValueBytes` that now has the same signature. (#6105)
|
- 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)
|
||||||
|
|
||||||
### 💡 Enhancements 💡
|
### 💡 Enhancements 💡
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,29 +64,29 @@ func (b *dataBuffer) logMetricDescriptor(md pmetric.Metric) {
|
||||||
b.logEntry(" -> Name: %s", md.Name())
|
b.logEntry(" -> Name: %s", md.Name())
|
||||||
b.logEntry(" -> Description: %s", md.Description())
|
b.logEntry(" -> Description: %s", md.Description())
|
||||||
b.logEntry(" -> Unit: %s", md.Unit())
|
b.logEntry(" -> Unit: %s", md.Unit())
|
||||||
b.logEntry(" -> DataType: %s", md.DataType().String())
|
b.logEntry(" -> DataType: %s", md.Type().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *dataBuffer) logMetricDataPoints(m pmetric.Metric) {
|
func (b *dataBuffer) logMetricDataPoints(m pmetric.Metric) {
|
||||||
switch m.DataType() {
|
switch m.Type() {
|
||||||
case pmetric.MetricDataTypeNone:
|
case pmetric.MetricTypeNone:
|
||||||
return
|
return
|
||||||
case pmetric.MetricDataTypeGauge:
|
case pmetric.MetricTypeGauge:
|
||||||
b.logNumberDataPoints(m.Gauge().DataPoints())
|
b.logNumberDataPoints(m.Gauge().DataPoints())
|
||||||
case pmetric.MetricDataTypeSum:
|
case pmetric.MetricTypeSum:
|
||||||
data := m.Sum()
|
data := m.Sum()
|
||||||
b.logEntry(" -> IsMonotonic: %t", data.IsMonotonic())
|
b.logEntry(" -> IsMonotonic: %t", data.IsMonotonic())
|
||||||
b.logEntry(" -> AggregationTemporality: %s", data.AggregationTemporality().String())
|
b.logEntry(" -> AggregationTemporality: %s", data.AggregationTemporality().String())
|
||||||
b.logNumberDataPoints(data.DataPoints())
|
b.logNumberDataPoints(data.DataPoints())
|
||||||
case pmetric.MetricDataTypeHistogram:
|
case pmetric.MetricTypeHistogram:
|
||||||
data := m.Histogram()
|
data := m.Histogram()
|
||||||
b.logEntry(" -> AggregationTemporality: %s", data.AggregationTemporality().String())
|
b.logEntry(" -> AggregationTemporality: %s", data.AggregationTemporality().String())
|
||||||
b.logHistogramDataPoints(data.DataPoints())
|
b.logHistogramDataPoints(data.DataPoints())
|
||||||
case pmetric.MetricDataTypeExponentialHistogram:
|
case pmetric.MetricTypeExponentialHistogram:
|
||||||
data := m.ExponentialHistogram()
|
data := m.ExponentialHistogram()
|
||||||
b.logEntry(" -> AggregationTemporality: %s", data.AggregationTemporality().String())
|
b.logEntry(" -> AggregationTemporality: %s", data.AggregationTemporality().String())
|
||||||
b.logExponentialHistogramDataPoints(data.DataPoints())
|
b.logExponentialHistogramDataPoints(data.DataPoints())
|
||||||
case pmetric.MetricDataTypeSummary:
|
case pmetric.MetricTypeSummary:
|
||||||
data := m.Summary()
|
data := m.Summary()
|
||||||
b.logDoubleSummaryDataPoints(data.DataPoints())
|
b.logDoubleSummaryDataPoints(data.DataPoints())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,29 +49,29 @@ func GenerateMetricsAllTypesEmpty() pmetric.Metrics {
|
||||||
ms := md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics()
|
ms := md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics()
|
||||||
|
|
||||||
doubleGauge := ms.AppendEmpty()
|
doubleGauge := ms.AppendEmpty()
|
||||||
initMetric(doubleGauge, TestGaugeDoubleMetricName, pmetric.MetricDataTypeGauge)
|
initMetric(doubleGauge, TestGaugeDoubleMetricName, pmetric.MetricTypeGauge)
|
||||||
doubleGauge.Gauge().DataPoints().AppendEmpty()
|
doubleGauge.Gauge().DataPoints().AppendEmpty()
|
||||||
intGauge := ms.AppendEmpty()
|
intGauge := ms.AppendEmpty()
|
||||||
initMetric(intGauge, TestGaugeIntMetricName, pmetric.MetricDataTypeGauge)
|
initMetric(intGauge, TestGaugeIntMetricName, pmetric.MetricTypeGauge)
|
||||||
intGauge.Gauge().DataPoints().AppendEmpty()
|
intGauge.Gauge().DataPoints().AppendEmpty()
|
||||||
doubleSum := ms.AppendEmpty()
|
doubleSum := ms.AppendEmpty()
|
||||||
initMetric(doubleSum, TestSumDoubleMetricName, pmetric.MetricDataTypeSum)
|
initMetric(doubleSum, TestSumDoubleMetricName, pmetric.MetricTypeSum)
|
||||||
doubleSum.Sum().DataPoints().AppendEmpty()
|
doubleSum.Sum().DataPoints().AppendEmpty()
|
||||||
intSum := ms.AppendEmpty()
|
intSum := ms.AppendEmpty()
|
||||||
initMetric(intSum, TestSumIntMetricName, pmetric.MetricDataTypeSum)
|
initMetric(intSum, TestSumIntMetricName, pmetric.MetricTypeSum)
|
||||||
intSum.Sum().DataPoints().AppendEmpty()
|
intSum.Sum().DataPoints().AppendEmpty()
|
||||||
histogram := ms.AppendEmpty()
|
histogram := ms.AppendEmpty()
|
||||||
initMetric(histogram, TestHistogramMetricName, pmetric.MetricDataTypeHistogram)
|
initMetric(histogram, TestHistogramMetricName, pmetric.MetricTypeHistogram)
|
||||||
histogram.Histogram().DataPoints().AppendEmpty()
|
histogram.Histogram().DataPoints().AppendEmpty()
|
||||||
summary := ms.AppendEmpty()
|
summary := ms.AppendEmpty()
|
||||||
initMetric(summary, TestSummaryMetricName, pmetric.MetricDataTypeSummary)
|
initMetric(summary, TestSummaryMetricName, pmetric.MetricTypeSummary)
|
||||||
summary.Summary().DataPoints().AppendEmpty()
|
summary.Summary().DataPoints().AppendEmpty()
|
||||||
return md
|
return md
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateMetricsMetricTypeInvalid() pmetric.Metrics {
|
func GenerateMetricsMetricTypeInvalid() pmetric.Metrics {
|
||||||
md := generateMetricsOneEmptyInstrumentationScope()
|
md := generateMetricsOneEmptyInstrumentationScope()
|
||||||
initMetric(md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().AppendEmpty(), TestSumIntMetricName, pmetric.MetricDataTypeNone)
|
initMetric(md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().AppendEmpty(), TestSumIntMetricName, pmetric.MetricTypeNone)
|
||||||
return md
|
return md
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ func GenerateMetrics(count int) pmetric.Metrics {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initGaugeIntMetric(im pmetric.Metric) {
|
func initGaugeIntMetric(im pmetric.Metric) {
|
||||||
initMetric(im, TestGaugeIntMetricName, pmetric.MetricDataTypeGauge)
|
initMetric(im, TestGaugeIntMetricName, pmetric.MetricTypeGauge)
|
||||||
|
|
||||||
idps := im.Gauge().DataPoints()
|
idps := im.Gauge().DataPoints()
|
||||||
idp0 := idps.AppendEmpty()
|
idp0 := idps.AppendEmpty()
|
||||||
|
|
@ -130,7 +130,7 @@ func initGaugeIntMetric(im pmetric.Metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initGaugeDoubleMetric(im pmetric.Metric) {
|
func initGaugeDoubleMetric(im pmetric.Metric) {
|
||||||
initMetric(im, TestGaugeDoubleMetricName, pmetric.MetricDataTypeGauge)
|
initMetric(im, TestGaugeDoubleMetricName, pmetric.MetricTypeGauge)
|
||||||
|
|
||||||
idps := im.Gauge().DataPoints()
|
idps := im.Gauge().DataPoints()
|
||||||
idp0 := idps.AppendEmpty()
|
idp0 := idps.AppendEmpty()
|
||||||
|
|
@ -146,7 +146,7 @@ func initGaugeDoubleMetric(im pmetric.Metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initSumIntMetric(im pmetric.Metric) {
|
func initSumIntMetric(im pmetric.Metric) {
|
||||||
initMetric(im, TestSumIntMetricName, pmetric.MetricDataTypeSum)
|
initMetric(im, TestSumIntMetricName, pmetric.MetricTypeSum)
|
||||||
|
|
||||||
idps := im.Sum().DataPoints()
|
idps := im.Sum().DataPoints()
|
||||||
idp0 := idps.AppendEmpty()
|
idp0 := idps.AppendEmpty()
|
||||||
|
|
@ -162,7 +162,7 @@ func initSumIntMetric(im pmetric.Metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initSumDoubleMetric(dm pmetric.Metric) {
|
func initSumDoubleMetric(dm pmetric.Metric) {
|
||||||
initMetric(dm, TestSumDoubleMetricName, pmetric.MetricDataTypeSum)
|
initMetric(dm, TestSumDoubleMetricName, pmetric.MetricTypeSum)
|
||||||
|
|
||||||
ddps := dm.Sum().DataPoints()
|
ddps := dm.Sum().DataPoints()
|
||||||
ddp0 := ddps.AppendEmpty()
|
ddp0 := ddps.AppendEmpty()
|
||||||
|
|
@ -179,7 +179,7 @@ func initSumDoubleMetric(dm pmetric.Metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initHistogramMetric(hm pmetric.Metric) {
|
func initHistogramMetric(hm pmetric.Metric) {
|
||||||
initMetric(hm, TestHistogramMetricName, pmetric.MetricDataTypeHistogram)
|
initMetric(hm, TestHistogramMetricName, pmetric.MetricTypeHistogram)
|
||||||
|
|
||||||
hdps := hm.Histogram().DataPoints()
|
hdps := hm.Histogram().DataPoints()
|
||||||
hdp0 := hdps.AppendEmpty()
|
hdp0 := hdps.AppendEmpty()
|
||||||
|
|
@ -206,7 +206,7 @@ func initHistogramMetric(hm pmetric.Metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initExponentialHistogramMetric(hm pmetric.Metric) {
|
func initExponentialHistogramMetric(hm pmetric.Metric) {
|
||||||
initMetric(hm, TestExponentialHistogramMetricName, pmetric.MetricDataTypeExponentialHistogram)
|
initMetric(hm, TestExponentialHistogramMetricName, pmetric.MetricTypeExponentialHistogram)
|
||||||
|
|
||||||
hdps := hm.ExponentialHistogram().DataPoints()
|
hdps := hm.ExponentialHistogram().DataPoints()
|
||||||
hdp0 := hdps.AppendEmpty()
|
hdp0 := hdps.AppendEmpty()
|
||||||
|
|
@ -259,7 +259,7 @@ func initExponentialHistogramMetric(hm pmetric.Metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initSummaryMetric(sm pmetric.Metric) {
|
func initSummaryMetric(sm pmetric.Metric) {
|
||||||
initMetric(sm, TestSummaryMetricName, pmetric.MetricDataTypeSummary)
|
initMetric(sm, TestSummaryMetricName, pmetric.MetricTypeSummary)
|
||||||
|
|
||||||
sdps := sm.Summary().DataPoints()
|
sdps := sm.Summary().DataPoints()
|
||||||
sdp0 := sdps.AppendEmpty()
|
sdp0 := sdps.AppendEmpty()
|
||||||
|
|
@ -281,24 +281,24 @@ func initSummaryMetric(sm pmetric.Metric) {
|
||||||
quantile.SetValue(15)
|
quantile.SetValue(15)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initMetric(m pmetric.Metric, name string, ty pmetric.MetricDataType) {
|
func initMetric(m pmetric.Metric, name string, ty pmetric.MetricType) {
|
||||||
m.SetName(name)
|
m.SetName(name)
|
||||||
m.SetDescription("")
|
m.SetDescription("")
|
||||||
m.SetUnit("1")
|
m.SetUnit("1")
|
||||||
switch ty {
|
switch ty {
|
||||||
case pmetric.MetricDataTypeGauge:
|
case pmetric.MetricTypeGauge:
|
||||||
m.SetEmptyGauge()
|
m.SetEmptyGauge()
|
||||||
case pmetric.MetricDataTypeSum:
|
case pmetric.MetricTypeSum:
|
||||||
sum := m.SetEmptySum()
|
sum := m.SetEmptySum()
|
||||||
sum.SetIsMonotonic(true)
|
sum.SetIsMonotonic(true)
|
||||||
sum.SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative)
|
sum.SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative)
|
||||||
case pmetric.MetricDataTypeHistogram:
|
case pmetric.MetricTypeHistogram:
|
||||||
histo := m.SetEmptyHistogram()
|
histo := m.SetEmptyHistogram()
|
||||||
histo.SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative)
|
histo.SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative)
|
||||||
case pmetric.MetricDataTypeExponentialHistogram:
|
case pmetric.MetricTypeExponentialHistogram:
|
||||||
histo := m.SetEmptyExponentialHistogram()
|
histo := m.SetEmptyExponentialHistogram()
|
||||||
histo.SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta)
|
histo.SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta)
|
||||||
case pmetric.MetricDataTypeSummary:
|
case pmetric.MetricTypeSummary:
|
||||||
m.SetEmptySummary()
|
m.SetEmptySummary()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,20 +57,20 @@ func (ms ${structName}) ${fieldName}() ${packageName}${returnType} {
|
||||||
return ${packageName}${returnType}(internal.New${returnType}(&ms.getOrig().${originFieldName}))
|
return ${packageName}${returnType}(internal.New${returnType}(&ms.getOrig().${originFieldName}))
|
||||||
}`
|
}`
|
||||||
|
|
||||||
const oneOfTypeAccessorHeaderTemplate = `// ${originFieldName}Type returns the type of the ${lowerOriginFieldName} for this ${structName}.
|
const oneOfTypeAccessorHeaderTemplate = `// ${typeFuncName} returns the type of the ${lowerOriginFieldName} for this ${structName}.
|
||||||
// Calling this function on zero-initialized ${structName} will cause a panic.
|
// Calling this function on zero-initialized ${structName} will cause a panic.
|
||||||
func (ms ${structName}) ${originFieldName}Type() ${typeName} {
|
func (ms ${structName}) ${typeFuncName}() ${typeName} {
|
||||||
switch ms.getOrig().${originFieldName}.(type) {`
|
switch ms.getOrig().${originFieldName}.(type) {`
|
||||||
|
|
||||||
const oneOfTypeAccessorHeaderTestTemplate = `func Test${structName}_${originFieldName}Type(t *testing.T) {
|
const oneOfTypeAccessorHeaderTestTemplate = `func Test${structName}_${typeFuncName}(t *testing.T) {
|
||||||
tv := New${structName}()
|
tv := New${structName}()
|
||||||
assert.Equal(t, ${typeName}None, tv.${originFieldName}Type())
|
assert.Equal(t, ${typeName}None, tv.${typeFuncName}())
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const accessorsOneOfMessageTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
|
const accessorsOneOfMessageTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}.
|
||||||
//
|
//
|
||||||
// Calling this function when ${originOneOfFieldName}Type() != ${typeName} returns an invalid
|
// Calling this function when ${originOneOfTypeFuncName}() != ${typeName} returns an invalid
|
||||||
// zero-initialized instance of ${returnType}. Note that using such ${returnType} instance can cause panic.
|
// zero-initialized instance of ${returnType}. Note that using such ${returnType} instance can cause panic.
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized ${structName} will cause a panic.
|
// Calling this function on zero-initialized ${structName} will cause a panic.
|
||||||
|
|
@ -84,7 +84,7 @@ func (ms ${structName}) ${fieldName}() ${returnType} {
|
||||||
|
|
||||||
// SetEmpty${fieldName} sets an empty ${lowerFieldName} to this ${structName}.
|
// SetEmpty${fieldName} sets an empty ${lowerFieldName} to this ${structName}.
|
||||||
//
|
//
|
||||||
// After this, ${originOneOfFieldName}Type() function will return ${typeName}".
|
// After this, ${originOneOfTypeFuncName}() function will return ${typeName}".
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized ${structName} will cause a panic.
|
// Calling this function on zero-initialized ${structName} will cause a panic.
|
||||||
func (ms ${structName}) SetEmpty${fieldName}() ${returnType} {
|
func (ms ${structName}) SetEmpty${fieldName}() ${returnType} {
|
||||||
|
|
@ -96,7 +96,7 @@ func (ms ${structName}) SetEmpty${fieldName}() ${returnType} {
|
||||||
const accessorsOneOfMessageTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) {
|
const accessorsOneOfMessageTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) {
|
||||||
ms := New${structName}()
|
ms := New${structName}()
|
||||||
internal.FillTest${returnType}(internal.${returnType}(ms.SetEmpty${fieldName}()))
|
internal.FillTest${returnType}(internal.${returnType}(ms.SetEmpty${fieldName}()))
|
||||||
assert.Equal(t, ${typeName}, ms.${originOneOfFieldName}Type())
|
assert.Equal(t, ${typeName}, ms.${originOneOfTypeFuncName}())
|
||||||
assert.Equal(t, ${returnType}(internal.GenerateTest${returnType}()), ms.${fieldName}())
|
assert.Equal(t, ${returnType}(internal.GenerateTest${returnType}()), ms.${fieldName}())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +128,7 @@ const accessorsOneOfPrimitiveTestTemplate = `func Test${structName}_${fieldName}
|
||||||
assert.Equal(t, ${defaultVal}, ms.${fieldName}())
|
assert.Equal(t, ${defaultVal}, ms.${fieldName}())
|
||||||
ms.Set${fieldName}(${testValue})
|
ms.Set${fieldName}(${testValue})
|
||||||
assert.Equal(t, ${testValue}, ms.${fieldName}())
|
assert.Equal(t, ${testValue}, ms.${fieldName}())
|
||||||
assert.Equal(t, ${typeName}, ms.${originOneOfFieldName}Type())
|
assert.Equal(t, ${typeName}, ms.${originOneOfTypeFuncName}())
|
||||||
}`
|
}`
|
||||||
|
|
||||||
const accessorsPrimitiveTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) {
|
const accessorsPrimitiveTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) {
|
||||||
|
|
@ -508,11 +508,12 @@ func (psf *primitiveSliceField) generateCopyToValue(ms baseStruct, sb *strings.B
|
||||||
var _ baseField = (*primitiveSliceField)(nil)
|
var _ baseField = (*primitiveSliceField)(nil)
|
||||||
|
|
||||||
type oneOfField struct {
|
type oneOfField struct {
|
||||||
originTypePrefix string
|
originTypePrefix string
|
||||||
originFieldName string
|
originFieldName string
|
||||||
typeName string
|
typeName string
|
||||||
testValueIdx int
|
testValueIdx int
|
||||||
values []oneOfValue
|
values []oneOfValue
|
||||||
|
omitOriginFieldNameInNames bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (of *oneOfField) generateAccessors(ms baseStruct, sb *strings.Builder) {
|
func (of *oneOfField) generateAccessors(ms baseStruct, sb *strings.Builder) {
|
||||||
|
|
@ -529,6 +530,8 @@ func (of *oneOfField) generateTypeAccessors(ms baseStruct, sb *strings.Builder)
|
||||||
switch name {
|
switch name {
|
||||||
case "lowerOriginFieldName":
|
case "lowerOriginFieldName":
|
||||||
return strings.ToLower(of.originFieldName)
|
return strings.ToLower(of.originFieldName)
|
||||||
|
case "typeFuncName":
|
||||||
|
return of.typeFuncName()
|
||||||
case "originFieldName":
|
case "originFieldName":
|
||||||
return of.originFieldName
|
return of.originFieldName
|
||||||
case "structName":
|
case "structName":
|
||||||
|
|
@ -548,13 +551,21 @@ func (of *oneOfField) generateTypeAccessors(ms baseStruct, sb *strings.Builder)
|
||||||
sb.WriteString("}\n")
|
sb.WriteString("}\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (of *oneOfField) typeFuncName() string {
|
||||||
|
const typeSuffix = "Type"
|
||||||
|
if of.omitOriginFieldNameInNames {
|
||||||
|
return typeSuffix
|
||||||
|
}
|
||||||
|
return of.originFieldName + typeSuffix
|
||||||
|
}
|
||||||
|
|
||||||
func (of *oneOfField) generateAccessorsTest(ms baseStruct, sb *strings.Builder) {
|
func (of *oneOfField) generateAccessorsTest(ms baseStruct, sb *strings.Builder) {
|
||||||
sb.WriteString(os.Expand(oneOfTypeAccessorHeaderTestTemplate, func(name string) string {
|
sb.WriteString(os.Expand(oneOfTypeAccessorHeaderTestTemplate, func(name string) string {
|
||||||
switch name {
|
switch name {
|
||||||
case "structName":
|
case "structName":
|
||||||
return ms.getName()
|
return ms.getName()
|
||||||
case "originFieldName":
|
case "typeFuncName":
|
||||||
return of.originFieldName
|
return of.typeFuncName()
|
||||||
case "typeName":
|
case "typeName":
|
||||||
return of.typeName
|
return of.typeName
|
||||||
default:
|
default:
|
||||||
|
|
@ -573,7 +584,7 @@ func (of *oneOfField) generateSetWithTestValue(sb *strings.Builder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (of *oneOfField) generateCopyToValue(_ baseStruct, sb *strings.Builder) {
|
func (of *oneOfField) generateCopyToValue(_ baseStruct, sb *strings.Builder) {
|
||||||
sb.WriteString("\tswitch ms." + of.originFieldName + "Type() {\n")
|
sb.WriteString("\tswitch ms." + of.typeFuncName() + "() {\n")
|
||||||
for _, v := range of.values {
|
for _, v := range of.values {
|
||||||
v.generateCopyToValue(of, sb)
|
v.generateCopyToValue(of, sb)
|
||||||
}
|
}
|
||||||
|
|
@ -583,7 +594,6 @@ func (of *oneOfField) generateCopyToValue(_ baseStruct, sb *strings.Builder) {
|
||||||
var _ baseField = (*oneOfField)(nil)
|
var _ baseField = (*oneOfField)(nil)
|
||||||
|
|
||||||
type oneOfValue interface {
|
type oneOfValue interface {
|
||||||
getFieldType() string
|
|
||||||
generateAccessors(ms baseStruct, of *oneOfField, sb *strings.Builder)
|
generateAccessors(ms baseStruct, of *oneOfField, sb *strings.Builder)
|
||||||
generateTests(ms baseStruct, of *oneOfField, sb *strings.Builder)
|
generateTests(ms baseStruct, of *oneOfField, sb *strings.Builder)
|
||||||
generateSetWithTestValue(of *oneOfField, sb *strings.Builder)
|
generateSetWithTestValue(of *oneOfField, sb *strings.Builder)
|
||||||
|
|
@ -600,10 +610,6 @@ type oneOfPrimitiveValue struct {
|
||||||
originFieldName string
|
originFieldName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opv *oneOfPrimitiveValue) getFieldType() string {
|
|
||||||
return opv.fieldType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (opv *oneOfPrimitiveValue) generateAccessors(ms baseStruct, of *oneOfField, sb *strings.Builder) {
|
func (opv *oneOfPrimitiveValue) generateAccessors(ms baseStruct, of *oneOfField, sb *strings.Builder) {
|
||||||
sb.WriteString(os.Expand(accessorsOneOfPrimitiveTemplate, func(name string) string {
|
sb.WriteString(os.Expand(accessorsOneOfPrimitiveTemplate, func(name string) string {
|
||||||
switch name {
|
switch name {
|
||||||
|
|
@ -641,8 +647,8 @@ func (opv *oneOfPrimitiveValue) generateTests(ms baseStruct, of *oneOfField, sb
|
||||||
return opv.fieldName
|
return opv.fieldName
|
||||||
case "testValue":
|
case "testValue":
|
||||||
return opv.testVal
|
return opv.testVal
|
||||||
case "originOneOfFieldName":
|
case "originOneOfTypeFuncName":
|
||||||
return of.originFieldName
|
return of.typeFuncName()
|
||||||
case "typeName":
|
case "typeName":
|
||||||
return of.typeName + opv.fieldType
|
return of.typeName + opv.fieldType
|
||||||
default:
|
default:
|
||||||
|
|
@ -675,10 +681,6 @@ type oneOfMessageValue struct {
|
||||||
returnMessage *messageValueStruct
|
returnMessage *messageValueStruct
|
||||||
}
|
}
|
||||||
|
|
||||||
func (omv *oneOfMessageValue) getFieldType() string {
|
|
||||||
return omv.fieldName
|
|
||||||
}
|
|
||||||
|
|
||||||
func (omv *oneOfMessageValue) generateAccessors(ms baseStruct, of *oneOfField, sb *strings.Builder) {
|
func (omv *oneOfMessageValue) generateAccessors(ms baseStruct, of *oneOfField, sb *strings.Builder) {
|
||||||
sb.WriteString(os.Expand(accessorsOneOfMessageTemplate, func(name string) string {
|
sb.WriteString(os.Expand(accessorsOneOfMessageTemplate, func(name string) string {
|
||||||
switch name {
|
switch name {
|
||||||
|
|
@ -688,6 +690,8 @@ func (omv *oneOfMessageValue) generateAccessors(ms baseStruct, of *oneOfField, s
|
||||||
return strings.ToLower(omv.fieldName)
|
return strings.ToLower(omv.fieldName)
|
||||||
case "originFieldName":
|
case "originFieldName":
|
||||||
return omv.originFieldName
|
return omv.originFieldName
|
||||||
|
case "originOneOfTypeFuncName":
|
||||||
|
return of.typeFuncName()
|
||||||
case "originOneOfFieldName":
|
case "originOneOfFieldName":
|
||||||
return of.originFieldName
|
return of.originFieldName
|
||||||
case "originFieldPackageName":
|
case "originFieldPackageName":
|
||||||
|
|
@ -716,8 +720,8 @@ func (omv *oneOfMessageValue) generateTests(ms baseStruct, of *oneOfField, sb *s
|
||||||
return omv.fieldName
|
return omv.fieldName
|
||||||
case "returnType":
|
case "returnType":
|
||||||
return omv.returnMessage.structName
|
return omv.returnMessage.structName
|
||||||
case "originOneOfFieldName":
|
case "originOneOfTypeFuncName":
|
||||||
return of.originFieldName
|
return of.typeFuncName()
|
||||||
case "typeName":
|
case "typeName":
|
||||||
return of.typeName + omv.returnMessage.structName
|
return of.typeName + omv.returnMessage.structName
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -127,10 +127,11 @@ var metric = &messageValueStruct{
|
||||||
testVal: `"1"`,
|
testVal: `"1"`,
|
||||||
},
|
},
|
||||||
&oneOfField{
|
&oneOfField{
|
||||||
typeName: "MetricDataType",
|
typeName: "MetricType",
|
||||||
originFieldName: "Data",
|
originFieldName: "Data",
|
||||||
originTypePrefix: "otlpmetrics.Metric_",
|
originTypePrefix: "otlpmetrics.Metric_",
|
||||||
testValueIdx: 1, // Sum
|
testValueIdx: 1, // Sum
|
||||||
|
omitOriginFieldNameInNames: true,
|
||||||
values: []oneOfValue{
|
values: []oneOfValue{
|
||||||
&oneOfMessageValue{
|
&oneOfMessageValue{
|
||||||
fieldName: "Gauge",
|
fieldName: "Gauge",
|
||||||
|
|
|
||||||
|
|
@ -630,27 +630,27 @@ func (ms Metric) SetUnit(v string) {
|
||||||
ms.getOrig().Unit = v
|
ms.getOrig().Unit = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// DataType returns the type of the data for this Metric.
|
// Type returns the type of the data for this Metric.
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
func (ms Metric) DataType() MetricDataType {
|
func (ms Metric) Type() MetricType {
|
||||||
switch ms.getOrig().Data.(type) {
|
switch ms.getOrig().Data.(type) {
|
||||||
case *otlpmetrics.Metric_Gauge:
|
case *otlpmetrics.Metric_Gauge:
|
||||||
return MetricDataTypeGauge
|
return MetricTypeGauge
|
||||||
case *otlpmetrics.Metric_Sum:
|
case *otlpmetrics.Metric_Sum:
|
||||||
return MetricDataTypeSum
|
return MetricTypeSum
|
||||||
case *otlpmetrics.Metric_Histogram:
|
case *otlpmetrics.Metric_Histogram:
|
||||||
return MetricDataTypeHistogram
|
return MetricTypeHistogram
|
||||||
case *otlpmetrics.Metric_ExponentialHistogram:
|
case *otlpmetrics.Metric_ExponentialHistogram:
|
||||||
return MetricDataTypeExponentialHistogram
|
return MetricTypeExponentialHistogram
|
||||||
case *otlpmetrics.Metric_Summary:
|
case *otlpmetrics.Metric_Summary:
|
||||||
return MetricDataTypeSummary
|
return MetricTypeSummary
|
||||||
}
|
}
|
||||||
return MetricDataTypeNone
|
return MetricTypeNone
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gauge returns the gauge associated with this Metric.
|
// Gauge returns the gauge associated with this Metric.
|
||||||
//
|
//
|
||||||
// Calling this function when DataType() != MetricDataTypeGauge returns an invalid
|
// Calling this function when Type() != MetricTypeGauge returns an invalid
|
||||||
// zero-initialized instance of Gauge. Note that using such Gauge instance can cause panic.
|
// zero-initialized instance of Gauge. Note that using such Gauge instance can cause panic.
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
|
|
@ -664,7 +664,7 @@ func (ms Metric) Gauge() Gauge {
|
||||||
|
|
||||||
// SetEmptyGauge sets an empty gauge to this Metric.
|
// SetEmptyGauge sets an empty gauge to this Metric.
|
||||||
//
|
//
|
||||||
// After this, DataType() function will return MetricDataTypeGauge".
|
// After this, Type() function will return MetricTypeGauge".
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
func (ms Metric) SetEmptyGauge() Gauge {
|
func (ms Metric) SetEmptyGauge() Gauge {
|
||||||
|
|
@ -675,7 +675,7 @@ func (ms Metric) SetEmptyGauge() Gauge {
|
||||||
|
|
||||||
// Sum returns the sum associated with this Metric.
|
// Sum returns the sum associated with this Metric.
|
||||||
//
|
//
|
||||||
// Calling this function when DataType() != MetricDataTypeSum returns an invalid
|
// Calling this function when Type() != MetricTypeSum returns an invalid
|
||||||
// zero-initialized instance of Sum. Note that using such Sum instance can cause panic.
|
// zero-initialized instance of Sum. Note that using such Sum instance can cause panic.
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
|
|
@ -689,7 +689,7 @@ func (ms Metric) Sum() Sum {
|
||||||
|
|
||||||
// SetEmptySum sets an empty sum to this Metric.
|
// SetEmptySum sets an empty sum to this Metric.
|
||||||
//
|
//
|
||||||
// After this, DataType() function will return MetricDataTypeSum".
|
// After this, Type() function will return MetricTypeSum".
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
func (ms Metric) SetEmptySum() Sum {
|
func (ms Metric) SetEmptySum() Sum {
|
||||||
|
|
@ -700,7 +700,7 @@ func (ms Metric) SetEmptySum() Sum {
|
||||||
|
|
||||||
// Histogram returns the histogram associated with this Metric.
|
// Histogram returns the histogram associated with this Metric.
|
||||||
//
|
//
|
||||||
// Calling this function when DataType() != MetricDataTypeHistogram returns an invalid
|
// Calling this function when Type() != MetricTypeHistogram returns an invalid
|
||||||
// zero-initialized instance of Histogram. Note that using such Histogram instance can cause panic.
|
// zero-initialized instance of Histogram. Note that using such Histogram instance can cause panic.
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
|
|
@ -714,7 +714,7 @@ func (ms Metric) Histogram() Histogram {
|
||||||
|
|
||||||
// SetEmptyHistogram sets an empty histogram to this Metric.
|
// SetEmptyHistogram sets an empty histogram to this Metric.
|
||||||
//
|
//
|
||||||
// After this, DataType() function will return MetricDataTypeHistogram".
|
// After this, Type() function will return MetricTypeHistogram".
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
func (ms Metric) SetEmptyHistogram() Histogram {
|
func (ms Metric) SetEmptyHistogram() Histogram {
|
||||||
|
|
@ -725,7 +725,7 @@ func (ms Metric) SetEmptyHistogram() Histogram {
|
||||||
|
|
||||||
// ExponentialHistogram returns the exponentialhistogram associated with this Metric.
|
// ExponentialHistogram returns the exponentialhistogram associated with this Metric.
|
||||||
//
|
//
|
||||||
// Calling this function when DataType() != MetricDataTypeExponentialHistogram returns an invalid
|
// Calling this function when Type() != MetricTypeExponentialHistogram returns an invalid
|
||||||
// zero-initialized instance of ExponentialHistogram. Note that using such ExponentialHistogram instance can cause panic.
|
// zero-initialized instance of ExponentialHistogram. Note that using such ExponentialHistogram instance can cause panic.
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
|
|
@ -739,7 +739,7 @@ func (ms Metric) ExponentialHistogram() ExponentialHistogram {
|
||||||
|
|
||||||
// SetEmptyExponentialHistogram sets an empty exponentialhistogram to this Metric.
|
// SetEmptyExponentialHistogram sets an empty exponentialhistogram to this Metric.
|
||||||
//
|
//
|
||||||
// After this, DataType() function will return MetricDataTypeExponentialHistogram".
|
// After this, Type() function will return MetricTypeExponentialHistogram".
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram {
|
func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram {
|
||||||
|
|
@ -750,7 +750,7 @@ func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram {
|
||||||
|
|
||||||
// Summary returns the summary associated with this Metric.
|
// Summary returns the summary associated with this Metric.
|
||||||
//
|
//
|
||||||
// Calling this function when DataType() != MetricDataTypeSummary returns an invalid
|
// Calling this function when Type() != MetricTypeSummary returns an invalid
|
||||||
// zero-initialized instance of Summary. Note that using such Summary instance can cause panic.
|
// zero-initialized instance of Summary. Note that using such Summary instance can cause panic.
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
|
|
@ -764,7 +764,7 @@ func (ms Metric) Summary() Summary {
|
||||||
|
|
||||||
// SetEmptySummary sets an empty summary to this Metric.
|
// SetEmptySummary sets an empty summary to this Metric.
|
||||||
//
|
//
|
||||||
// After this, DataType() function will return MetricDataTypeSummary".
|
// After this, Type() function will return MetricTypeSummary".
|
||||||
//
|
//
|
||||||
// Calling this function on zero-initialized Metric will cause a panic.
|
// Calling this function on zero-initialized Metric will cause a panic.
|
||||||
func (ms Metric) SetEmptySummary() Summary {
|
func (ms Metric) SetEmptySummary() Summary {
|
||||||
|
|
@ -778,16 +778,16 @@ func (ms Metric) CopyTo(dest Metric) {
|
||||||
dest.SetName(ms.Name())
|
dest.SetName(ms.Name())
|
||||||
dest.SetDescription(ms.Description())
|
dest.SetDescription(ms.Description())
|
||||||
dest.SetUnit(ms.Unit())
|
dest.SetUnit(ms.Unit())
|
||||||
switch ms.DataType() {
|
switch ms.Type() {
|
||||||
case MetricDataTypeGauge:
|
case MetricTypeGauge:
|
||||||
ms.Gauge().CopyTo(dest.SetEmptyGauge())
|
ms.Gauge().CopyTo(dest.SetEmptyGauge())
|
||||||
case MetricDataTypeSum:
|
case MetricTypeSum:
|
||||||
ms.Sum().CopyTo(dest.SetEmptySum())
|
ms.Sum().CopyTo(dest.SetEmptySum())
|
||||||
case MetricDataTypeHistogram:
|
case MetricTypeHistogram:
|
||||||
ms.Histogram().CopyTo(dest.SetEmptyHistogram())
|
ms.Histogram().CopyTo(dest.SetEmptyHistogram())
|
||||||
case MetricDataTypeExponentialHistogram:
|
case MetricTypeExponentialHistogram:
|
||||||
ms.ExponentialHistogram().CopyTo(dest.SetEmptyExponentialHistogram())
|
ms.ExponentialHistogram().CopyTo(dest.SetEmptyExponentialHistogram())
|
||||||
case MetricDataTypeSummary:
|
case MetricTypeSummary:
|
||||||
ms.Summary().CopyTo(dest.SetEmptySummary())
|
ms.Summary().CopyTo(dest.SetEmptySummary())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -473,15 +473,15 @@ func TestMetric_Unit(t *testing.T) {
|
||||||
assert.Equal(t, "1", ms.Unit())
|
assert.Equal(t, "1", ms.Unit())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMetric_DataType(t *testing.T) {
|
func TestMetric_Type(t *testing.T) {
|
||||||
tv := NewMetric()
|
tv := NewMetric()
|
||||||
assert.Equal(t, MetricDataTypeNone, tv.DataType())
|
assert.Equal(t, MetricTypeNone, tv.Type())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMetric_Gauge(t *testing.T) {
|
func TestMetric_Gauge(t *testing.T) {
|
||||||
ms := NewMetric()
|
ms := NewMetric()
|
||||||
internal.FillTestGauge(internal.Gauge(ms.SetEmptyGauge()))
|
internal.FillTestGauge(internal.Gauge(ms.SetEmptyGauge()))
|
||||||
assert.Equal(t, MetricDataTypeGauge, ms.DataType())
|
assert.Equal(t, MetricTypeGauge, ms.Type())
|
||||||
assert.Equal(t, Gauge(internal.GenerateTestGauge()), ms.Gauge())
|
assert.Equal(t, Gauge(internal.GenerateTestGauge()), ms.Gauge())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -496,7 +496,7 @@ func TestMetric_CopyTo_Gauge(t *testing.T) {
|
||||||
func TestMetric_Sum(t *testing.T) {
|
func TestMetric_Sum(t *testing.T) {
|
||||||
ms := NewMetric()
|
ms := NewMetric()
|
||||||
internal.FillTestSum(internal.Sum(ms.SetEmptySum()))
|
internal.FillTestSum(internal.Sum(ms.SetEmptySum()))
|
||||||
assert.Equal(t, MetricDataTypeSum, ms.DataType())
|
assert.Equal(t, MetricTypeSum, ms.Type())
|
||||||
assert.Equal(t, Sum(internal.GenerateTestSum()), ms.Sum())
|
assert.Equal(t, Sum(internal.GenerateTestSum()), ms.Sum())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -511,7 +511,7 @@ func TestMetric_CopyTo_Sum(t *testing.T) {
|
||||||
func TestMetric_Histogram(t *testing.T) {
|
func TestMetric_Histogram(t *testing.T) {
|
||||||
ms := NewMetric()
|
ms := NewMetric()
|
||||||
internal.FillTestHistogram(internal.Histogram(ms.SetEmptyHistogram()))
|
internal.FillTestHistogram(internal.Histogram(ms.SetEmptyHistogram()))
|
||||||
assert.Equal(t, MetricDataTypeHistogram, ms.DataType())
|
assert.Equal(t, MetricTypeHistogram, ms.Type())
|
||||||
assert.Equal(t, Histogram(internal.GenerateTestHistogram()), ms.Histogram())
|
assert.Equal(t, Histogram(internal.GenerateTestHistogram()), ms.Histogram())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -526,7 +526,7 @@ func TestMetric_CopyTo_Histogram(t *testing.T) {
|
||||||
func TestMetric_ExponentialHistogram(t *testing.T) {
|
func TestMetric_ExponentialHistogram(t *testing.T) {
|
||||||
ms := NewMetric()
|
ms := NewMetric()
|
||||||
internal.FillTestExponentialHistogram(internal.ExponentialHistogram(ms.SetEmptyExponentialHistogram()))
|
internal.FillTestExponentialHistogram(internal.ExponentialHistogram(ms.SetEmptyExponentialHistogram()))
|
||||||
assert.Equal(t, MetricDataTypeExponentialHistogram, ms.DataType())
|
assert.Equal(t, MetricTypeExponentialHistogram, ms.Type())
|
||||||
assert.Equal(t, ExponentialHistogram(internal.GenerateTestExponentialHistogram()), ms.ExponentialHistogram())
|
assert.Equal(t, ExponentialHistogram(internal.GenerateTestExponentialHistogram()), ms.ExponentialHistogram())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -541,7 +541,7 @@ func TestMetric_CopyTo_ExponentialHistogram(t *testing.T) {
|
||||||
func TestMetric_Summary(t *testing.T) {
|
func TestMetric_Summary(t *testing.T) {
|
||||||
ms := NewMetric()
|
ms := NewMetric()
|
||||||
internal.FillTestSummary(internal.Summary(ms.SetEmptySummary()))
|
internal.FillTestSummary(internal.Summary(ms.SetEmptySummary()))
|
||||||
assert.Equal(t, MetricDataTypeSummary, ms.DataType())
|
assert.Equal(t, MetricTypeSummary, ms.Type())
|
||||||
assert.Equal(t, Summary(internal.GenerateTestSummary()), ms.Summary())
|
assert.Equal(t, Summary(internal.GenerateTestSummary()), ms.Summary())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,16 +82,16 @@ func (ms Metrics) DataPointCount() (dataPointCount int) {
|
||||||
ms := ilm.Metrics()
|
ms := ilm.Metrics()
|
||||||
for k := 0; k < ms.Len(); k++ {
|
for k := 0; k < ms.Len(); k++ {
|
||||||
m := ms.At(k)
|
m := ms.At(k)
|
||||||
switch m.DataType() {
|
switch m.Type() {
|
||||||
case MetricDataTypeGauge:
|
case MetricTypeGauge:
|
||||||
dataPointCount += m.Gauge().DataPoints().Len()
|
dataPointCount += m.Gauge().DataPoints().Len()
|
||||||
case MetricDataTypeSum:
|
case MetricTypeSum:
|
||||||
dataPointCount += m.Sum().DataPoints().Len()
|
dataPointCount += m.Sum().DataPoints().Len()
|
||||||
case MetricDataTypeHistogram:
|
case MetricTypeHistogram:
|
||||||
dataPointCount += m.Histogram().DataPoints().Len()
|
dataPointCount += m.Histogram().DataPoints().Len()
|
||||||
case MetricDataTypeExponentialHistogram:
|
case MetricTypeExponentialHistogram:
|
||||||
dataPointCount += m.ExponentialHistogram().DataPoints().Len()
|
dataPointCount += m.ExponentialHistogram().DataPoints().Len()
|
||||||
case MetricDataTypeSummary:
|
case MetricTypeSummary:
|
||||||
dataPointCount += m.Summary().DataPoints().Len()
|
dataPointCount += m.Summary().DataPoints().Len()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -100,32 +100,55 @@ func (ms Metrics) DataPointCount() (dataPointCount int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// MetricDataType specifies the type of data in a Metric.
|
// Deprecated: [v0.61.0] use MetricType.
|
||||||
type MetricDataType int32
|
type MetricDataType = MetricType
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MetricDataTypeNone MetricDataType = iota
|
// Deprecated: [v0.61.0] use MetricTypeNone.
|
||||||
MetricDataTypeGauge
|
MetricDataTypeNone = MetricTypeNone
|
||||||
MetricDataTypeSum
|
// Deprecated: [v0.61.0] use MetricTypeGauge.
|
||||||
MetricDataTypeHistogram
|
MetricDataTypeGauge = MetricTypeGauge
|
||||||
MetricDataTypeExponentialHistogram
|
// Deprecated: [v0.61.0] use MetricTypeSum.
|
||||||
MetricDataTypeSummary
|
MetricDataTypeSum = MetricTypeSum
|
||||||
|
// Deprecated: [v0.61.0] use MetricTypeHistogram.
|
||||||
|
MetricDataTypeHistogram = MetricTypeHistogram
|
||||||
|
// Deprecated: [v0.61.0] use MetricTypeExponentialHistogram.
|
||||||
|
MetricDataTypeExponentialHistogram = MetricTypeExponentialHistogram
|
||||||
|
// Deprecated: [v0.61.0] use MetricTypeSummary.
|
||||||
|
MetricDataTypeSummary = MetricTypeSummary
|
||||||
)
|
)
|
||||||
|
|
||||||
// String returns the string representation of the MetricDataType.
|
// Deprecated: [v0.61.0] use Metric.Type().
|
||||||
func (mdt MetricDataType) String() string {
|
func (ms Metric) DataType() MetricDataType {
|
||||||
|
return ms.Type()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MetricType specifies the type of data in a Metric.
|
||||||
|
type MetricType int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
MetricTypeNone MetricType = iota
|
||||||
|
MetricTypeGauge
|
||||||
|
MetricTypeSum
|
||||||
|
MetricTypeHistogram
|
||||||
|
MetricTypeExponentialHistogram
|
||||||
|
MetricTypeSummary
|
||||||
|
)
|
||||||
|
|
||||||
|
// String returns the string representation of the MetricType.
|
||||||
|
func (mdt MetricType) String() string {
|
||||||
switch mdt {
|
switch mdt {
|
||||||
case MetricDataTypeNone:
|
case MetricTypeNone:
|
||||||
return "None"
|
return "None"
|
||||||
case MetricDataTypeGauge:
|
case MetricTypeGauge:
|
||||||
return "Gauge"
|
return "Gauge"
|
||||||
case MetricDataTypeSum:
|
case MetricTypeSum:
|
||||||
return "Sum"
|
return "Sum"
|
||||||
case MetricDataTypeHistogram:
|
case MetricTypeHistogram:
|
||||||
return "Histogram"
|
return "Histogram"
|
||||||
case MetricDataTypeExponentialHistogram:
|
case MetricTypeExponentialHistogram:
|
||||||
return "ExponentialHistogram"
|
return "ExponentialHistogram"
|
||||||
case MetricDataTypeSummary:
|
case MetricTypeSummary:
|
||||||
return "Summary"
|
return "Summary"
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,14 @@ const (
|
||||||
endTime = uint64(12578940000000054321)
|
endTime = uint64(12578940000000054321)
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMetricDataTypeString(t *testing.T) {
|
func TestMetricTypeString(t *testing.T) {
|
||||||
assert.Equal(t, "None", MetricDataTypeNone.String())
|
assert.Equal(t, "None", MetricTypeNone.String())
|
||||||
assert.Equal(t, "Gauge", MetricDataTypeGauge.String())
|
assert.Equal(t, "Gauge", MetricTypeGauge.String())
|
||||||
assert.Equal(t, "Sum", MetricDataTypeSum.String())
|
assert.Equal(t, "Sum", MetricTypeSum.String())
|
||||||
assert.Equal(t, "Histogram", MetricDataTypeHistogram.String())
|
assert.Equal(t, "Histogram", MetricTypeHistogram.String())
|
||||||
assert.Equal(t, "ExponentialHistogram", MetricDataTypeExponentialHistogram.String())
|
assert.Equal(t, "ExponentialHistogram", MetricTypeExponentialHistogram.String())
|
||||||
assert.Equal(t, "Summary", MetricDataTypeSummary.String())
|
assert.Equal(t, "Summary", MetricTypeSummary.String())
|
||||||
assert.Equal(t, "", (MetricDataTypeSummary + 1).String())
|
assert.Equal(t, "", (MetricTypeSummary + 1).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNumberDataPointValueTypeString(t *testing.T) {
|
func TestNumberDataPointValueTypeString(t *testing.T) {
|
||||||
|
|
@ -256,7 +256,7 @@ func TestOtlpToInternalReadOnly(t *testing.T) {
|
||||||
assert.EqualValues(t, "my_metric_int", metricInt.Name())
|
assert.EqualValues(t, "my_metric_int", metricInt.Name())
|
||||||
assert.EqualValues(t, "My metric", metricInt.Description())
|
assert.EqualValues(t, "My metric", metricInt.Description())
|
||||||
assert.EqualValues(t, "ms", metricInt.Unit())
|
assert.EqualValues(t, "ms", metricInt.Unit())
|
||||||
assert.EqualValues(t, MetricDataTypeGauge, metricInt.DataType())
|
assert.EqualValues(t, MetricTypeGauge, metricInt.Type())
|
||||||
gaugeDataPoints := metricInt.Gauge().DataPoints()
|
gaugeDataPoints := metricInt.Gauge().DataPoints()
|
||||||
assert.EqualValues(t, 2, gaugeDataPoints.Len())
|
assert.EqualValues(t, 2, gaugeDataPoints.Len())
|
||||||
// First point
|
// First point
|
||||||
|
|
@ -275,7 +275,7 @@ func TestOtlpToInternalReadOnly(t *testing.T) {
|
||||||
assert.EqualValues(t, "my_metric_double", metricDouble.Name())
|
assert.EqualValues(t, "my_metric_double", metricDouble.Name())
|
||||||
assert.EqualValues(t, "My metric", metricDouble.Description())
|
assert.EqualValues(t, "My metric", metricDouble.Description())
|
||||||
assert.EqualValues(t, "ms", metricDouble.Unit())
|
assert.EqualValues(t, "ms", metricDouble.Unit())
|
||||||
assert.EqualValues(t, MetricDataTypeSum, metricDouble.DataType())
|
assert.EqualValues(t, MetricTypeSum, metricDouble.Type())
|
||||||
dsd := metricDouble.Sum()
|
dsd := metricDouble.Sum()
|
||||||
assert.EqualValues(t, MetricAggregationTemporalityCumulative, dsd.AggregationTemporality())
|
assert.EqualValues(t, MetricAggregationTemporalityCumulative, dsd.AggregationTemporality())
|
||||||
sumDataPoints := dsd.DataPoints()
|
sumDataPoints := dsd.DataPoints()
|
||||||
|
|
@ -296,7 +296,7 @@ func TestOtlpToInternalReadOnly(t *testing.T) {
|
||||||
assert.EqualValues(t, "my_metric_histogram", metricHistogram.Name())
|
assert.EqualValues(t, "my_metric_histogram", metricHistogram.Name())
|
||||||
assert.EqualValues(t, "My metric", metricHistogram.Description())
|
assert.EqualValues(t, "My metric", metricHistogram.Description())
|
||||||
assert.EqualValues(t, "ms", metricHistogram.Unit())
|
assert.EqualValues(t, "ms", metricHistogram.Unit())
|
||||||
assert.EqualValues(t, MetricDataTypeHistogram, metricHistogram.DataType())
|
assert.EqualValues(t, MetricTypeHistogram, metricHistogram.Type())
|
||||||
dhd := metricHistogram.Histogram()
|
dhd := metricHistogram.Histogram()
|
||||||
assert.EqualValues(t, MetricAggregationTemporalityDelta, dhd.AggregationTemporality())
|
assert.EqualValues(t, MetricAggregationTemporalityDelta, dhd.AggregationTemporality())
|
||||||
histogramDataPoints := dhd.DataPoints()
|
histogramDataPoints := dhd.DataPoints()
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,9 @@ func splitMetrics(size int, src pmetric.Metrics) pmetric.Metrics {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If possible to move all points do that.
|
// If possible to move all points do that.
|
||||||
srcMetricDataPointCount := metricDPC(srcMetric)
|
srcMetricPointCount := metricDPC(srcMetric)
|
||||||
if srcMetricDataPointCount+totalCopiedDataPoints <= size {
|
if srcMetricPointCount+totalCopiedDataPoints <= size {
|
||||||
totalCopiedDataPoints += srcMetricDataPointCount
|
totalCopiedDataPoints += srcMetricPointCount
|
||||||
srcMetric.MoveTo(destIlm.Metrics().AppendEmpty())
|
srcMetric.MoveTo(destIlm.Metrics().AppendEmpty())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -108,16 +108,16 @@ func scopeMetricsDPC(ilm pmetric.ScopeMetrics) int {
|
||||||
|
|
||||||
// metricDPC calculates the total number of data points in the pmetric.Metric.
|
// metricDPC calculates the total number of data points in the pmetric.Metric.
|
||||||
func metricDPC(ms pmetric.Metric) int {
|
func metricDPC(ms pmetric.Metric) int {
|
||||||
switch ms.DataType() {
|
switch ms.Type() {
|
||||||
case pmetric.MetricDataTypeGauge:
|
case pmetric.MetricTypeGauge:
|
||||||
return ms.Gauge().DataPoints().Len()
|
return ms.Gauge().DataPoints().Len()
|
||||||
case pmetric.MetricDataTypeSum:
|
case pmetric.MetricTypeSum:
|
||||||
return ms.Sum().DataPoints().Len()
|
return ms.Sum().DataPoints().Len()
|
||||||
case pmetric.MetricDataTypeHistogram:
|
case pmetric.MetricTypeHistogram:
|
||||||
return ms.Histogram().DataPoints().Len()
|
return ms.Histogram().DataPoints().Len()
|
||||||
case pmetric.MetricDataTypeExponentialHistogram:
|
case pmetric.MetricTypeExponentialHistogram:
|
||||||
return ms.ExponentialHistogram().DataPoints().Len()
|
return ms.ExponentialHistogram().DataPoints().Len()
|
||||||
case pmetric.MetricDataTypeSummary:
|
case pmetric.MetricTypeSummary:
|
||||||
return ms.Summary().DataPoints().Len()
|
return ms.Summary().DataPoints().Len()
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -130,23 +130,23 @@ func splitMetric(ms, dest pmetric.Metric, size int) (int, bool) {
|
||||||
dest.SetDescription(ms.Description())
|
dest.SetDescription(ms.Description())
|
||||||
dest.SetUnit(ms.Unit())
|
dest.SetUnit(ms.Unit())
|
||||||
|
|
||||||
switch ms.DataType() {
|
switch ms.Type() {
|
||||||
case pmetric.MetricDataTypeGauge:
|
case pmetric.MetricTypeGauge:
|
||||||
return splitNumberDataPoints(ms.Gauge().DataPoints(), dest.SetEmptyGauge().DataPoints(), size)
|
return splitNumberDataPoints(ms.Gauge().DataPoints(), dest.SetEmptyGauge().DataPoints(), size)
|
||||||
case pmetric.MetricDataTypeSum:
|
case pmetric.MetricTypeSum:
|
||||||
destSum := dest.SetEmptySum()
|
destSum := dest.SetEmptySum()
|
||||||
destSum.SetAggregationTemporality(ms.Sum().AggregationTemporality())
|
destSum.SetAggregationTemporality(ms.Sum().AggregationTemporality())
|
||||||
destSum.SetIsMonotonic(ms.Sum().IsMonotonic())
|
destSum.SetIsMonotonic(ms.Sum().IsMonotonic())
|
||||||
return splitNumberDataPoints(ms.Sum().DataPoints(), destSum.DataPoints(), size)
|
return splitNumberDataPoints(ms.Sum().DataPoints(), destSum.DataPoints(), size)
|
||||||
case pmetric.MetricDataTypeHistogram:
|
case pmetric.MetricTypeHistogram:
|
||||||
destHistogram := dest.SetEmptyHistogram()
|
destHistogram := dest.SetEmptyHistogram()
|
||||||
destHistogram.SetAggregationTemporality(ms.Histogram().AggregationTemporality())
|
destHistogram.SetAggregationTemporality(ms.Histogram().AggregationTemporality())
|
||||||
return splitHistogramDataPoints(ms.Histogram().DataPoints(), destHistogram.DataPoints(), size)
|
return splitHistogramDataPoints(ms.Histogram().DataPoints(), destHistogram.DataPoints(), size)
|
||||||
case pmetric.MetricDataTypeExponentialHistogram:
|
case pmetric.MetricTypeExponentialHistogram:
|
||||||
destHistogram := dest.SetEmptyExponentialHistogram()
|
destHistogram := dest.SetEmptyExponentialHistogram()
|
||||||
destHistogram.SetAggregationTemporality(ms.ExponentialHistogram().AggregationTemporality())
|
destHistogram.SetAggregationTemporality(ms.ExponentialHistogram().AggregationTemporality())
|
||||||
return splitExponentialHistogramDataPoints(ms.ExponentialHistogram().DataPoints(), destHistogram.DataPoints(), size)
|
return splitExponentialHistogramDataPoints(ms.ExponentialHistogram().DataPoints(), destHistogram.DataPoints(), size)
|
||||||
case pmetric.MetricDataTypeSummary:
|
case pmetric.MetricTypeSummary:
|
||||||
return splitSummaryDataPoints(ms.Summary().DataPoints(), dest.SetEmptySummary().DataPoints(), size)
|
return splitSummaryDataPoints(ms.Summary().DataPoints(), dest.SetEmptySummary().DataPoints(), size)
|
||||||
}
|
}
|
||||||
return size, false
|
return size, false
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue