Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pdata] Deprecate FlagsStruct in favor of Flags #5842

Merged
merged 6 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
- `component.ReceiverFactory.MetricsReceiverStability`
- `component.ReceiverFactory.LogsReceiverStability`
- Deprecate `obsreport.ProcessorSettings.Level` and `obsreport.ExporterSettings.Level`, use MetricsLevel from CreateSettings (#5824)
- Deprecates `FlagsStruct` in favor of `Flags` (#5842)
- `MetricDataPointFlagsStruct` -> `MetricDataPointFlags`
- `NewMetricDataPointFlagsStruct` -> `NewMetricDataPointFlags`
- `FlagsStruct` -> `Flags`

### 💡 Enhancements 💡

Expand Down
14 changes: 7 additions & 7 deletions pdata/internal/cmd/pdatagen/internal/metrics_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ var numberDataPoint = &messageValueStruct{
},
},
exemplarsField,
dataPointFlagsFieldStruct,
dataPointFlagsField,
},
}

Expand All @@ -288,7 +288,7 @@ var histogramDataPoint = &messageValueStruct{
bucketCountsField,
explicitBoundsField,
exemplarsField,
dataPointFlagsFieldStruct,
dataPointFlagsField,
&optionalPrimitiveValue{
fieldName: "Min",
fieldType: "Double",
Expand Down Expand Up @@ -363,7 +363,7 @@ var exponentialHistogramDataPoint = &messageValueStruct{
returnMessage: bucketsValues,
},
exemplarsField,
dataPointFlagsFieldStruct,
dataPointFlagsField,
&optionalPrimitiveValue{
fieldName: "Min",
fieldType: "Double",
Expand Down Expand Up @@ -422,7 +422,7 @@ var summaryDataPoint = &messageValueStruct{
originFieldName: "QuantileValues",
returnSlice: quantileValuesSlice,
},
dataPointFlagsFieldStruct,
dataPointFlagsField,
},
}

Expand Down Expand Up @@ -489,11 +489,11 @@ var exemplar = &messageValueStruct{
},
}

