Skip to content

Commit

Permalink
[pdata] Deprecate FlagsStruct in favor of Flags (#5842)
Browse files Browse the repository at this point in the history
* Deprecate FlagsStruct in favor of Flags

* Updated changelog

* Fix lint

* Simplification

* Update pdata/pmetric/alias.go

Co-authored-by: Bogdan Drutu <lazy@splunk.com>

* Update pdata/pmetric/alias.go

Co-authored-by: Bogdan Drutu <lazy@splunk.com>

Co-authored-by: Bogdan Drutu <lazy@splunk.com>
  • Loading branch information
TylerHelmuth and Bogdan Drutu authored Aug 5, 2022
1 parent caffd41 commit aa6074d
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 74 deletions.
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

0 comments on commit aa6074d

Please sign in to comment.