| 1 |
# Scraping Metrics Receivers |
| 2 |
|
| 3 |
Scraping metrics receivers are receivers that pull data from external sources at regular intervals and translate it |
| 4 |
into [pdata](../pdata/README.md) which is sent further in the pipeline. The external source of metrics usually is a |
| 5 |
monitored system providing data about itself in some arbitrary format. There are two types of scraping metrics |
| 6 |
receivers: |
| 7 |
|
| 8 |
- **Generic scraping metrics receivers:** The set of metrics emitted by this type of receiver fully depends on the |
| 9 |
state of the external source and/or the user settings. Examples: |
| 10 |
- [Prometheus Receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/prometheusreceiver) |
| 11 |
- [SQL Query Receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sqlqueryreceiver) |
| 12 |
|
| 13 |
- **Built-in scraping metrics receivers:** Receivers of this type emit a predefined set of metrics. However, the |
| 14 |
metrics themselves are configurable via user settings. Examples of scrapings metrics receivers: |
| 15 |
- [Redis Receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/redisreceiver) |
| 16 |
- [Zookeeper Receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/zookeeperreceiver) |
| 17 |
|
| 18 |
This document covers built-in scraping metrics receivers. It defines which metrics these receivers can emit, |
| 19 |
defines stability guarantees and provides guidelines for metric updates. |
| 20 |
|
| 21 |
## Defining emitted metrics |
| 22 |
|
| 23 |
Each built-in scraping metrics receiver has a `metadata.yaml` file that MUST define all the metrics emitted by the |
| 24 |
receiver. The file is being used to generate an API for metrics recording, user settings to customize the emitted |
| 25 |
metrics and user documentation. The file schema is defined in |
| 26 |
https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/mdatagen/metadata-schema.yaml |
| 27 |
Defining a metric in `metadata.yaml` DOES NOT guarantee that the metric will always be produced by the receiver. In |
| 28 |
some cases it may be impossible to fetch particular metrics from a system in a particular state. |
| 29 |
|
| 30 |
There are two categories of the metrics emitted by scraping receivers: |
| 31 |
|
| 32 |
- **Default metrics**: emitted by default, but can be disabled in user settings. |
| 33 |
|
| 34 |
- **Optional metrics**: not emitted by default, but can be enabled in user settings. |
| 35 |
|
| 36 |
See also [Semantic Convention compatibility](./coding-guidelines.md#semantic-conventions-compatibility) guidance. |
| 37 |
|
| 38 |
### How to identify if new metric should be default or optional? |
| 39 |
|
| 40 |
There is no strict rule to differentiate default metrics from optional. As a rule of thumb, default metrics SHOULD be |
| 41 |
treated as metrics essential to determine healthiness of a particular monitored system. Optional metrics on the |
| 42 |
other hand SHOULD be treated as a source of additional information about the monitored system. |
| 43 |
|
| 44 |
Additionally, if any of the following conditions can be applied to a metric, it MUST be marked as optional: |
| 45 |
|
| 46 |
- **It is redundant with another metric.** For example system CPU usage can be emitted as two different metrics: |
| 47 |
`system.cpu.time` (CPU time reported as cumulative sum in seconds) or `system.cpu.utilization` (fraction of CPU |
| 48 |
time spent in different states reported as gauge), one of them has to be marked as option. |
| 49 |
- **It creates a disproportionately high cardinality of resources and/or data points.** |
| 50 |
- **There is a notable expected performance impact.** |
| 51 |
- **The source must be configured in an unusual way.** |
| 52 |
- **It requires dedicated configuration in the receiver.** |
| 53 |
|
| 54 |
## Stability levels of scraping receivers |
| 55 |
|
| 56 |
All the requirements defined for components in [the Collector's README](../README.md#stability-levels) are |
| 57 |
applicable to the scraping receivers as well. In addition, the following rules applied specifically to scraping |
| 58 |
metrics receivers: |
| 59 |
|
| 60 |
### Development |
| 61 |
|
| 62 |
The receiver is not ready for use. All the metrics emitted by the receiver are not finalized and can change in any way. |
| 63 |
|
| 64 |
### Alpha |
| 65 |
|
| 66 |
The receiver is ready for limited non-critical workloads. The list of emitted default metrics SHOULD be |
| 67 |
considered as complete, but any changes to the `metadata.yaml` still MAY be applied. |
| 68 |
|
| 69 |
### Beta |
| 70 |
|
| 71 |
The receiver is ready for non-critical production workloads. The list of emitted default metrics MUST be |
| 72 |
considered as complete. Breaking changes to the emitted metrics SHOULD be applied following [the deprecation |
| 73 |
process](#changing-the-emitted-metrics). |
| 74 |
|
| 75 |
### Stable |
| 76 |
|
| 77 |
The receiver is ready for production workloads. Breaking changes to the emitted metrics SHOULD be avoided. |
| 78 |
Nevertheless, metrics that are emitted by default MUST be always kept up-to-date with the latest stable version of the |
| 79 |
monitored system. Given that, occasional breaking changes in the emitted metrics are expected even in the stable |
| 80 |
receivers. Any breaking change MUST be applied following [the deprecation process](#changing-the-emitted-metrics). |
| 81 |
|
| 82 |
## Changing the emitted metrics |
| 83 |
|
| 84 |
Some changes are not considered breaking and can be applied to metrics emitted by scraping receivers of any |
| 85 |
stability level: |
| 86 |
|
| 87 |
- Adding a new optional metric. |
| 88 |
|
| 89 |
Most of other changes to the emitted metrics are considered breaking and MUST be handled according to the stability |
| 90 |
level of the receiver. Each type of breaking change defines a set of steps that MUST (or SHOULD) be applied across |
| 91 |
several releases for a Stable (or Beta) components. At least 3 versions SHOULD be kept between the steps to give |
| 92 |
users time to prepare, e.g. if the first step is released in v0.62.0, the second step SHOULD be released not earlier |
| 93 |
than 0.65.0. Any warnings SHOULD include the version starting from which the next step will take effect. If a |
| 94 |
breaking change is more complicated and many metrics are involved in the change, feature gates SHOULD be used instead. |
| 95 |
|
| 96 |
### Removing an optional metric |
| 97 |
|
| 98 |
Steps to remove an optional metric: |
| 99 |
|
| 100 |
1. Mark the metric as deprecated in `metadata.yaml` by adding "[DEPRECATED]" in its description. Show a warning that |
| 101 |
the metric will be removed if the `enabled` option is set explicitly to `true` in user settings. |
| 102 |
2. Remove the metric. |
| 103 |
|
| 104 |
### Removing a default metric |
| 105 |
|
| 106 |
Steps to remove a default metric: |
| 107 |
|
| 108 |
1. Mark the metric as deprecated in `metadata.yaml` by adding "[DEPRECATED]" in its description. Show a warning that |
| 109 |
the metric will be removed if the `enabled` option is not explicitly set to `false` in user settings. |
| 110 |
2. Make the metric optional. Show a warning that the metric will be removed if the `enabled` option is set to `true` |
| 111 |
in user settings. |
| 112 |
3. Remove the metric. |
| 113 |
|
| 114 |
### Making a default metric optional |
| 115 |
|
| 116 |
Steps to turn a metric from default to optional: |
| 117 |
|
| 118 |
1. Add a warning that the metric will be turned into optional if `enabled` field is not set explicitly to any value in |
| 119 |
user settings. Warning example: "WARNING: Metric `foo.bar` will be disabled by default in v0.65.0. If you want to |
| 120 |
keep it, please enable it explicitly in the receiver settings." |
| 121 |
2. Remove the warning and update `metadata.yaml` to make the metric optional. |
| 122 |
|
| 123 |
### Adding a new default metric or turning an existing optional metric into default |
| 124 |
|
| 125 |
Adding a new default metric is a breaking change for a scraping receiver because it introduces an unexpected output |
| 126 |
for users and additional load on metric backends. Steps to apply such a change: |
| 127 |
|
| 128 |
1. If the metric doesn't exist yet, add one as an optional metric. Add a warning that the metric will be turned into |
| 129 |
default if the `enabled` option is not set explicitly to any value in user settings. A warning example: "WARNING: |
| 130 |
Metric `foo.bar` will be enabled by default in v0.65.0. If you don't want the metric to be emitted, please |
| 131 |
disable it in the receiver settings." |
| 132 |
2. Remove the warning and update `metadata.yaml` to make the metric default. |
| 133 |
|
| 134 |
### Other changes |
| 135 |
|
| 136 |
Other breaking changes SHOULD follow similar strategies inspecting presence of `enabled` field in user settings. For |
| 137 |
example, if a metric has to be renamed for any reason, the guidelines for "Removing an optional metric" and "Adding a |
| 138 |
new default metric" SHOULD be followed simultaneously. |
| 139 |
|
| 140 |
Breaking changes that cannot be done through enabling/disabling metrics (e.g. removing or adding an extra attribute) |
| 141 |
SHOULD be applied using a feature gate with the following steps: |
| 142 |
|
| 143 |
1. Add a feature gate that is disabled by default. Enabling the feature gate changes the metrics behavior in a desired |
| 144 |
way. For example, if several metrics emitted by host metrics receiver need to be updated to have an additional |
| 145 |
`direction` attribute, the following feature gate can be used: |
| 146 |
`receiver.hostmetricsreceiver.emitMetricsWithDirectionAttribute`. Show user a warning if the feature gate is not |
| 147 |
enabled explicitly, for example: "[WARNING] Metrics `system.network.packets` and `system.network.errors` will be |
| 148 |
changed in v0.65.0 to emit an additional `direction` attribute, enable a feature gate |
| 149 |
`receiver.hostmetricsreceiver.emitMetricsWithDirectionAttribute` to apply and test the upcoming changes earlier". |
| 150 |
2. Enable the feature gate by default and update the warning thrown if user disables the feature gate explicitly. |
| 151 |
3. Remove the feature gate along with the old behavior. |