Skip to content

Commit

Permalink
[pkg/otlp/metrics] Add support for NoRecordedValue flag (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed May 17, 2024
1 parent 90e0f33 commit 408e1b1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .chloggen/mx-psi_no-recorded-flag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component (e.g. pkg/quantile)
component: pkg/otlp/metrics

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Ignore metric datapoints with 'no recorded value' flag

# The PR related to this change
issues: [330]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
- This flag is not supported by Datadog, so we just ignore these datapoints.
20 changes: 20 additions & 0 deletions pkg/otlp/metrics/metrics_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func (t *Translator) mapNumberMetrics(

for i := 0; i < slice.Len(); i++ {
p := slice.At(i)
if p.Flags().NoRecordedValue() {
// No recorded value, skip.
continue
}

pointDims := dims.WithAttributeMap(p.Attributes())
var val float64
switch p.ValueType() {
Expand Down Expand Up @@ -203,6 +208,11 @@ func (t *Translator) mapNumberMonotonicMetrics(
) {
for i := 0; i < slice.Len(); i++ {
p := slice.At(i)
if p.Flags().NoRecordedValue() {
// No recorded value, skip.
continue
}

ts := uint64(p.Timestamp())
startTs := uint64(p.StartTimestamp())
pointDims := dims.WithAttributeMap(p.Attributes())
Expand Down Expand Up @@ -450,6 +460,11 @@ func (t *Translator) mapHistogramMetrics(
) {
for i := 0; i < slice.Len(); i++ {
p := slice.At(i)
if p.Flags().NoRecordedValue() {
// No recorded value, skip.
continue
}

startTs := uint64(p.StartTimestamp())
ts := uint64(p.Timestamp())
pointDims := dims.WithAttributeMap(p.Attributes())
Expand Down Expand Up @@ -554,6 +569,11 @@ func (t *Translator) mapSummaryMetrics(

for i := 0; i < slice.Len(); i++ {
p := slice.At(i)
if p.Flags().NoRecordedValue() {
// No recorded value, skip.
continue
}

startTs := uint64(p.StartTimestamp())
ts := uint64(p.Timestamp())
pointDims := dims.WithAttributeMap(p.Attributes())
Expand Down
34 changes: 34 additions & 0 deletions pkg/otlp/metrics/metrics_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,40 @@ func TestMapIntMonotonicWithRebootWithinSlice(t *testing.T) {
})
}

// This test checks that in the case of a reboot within a NumberDataPointSlice,
// we cache the value but we do NOT compute first value for the value at reset.
func TestMapIntMonotonicWithNoRecordedValueWithinSlice(t *testing.T) {

buildMonotonicWithNoRecorded := func() (slice pmetric.NumberDataPointSlice) {
values := []int64{0, 30, 0, 40}
slice = pmetric.NewNumberDataPointSlice()
slice.EnsureCapacity(len(values))

for i, val := range values {
point := slice.AppendEmpty()
point.SetTimestamp(seconds(i * 10))
point.SetIntValue(val)
}

var flags pmetric.DataPointFlags
slice.At(2).SetFlags(flags.WithNoRecordedValue(true))
return
}

slice := buildMonotonicWithNoRecorded()
ctx := context.Background()
tr := newTranslator(t, zap.NewNop())
consumer := &mockTimeSeriesConsumer{}
tr.mapNumberMonotonicMetrics(ctx, consumer, exampleDims, slice)
assert.ElementsMatch(t,
consumer.metrics,
[]metric{
newCount(exampleDims, uint64(seconds(10)), 30),
newCount(exampleDims, uint64(seconds(30)), 10),
},
)
}

// This test checks that in the case of a reboot at the first point in a NumberDataPointSlice:
// - diff: we cache the value AND compute first value
// - rate: we cache the value AND don't compute first value
Expand Down

0 comments on commit 408e1b1

Please sign in to comment.