Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/sqlquery] add support for logs #20730

Merged
merged 60 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
03de16d
feat: add config option for logs
andrzej-stencel Apr 6, 2023
38bebb5
ci: add changelog entry
andrzej-stencel Apr 6, 2023
c7e54fc
style: apply Prettier's fixes in README.md
andrzej-stencel Apr 6, 2023
b0f213e
docs: add logs support to the status table
andrzej-stencel Apr 7, 2023
b093dc2
test: add integration tests for reading logs
andrzej-stencel Apr 7, 2023
d2e96d0
scrape logs
dmolenda-sumo Apr 13, 2023
831f1e0
read simple logs from database
dmolenda-sumo Apr 17, 2023
284a5ee
feat: panic on query errors from db
andrzej-stencel Apr 24, 2023
770dbc5
test: fix Oracle integration test
andrzej-stencel Apr 24, 2023
3efc74a
test(integration): expect 5 log records
andrzej-stencel Apr 25, 2023
ada5a55
feat: make body column configurable
andrzej-stencel Apr 25, 2023
8cb5fe4
feat: collect logs periodically
andrzej-stencel Apr 26, 2023
e8edb18
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel Apr 26, 2023
2da8e7b
refactor: go mod tidy
andrzej-stencel Apr 26, 2023
5213532
feat: support tracking processed rows
andrzej-stencel Apr 27, 2023
84e645b
fix: do not try to store tracking value when not configured
andrzej-stencel Apr 28, 2023
7fb2aa2
fix: initialize shutdown channel
andrzej-stencel Apr 28, 2023
cf12ef4
fix: do not send empty logs data
andrzej-stencel Apr 28, 2023
55c232b
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel May 9, 2023
6391a24
SQL Query receiver - support timestamp in tracking column
dmolenda-sumo May 11, 2023
db391d2
Merge pull request #2 from dmolenda-sumo/sqlqueryreceiver-support-tim…
dmolenda-sumo May 11, 2023
1a5175d
Merge remote-tracking branch 'upstream/main' into sqlquery-receiver-a…
dmolenda-sumo May 11, 2023
66a772a
fix integration tests
dmolenda-sumo May 12, 2023
ef5782d
Merge pull request #3 from dmolenda-sumo/sqlqueryreceiver-fix-integra…
dmolenda-sumo May 12, 2023
27b4c3f
feat: add observability (metrics) for sqlquery receiver (#1)
kasia-kujawa May 12, 2023
e1e0684
SQL Query receiver: add logs to mysql integration test
dmolenda-sumo May 12, 2023
4b58330
Merge pull request #5 from dmolenda-sumo/sqlqueryreceiver-add-logs-to…
dmolenda-sumo May 12, 2023
18407d0
feat: persist tracking value in storage
andrzej-stencel May 12, 2023
a63f68b
feat(sqlqueryreceiver) add error count metrics for receiver (#4)
kasia-kujawa May 16, 2023
95e6c31
docs: add link to a storage extension
andrzej-stencel May 16, 2023
353b38a
style: remove unused code
andrzej-stencel May 16, 2023
0a5ddd3
test: terminate DB containers after test
andrzej-stencel May 16, 2023
8268a3b
Merge branch 'sqlquery-receiver-add-logs' into persistence
andrzej-stencel May 16, 2023
55c8add
Merge pull request #6 from dmolenda-sumo/persistence
andrzej-stencel May 16, 2023
099056b
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel May 16, 2023
a55c95e
test: fix after metadata update
andrzej-stencel May 16, 2023
155de51
refactor: use metadata for logs stability level
andrzej-stencel May 16, 2023
cda1cf9
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel May 17, 2023
d98c0b0
docs: add note about storage
andrzej-stencel May 17, 2023
ef97e41
docs: fix parameter notation in configuration
andrzej-stencel May 17, 2023
6a66195
chore: go mod tidy
andrzej-stencel May 17, 2023
553fd46
fix lint errors
andrzej-stencel May 18, 2023
355081b
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel May 18, 2023
03d04ff
chore: update license to short form
andrzej-stencel May 18, 2023
fab7a33
chore: make crosslink
andrzej-stencel May 18, 2023
6fe88c2
chore: make gotidy
andrzej-stencel May 18, 2023
c5eddd6
docs: disable Prettier formatting to pass CI check
andrzej-stencel May 18, 2023
152033f
feat(sqlqueryreceiver) add traces to monitor logs received
kasia-kujawa May 18, 2023
323f5d2
chore: make generate
andrzej-stencel May 18, 2023
88ed5c8
Merge pull request #7 from kkujawa-sumo/kk-add-traces
andrzej-stencel May 18, 2023
f180fd6
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel May 18, 2023
b192b0f
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel May 23, 2023
a6f2c5d
fix integration test
andrzej-stencel May 23, 2023
9a46ae9
test: clean up tests
andrzej-stencel May 23, 2023
a1ab2d3
fix: prevent panic on shutdown
andrzej-stencel May 25, 2023
2c50539
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel May 29, 2023
923df54
remove duplicate metrics
andrzej-stencel May 29, 2023
8790642
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel Jun 12, 2023
cd997f8
refactor: remove unused error path
andrzej-stencel Jun 13, 2023
e20996a
Merge branch 'main' into sqlquery-receiver-add-logs
andrzej-stencel Jun 14, 2023
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
16 changes: 16 additions & 0 deletions .chloggen/sqlquery-receiver-add-logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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. filelogreceiver)
component: sqlqueryreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for logs

# One or more tracking issues related to the change
issues: [20284]

# (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:
70 changes: 50 additions & 20 deletions receiver/sqlqueryreceiver/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SQL Query Receiver (Alpha)

| Status | |
|--------------------------|-----------|
| ------------------------ | --------- |
| Stability | [alpha] |
| Supported pipeline types | metrics |
andrzej-stencel marked this conversation as resolved.
Show resolved Hide resolved
| Distributions | [contrib] |
Expand All @@ -21,29 +21,58 @@ The configuration supports the following top-level fields:
a driver-specific string usually consisting of at least a database name and connection information. This is sometimes
referred to as the "connection string" in driver documentation.
e.g. _host=localhost port=5432 user=me password=s3cr3t sslmode=disable_
- `queries`(required): A list of queries, where a query is a sql statement and one or more metrics (details below).
- `queries`(required): A list of queries, where a query is a sql statement and one or more `logs` and/or `metrics` sections (details below).
- `collection_interval`(optional): The time interval between query executions. Defaults to _10s_.

### Queries

A _query_ consists of a sql statement and one or more _metrics_, where each metric consists of a
A _query_ consists of a sql statement and one or more `logs` and/or `metrics` section.
At least one `logs` or one `metrics` section is required.
Note that technically you can put both `logs` and `metrics` sections in a single query section,
but it's probably not a real world use case, as the requirements for logs and metrics queries
are quite different.

Example:

```yaml
receivers:
sqlquery:
driver: postgres
datasource: "host=localhost port=5432 user=postgres password=s3cr3t sslmode=disable"
queries:
- sql: "select * from my_logs"
logs:
- {}
- sql: "select count(*) as count, genre from movie group by genre"
metrics:
- metric_name: movie.genres
value_column: "count"
```

#### Logs Queries

The `logs` section currently has no options. This section is in development.

#### Metrics queries

Each `metrics` section consists of a
`metric_name`, a `value_column`, and additional optional fields.
Each _metric_ in the configuration will produce one OTel metric per row returned from its sql query.

* `metric_name`(required): the name assigned to the OTel metric.
* `value_column`(required): the column name in the returned dataset used to set the value of the metric's datapoint.
- `metric_name`(required): the name assigned to the OTel metric.
- `value_column`(required): the column name in the returned dataset used to set the value of the metric's datapoint.
This may be case-sensitive, depending on the driver (e.g. Oracle DB).
* `attribute_columns`(optional): a list of column names in the returned dataset used to set attibutes on the datapoint.
- `attribute_columns`(optional): a list of column names in the returned dataset used to set attibutes on the datapoint.
These attributes may be case-sensitive, depending on the driver (e.g. Oracle DB).
* `data_type` (optional): can be `gauge` or `sum`; defaults to `gauge`.
* `value_type` (optional): can be `int` or `double`; defaults to `int`.
* `monotonic` (optional): boolean; whether a cumulative sum's value is monotonically increasing (i.e. never rolls over
- `data_type` (optional): can be `gauge` or `sum`; defaults to `gauge`.
- `value_type` (optional): can be `int` or `double`; defaults to `int`.
- `monotonic` (optional): boolean; whether a cumulative sum's value is monotonically increasing (i.e. never rolls over
or resets); defaults to false.
* `aggregation` (optional): only applicable for `data_type=sum`; can be `cumulative` or `delta`; defaults
- `aggregation` (optional): only applicable for `data_type=sum`; can be `cumulative` or `delta`; defaults
to `cumulative`.
* `description` (optional): the description applied to the metric.
* `unit` (optional): the units applied to the metric.
* `static_attributes` (optional): static attributes applied to the metrics
- `description` (optional): the description applied to the metric.
- `unit` (optional): the units applied to the metric.
- `static_attributes` (optional): static attributes applied to the metrics

