Static labels disappear when being copied from one processor to another in a chain
- Dominant language
- C
- Stars
- 8.1k
- Forks
- 2k
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 71
Description
## Bug Report
**Describe the bug**
When multiple `labels` metric processors are chained, `upsert` labels created by an earlier processor disappear.
The processor creates a new CMetrics context and copies the previous one with `cmt_cat()`:
https://github.com/fluent/fluent-bit/blob/master/plugins/processor_labels/labels.c
`cmt_cat()` does not copy CMetrics static labels:
https://github.com/fluent/fluent-bit/blob/master/lib/cmetrics/src/cmt_cat.c
**To Reproduce**
```text
test_metric{original="value"} 1
````
```yaml
pipeline:
inputs:
- name: prometheus_scrape
tag: test
host: 127.0.0.1
port: 9090
processors:
metrics:
- name: labels
upsert: "first one"
- name: labels
upsert: "second two"
outputs:
- name: prometheus_exporter
match: test
port: 2021
```
**Expected**
```text
test_metric{original="value",first="one",second="two"} 1
```
**Actual**
```text
test_metric{original="value",second="two"} 1
```
**Your Environment**
* Version: `5.1-debug`
* Plugins: `prometheus_scrape`, `labels`, `prometheus_exporter`
Contributor guide
Research direction
Start with plugins/processor_labels/labels.c to trace how a chained processor creates and copies the CMetrics context, then read lib/cmetrics/src/cmt_cat.c and its related tests. Reproduce the two-processor configuration from the report and verify that static labels from earlier processors remain in the final metric, adding or updating focused tests for the expected labels.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- observability-sre, stream-processing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100