Skip to content

Commit ad8da77

Browse files
committed
[chore] [mdatagen] Add docs for the new re-aggregation capability
1 parent ffebda4 commit ad8da77

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

cmd/mdatagen/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,94 @@ The `config` section is based on [JSON Schema standard](https://json-schema.org/
9898
- **Reusable definitions**: Define common schemas in `$defs` and reference them with `$ref`
9999
- **Schema composition**: Use `allOf` for complex configurations
100100

101+
### Metrics Builder Configuration
102+
103+
For receivers, scrapers, and other components that emit metrics, `mdatagen` can generate metrics builder
104+
configuration from `metadata.yaml`.
105+
106+
```yaml
107+
type: myreceiver
108+
status:
109+
class: receiver
110+
stability:
111+
beta: [metrics]
112+
113+
resource_attributes:
114+
transport:
115+
description: Transport used by the request.
116+
type: string
117+
enabled: true
118+
119+
attributes:
120+
status_code:
121+
description: Response status code.
122+
type: int
123+
requirement_level: opt_in
124+
125+
metrics:
126+
http.server.request.count:
127+
enabled: true
128+
description: Number of received requests.
129+
unit: "{request}"
130+
sum:
131+
value_type: int
132+
monotonic: true
133+
aggregation_temporality: cumulative
134+
attributes: [status_code]
135+
```
136+
137+
This lets users:
138+
139+
- enable or disable individual metrics
140+
- enable or disable resource attributes
141+
- use `metrics_include` and `metrics_exclude` on resource attributes to only emit metrics with matching resource attribute values
142+
143+
### Metric Reaggregation Configuration
144+
145+
Set `reaggregation_enabled: true` to let users reduce metric cardinality by dropping selected metric
146+
attributes and aggregating the resulting datapoints.
147+
148+
```yaml
149+
reaggregation_enabled: true
150+
151+
attributes:
152+
transport:
153+
description: Transport used by the request.
154+
type: string
155+
requirement_level: recommended
156+
status_code:
157+
description: Response status code.
158+
type: int
159+
requirement_level: opt_in
160+
```
161+
162+
This adds two per-metric settings for metrics that declare attributes:
163+
164+
- `attributes`: the subset of metric attributes to keep in the emitted metric stream
165+
- `aggregation_strategy`: how collapsed datapoints are merged, using `sum`, `avg`, `min`, or `max`
166+
167+
Defaults:
168+
169+
- sum metrics use `sum`; gauge metrics use `avg`
170+
- `required` attributes are always kept
171+
- `recommended` and `conditionally_required` attributes are kept by default, but users can remove them
172+
- `opt_in` attributes are omitted by default, so that dimension is aggregated unless the user adds it
173+
174+
Example user configuration:
175+
176+
```yaml
177+
receivers:
178+
myreceiver:
179+
metrics:
180+
http.server.request.count:
181+
enabled: true
182+
aggregation_strategy: sum
183+
attributes: [transport]
184+
```
185+
186+
In this example, datapoints that only differ by `status_code` are aggregated together, while
187+
`transport` remains part of the output identity.
188+
101189
### Feature Gates Documentation
102190

103191
The metadata generator supports automatic documentation generation for feature gates used by components. Feature gates are documented by adding a `feature_gates` section to your `metadata.yaml`:

cmd/mdatagen/metadata-schema.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ scope_name: string
1919
# Optional: The name of the package that mdatagen generates. If not set, the name "metadata" will be used.
2020
generated_package_name: string
2121

22+
# Optional: Enables per-metric reaggregation config generation for metrics with attributes.
23+
# When enabled, generated metrics config includes `aggregation_strategy` and `attributes`
24+
# fields that let users reduce metric cardinality by choosing which dimensions are kept.
25+
reaggregation_enabled: bool
26+
2227
# Required for components (Optional for subcomponents): A high-level view of the development status and use of this component
2328
status:
2429
# Required: The class of the component (For example receiver)

0 commit comments

Comments
 (0)