### Example

Expand All @@ -53,27 +82,29 @@ receivers:
driver: postgres
datasource: "host=localhost port=5432 user=postgres password=s3cr3t sslmode=disable"
queries:
- sql: "select * from my_logs"
logs: {}
- sql: "select count(*) as count, genre from movie group by genre"
metrics:
- metric_name: movie.genres
value_column: "count"
attribute_columns: [ "genre" ]
attribute_columns: ["genre"]
static_attributes:
dbinstance: mydbinstance
```

Given a `movie` table with three rows:

| name | genre |
|-----------|--------|
| --------- | ------ |
| E.T. | sci-fi |
| Star Wars | sci-fi |
| Die Hard | action |

If there are two rows returned from the query `select count(*) as count, genre from movie group by genre`:

| count | genre |
|-------|--------|
| ----- | ------ |
| 2 | sci-fi |
| 1 | action |

Expand All @@ -87,7 +118,7 @@ Descriptor:
NumberDataPoints #0
Data point attributes:
-> genre: STRING(sci-fi)
-> dbinstance: STRING(mydbinstance)
-> dbinstance: STRING(mydbinstance)
Value: 2

Metric #1
Expand Down Expand Up @@ -115,6 +146,5 @@ The Oracle DB driver documentation can be found [here.](https://github.com/sijms
Another usage example is the `go_ora`
example [here.](https://blogs.oracle.com/developers/post/connecting-a-go-application-to-oracle-database)

[alpha]:https://github.com/open-telemetry/opentelemetry-collector#alpha

[contrib]:https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
18 changes: 16 additions & 2 deletions receiver/sqlqueryreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,21 @@ func (c Config) Validate() error {
type Query struct {
SQL string `mapstructure:"sql"`
Metrics []MetricCfg `mapstructure:"metrics"`
Logs []LogsCfg `mapstructure:"logs"`
}

func (q Query) Validate() error {
var errs error
if q.SQL == "" {
errs = multierr.Append(errs, errors.New("'query.sql' cannot be empty"))
}
if len(q.Metrics) == 0 {
errs = multierr.Append(errs, errors.New("'query.metrics' cannot be empty"))
if len(q.Logs) == 0 && len(q.Metrics) == 0 {
errs = multierr.Append(errs, errors.New("at least one of 'query.logs' and 'query.metrics' must not be empty"))
}
for _, logs := range q.Logs {
if err := logs.Validate(); err != nil {
errs = multierr.Append(errs, err)
}
}
for _, metric := range q.Metrics {
if err := metric.Validate(); err != nil {
Expand All @@ -70,6 +76,14 @@ func (q Query) Validate() error {
return errs
}

type LogsCfg struct {
}

func (config LogsCfg) Validate() error {
var errs error
return errs
}

type MetricCfg struct {
MetricName string `mapstructure:"metric_name"`
ValueColumn string `mapstructure:"value_column"`
Expand Down
25 changes: 22 additions & 3 deletions receiver/sqlqueryreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,34 @@ func TestLoadConfig(t *testing.T) {
errorMessage: "'driver' cannot be empty",
},
{
fname: "config-invalid-missing-metrics.yaml",
fname: "config-invalid-missing-logs-metrics.yaml",
id: component.NewIDWithName(typeStr, ""),
errorMessage: "'query.metrics' cannot be empty",
errorMessage: "at least one of 'query.logs' and 'query.metrics' must not be empty",
},
{
fname: "config-invalid-missing-datasource.yaml",
id: component.NewIDWithName(typeStr, ""),
errorMessage: "'datasource' cannot be empty",
},
{
fname: "config-logs.yaml",
id: component.NewIDWithName(typeStr, ""),
expected: &Config{
ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
CollectionInterval: 10 * time.Second,
},
Driver: "mydriver",
DataSource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable",
Queries: []Query{
{
SQL: "select * from test_logs",
Logs: []LogsCfg{
{},
},
},
},
},
},
{
fname: "config-unnecessary-aggregation.yaml",
id: component.NewIDWithName(typeStr, ""),
Expand All @@ -121,7 +140,7 @@ func TestLoadConfig(t *testing.T) {
}

for _, tt := range tests {
t.Run(tt.id.String(), func(t *testing.T) {
t.Run(tt.fname, func(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", tt.fname))
require.NoError(t, err)

Expand Down
8 changes: 8 additions & 0 deletions receiver/sqlqueryreceiver/testdata/config-logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sqlquery:
collection_interval: 10s
driver: mydriver
datasource: "host=localhost port=5432 user=me password=s3cr3t sslmode=disable"
queries:
- sql: "select * from test_logs"
logs:
- {}