var dataPointFlagsFieldStruct = &messageValueField{
fieldName: "FlagsStruct",
var dataPointFlagsField = &messageValueField{
fieldName: "Flags",
originFieldName: "Flags",
returnMessage: &messageValueStruct{
structName: "MetricDataPointFlagsStruct",
structName: "MetricDataPointFlags",
originFullName: "uint32",
},
}
Expand Down
32 changes: 16 additions & 16 deletions pdata/internal/generated_pmetric.go

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

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

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

48 changes: 36 additions & 12 deletions pdata/internal/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,50 +183,74 @@ func (at MetricAggregationTemporality) String() string {
return otlpmetrics.AggregationTemporality(at).String()
}

// MetricDataPointFlagsStruct defines how a metric aggregator reports aggregated values.
// FlagsStruct returns the flagsstruct associated with this NumberDataPoint.
// Deprecated [0.58.0] Use Flags() instead
func (ms NumberDataPoint) FlagsStruct() MetricDataPointFlags {
return ms.Flags()
}

// FlagsStruct returns the flagsstruct associated with this HistogramDataPoint.
// Deprecated [0.58.0] Use Flags() instead
func (ms HistogramDataPoint) FlagsStruct() MetricDataPointFlags {
return ms.Flags()
}

// FlagsStruct returns the flagsstruct associated with this ExponentialHistogramDataPoint.
// Deprecated [0.58.0] Use Flags() instead
func (ms ExponentialHistogramDataPoint) FlagsStruct() MetricDataPointFlags {
return ms.Flags()
}

// FlagsStruct returns the flagsstruct associated with this SummaryDataPoint.
// Deprecated [0.58.0] Use Flags() instead
func (ms SummaryDataPoint) FlagsStruct() MetricDataPointFlags {
return ms.Flags()
}

// MetricDataPointFlags defines how a metric aggregator reports aggregated values.
// It describes how those values relate to the time interval over which they are aggregated.
//
// This is a reference type, if passed by value and callee modifies it the
// caller will see the modification.
//
// Must use NewMetricDataPointFlagsStruct function to create new instances.
// Important: zero-initialized instance is not valid for use.
type MetricDataPointFlagsStruct struct {
type MetricDataPointFlags struct {
orig *uint32
}

func newMetricDataPointFlagsStruct(orig *uint32) MetricDataPointFlagsStruct {
return MetricDataPointFlagsStruct{orig: orig}
func newMetricDataPointFlags(orig *uint32) MetricDataPointFlags {
return MetricDataPointFlags{orig: orig}
}

// NewMetricDataPointFlagsStruct creates a new empty MetricDataPointFlagsStruct.
// NewMetricDataPointFlags creates a new empty MetricDataPointFlags.
//
// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice,
// OR directly access the member if this is embedded in another struct.
func NewMetricDataPointFlagsStruct() MetricDataPointFlagsStruct {
return newMetricDataPointFlagsStruct(new(uint32))
func NewMetricDataPointFlags() MetricDataPointFlags {
return newMetricDataPointFlags(new(uint32))
}

// MoveTo moves all properties from the current struct to dest
// resetting the current instance to its zero value
func (ms MetricDataPointFlagsStruct) MoveTo(dest MetricDataPointFlagsStruct) {
func (ms MetricDataPointFlags) MoveTo(dest MetricDataPointFlags) {
*dest.orig = *ms.orig
*ms.orig = uint32(otlpmetrics.DataPointFlags_FLAG_NONE)
}

// CopyTo copies all properties from the current struct to the dest.
func (ms MetricDataPointFlagsStruct) CopyTo(dest MetricDataPointFlagsStruct) {
func (ms MetricDataPointFlags) CopyTo(dest MetricDataPointFlags) {
*dest.orig = *ms.orig
}

// NoRecordedValue returns true if the MetricDataPointFlags contains the NO_RECORDED_VALUE flag.
func (ms MetricDataPointFlagsStruct) NoRecordedValue() bool {
func (ms MetricDataPointFlags) NoRecordedValue() bool {
return *ms.orig&uint32(otlpmetrics.DataPointFlags_FLAG_NO_RECORDED_VALUE) != 0
}

// SetNoRecordedValue sets the FLAG_NO_RECORDED_VALUE flag if true and removes it if false.
// Setting this Flag when it is already set will change nothing.
func (ms MetricDataPointFlagsStruct) SetNoRecordedValue(b bool) {
func (ms MetricDataPointFlags) SetNoRecordedValue(b bool) {
if b {
*ms.orig |= uint32(otlpmetrics.DataPointFlags_FLAG_NO_RECORDED_VALUE)
} else {
Expand All @@ -235,7 +259,7 @@ func (ms MetricDataPointFlagsStruct) SetNoRecordedValue(b bool) {
}

// String returns the string representation of the MetricDataPointFlags.
func (ms MetricDataPointFlagsStruct) String() string {
func (ms MetricDataPointFlags) String() string {
return otlpmetrics.DataPointFlags(*ms.orig).String()
}

Expand Down
42 changes: 21 additions & 21 deletions pdata/internal/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,23 +691,23 @@ func TestMetricsClone(t *testing.T) {
func TestMetricsDataPointFlags(t *testing.T) {
gauge := generateTestGauge()

assert.False(t, gauge.DataPoints().At(0).FlagsStruct().NoRecordedValue())
assert.Equal(t, "FLAG_NONE", gauge.DataPoints().At(0).FlagsStruct().String())

gauge.DataPoints().At(1).FlagsStruct().SetNoRecordedValue(true)
assert.True(t, gauge.DataPoints().At(1).FlagsStruct().NoRecordedValue())
assert.Equal(t, "FLAG_NO_RECORDED_VALUE", gauge.DataPoints().At(1).FlagsStruct().String())
gauge.DataPoints().At(1).FlagsStruct().SetNoRecordedValue(false)
assert.False(t, gauge.DataPoints().At(1).FlagsStruct().NoRecordedValue())

gauge.DataPoints().At(1).FlagsStruct().SetNoRecordedValue(true)
gauge.DataPoints().At(1).FlagsStruct().SetNoRecordedValue(true)
assert.True(t, gauge.DataPoints().At(1).FlagsStruct().NoRecordedValue())

gauge.DataPoints().At(0).FlagsStruct().SetNoRecordedValue(true)
gauge.DataPoints().At(0).FlagsStruct().MoveTo(gauge.DataPoints().At(1).FlagsStruct())
assert.False(t, gauge.DataPoints().At(0).FlagsStruct().NoRecordedValue())
assert.True(t, gauge.DataPoints().At(1).FlagsStruct().NoRecordedValue())
assert.False(t, gauge.DataPoints().At(0).Flags().NoRecordedValue())
assert.Equal(t, "FLAG_NONE", gauge.DataPoints().At(0).Flags().String())

gauge.DataPoints().At(1).Flags().SetNoRecordedValue(true)
assert.True(t, gauge.DataPoints().At(1).Flags().NoRecordedValue())
assert.Equal(t, "FLAG_NO_RECORDED_VALUE", gauge.DataPoints().At(1).Flags().String())
gauge.DataPoints().At(1).Flags().SetNoRecordedValue(false)
assert.False(t, gauge.DataPoints().At(1).Flags().NoRecordedValue())

gauge.DataPoints().At(1).Flags().SetNoRecordedValue(true)
gauge.DataPoints().At(1).Flags().SetNoRecordedValue(true)
assert.True(t, gauge.DataPoints().At(1).Flags().NoRecordedValue())

gauge.DataPoints().At(0).Flags().SetNoRecordedValue(true)
gauge.DataPoints().At(0).Flags().MoveTo(gauge.DataPoints().At(1).Flags())
assert.False(t, gauge.DataPoints().At(0).Flags().NoRecordedValue())
assert.True(t, gauge.DataPoints().At(1).Flags().NoRecordedValue())
}

func BenchmarkMetricsClone(b *testing.B) {
Expand Down Expand Up @@ -1016,12 +1016,12 @@ func generateMetricsEmptyDataPoints() Metrics {
}}
}

func fillTestMetricDataPointFlagsStruct(tv MetricDataPointFlagsStruct) {
func fillTestMetricDataPointFlags(tv MetricDataPointFlags) {
*tv.orig = uint32(otlpmetrics.DataPointFlags_FLAG_NONE)
}

func generateTestMetricDataPointFlagsStruct() MetricDataPointFlagsStruct {
tv := NewMetricDataPointFlagsStruct()
fillTestMetricDataPointFlagsStruct(tv)
func generateTestMetricDataPointFlags() MetricDataPointFlags {
tv := NewMetricDataPointFlags()
fillTestMetricDataPointFlags(tv)
return tv
}
Loading