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 `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 `pmetric.MetricDataType` and related constants in favor of `pmetric.MetricType`. (#6127)
|
||||
- Deprecate `pmetric.Metric.DataType()` in favor of `pmetric.Metric.Type()`. (#6127)
|
||||
|
||||
### 💡 Enhancements 💡
|
||||
|
||||
|
|
|
|||
|
|
@ -64,29 +64,29 @@ func (b *dataBuffer) logMetricDescriptor(md pmetric.Metric) {
|
|||
b.logEntry(" -> Name: %s", md.Name())
|
||||
b.logEntry(" -> Description: %s", md.Description())
|
||||
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) {
|
||||
switch m.DataType() {
|
||||
case pmetric.MetricDataTypeNone:
|
||||
switch m.Type() {
|
||||
case pmetric.MetricTypeNone:
|
||||
return
|
||||
case pmetric.MetricDataTypeGauge:
|
||||
case pmetric.MetricTypeGauge:
|
||||
b.logNumberDataPoints(m.Gauge().DataPoints())
|
||||
case pmetric.MetricDataTypeSum:
|
||||
case pmetric.MetricTypeSum:
|
||||
data := m.Sum()
|
||||
b.logEntry(" -> IsMonotonic: %t", data.IsMonotonic())
|
||||
b.logEntry(" -> AggregationTemporality: %s", data.AggregationTemporality().String())
|
||||
b.logNumberDataPoints(data.DataPoints())
|
||||
case pmetric.MetricDataTypeHistogram:
|
||||
case pmetric.MetricTypeHistogram:
|
||||
data := m.Histogram()
|
||||
b.logEntry(" -> AggregationTemporality: %s", data.AggregationTemporality().String())
|
||||
b.logHistogramDataPoints(data.DataPoints())
|
||||
case pmetric.MetricDataTypeExponentialHistogram:
|
||||
case pmetric.MetricTypeExponentialHistogram:
|
||||
data := m.ExponentialHistogram()
|
||||
b.logEntry(" -> AggregationTemporality: %s", data.AggregationTemporality().String())
|
||||
b.logExponentialHistogramDataPoints(data.DataPoints())
|
||||
case pmetric.MetricDataTypeSummary:
|
||||
case pmetric.MetricTypeSummary:
|
||||
data := m.Summary()
|
||||
b.logDoubleSummaryDataPoints(data.DataPoints())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,29 +49,29 @@ func GenerateMetricsAllTypesEmpty() pmetric.Metrics {
|
|||
ms := md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics()
|
||||
|
||||
doubleGauge := ms.AppendEmpty()
|
||||
initMetric(doubleGauge, TestGaugeDoubleMetricName, pmetric.MetricDataTypeGauge)
|
||||
initMetric(doubleGauge, TestGaugeDoubleMetricName, pmetric.MetricTypeGauge)
|
||||
doubleGauge.Gauge().DataPoints().AppendEmpty()
|
||||
intGauge := ms.AppendEmpty()
|
||||
initMetric(intGauge, TestGaugeIntMetricName, pmetric.MetricDataTypeGauge)
|
||||
initMetric(intGauge, TestGaugeIntMetricName, pmetric.MetricTypeGauge)
|
||||
intGauge.Gauge().DataPoints().AppendEmpty()
|
||||
doubleSum := ms.AppendEmpty()
|
||||
initMetric(doubleSum, TestSumDoubleMetricName, pmetric.MetricDataTypeSum)
|
||||
initMetric(doubleSum, TestSumDoubleMetricName, pmetric.MetricTypeSum)
|
||||
doubleSum.Sum().DataPoints().AppendEmpty()
|
||||
intSum := ms.AppendEmpty()
|
||||
initMetric(intSum, TestSumIntMetricName, pmetric.MetricDataTypeSum)
|
||||
initMetric(intSum, TestSumIntMetricName, pmetric.MetricTypeSum)
|
||||
intSum.Sum().DataPoints().AppendEmpty()
|
||||
histogram := ms.AppendEmpty()
|
||||
initMetric(histogram, TestHistogramMetricName, pmetric.MetricDataTypeHistogram)
|
||||
initMetric(histogram, TestHistogramMetricName, pmetric.MetricTypeHistogram)
|
||||
histogram.Histogram().DataPoints().AppendEmpty()
|
||||
summary := ms.AppendEmpty()
|
||||
initMetric(summary, TestSummaryMetricName, pmetric.MetricDataTypeSummary)
|
||||
initMetric(summary, TestSummaryMetricName, pmetric.MetricTypeSummary)
|
||||
summary.Summary().DataPoints().AppendEmpty()
|
||||
return md
|
||||
}
|
||||
|
||||
func GenerateMetricsMetricTypeInvalid() pmetric.Metrics {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ func GenerateMetrics(count int) pmetric.Metrics {
|
|||
}
|
||||
|
||||
func initGaugeIntMetric(im pmetric.Metric) {
|
||||
initMetric(im, TestGaugeIntMetricName, pmetric.MetricDataTypeGauge)
|
||||
initMetric(im, TestGaugeIntMetricName, pmetric.MetricTypeGauge)
|
||||
|
||||
idps := im.Gauge().DataPoints()
|
||||
idp0 := idps.AppendEmpty()
|
||||
|
|
@ -130,7 +130,7 @@ func initGaugeIntMetric(im pmetric.Metric) {
|
|||
}
|
||||
|
||||
func initGaugeDoubleMetric(im pmetric.Metric) {
|
||||
initMetric(im, TestGaugeDoubleMetricName, pmetric.MetricDataTypeGauge)
|
||||
initMetric(im, TestGaugeDoubleMetricName, pmetric.MetricTypeGauge)
|
||||
|
||||
idps := im.Gauge().DataPoints()
|
||||
idp0 := idps.AppendEmpty()
|
||||
|
|
@ -146,7 +146,7 @@ func initGaugeDoubleMetric(im pmetric.Metric) {
|
|||
}
|
||||
|
||||
func initSumIntMetric(im pmetric.Metric) {
|
||||
initMetric(im, TestSumIntMetricName, pmetric.MetricDataTypeSum)
|
||||
initMetric(im, TestSumIntMetricName, pmetric.MetricTypeSum)
|
||||
|
||||
idps := im.Sum().DataPoints()
|
||||
idp0 := idps.AppendEmpty()
|
||||
|
|
@ -162,7 +162,7 @@ func initSumIntMetric(im pmetric.Metric) {
|
|||
}
|
||||
|
||||
func initSumDoubleMetric(dm pmetric.Metric) {
|
||||
initMetric(dm, TestSumDoubleMetricName, pmetric.MetricDataTypeSum)
|
||||
initMetric(dm, TestSumDoubleMetricName, pmetric.MetricTypeSum)
|
||||
|
||||
ddps := dm.Sum().DataPoints()
|
||||
ddp0 := ddps.AppendEmpty()
|
||||
|
|
@ -179,7 +179,7 @@ func initSumDoubleMetric(dm pmetric.Metric) {
|
|||
}
|
||||
|
||||
func initHistogramMetric(hm pmetric.Metric) {
|
||||
initMetric(hm, TestHistogramMetricName, pmetric.MetricDataTypeHistogram)
|
||||
initMetric(hm, TestHistogramMetricName, pmetric.MetricTypeHistogram)
|
||||
|
||||
hdps := hm.Histogram().DataPoints()
|
||||
hdp0 := hdps.AppendEmpty()
|
||||
|
|
@ -206,7 +206,7 @@ func initHistogramMetric(hm pmetric.Metric) {
|
|||
}
|
||||
|
||||
func initExponentialHistogramMetric(hm pmetric.Metric) {
|
||||
initMetric(hm, TestExponentialHistogramMetricName, pmetric.MetricDataTypeExponentialHistogram)
|
||||
initMetric(hm, TestExponentialHistogramMetricName, pmetric.MetricTypeExponentialHistogram)
|
||||
|
||||
hdps := hm.ExponentialHistogram().DataPoints()
|
||||
hdp0 := hdps.AppendEmpty()
|
||||
|
|
@ -259,7 +259,7 @@ func initExponentialHistogramMetric(hm pmetric.Metric) {
|
|||
}
|
||||
|
||||
func initSummaryMetric(sm pmetric.Metric) {
|
||||
initMetric(sm, TestSummaryMetricName, pmetric.MetricDataTypeSummary)
|
||||
initMetric(sm, TestSummaryMetricName, pmetric.MetricTypeSummary)
|
||||
|
||||
sdps := sm.Summary().DataPoints()
|
||||
sdp0 := sdps.AppendEmpty()
|
||||
|
|
@ -281,24 +281,24 @@ func initSummaryMetric(sm pmetric.Metric) {
|
|||
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.SetDescription("")
|
||||
m.SetUnit("1")
|
||||
switch ty {
|
||||
case pmetric.MetricDataTypeGauge:
|
||||
case pmetric.MetricTypeGauge:
|
||||
m.SetEmptyGauge()
|
||||
case pmetric.MetricDataTypeSum:
|
||||
case pmetric.MetricTypeSum:
|
||||
sum := m.SetEmptySum()
|
||||
sum.SetIsMonotonic(true)
|
||||
sum.SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative)
|
||||
case pmetric.MetricDataTypeHistogram:
|
||||
case pmetric.MetricTypeHistogram:
|
||||
histo := m.SetEmptyHistogram()
|
||||
histo.SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative)
|
||||
case pmetric.MetricDataTypeExponentialHistogram:
|
||||
case pmetric.MetricTypeExponentialHistogram:
|
||||
histo := m.SetEmptyExponentialHistogram()
|
||||
histo.SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta)
|
||||
case pmetric.MetricDataTypeSummary:
|
||||
case pmetric.MetricTypeSummary:
|
||||
m.SetEmptySummary()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,20 +57,20 @@ func (ms ${structName}) ${fieldName}() ${packageName}${returnType} {
|
|||
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.
|
||||
func (ms ${structName}) ${originFieldName}Type() ${typeName} {
|
||||
func (ms ${structName}) ${typeFuncName}() ${typeName} {
|
||||
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}()
|
||||
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}.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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}.
|
||||
//
|
||||
// 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.
|
||||
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) {
|
||||
ms := New${structName}()
|
||||
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}())
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ const accessorsOneOfPrimitiveTestTemplate = `func Test${structName}_${fieldName}
|
|||
assert.Equal(t, ${defaultVal}, ms.${fieldName}())
|
||||
ms.Set${fieldName}(${testValue})
|
||||
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) {
|
||||
|
|
@ -508,11 +508,12 @@ func (psf *primitiveSliceField) generateCopyToValue(ms baseStruct, sb *strings.B
|
|||
var _ baseField = (*primitiveSliceField)(nil)
|
||||
|
||||
type oneOfField struct {
|
||||
originTypePrefix string
|
||||
originFieldName string
|
||||
typeName string
|
||||
testValueIdx int
|
||||
values []oneOfValue
|
||||
originTypePrefix string
|
||||
originFieldName string
|
||||
typeName string
|
||||
testValueIdx int
|
||||
values []oneOfValue
|
||||
omitOriginFieldNameInNames bool
|
||||
}
|
||||
|
||||
func (of *oneOfField) generateAccessors(ms baseStruct, sb *strings.Builder) {
|
||||
|
|
@ -529,6 +530,8 @@ func (of *oneOfField) generateTypeAccessors(ms baseStruct, sb *strings.Builder)
|
|||
switch name {
|
||||
case "lowerOriginFieldName":
|
||||
return strings.ToLower(of.originFieldName)
|
||||
case "typeFuncName":
|
||||
return of.typeFuncName()
|
||||
case "originFieldName":
|
||||
return of.originFieldName
|
||||
case "structName":
|
||||
|
|
@ -548,13 +551,21 @@ func (of *oneOfField) generateTypeAccessors(ms baseStruct, sb *strings.Builder)
|
|||
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) {
|
||||
sb.WriteString(os.Expand(oneOfTypeAccessorHeaderTestTemplate, func(name string) string {
|
||||
switch name {
|
||||
case "structName":
|
||||
return ms.getName()
|
||||
case "originFieldName":
|
||||
return of.originFieldName
|
||||
case "typeFuncName":
|
||||
return of.typeFuncName()
|
||||
case "typeName":
|
||||
return of.typeName
|
||||
default:
|
||||
|
|
@ -573,7 +584,7 @@ func (of *oneOfField) generateSetWithTestValue(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 {
|
||||
v.generateCopyToValue(of, sb)
|
||||
}
|
||||
|
|
@ -583,7 +594,6 @@ func (of *oneOfField) generateCopyToValue(_ baseStruct, sb *strings.Builder) {
|
|||
var _ baseField = (*oneOfField)(nil)
|
||||
|
||||
type oneOfValue interface {
|
||||
getFieldType() string
|
||||
generateAccessors(ms baseStruct, of *oneOfField, sb *strings.Builder)
|
||||
generateTests(ms baseStruct, of *oneOfField, sb *strings.Builder)
|
||||
generateSetWithTestValue(of *oneOfField, sb *strings.Builder)
|
||||
|
|
@ -600,10 +610,6 @@ type oneOfPrimitiveValue struct {
|
|||
originFieldName string
|
||||
}
|
||||
|
||||
func (opv *oneOfPrimitiveValue) getFieldType() string {
|
||||
return opv.fieldType
|
||||
}
|
||||
|
||||
func (opv *oneOfPrimitiveValue) generateAccessors(ms baseStruct, of *oneOfField, sb *strings.Builder) {
|
||||
sb.WriteString(os.Expand(accessorsOneOfPrimitiveTemplate, func(name string) string {
|
||||
switch name {
|
||||
|
|
@ -641,8 +647,8 @@ func (opv *oneOfPrimitiveValue) generateTests(ms baseStruct, of *oneOfField, sb
|
|||
return opv.fieldName
|
||||
case "testValue":
|
||||
return opv.testVal
|
||||
case "originOneOfFieldName":
|
||||
return of.originFieldName
|
||||
case "originOneOfTypeFuncName":
|
||||
return of.typeFuncName()
|
||||
case "typeName":
|
||||
return of.typeName + opv.fieldType
|
||||
default:
|
||||
|
|
@ -675,10 +681,6 @@ type oneOfMessageValue struct {
|
|||
returnMessage *messageValueStruct
|
||||
}
|
||||
|
||||
func (omv *oneOfMessageValue) getFieldType() string {
|
||||
return omv.fieldName
|
||||
}
|
||||
|
||||
func (omv *oneOfMessageValue) generateAccessors(ms baseStruct, of *oneOfField, sb *strings.Builder) {
|
||||
sb.WriteString(os.Expand(accessorsOneOfMessageTemplate, func(name string) string {
|
||||
switch name {
|
||||
|
|
@ -688,6 +690,8 @@ func (omv *oneOfMessageValue) generateAccessors(ms baseStruct, of *oneOfField, s
|
|||
return strings.ToLower(omv.fieldName)
|
||||
case "originFieldName":
|
||||
return omv.originFieldName
|
||||
case "originOneOfTypeFuncName":
|
||||
return of.typeFuncName()
|
||||
case "originOneOfFieldName":
|
||||
return of.originFieldName
|
||||
case "originFieldPackageName":
|
||||
|
|
@ -716,8 +720,8 @@ func (omv *oneOfMessageValue) generateTests(ms baseStruct, of *oneOfField, sb *s
|
|||
return omv.fieldName
|
||||
case "returnType":
|
||||
return omv.returnMessage.structName
|
||||
case "originOneOfFieldName":
|
||||
return of.originFieldName
|
||||
case "originOneOfTypeFuncName":
|
||||
return of.typeFuncName()
|
||||
case "typeName":
|
||||
return of.typeName + omv.returnMessage.structName
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -127,10 +127,11 @@ var metric = &messageValueStruct{
|
|||
testVal: `"1"`,
|
||||
},
|
||||
&oneOfField{
|
||||
typeName: "MetricDataType",
|
||||
originFieldName: "Data",
|
||||
originTypePrefix: "otlpmetrics.Metric_",
|
||||
testValueIdx: 1, // Sum
|
||||
typeName: "MetricType",
|
||||
originFieldName: "Data",
|
||||
originTypePrefix: "otlpmetrics.Metric_",
|
||||
testValueIdx: 1, // Sum
|
||||
omitOriginFieldNameInNames: true,
|
||||
values: []oneOfValue{
|
||||
&oneOfMessageValue{
|
||||
fieldName: "Gauge",
|
||||
|
|
|
|||
|
|
@ -630,27 +630,27 @@ func (ms Metric) SetUnit(v string) {
|
|||
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.
|
||||
func (ms Metric) DataType() MetricDataType {
|
||||
func (ms Metric) Type() MetricType {
|
||||
switch ms.getOrig().Data.(type) {
|
||||
case *otlpmetrics.Metric_Gauge:
|
||||
return MetricDataTypeGauge
|
||||
return MetricTypeGauge
|
||||
case *otlpmetrics.Metric_Sum:
|
||||
return MetricDataTypeSum
|
||||
return MetricTypeSum
|
||||
case *otlpmetrics.Metric_Histogram:
|
||||
return MetricDataTypeHistogram
|
||||
return MetricTypeHistogram
|
||||
case *otlpmetrics.Metric_ExponentialHistogram:
|
||||
return MetricDataTypeExponentialHistogram
|
||||
return MetricTypeExponentialHistogram
|
||||
case *otlpmetrics.Metric_Summary:
|
||||
return MetricDataTypeSummary
|
||||
return MetricTypeSummary
|
||||
}
|
||||
return MetricDataTypeNone
|
||||
return MetricTypeNone
|
||||
}
|
||||
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
func (ms Metric) SetEmptyGauge() Gauge {
|
||||
|
|
@ -675,7 +675,7 @@ func (ms Metric) SetEmptyGauge() Gauge {
|
|||
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
func (ms Metric) SetEmptySum() Sum {
|
||||
|
|
@ -700,7 +700,7 @@ func (ms Metric) SetEmptySum() Sum {
|
|||
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
func (ms Metric) SetEmptyHistogram() Histogram {
|
||||
|
|
@ -725,7 +725,7 @@ func (ms Metric) SetEmptyHistogram() Histogram {
|
|||
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram {
|
||||
|
|
@ -750,7 +750,7 @@ func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram {
|
|||
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
func (ms Metric) SetEmptySummary() Summary {
|
||||
|
|
@ -778,16 +778,16 @@ func (ms Metric) CopyTo(dest Metric) {
|
|||
dest.SetName(ms.Name())
|
||||
dest.SetDescription(ms.Description())
|
||||
dest.SetUnit(ms.Unit())
|
||||
switch ms.DataType() {
|
||||
case MetricDataTypeGauge:
|
||||
switch ms.Type() {
|
||||
case MetricTypeGauge:
|
||||
ms.Gauge().CopyTo(dest.SetEmptyGauge())
|
||||
case MetricDataTypeSum:
|
||||
case MetricTypeSum:
|
||||
ms.Sum().CopyTo(dest.SetEmptySum())
|
||||
case MetricDataTypeHistogram:
|
||||
case MetricTypeHistogram:
|
||||
ms.Histogram().CopyTo(dest.SetEmptyHistogram())
|
||||
case MetricDataTypeExponentialHistogram:
|
||||
case MetricTypeExponentialHistogram:
|
||||
ms.ExponentialHistogram().CopyTo(dest.SetEmptyExponentialHistogram())
|
||||
case MetricDataTypeSummary:
|
||||
case MetricTypeSummary:
|
||||
ms.Summary().CopyTo(dest.SetEmptySummary())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -473,15 +473,15 @@ func TestMetric_Unit(t *testing.T) {
|
|||
assert.Equal(t, "1", ms.Unit())
|
||||
}
|
||||
|
||||
func TestMetric_DataType(t *testing.T) {
|
||||
func TestMetric_Type(t *testing.T) {
|
||||
tv := NewMetric()
|
||||
assert.Equal(t, MetricDataTypeNone, tv.DataType())
|
||||
assert.Equal(t, MetricTypeNone, tv.Type())
|
||||
}
|
||||
|
||||
func TestMetric_Gauge(t *testing.T) {
|
||||
ms := NewMetric()
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
@ -496,7 +496,7 @@ func TestMetric_CopyTo_Gauge(t *testing.T) {
|
|||
func TestMetric_Sum(t *testing.T) {
|
||||
ms := NewMetric()
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
@ -511,7 +511,7 @@ func TestMetric_CopyTo_Sum(t *testing.T) {
|
|||
func TestMetric_Histogram(t *testing.T) {
|
||||
ms := NewMetric()
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
@ -526,7 +526,7 @@ func TestMetric_CopyTo_Histogram(t *testing.T) {
|
|||
func TestMetric_ExponentialHistogram(t *testing.T) {
|
||||
ms := NewMetric()
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
@ -541,7 +541,7 @@ func TestMetric_CopyTo_ExponentialHistogram(t *testing.T) {
|
|||
func TestMetric_Summary(t *testing.T) {
|
||||
ms := NewMetric()
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,16 +82,16 @@ func (ms Metrics) DataPointCount() (dataPointCount int) {
|
|||
ms := ilm.Metrics()
|
||||
for k := 0; k < ms.Len(); k++ {
|
||||
m := ms.At(k)
|
||||
switch m.DataType() {
|
||||
case MetricDataTypeGauge:
|
||||
switch m.Type() {
|
||||
case MetricTypeGauge:
|
||||
dataPointCount += m.Gauge().DataPoints().Len()
|
||||
case MetricDataTypeSum:
|
||||
case MetricTypeSum:
|
||||
dataPointCount += m.Sum().DataPoints().Len()
|
||||
case MetricDataTypeHistogram:
|
||||
case MetricTypeHistogram:
|
||||
dataPointCount += m.Histogram().DataPoints().Len()
|
||||
case MetricDataTypeExponentialHistogram:
|
||||
case MetricTypeExponentialHistogram:
|
||||
dataPointCount += m.ExponentialHistogram().DataPoints().Len()
|
||||
case MetricDataTypeSummary:
|
||||
case MetricTypeSummary:
|
||||
dataPointCount += m.Summary().DataPoints().Len()
|
||||
}
|
||||
}
|
||||
|
|
@ -100,32 +100,55 @@ func (ms Metrics) DataPointCount() (dataPointCount int) {
|
|||
return
|
||||
}
|
||||
|
||||
// MetricDataType specifies the type of data in a Metric.
|
||||
type MetricDataType int32
|
||||
// Deprecated: [v0.61.0] use MetricType.
|
||||
type MetricDataType = MetricType
|
||||
|
||||
const (
|
||||
MetricDataTypeNone MetricDataType = iota
|
||||
MetricDataTypeGauge
|
||||
MetricDataTypeSum
|
||||
MetricDataTypeHistogram
|
||||
MetricDataTypeExponentialHistogram
|
||||
MetricDataTypeSummary
|
||||
// Deprecated: [v0.61.0] use MetricTypeNone.
|
||||
MetricDataTypeNone = MetricTypeNone
|
||||
// Deprecated: [v0.61.0] use MetricTypeGauge.
|
||||
MetricDataTypeGauge = MetricTypeGauge
|
||||
// Deprecated: [v0.61.0] use MetricTypeSum.
|
||||
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.
|
||||
func (mdt MetricDataType) String() string {
|
||||
// Deprecated: [v0.61.0] use Metric.Type().
|
||||
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 {
|
||||
case MetricDataTypeNone:
|
||||
case MetricTypeNone:
|
||||
return "None"
|
||||
case MetricDataTypeGauge:
|
||||
case MetricTypeGauge:
|
||||
return "Gauge"
|
||||
case MetricDataTypeSum:
|
||||
case MetricTypeSum:
|
||||
return "Sum"
|
||||
case MetricDataTypeHistogram:
|
||||
case MetricTypeHistogram:
|
||||
return "Histogram"
|
||||
case MetricDataTypeExponentialHistogram:
|
||||
case MetricTypeExponentialHistogram:
|
||||
return "ExponentialHistogram"
|
||||
case MetricDataTypeSummary:
|
||||
case MetricTypeSummary:
|
||||
return "Summary"
|
||||
}
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -35,14 +35,14 @@ const (
|
|||
endTime = uint64(12578940000000054321)
|
||||
)
|
||||
|
||||
func TestMetricDataTypeString(t *testing.T) {
|
||||
assert.Equal(t, "None", MetricDataTypeNone.String())
|
||||
assert.Equal(t, "Gauge", MetricDataTypeGauge.String())
|
||||
assert.Equal(t, "Sum", MetricDataTypeSum.String())
|
||||
assert.Equal(t, "Histogram", MetricDataTypeHistogram.String())
|
||||
assert.Equal(t, "ExponentialHistogram", MetricDataTypeExponentialHistogram.String())
|
||||
assert.Equal(t, "Summary", MetricDataTypeSummary.String())
|
||||
assert.Equal(t, "", (MetricDataTypeSummary + 1).String())
|
||||
func TestMetricTypeString(t *testing.T) {
|
||||
assert.Equal(t, "None", MetricTypeNone.String())
|
||||
assert.Equal(t, "Gauge", MetricTypeGauge.String())
|
||||
assert.Equal(t, "Sum", MetricTypeSum.String())
|
||||
assert.Equal(t, "Histogram", MetricTypeHistogram.String())
|
||||
assert.Equal(t, "ExponentialHistogram", MetricTypeExponentialHistogram.String())
|
||||
assert.Equal(t, "Summary", MetricTypeSummary.String())
|
||||
assert.Equal(t, "", (MetricTypeSummary + 1).String())
|
||||
}
|
||||
|
||||
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", metricInt.Description())
|
||||
assert.EqualValues(t, "ms", metricInt.Unit())
|
||||
assert.EqualValues(t, MetricDataTypeGauge, metricInt.DataType())
|
||||
assert.EqualValues(t, MetricTypeGauge, metricInt.Type())
|
||||
gaugeDataPoints := metricInt.Gauge().DataPoints()
|
||||
assert.EqualValues(t, 2, gaugeDataPoints.Len())
|
||||
// First point
|
||||
|
|
@ -275,7 +275,7 @@ func TestOtlpToInternalReadOnly(t *testing.T) {
|
|||
assert.EqualValues(t, "my_metric_double", metricDouble.Name())
|
||||
assert.EqualValues(t, "My metric", metricDouble.Description())
|
||||
assert.EqualValues(t, "ms", metricDouble.Unit())
|
||||
assert.EqualValues(t, MetricDataTypeSum, metricDouble.DataType())
|
||||
assert.EqualValues(t, MetricTypeSum, metricDouble.Type())
|
||||
dsd := metricDouble.Sum()
|
||||
assert.EqualValues(t, MetricAggregationTemporalityCumulative, dsd.AggregationTemporality())
|
||||
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", metricHistogram.Description())
|
||||
assert.EqualValues(t, "ms", metricHistogram.Unit())
|
||||
assert.EqualValues(t, MetricDataTypeHistogram, metricHistogram.DataType())
|
||||
assert.EqualValues(t, MetricTypeHistogram, metricHistogram.Type())
|
||||
dhd := metricHistogram.Histogram()
|
||||
assert.EqualValues(t, MetricAggregationTemporalityDelta, dhd.AggregationTemporality())
|
||||
histogramDataPoints := dhd.DataPoints()
|
||||
|
|
|
|||
|
|
@ -66,9 +66,9 @@ func splitMetrics(size int, src pmetric.Metrics) pmetric.Metrics {
|
|||
}
|
||||
|
||||
// If possible to move all points do that.
|
||||
srcMetricDataPointCount := metricDPC(srcMetric)
|
||||
if srcMetricDataPointCount+totalCopiedDataPoints <= size {
|
||||
totalCopiedDataPoints += srcMetricDataPointCount
|
||||
srcMetricPointCount := metricDPC(srcMetric)
|
||||
if srcMetricPointCount+totalCopiedDataPoints <= size {
|
||||
totalCopiedDataPoints += srcMetricPointCount
|
||||
srcMetric.MoveTo(destIlm.Metrics().AppendEmpty())
|
||||
return true
|
||||
}
|
||||
|
|
@ -108,16 +108,16 @@ func scopeMetricsDPC(ilm pmetric.ScopeMetrics) int {
|
|||
|
||||
// metricDPC calculates the total number of data points in the pmetric.Metric.
|
||||
func metricDPC(ms pmetric.Metric) int {
|
||||
switch ms.DataType() {
|
||||
case pmetric.MetricDataTypeGauge:
|
||||
switch ms.Type() {
|
||||
case pmetric.MetricTypeGauge:
|
||||
return ms.Gauge().DataPoints().Len()
|
||||
case pmetric.MetricDataTypeSum:
|
||||
case pmetric.MetricTypeSum:
|
||||
return ms.Sum().DataPoints().Len()
|
||||
case pmetric.MetricDataTypeHistogram:
|
||||
case pmetric.MetricTypeHistogram:
|
||||
return ms.Histogram().DataPoints().Len()
|
||||
case pmetric.MetricDataTypeExponentialHistogram:
|
||||
case pmetric.MetricTypeExponentialHistogram:
|
||||
return ms.ExponentialHistogram().DataPoints().Len()
|
||||
case pmetric.MetricDataTypeSummary:
|
||||
case pmetric.MetricTypeSummary:
|
||||
return ms.Summary().DataPoints().Len()
|
||||
}
|
||||
return 0
|
||||
|
|
@ -130,23 +130,23 @@ func splitMetric(ms, dest pmetric.Metric, size int) (int, bool) {
|
|||
dest.SetDescription(ms.Description())
|
||||
dest.SetUnit(ms.Unit())
|
||||
|
||||
switch ms.DataType() {
|
||||
case pmetric.MetricDataTypeGauge:
|
||||
switch ms.Type() {
|
||||
case pmetric.MetricTypeGauge:
|
||||
return splitNumberDataPoints(ms.Gauge().DataPoints(), dest.SetEmptyGauge().DataPoints(), size)
|
||||
case pmetric.MetricDataTypeSum:
|
||||
case pmetric.MetricTypeSum:
|
||||
destSum := dest.SetEmptySum()
|
||||
destSum.SetAggregationTemporality(ms.Sum().AggregationTemporality())
|
||||
destSum.SetIsMonotonic(ms.Sum().IsMonotonic())
|
||||
return splitNumberDataPoints(ms.Sum().DataPoints(), destSum.DataPoints(), size)
|
||||
case pmetric.MetricDataTypeHistogram:
|
||||
case pmetric.MetricTypeHistogram:
|
||||
destHistogram := dest.SetEmptyHistogram()
|
||||
destHistogram.SetAggregationTemporality(ms.Histogram().AggregationTemporality())
|
||||
return splitHistogramDataPoints(ms.Histogram().DataPoints(), destHistogram.DataPoints(), size)
|
||||
case pmetric.MetricDataTypeExponentialHistogram:
|
||||
case pmetric.MetricTypeExponentialHistogram:
|
||||
destHistogram := dest.SetEmptyExponentialHistogram()
|
||||
destHistogram.SetAggregationTemporality(ms.ExponentialHistogram().AggregationTemporality())
|
||||
return splitExponentialHistogramDataPoints(ms.ExponentialHistogram().DataPoints(), destHistogram.DataPoints(), size)
|
||||
case pmetric.MetricDataTypeSummary:
|
||||
case pmetric.MetricTypeSummary:
|
||||
return splitSummaryDataPoints(ms.Summary().DataPoints(), dest.SetEmptySummary().DataPoints(), size)
|
||||
}
|
||||
return size, false
|
||||
|
|
|
|||
Loading…
Reference in New Issue