Skip to content

Commit

Permalink
[pdata] Split pmetric.MetricValueType into specific types (#5233)
Browse files Browse the repository at this point in the history
Split `pmetric.MetricValueType` into `NumberDataPointValueType` and `ExemplarValueType`

1. `NumberDataPoint.ValueType()` now returns a `NumberDataPointValueType` that can be `NumberDataPointValueTypeInt` or `NumberDataPointValueTypeDouble`.

2. `pmetric.Exemplar.ValueType()` now returns a `ExemplarValueType` that can be `ExemplarValueInt` or `ExemplarValueDouble`.

1 Use case is the most common. Thats why we are keeping backward compatibility for it. 2 is rarely being used. So we don't keep backward compatibility for it to avoid mixing the split types.

Co-authored-by: Alex Boten <aboten@lightstep.com>
  • Loading branch information
dmitryax and Alex Boten committed Apr 20, 2022
1 parent 87069a8 commit 24cf5c4
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 48 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Remove pdata deprecated funcs from 2 versions (v0.48.0) ago. (#5219)
- Remove non pdata deprecated funcs/structs (#5220)
- `pmetric.Exemplar.ValueType()` now returns new type `ExemplarValueType` (#5233)

### 🚩 Deprecations 🚩

Expand All @@ -15,6 +16,11 @@
- `plogotlp.Request.SetLogs` func is deprecated in favor of `plogotlp.NewRequestFromLogs`
- `pmetricotlp.Request.SetMetrics` func is deprecated in favor of `pmetricotlp.NewRequestFromMetrics`
- `ptraceotlp.Request.SetTraces` func is deprecated in favor of `ptraceotlp.NewRequestFromTraces`
- `pmetric.NumberDataPoint.ValueType()` now returns new type `NumberDataPointValueType` (#5233)
- `pmetric.MetricValueType` is deprecated in favor of `NumberDataPointValueType`
- `pmetric.MetricValueTypeNone` is deprecated in favor of `NumberDataPointValueTypeNone`
- `pmetric.MetricValueTypeInt` is deprecated in favor of `NumberDataPointValueTypeInt`
- `pmetric.MetricValueTypeDouble` is deprecated in favor of `NumberDataPointValueTypeDouble`

### 💡 Enhancements 💡

Expand Down
4 changes: 2 additions & 2 deletions internal/otlptext/databuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func (b *dataBuffer) logNumberDataPoints(ps pmetric.NumberDataPointSlice) {
b.logEntry("StartTimestamp: %s", p.StartTimestamp())
b.logEntry("Timestamp: %s", p.Timestamp())
switch p.ValueType() {
case pmetric.MetricValueTypeInt:
case pmetric.NumberDataPointValueTypeInt:
b.logEntry("Value: %d", p.IntVal())
case pmetric.MetricValueTypeDouble:
case pmetric.NumberDataPointValueTypeDouble:
b.logEntry("Value: %f", p.DoubleVal())
}
}
Expand Down
8 changes: 4 additions & 4 deletions model/pdata/metrics_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ const (

// MetricValueType is an alias for pmetric.MetricValueType type.
// Deprecated: [v0.49.0] Use pmetric.MetricValueType instead.
type MetricValueType = pmetric.MetricValueType
type MetricValueType = pmetric.MetricValueType //nolint:staticcheck

const (

// Deprecated: [v0.49.0] Use pmetric.MetricValueTypeNone instead.
MetricValueTypeNone = pmetric.MetricValueTypeNone
MetricValueTypeNone = pmetric.MetricValueTypeNone //nolint:staticcheck

// Deprecated: [v0.49.0] Use pmetric.MetricValueTypeInt instead.
MetricValueTypeInt = pmetric.MetricValueTypeInt
MetricValueTypeInt = pmetric.MetricValueTypeInt //nolint:staticcheck

// Deprecated: [v0.49.0] Use pmetric.MetricValueTypeDouble instead.
MetricValueTypeDouble = pmetric.MetricValueTypeDouble
MetricValueTypeDouble = pmetric.MetricValueTypeDouble //nolint:staticcheck
)
4 changes: 2 additions & 2 deletions pdata/internal/cmd/pdatagen/internal/metrics_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ var numberDataPoint = &messageValueStruct{
startTimeField,
timeField,
&oneOfField{
typeName: "MetricValueType",
typeName: "NumberDataPointValueType",
originFieldName: "Value",
originTypePrefix: "otlpmetrics.NumberDataPoint_",
testValueIdx: 0, // Double
Expand Down Expand Up @@ -412,7 +412,7 @@ var exemplar = &messageValueStruct{
fields: []baseField{
timeField,
&oneOfField{
typeName: "MetricValueType",
typeName: "ExemplarValueType",
originFieldName: "Value",
originTypePrefix: "otlpmetrics.Exemplar_",
testValueIdx: 1, // Int
Expand Down
24 changes: 12 additions & 12 deletions pdata/internal/generated_pmetric.go

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

16 changes: 8 additions & 8 deletions pdata/internal/generated_pmetric_test.go

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

44 changes: 33 additions & 11 deletions pdata/internal/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,45 @@ const (
MetricDataPointFlagNoRecordedValue = MetricDataPointFlag(otlpmetrics.DataPointFlags_FLAG_NO_RECORDED_VALUE)
)

// MetricValueType specifies the type of NumberDataPoint.
type MetricValueType int32
// NumberDataPointValueType specifies the type of NumberDataPoint value.
type NumberDataPointValueType int32

const (
MetricValueTypeNone MetricValueType = iota
MetricValueTypeInt
MetricValueTypeDouble
NumberDataPointValueTypeNone NumberDataPointValueType = iota
NumberDataPointValueTypeInt
NumberDataPointValueTypeDouble
)

// String returns the string representation of the MetricValueType.
func (mdt MetricValueType) String() string {
switch mdt {
case MetricValueTypeNone:
// String returns the string representation of the NumberDataPointValueType.
func (nt NumberDataPointValueType) String() string {
switch nt {
case NumberDataPointValueTypeNone:
return "None"
case NumberDataPointValueTypeInt:
return "Int"
case NumberDataPointValueTypeDouble:
return "Double"
}
return ""
}

// ExemplarValueType specifies the type of Exemplar measurement value.
type ExemplarValueType int32

const (
ExemplarValueTypeNone ExemplarValueType = iota
ExemplarValueTypeInt
ExemplarValueTypeDouble
)

// String returns the string representation of the ExemplarValueType.
func (nt ExemplarValueType) String() string {
switch nt {
case ExemplarValueTypeNone:
return "None"
case MetricValueTypeInt:
case ExemplarValueTypeInt:
return "Int"
case MetricValueTypeDouble:
case ExemplarValueTypeDouble:
return "Double"
}
return ""
Expand Down
17 changes: 12 additions & 5 deletions pdata/internal/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ func TestMetricDataTypeString(t *testing.T) {
assert.Equal(t, "", (MetricDataTypeSummary + 1).String())
}

func TestPointMetricValueTypeString(t *testing.T) {
assert.Equal(t, "None", MetricValueTypeNone.String())
assert.Equal(t, "Int", MetricValueTypeInt.String())
assert.Equal(t, "Double", MetricValueTypeDouble.String())
assert.Equal(t, "", (MetricValueTypeDouble + 1).String())
func TestNumberDataPointValueTypeString(t *testing.T) {
assert.Equal(t, "None", NumberDataPointValueTypeNone.String())
assert.Equal(t, "Int", NumberDataPointValueTypeInt.String())
assert.Equal(t, "Double", NumberDataPointValueTypeDouble.String())
assert.Equal(t, "", (NumberDataPointValueTypeDouble + 1).String())
}

func TestExemplarValueTypeString(t *testing.T) {
assert.Equal(t, "None", ExemplarValueTypeNone.String())
assert.Equal(t, "Int", ExemplarValueTypeInt.String())
assert.Equal(t, "Double", ExemplarValueTypeDouble.String())
assert.Equal(t, "", (ExemplarValueTypeDouble + 1).String())
}

func TestResourceMetricsWireCompatibility(t *testing.T) {
Expand Down
32 changes: 28 additions & 4 deletions pdata/pmetric/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,34 @@ const (
)

// MetricValueType specifies the type of NumberDataPoint.
type MetricValueType = internal.MetricValueType
// Deprecated: [v0.50.0] Use NumberDataPointValueType or ExemplarValueType instead.
type MetricValueType = internal.NumberDataPointValueType

const (
MetricValueTypeNone = internal.MetricValueTypeNone
MetricValueTypeInt = internal.MetricValueTypeInt
MetricValueTypeDouble = internal.MetricValueTypeDouble
// Deprecated: [v0.50.0] Use NumberDataPointValueTypeNone instead.
MetricValueTypeNone = internal.NumberDataPointValueTypeNone

// Deprecated: [v0.50.0] Use NumberDataPointValueTypeInt.
MetricValueTypeInt = internal.NumberDataPointValueTypeInt

// Deprecated: [v0.50.0] Use NumberDataPointValueTypeDouble instead.
MetricValueTypeDouble = internal.NumberDataPointValueTypeDouble
)

// NumberDataPointValueType specifies the type of NumberDataPoint value.
type NumberDataPointValueType = internal.NumberDataPointValueType

const (
NumberDataPointValueTypeNone = internal.NumberDataPointValueTypeNone
NumberDataPointValueTypeInt = internal.NumberDataPointValueTypeInt
NumberDataPointValueTypeDouble = internal.NumberDataPointValueTypeDouble
)

// ExemplarValueType specifies the type of Exemplar measurement value.
type ExemplarValueType = internal.ExemplarValueType

const (
ExemplarValueTypeNone = internal.ExemplarValueTypeNone
ExemplarValueTypeInt = internal.ExemplarValueTypeInt
ExemplarValueTypeDouble = internal.ExemplarValueTypeDouble
)

0 comments on commit 24cf5c4

Please sign in to comment.