You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixesopen-telemetry#20284
This introduces initial support for retrieving rows from SQL databases
into logs.
This PR aims to provide an initial, not feature rich, but production
ready implementation. The following features are available:
- Use `body_column` to select the column to use to fill the Body field
of the created log
- Use `tracking_start_value` and `tracking_column` properties to track
rows that were already ingested
- Use `storage` property to persist the tracking value across collector
restarts
In this state and marked as "development" stability, the component can
be used for experimentation and to guide future development.
There are definitely more things that need to be implemented for this
component to be considered "alpha" quality - like filling in other [log
fields](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.21.0/specification/logs/data-model.md#log-and-event-record-definition)
like Timestamp, ObservedTimestamp and others. I would like to add them
in subsequent pull requests, as this pull request is already way too
big.
---------
Co-authored-by: Dominika Molenda <[email protected]>
Co-authored-by: Dominika Molenda <[email protected]>
Co-authored-by: Katarzyna Kujawa <[email protected]>
Co-authored-by: Katarzyna Kujawa <[email protected]>
@@ -28,29 +30,88 @@ The configuration supports the following top-level fields:
28
30
a driver-specific string usually consisting of at least a database name and connection information. This is sometimes
29
31
referred to as the "connection string" in driver documentation.
30
32
e.g. _host=localhost port=5432 user=me password=s3cr3t sslmode=disable_
31
-
-`queries`(required): A list of queries, where a query is a sql statement and one or more metrics (details below).
33
+
-`queries`(required): A list of queries, where a query is a sql statement and one or more `logs` and/or `metrics` sections (details below).
32
34
-`collection_interval`(optional): The time interval between query executions. Defaults to _10s_.
35
+
-`storage` (optional, default `""`): The ID of a [storage][storage_extension] extension to be used to [track processed results](#tracking-processed-results).
- sql: "select count(*) as count, genre from movie group by genre"
69
+
metrics:
70
+
- metric_name: movie.genres
71
+
value_column: "count"
72
+
```
73
+
74
+
#### Logs Queries
75
+
76
+
The `logs` section is in development.
77
+
78
+
- `body_column`(required) defines the column to use as the log record's body.
79
+
80
+
##### Tracking processed results
81
+
82
+
With the default configuration and a non-parameterized logs query like `select * from my_logs`,
83
+
the receiver will run the same query every collection interval, which can cause reading the same rows
84
+
over and over again, unless there's an external actor removing the old rows from the `my_logs` table.
85
+
86
+
To prevent reading the same rows on every collection interval, use a parameterized query like `select * from my_logs where id_column > ?`,
87
+
together with the `tracking_start_value` and `tracking_column` configuration properties.
88
+
The receiver will use the configured `tracking_start_value` as the value for the query parameter when running the query for the first time.
89
+
After each query run, the receiver will store the value of the `tracking_column` from the last row of the result set and use it as the value for the query parameter on next collection interval. To prevent duplicate log downloads, make sure to sort the query results in ascending order by the tracking_column value.
90
+
91
+
Note that the notation for the parameter depends on the database backend. For example in MySQL this is `?`, in PostgreSQL this is `$1`, in Oracle this is any string identifier starting with a colon `:`, for example `:my_parameter`.
92
+
93
+
Use the `storage` configuration property of the receiver to persist the tracking value across collector restarts.
94
+
95
+
#### Metrics queries
96
+
97
+
Each `metrics` section consists of a
37
98
`metric_name`, a `value_column`, and additional optional fields.
38
99
Each _metric_ in the configuration will produce one OTel metric per row returned from its sql query.
39
100
40
-
*`metric_name`(required): the name assigned to the OTel metric.
41
-
*`value_column`(required): the column name in the returned dataset used to set the value of the metric's datapoint.
101
+
-`metric_name`(required): the name assigned to the OTel metric.
102
+
-`value_column`(required): the column name in the returned dataset used to set the value of the metric's datapoint.
42
103
This may be case-sensitive, depending on the driver (e.g. Oracle DB).
43
-
*`attribute_columns`(optional): a list of column names in the returned dataset used to set attibutes on the datapoint.
104
+
-`attribute_columns`(optional): a list of column names in the returned dataset used to set attibutes on the datapoint.
44
105
These attributes may be case-sensitive, depending on the driver (e.g. Oracle DB).
45
-
*`data_type` (optional): can be `gauge` or `sum`; defaults to `gauge`.
46
-
*`value_type` (optional): can be `int` or `double`; defaults to `int`.
47
-
*`monotonic` (optional): boolean; whether a cumulative sum's value is monotonically increasing (i.e. never rolls over
106
+
-`data_type` (optional): can be `gauge` or `sum`; defaults to `gauge`.
107
+
-`value_type` (optional): can be `int` or `double`; defaults to `int`.
108
+
-`monotonic` (optional): boolean; whether a cumulative sum's value is monotonically increasing (i.e. never rolls over
48
109
or resets); defaults to false.
49
-
*`aggregation` (optional): only applicable for `data_type=sum`; can be `cumulative` or `delta`; defaults
110
+
-`aggregation` (optional): only applicable for `data_type=sum`; can be `cumulative` or `delta`; defaults
50
111
to `cumulative`.
51
-
*`description` (optional): the description applied to the metric.
52
-
*`unit` (optional): the units applied to the metric.
53
-
*`static_attributes` (optional): static attributes applied to the metrics
112
+
-`description` (optional): the description applied to the metric.
113
+
-`unit` (optional): the units applied to the metric.
114
+
-`static_attributes` (optional): static attributes applied to the metrics
0 commit comments