Skip to content
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
27 changes: 27 additions & 0 deletions .chloggen/signaltometrics-sum-monotonic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
component: connector/signal_to_metrics

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add `sum.monotonic` property for improved counter handling

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [45865]

# (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: ''

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: ['user']
6 changes: 6 additions & 0 deletions connector/signaltometricsconnector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,25 @@ signal_to_metrics:
description: Count of spans
sum:
value: Int(AdjustedCount()) # Count of total spans represented by each span
monotonic: true
datapoints:
- name: datapoint.count
description: Count of datapoints
sum:
value: "1" # increment by 1 for each datapoint
monotonic: true
logs:
- name: logrecord.count
description: Count of log records
sum:
value: "1" # increment by 1 for each log record
monotonic: true
profiles:
- name: profile.count
description: Count of profiles
sum:
value: "1" # increment by 1 for each profile
monotonic: true
```

### Error Handling
Expand Down Expand Up @@ -104,13 +108,15 @@ Sum metrics have the following configurations:
```yaml
sum:
value: <ottl_value_expression>
monotonic: <bool>
```

- [**Required**] `value` represents an OTTL expression to extract a value from the
incoming data. Only OTTL expressions that return a value are accepted. The
returned value determines the value type of the `sum` metric (`int` or `double`).
[OTTL converters](https://pkg.go.dev/github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlfuncs#readme-converters)
can be used to transform the data.
- [**Optional**] `monotonic` whether the generated metric is monotonic. It defaults to `false`.

#### Gauge

Expand Down
3 changes: 2 additions & 1 deletion connector/signaltometricsconnector/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ type ExponentialHistogram struct {
}

type Sum struct {
Value string `mapstructure:"value"`
Value string `mapstructure:"value"`
IsMonotonic bool `mapstructure:"monotonic"`
// prevent unkeyed literal initialization
_ struct{}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,7 @@ $defs:
sum:
type: object
properties:
monotonic:
type: boolean
value:
type: string
9 changes: 6 additions & 3 deletions connector/signaltometricsconnector/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func TestConfig(t *testing.T) {
`IsDouble(attributes["some.optional.1"])`,
},
Sum: configoptional.Some(Sum{
Value: `attributes["some.optional.1"]`,
Value: `attributes["some.optional.1"]`,
IsMonotonic: false,
}),
},
},
Expand All @@ -200,7 +201,8 @@ func TestConfig(t *testing.T) {
`attributes["some.optional.1"] != nil`,
},
Sum: configoptional.Some(Sum{
Value: "1",
Value: "1",
IsMonotonic: true,
}),
},
},
Expand All @@ -218,7 +220,8 @@ func TestConfig(t *testing.T) {
`duration_unix_nano > 0`,
},
Sum: configoptional.Some(Sum{
Value: "1",
Value: "1",
IsMonotonic: true,
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (a *Aggregator[K]) Finalize(mds []model.MetricDef[K]) {
destMetric.SetDescription(md.Key.Description)
destCounter := destMetric.SetEmptySum()
destCounter.SetAggregationTemporality(pmetric.AggregationTemporalityDelta)
destCounter.SetIsMonotonic(md.Sum.IsMonotonic)
destCounter.DataPoints().EnsureCapacity(len(dpMap))
for _, dp := range dpMap {
dp.Copy(a.timestamp, destCounter.DataPoints().AppendEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (h *ExponentialHistogram[K]) fromConfig(
}

type Sum[K any] struct {
Value *ottl.ValueExpression[K]
Value *ottl.ValueExpression[K]
IsMonotonic bool
}

func (s *Sum[K]) fromConfig(
Expand All @@ -103,6 +104,7 @@ func (s *Sum[K]) fromConfig(
if err != nil {
return fmt.Errorf("failed to parse value OTTL expression for sum: %w", err)
}
s.IsMonotonic = mi.IsMonotonic
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ signal_to_metrics:
- IsDouble(attributes["some.optional.1"])
sum:
value: attributes["some.optional.1"]
monotonic: false
logs:
- name: log.sum
description: Sum
Expand All @@ -69,6 +70,7 @@ signal_to_metrics:
- attributes["some.optional.1"] != nil
sum:
value: "1"
monotonic: true
profiles:
- name: profile.sum
description: Sum
Expand All @@ -85,3 +87,4 @@ signal_to_metrics:
- duration_unix_nano > 0
sum:
value: "1"
monotonic: true
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ signal_to_metrics:
description: Count total number of log records
sum:
value: "1"
monotonic: true
- name: total.logrecords.resource.foo.sum
description: Count total number of log records with resource attribute foo
include_resource_attributes:
- key: resource.foo
sum:
value: "1"
monotonic: true
- name: log.foo.sum
description: Count total number of log records as per log.foo attribute
attributes:
- key: log.foo
sum:
value: "1"
monotonic: true
- name: log.bar.sum
description: Count total number of log records as per log.bar attribute
conditions: # Will evaluate to true
Expand All @@ -25,6 +28,7 @@ signal_to_metrics:
- key: log.bar
sum:
value: "1"
monotonic: true
- name: ignored.sum
description: Will be ignored due to conditions evaluating to false
conditions: # Will evaluate to false
Expand All @@ -33,3 +37,4 @@ signal_to_metrics:
- key: log.bar
sum:
value: "2"
monotonic: true
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resourceMetrics:
dataPoints:
- asInt: "4"
timeUnixNano: "1000000"
isMonotonic: true
- description: Count total number of log records as per log.foo attribute
name: log.foo.sum
sum:
Expand All @@ -36,6 +37,7 @@ resourceMetrics:
value:
stringValue: notfoo
timeUnixNano: "1000000"
isMonotonic: true
- description: Count total number of log records as per log.bar attribute
name: log.bar.sum
sum:
Expand All @@ -53,6 +55,7 @@ resourceMetrics:
value:
stringValue: notbar
timeUnixNano: "1000000"
isMonotonic: true
scope:
name: github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector
- resource:
Expand All @@ -72,5 +75,6 @@ resourceMetrics:
dataPoints:
- asInt: "4"
timeUnixNano: "1000000"
isMonotonic: true
scope:
name: github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ resourceMetrics:
timeUnixNano: "1581452773000000789"
name: gauge-double
unit: "1"
- name: counter-int
- name: sum-int
sum:
aggregationTemporality: 2
dataPoints:
Expand All @@ -91,7 +91,7 @@ resourceMetrics:
stringValue: bar
startTimeUnixNano: "1581452772000000321"
timeUnixNano: "1581452773000000789"
- asInt: "456"
- asInt: "-456"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this break some other tests too? What's the rationale for this change of test value?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what is happening now, this specific test data was only used for counting. LGTM!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention was to make this test a generic 'sum' test case without specifying is_monotonic explicitly.

- name: non.monotonic.sum
description: A non-monotonic sum
conditions:
- metric.name == "sum-int"
sum:
value: datapoint.value_int
# monotonic: false by default

So I wanted to make sure that we are not testing only a 'special' case, in which all increments are positive, and the metric can go only up.

attributes:
- key: datapoint.foo
value:
Expand All @@ -111,7 +111,7 @@ resourceMetrics:
- asInt: "0"
startTimeUnixNano: "1581452772000000321"
timeUnixNano: "1581452773000000789"
isMonotonic: true
isMonotonic: false
unit: "1"
- name: counter-double
sum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ signal_to_metrics:
description: Count total number of datapoints
sum:
value: "1"
monotonic: true
- name: datapoint.foo.sum
description: Count total number of datapoints as per datapoint.foo attribute
attributes:
- key: datapoint.foo
sum:
value: "1"
monotonic: true
- name: datapoint.bar.sum
description: Count total number of datapoints as per datapoint.bar attribute
conditions: # Will evaluate to true
Expand All @@ -19,6 +21,7 @@ signal_to_metrics:
- key: datapoint.bar
sum:
value: "1"
monotonic: true
- name: ignored.sum
description: Will be ignored due to conditions evaluating to false
conditions: # Will evaluate to false
Expand All @@ -27,3 +30,11 @@ signal_to_metrics:
- key: datapoint.bar
sum:
value: "2"
monotonic: true
- name: non.monotonic.sum
description: A non-monotonic sum
conditions:
- metric.name == "sum-int"
sum:
value: datapoint.value_int
# monotonic: false by default
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resourceMetrics:
dataPoints:
- asInt: "24"
timeUnixNano: "1000000"
isMonotonic: true
- description: Count total number of datapoints as per datapoint.foo attribute
name: datapoint.foo.sum
sum:
Expand All @@ -36,6 +37,7 @@ resourceMetrics:
value:
stringValue: notfoo
timeUnixNano: "1000000"
isMonotonic: true
- description: Count total number of datapoints as per datapoint.bar attribute
name: datapoint.bar.sum
sum:
Expand All @@ -53,5 +55,14 @@ resourceMetrics:
value:
stringValue: notbar
timeUnixNano: "1000000"
isMonotonic: true
- description: A non-monotonic sum
name: non.monotonic.sum
sum:
aggregationTemporality: 1
dataPoints:
- asInt: "456"
timeUnixNano: "1000000"
isMonotonic: false
scope:
name: github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ signal_to_metrics:
description: Count total number of profiles
sum:
value: "1"
monotonic: true
- name: total.profiles.resource.foo.sum
description: Count total number of profiles with resource attribute foo
include_resource_attributes:
- key: resource.foo
sum:
value: "1"
monotonic: true
- name: profiles.foo.sum
description: Count total number of profiles as per profile.foo attribute
attributes:
- key: profile.foo
sum:
value: "1"
monotonic: true
- name: profiles.bar.sum
description: Count total number of profiles as per profiles.bar attribute
conditions: # Will evaluate to true
Expand All @@ -25,6 +28,7 @@ signal_to_metrics:
- key: profiles.bar
sum:
value: "1"
monotonic: true
- name: ignored.sum
description: Will be ignored due to conditions evaluating to false
conditions: # Will evaluate to false
Expand All @@ -33,3 +37,4 @@ signal_to_metrics:
- key: profiles.bar
sum:
value: "2"
monotonic: true
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resourceMetrics:
dataPoints:
- asInt: "3"
timeUnixNano: "1000000"
isMonotonic: true
- description: Count total number of profiles as per profile.foo attribute
name: profiles.foo.sum
sum:
Expand All @@ -30,6 +31,7 @@ resourceMetrics:
value:
stringValue: foo
timeUnixNano: "1000000"
isMonotonic: true
scope:
name: github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector
- resource:
Expand All @@ -49,5 +51,6 @@ resourceMetrics:
dataPoints:
- asInt: "3"
timeUnixNano: "1000000"
isMonotonic: true
scope:
name: github.com/open-telemetry/opentelemetry-collector-contrib/connector/signaltometricsconnector
Loading
Loading