From fc17a1e0f903cfda9c368ad763836ef6e458f37a Mon Sep 17 00:00:00 2001 From: Michal Grandys Date: Fri, 31 Jan 2025 21:44:51 +0100 Subject: [PATCH 1/4] [reciver/sqlqueryreceiver] Add support for sybase database connections #36328 --- .chloggen/feat-sqlqueryreciver-sap-ase.yaml | 26 +++ internal/sqlquery/db_client.go | 1 + internal/sqlquery/go.mod | 1 + internal/sqlquery/go.sum | 12 ++ receiver/sqlqueryreceiver/README.md | 10 +- receiver/sqlqueryreceiver/go.mod | 1 + receiver/sqlqueryreceiver/go.sum | 12 ++ receiver/sqlqueryreceiver/integration_test.go | 125 ++++++++++--- .../testdata/integration/sybase/entrypoint.sh | 165 ++++++++++++++++++ .../testdata/integration/sybase/expected.yaml | 42 +++++ receiver/sqlserverreceiver/go.mod | 1 + receiver/sqlserverreceiver/go.sum | 12 ++ 12 files changed, 383 insertions(+), 25 deletions(-) create mode 100644 .chloggen/feat-sqlqueryreciver-sap-ase.yaml create mode 100755 receiver/sqlqueryreceiver/testdata/integration/sybase/entrypoint.sh create mode 100644 receiver/sqlqueryreceiver/testdata/integration/sybase/expected.yaml diff --git a/.chloggen/feat-sqlqueryreciver-sap-ase.yaml b/.chloggen/feat-sqlqueryreciver-sap-ase.yaml new file mode 100644 index 0000000000000..b909e76834089 --- /dev/null +++ b/.chloggen/feat-sqlqueryreciver-sap-ase.yaml @@ -0,0 +1,26 @@ +# Use this changelog template to create an entry for release notes. + +# 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: receiver/sqlqueryreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add support for SapASE (sybase) database connections + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [36328] + +# (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: +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/internal/sqlquery/db_client.go b/internal/sqlquery/db_client.go index e702a6b829236..66d1a8427bd12 100644 --- a/internal/sqlquery/db_client.go +++ b/internal/sqlquery/db_client.go @@ -15,6 +15,7 @@ import ( _ "github.com/microsoft/go-mssqldb/integratedauth/krb5" _ "github.com/sijms/go-ora/v2" _ "github.com/snowflakedb/gosnowflake" + _ "github.com/thda/tds" "go.uber.org/zap" ) diff --git a/internal/sqlquery/go.mod b/internal/sqlquery/go.mod index ec8ecd4f030cb..e3d5f65a123ad 100644 --- a/internal/sqlquery/go.mod +++ b/internal/sqlquery/go.mod @@ -10,6 +10,7 @@ require ( github.com/sijms/go-ora/v2 v2.8.23 github.com/snowflakedb/gosnowflake v1.12.0 github.com/stretchr/testify v1.10.0 + github.com/thda/tds v0.1.7 go.opentelemetry.io/collector/component v0.120.1-0.20250219144032-c2af75d88e89 go.opentelemetry.io/collector/component/componenttest v0.120.1-0.20250219144032-c2af75d88e89 go.opentelemetry.io/collector/pdata v1.26.1-0.20250219144032-c2af75d88e89 diff --git a/internal/sqlquery/go.sum b/internal/sqlquery/go.sum index 29af9ef8927b4..f7f66f99a5c4e 100644 --- a/internal/sqlquery/go.sum +++ b/internal/sqlquery/go.sum @@ -64,6 +64,9 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 h1:cwIxeBttqPN3qkaAjcEcsh8NYr8n github.com/aws/aws-sdk-go-v2/service/sts v1.28.6/go.mod h1:FZf1/nKNEkHdGGJP/cI2MoIMquumuRK6ol3QQJNDxmw= github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -144,6 +147,7 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/microsoft/go-mssqldb v1.8.0 h1:7cyZ/AT7ycDsEoWPIXibd+aVKFtteUNhDGf3aobP+tw= github.com/microsoft/go-mssqldb v1.8.0/go.mod h1:6znkekS3T2vp0waiMhen4GPU1BiAsrP+iXHcE7a7rFo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -181,6 +185,9 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/thda/tds v0.1.7 h1:s29kbnJK0agL3ps85A/sb9XS2uxgKF5UJ6AZjbyqXX4= +github.com/thda/tds v0.1.7/go.mod h1:isLIF1oZdXfkqVMJM8RyNrsjlHPlTKnPlnsBs7ngZcM= +github.com/xo/tblfmt v0.0.0-20190609041254-28c54ec42ce8/go.mod h1:3U5kKQdIhwACye7ml3acccHmjGExY9WmUGU7rnDWgv0= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -237,6 +244,7 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -252,6 +260,7 @@ golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -269,6 +278,7 @@ golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -286,12 +296,14 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190802003818-e9bb7d36c060/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= diff --git a/receiver/sqlqueryreceiver/README.md b/receiver/sqlqueryreceiver/README.md index 4a10ec00daa1d..72da7e11b4f00 100644 --- a/receiver/sqlqueryreceiver/README.md +++ b/receiver/sqlqueryreceiver/README.md @@ -25,11 +25,15 @@ The SQL Query Receiver uses custom SQL queries to generate metrics from a databa The configuration supports the following top-level fields: - `driver`(required): The name of the database driver: one of _postgres_, _mysql_, _snowflake_, _sqlserver_, _hdb_ (SAP - HANA), or _oracle_ (Oracle DB). + HANA), _oracle_ (Oracle DB), _tds_ (SapASE/Sybase). - `datasource`(required): The datasource value passed to [sql.Open](https://pkg.go.dev/database/sql#Open). This is 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_ + referred to as the "connection string" in driver documentation. Examples: + - [postgres](https://github.com/lib/pq) - `host=localhost port=5432 user=username password=user_password sslmode=disable` + - [mysql](https://github.com/go-sql-driver/mysql) - `username:user_password@tcp(localhost:3306)/db_name` + - [oracle](https://github.com/sijms/go-ora) - `oracle://username:user_password@localhost:1521/FREEPDB1` + - [sqlserver](https://github.com/go-sql-driver/mysql) - `sqlserver://username:user_password@localhost:1433?database=db_name` + - [sapAse](https://github.com/thda/tds) - `tds://username:user_password@localhost:5000/db_name` - `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_. - `storage` (optional, default `""`): The ID of a [storage][storage_extension] extension to be used to [track processed results](#tracking-processed-results). diff --git a/receiver/sqlqueryreceiver/go.mod b/receiver/sqlqueryreceiver/go.mod index 6a5b0f61a49ea..70d9a93e6da50 100644 --- a/receiver/sqlqueryreceiver/go.mod +++ b/receiver/sqlqueryreceiver/go.mod @@ -137,6 +137,7 @@ require ( github.com/sijms/go-ora/v2 v2.8.23 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/snowflakedb/gosnowflake v1.12.0 // indirect + github.com/thda/tds v0.1.7 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/valyala/fastjson v1.6.4 // indirect diff --git a/receiver/sqlqueryreceiver/go.sum b/receiver/sqlqueryreceiver/go.sum index b37148d9e001a..7ec9270a834f9 100644 --- a/receiver/sqlqueryreceiver/go.sum +++ b/receiver/sqlqueryreceiver/go.sum @@ -78,6 +78,9 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3 github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= @@ -206,6 +209,7 @@ github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/microsoft/go-mssqldb v1.8.0 h1:7cyZ/AT7ycDsEoWPIXibd+aVKFtteUNhDGf3aobP+tw= github.com/microsoft/go-mssqldb v1.8.0/go.mod h1:6znkekS3T2vp0waiMhen4GPU1BiAsrP+iXHcE7a7rFo= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= @@ -277,12 +281,15 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/testcontainers/testcontainers-go v0.35.0 h1:uADsZpTKFAtp8SLK+hMwSaa+X+JiERHtd4sQAFmXeMo= github.com/testcontainers/testcontainers-go v0.35.0/go.mod h1:oEVBj5zrfJTrgjwONs1SsRbnBtH9OKl+IGl3UMcr2B4= +github.com/thda/tds v0.1.7 h1:s29kbnJK0agL3ps85A/sb9XS2uxgKF5UJ6AZjbyqXX4= +github.com/thda/tds v0.1.7/go.mod h1:isLIF1oZdXfkqVMJM8RyNrsjlHPlTKnPlnsBs7ngZcM= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ= github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= +github.com/xo/tblfmt v0.0.0-20190609041254-28c54ec42ce8/go.mod h1:3U5kKQdIhwACye7ml3acccHmjGExY9WmUGU7rnDWgv0= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -361,6 +368,7 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -376,6 +384,7 @@ golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -393,6 +402,7 @@ golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -415,6 +425,7 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= @@ -423,6 +434,7 @@ golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190802003818-e9bb7d36c060/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= diff --git a/receiver/sqlqueryreceiver/integration_test.go b/receiver/sqlqueryreceiver/integration_test.go index 123ca2f21b0f5..0b1addf58ea88 100644 --- a/receiver/sqlqueryreceiver/integration_test.go +++ b/receiver/sqlqueryreceiver/integration_test.go @@ -40,6 +40,7 @@ const ( oraclePort = "1521" mysqlPort = "3306" sqlServerPort = "1433" + sapAsePort = "5000" ) type DbEngineUnderTest struct { @@ -173,6 +174,38 @@ var ( ).WithDeadline(5 * time.Minute), }, } + SapASE = DbEngineUnderTest{ + Port: sapAsePort, + SQLParameter: func(_ int) string { + return "?" + }, + CheckCompatibility: func(t *testing.T) { + t.Skip("Skipping the test until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27577 is fixed") + }, + ConnectionString: func(host string, externalPort nat.Port) string { + return fmt.Sprintf("tds://otel:otel1234@%s:%s/otel", host, externalPort.Port()) + }, + Driver: "tds", + ConvertColumnName: func(name string) string { return name }, + ContainerRequest: testcontainers.ContainerRequest{ + Image: "datagrip/sybase:16.0", + Env: map[string]string{ + "SYBASE_USER": "otel", + "SYBASE_DB": "otel", + "SYBASE_PASSWORD": "otel1234", + }, + Files: []testcontainers.ContainerFile{{ + HostFilePath: filepath.Join("testdata", "integration", "sybase", "entrypoint.sh"), + ContainerFilePath: "/entrypoint.sh", + FileMode: 777, + }}, + ExposedPorts: []string{sapAsePort}, + WaitingFor: wait.ForAll( + wait.ForListeningPort(sapAsePort).WithStartupTimeout(5*time.Minute), + wait.ForLog("SYBASE INITIALIZED").WithStartupTimeout(5*time.Minute), + ).WithDeadline(5 * time.Minute), + }, + } ) func TestIntegrationLogsTracking(t *testing.T) { @@ -182,46 +215,54 @@ func TestIntegrationLogsTracking(t *testing.T) { }{ Postgres.Driver: { {name: "PostgresWithStorage", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithStorage(t, engine, container) + runTestForLogTrackingWithStorage(t, engine, container, "select * from simple_logs where id > $1 order by id asc") }}, {name: "PostgresById", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithoutStorage(t, engine, container, "id", "0", "") + runTestForLogTrackingWithoutStorage(t, engine, container, "id", "0", "select * from simple_logs where id > $1 order by id asc") }}, {name: "PostgresByTimestamp", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithoutStorage(t, engine, container, "insert_time", "2022-06-03 21:00:00+00", "") + runTestForLogTrackingWithoutStorage(t, engine, container, "insert_time", "2022-06-03 21:00:00+00", "select * from simple_logs where insert_time > $1 order by insert_time asc") }}, }, MySQL.Driver: { {name: "MySQLWithStorage", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithStorage(t, engine, container) + runTestForLogTrackingWithStorage(t, engine, container, "select * from simple_logs where id > ? order by id asc") }}, {name: "MySQLById", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithoutStorage(t, engine, container, "id", "0", "") + runTestForLogTrackingWithoutStorage(t, engine, container, "id", "0", "select * from simple_logs where id > ? order by id asc") }}, {name: "MySQLByTimestamp", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithoutStorage(t, engine, container, "insert_time", "2022-06-03 21:00:00", "") + runTestForLogTrackingWithoutStorage(t, engine, container, "insert_time", "2022-06-03 21:00:00", "select * from simple_logs where insert_time > ? order by insert_time asc") }}, }, SQLServer.Driver: { {name: "SQLServerWithStorage", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithStorage(t, engine, container) + runTestForLogTrackingWithStorage(t, engine, container, "select * from simple_logs where id > @p1 order by id asc") }}, {name: "SQLServerById", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithoutStorage(t, engine, container, "id", "0", "") + runTestForLogTrackingWithoutStorage(t, engine, container, "id", "0", "select * from simple_logs where id > @p1 order by id asc") }}, {name: "SQLServerByTimestamp", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithoutStorage(t, engine, container, "insert_time", "2022-06-03 21:00:00", "") + runTestForLogTrackingWithoutStorage(t, engine, container, "insert_time", "2022-06-03 21:00:00", "select * from simple_logs where insert_time > @p1 order by insert_time asc") }}, }, Oracle.Driver: { {name: "OracleWithStorage", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithStorage(t, engine, container) + runTestForLogTrackingWithStorage(t, engine, container, "select * from simple_logs where ID > :1 order by ID asc") }}, {name: "OracleById", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithoutStorage(t, engine, container, "ID", "0", "") + runTestForLogTrackingWithoutStorage(t, engine, container, "ID", "0", "select * from simple_logs where ID > :1 order by ID asc") }}, {name: "OracleByTimestamp", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { - runTestForLogTrackingWithoutStorage(t, engine, container, "INSERT_TIME", "2022-06-03T21:00:00.000Z", "TO_TIMESTAMP_TZ(:1, 'YYYY-MM-DD\"T\"HH24:MI:SS.FF6TZH:TZM')") + runTestForLogTrackingWithoutStorage(t, engine, container, "INSERT_TIME", "2022-06-03T21:00:00.000Z", "select * from simple_logs where INSERT_TIME > TO_TIMESTAMP_TZ(:1, 'YYYY-MM-DD\"T\"HH24:MI:SS.FF6TZH:TZM') order by INSERT_TIME asc") + }}, + }, + SapASE.Driver: { + {name: "SapASEWithStorage", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { + runTestForLogTrackingWithStorage(t, engine, container, "select * from simple_logs where convert(varchar,id) > ? order by id asc") + }}, + {name: "SapASEById", runTest: func(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { + runTestForLogTrackingWithoutStorage(t, engine, container, "id", "0", "select * from simple_logs where convert(varchar,id) > ? order by id asc") }}, }, } @@ -261,12 +302,14 @@ func getDbEngine(driver string) DbEngineUnderTest { return SQLServer case Oracle.Driver: return Oracle + case SapASE.Driver: + return SapASE default: panic(fmt.Sprintf("unsupported driver: %s", driver)) } } -func runTestForLogTrackingWithStorage(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container) { +func runTestForLogTrackingWithStorage(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container, querySQL string) { dbHost, dbPort := getContainerHostAndPort(t, container, engine.Port) storageDir := t.TempDir() storageExtension := storagetest.NewFileBackedStorageExtension("test", storageDir) @@ -281,7 +324,7 @@ func runTestForLogTrackingWithStorage(t *testing.T, engine DbEngineUnderTest, co config.StorageID = &storageExtension.ID config.Queries = []sqlquery.Query{ { - SQL: fmt.Sprintf("select * from simple_logs where %s > %s", trackingColumn, engine.SQLParameter(1)), + SQL: querySQL, Logs: []sqlquery.LogsCfg{ { BodyColumn: engine.ConvertColumnName("body"), @@ -320,7 +363,7 @@ func runTestForLogTrackingWithStorage(t *testing.T, engine DbEngineUnderTest, co config.StorageID = &storageExtension.ID config.Queries = []sqlquery.Query{ { - SQL: fmt.Sprintf("select * from simple_logs where %s > %s", trackingColumn, engine.SQLParameter(1)), + SQL: querySQL, Logs: []sqlquery.LogsCfg{ { BodyColumn: engine.ConvertColumnName("body"), @@ -351,7 +394,7 @@ func runTestForLogTrackingWithStorage(t *testing.T, engine DbEngineUnderTest, co config.StorageID = &storageExtension.ID config.Queries = []sqlquery.Query{ { - SQL: fmt.Sprintf("select * from simple_logs where %s > %s", trackingColumn, engine.SQLParameter(1)), + SQL: querySQL, Logs: []sqlquery.LogsCfg{ { BodyColumn: engine.ConvertColumnName("body"), @@ -381,7 +424,7 @@ func runTestForLogTrackingWithStorage(t *testing.T, engine DbEngineUnderTest, co require.Equal(t, newLogCount, consumer.LogRecordCount()) } -func runTestForLogTrackingWithoutStorage(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container, trackingColumn, trackingStartValue, trackingStartValueFormat string) { +func runTestForLogTrackingWithoutStorage(t *testing.T, engine DbEngineUnderTest, container testcontainers.Container, trackingColumn, trackingStartValue, sqlQuery string) { receiverCreateSettings := receivertest.NewNopSettingsWithType(metadata.Type) dbHost, dbPort := getContainerHostAndPort(t, container, engine.Port) receiver, config, consumer := createTestLogsReceiver(t, engine.Driver, engine.ConnectionString(dbHost, dbPort), receiverCreateSettings) @@ -389,14 +432,10 @@ func runTestForLogTrackingWithoutStorage(t *testing.T, engine DbEngineUnderTest, config.Telemetry.Logs.Query = true trackingColumn = engine.ConvertColumnName(trackingColumn) - trackingColumnParameter := engine.SQLParameter(1) - if trackingStartValueFormat != "" { - trackingColumnParameter = trackingStartValueFormat - } config.Queries = []sqlquery.Query{ { - SQL: fmt.Sprintf("select * from simple_logs where %s > %s order by %s asc", trackingColumn, trackingColumnParameter, trackingColumn), + SQL: sqlQuery, Logs: []sqlquery.LogsCfg{ { BodyColumn: engine.ConvertColumnName("body"), @@ -792,3 +831,45 @@ func TestSQLServerIntegrationMetrics(t *testing.T) { ), ).Run(t) } + +func TestSapASEIntegrationMetrics(t *testing.T) { + SapASE.CheckCompatibility(t) + scraperinttest.NewIntegrationTest( + NewFactory(), + scraperinttest.WithContainerRequest(SapASE.ContainerRequest), + scraperinttest.WithCustomConfig( + func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) { + rCfg := cfg.(*Config) + rCfg.Driver = SapASE.Driver + rCfg.DataSource = SapASE.ConnectionString(ci.Host(t), nat.Port(ci.MappedPort(t, SapASE.Port))) + rCfg.Queries = []sqlquery.Query{ + { + SQL: "SELECT genre, COUNT(*) AS movie_count, AVG(imdb_rating) AS movie_avg FROM movie GROUP BY genre ORDER BY genre", + Metrics: []sqlquery.MetricCfg{ + { + MetricName: "genre.count", + ValueColumn: "movie_count", + AttributeColumns: []string{"genre"}, + ValueType: sqlquery.MetricValueTypeInt, + DataType: sqlquery.MetricTypeGauge, + }, + { + MetricName: "genre.imdb", + ValueColumn: "movie_avg", + AttributeColumns: []string{"genre"}, + ValueType: sqlquery.MetricValueTypeDouble, + DataType: sqlquery.MetricTypeGauge, + }, + }, + }, + } + }), + scraperinttest.WithExpectedFile( + filepath.Join("testdata", "integration", "sybase", "expected.yaml"), + ), + scraperinttest.WithCompareOptions( + pmetrictest.IgnoreTimestamp(), + pmetrictest.IgnoreMetricsOrder(), + ), + ).Run(t) +} diff --git a/receiver/sqlqueryreceiver/testdata/integration/sybase/entrypoint.sh b/receiver/sqlqueryreceiver/testdata/integration/sybase/entrypoint.sh new file mode 100755 index 0000000000000..cd69fce08e621 --- /dev/null +++ b/receiver/sqlqueryreceiver/testdata/integration/sybase/entrypoint.sh @@ -0,0 +1,165 @@ +#!/bin/bash +# +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 +# +# +export SYBASE=/opt/sybase +source /opt/sybase/SYBASE.sh + +sh /opt/sybase/SYBASE.sh && sh /opt/sybase/ASE-16_0/install/RUN_MYSYBASE > /dev/null & + +#waiting for sybase to start +export STATUS=0 +i=1 +echo =============== WAITING FOR master.dat SPACE ALLOCATION ========================== +while (( $i < 60 )); do + sleep 1 + i=$((i+1)) + STATUS=$(grep "Performing space allocation for device '/opt/sybase/data/master.dat'" /opt/sybase/ASE-16_0/install/MYSYBASE.log | wc -c) + if (( $STATUS > 300 )); then + break + fi +done + +echo =============== WAITING FOR INITIALIZATION ========================== +export STATUS2=0 +j=1 +while (( $j < 30 )); do + sleep 1 + j=$((j+1)) + STATUS2=$(grep "Finished initialization." /opt/sybase/ASE-16_0/install/MYSYBASE.log | wc -c) + if (( $STATUS2 > 350 )); then + break + fi +done + +echo =============== SYBASE STARTED ========================== +cd /opt/sybase + +if [ ! -z $SYBASE_USER ]; then + echo "SYBASE_USER: $SYBASE_USER" +else + SYBASE_USER=tester + echo "SYBASE_USER: $SYBASE_USER" +fi + +if [ ! -z $SYBASE_PASSWORD ]; then + echo "SYBASE_PASSWORD: $SYBASE_PASSWORD" +else + SYBASE_PASSWORD=guest1234 + echo "SYBASE_PASSWORD: $SYBASE_PASSWORD" +fi + +if [ ! -z $SYBASE_DB ]; then + echo "SYBASE_DB: $SYBASE_DB" +else + SYBASE_DB=testdb + echo "SYBASE_DB: $SYBASE_DB" +fi + +echo =============== CREATING LOGIN/PWD ========================== +cat <<-EOSQL > init1.sql +use master +go +disk resize name='master', size='60m' +go +create database $SYBASE_DB on master = '48m' +go +exec sp_extendsegment logsegment, $SYBASE_DB, master +go +create login $SYBASE_USER with password $SYBASE_PASSWORD +go +exec sp_dboption $SYBASE_DB, 'abort tran on log full', true +go +exec sp_dboption $SYBASE_DB, 'allow nulls by default', true +go +exec sp_dboption $SYBASE_DB, 'ddl in tran', true +go +exec sp_dboption $SYBASE_DB, 'trunc log on chkpt', true +go +exec sp_dboption $SYBASE_DB, 'full logging for select into', true +go +exec sp_dboption $SYBASE_DB, 'full logging for alter table', true +go +sp_dboption $SYBASE_DB, "select into", true +go + +EOSQL + +/opt/sybase/OCS-16_0/bin/isql -Usa -PmyPassword -SMYSYBASE -i"./init1.sql" + +echo =============== CREATING DB ========================== +cat <<-EOSQL > init2.sql +use $SYBASE_DB +go + +sp_adduser '$SYBASE_USER', '$SYBASE_USER', null +go + +grant create default to $SYBASE_USER +go +grant create table to $SYBASE_USER +go +grant create view to $SYBASE_USER +go +grant create rule to $SYBASE_USER +go +grant create function to $SYBASE_USER +go +grant create procedure to $SYBASE_USER +go +create table movie(title text, genre varchar(255), imdb_rating float) +go +grant select on movie to $SYBASE_USER +go +insert into movie (title, genre, imdb_rating) values ('E.T.', 'SciFi', 7.9) +go +insert into movie (title, genre, imdb_rating) values ('Blade Runner', 'SciFi', 8.1) +go +insert into movie (title, genre, imdb_rating) values ('Star Wars', 'SciFi', 8.6) +go +insert into movie (title, genre, imdb_rating) values ('Die Hard', 'Action', 8.2) +go +insert into movie (title, genre, imdb_rating) values ('Mission Impossible', 'Action', 7.1) +go +create table simple_logs(id int primary key not null, insert_time bigdatetime default getdate(), body text, attribute text) +go +grant select, insert, delete on simple_logs to $SYBASE_USER +go +insert into simple_logs (id, insert_time, body, attribute) values (1, '2022-06-03 21:59:26', '- - - [03/Jun/2022:21:59:26 +0000] "GET /api/health HTTP/1.1" 200 6197 4 "-" "-" 445af8e6c428303f -', 'TLSv1.2') +go +insert into simple_logs (id, insert_time, body, attribute) values (2, '2022-06-03 21:59:26.692991', '- - - [03/Jun/2022:21:59:26 +0000] "GET /api/health HTTP/1.1" 200 6205 5 "-" "-" 3285f43cd4baa202 -', 'TLSv1') +go +insert into simple_logs (id, insert_time, body, attribute) values (3, '2022-06-03 21:59:29.212212', '- - - [03/Jun/2022:21:59:29 +0000] "GET /api/health HTTP/1.1" 200 6233 4 "-" "-" 579e8362d3185b61 -', 'TLSv1.2') +go +insert into simple_logs (id, insert_time, body, attribute) values (4, '2022-06-03 21:59:31', '- - - [03/Jun/2022:21:59:31 +0000] "GET /api/health HTTP/1.1" 200 6207 5 "-" "-" 8c6ac61ae66e509f -', 'TLSv1') +go +insert into simple_logs (id, insert_time, body, attribute) values (5, '2022-06-03 21:59:31.332121', '- - - [03/Jun/2022:21:59:31 +0000] "GET /api/health HTTP/1.1" 200 6200 4 "-" "-" c163495861e873d8 -', 'TLSv1.2') +go +commit +go +commit +go + +EOSQL + +/opt/sybase/OCS-16_0/bin/isql -Usa -PmyPassword -SMYSYBASE -i"./init2.sql" + +#echo =============== CREATING SCHEMA ========================== +#cat <<-EOSQL > init3.sql +#use $SYBASE_DB +#go +#create schema authorization $SYBASE_USER +#go +# +#EOSQL +#/opt/sybase/OCS-16_0/bin/isql -Usa -PmyPassword -SMYSYBASE -i"./init3.sql" + +echo =============== SYBASE INITIALIZED ========================== + +#trap +while [ "$END" == '' ]; do + sleep 1 + trap "/etc/init.d/sybase stop && END=1" INT TERM +done diff --git a/receiver/sqlqueryreceiver/testdata/integration/sybase/expected.yaml b/receiver/sqlqueryreceiver/testdata/integration/sybase/expected.yaml new file mode 100644 index 0000000000000..5c08dbe7ee1a5 --- /dev/null +++ b/receiver/sqlqueryreceiver/testdata/integration/sybase/expected.yaml @@ -0,0 +1,42 @@ +resourceMetrics: + - resource: {} + scopeMetrics: + - metrics: + - gauge: + dataPoints: + - asInt: "2" + attributes: + - key: genre + value: + stringValue: Action + timeUnixNano: "1734876925424574000" + name: genre.count + - gauge: + dataPoints: + - asInt: "3" + attributes: + - key: genre + value: + stringValue: SciFi + timeUnixNano: "1734876925424574000" + name: genre.count + - gauge: + dataPoints: + - asDouble: 7.6499999999999995 + attributes: + - key: genre + value: + stringValue: Action + timeUnixNano: "1734876925424574000" + name: genre.imdb + - gauge: + dataPoints: + - asDouble: 8.200000000000001 + attributes: + - key: genre + value: + stringValue: SciFi + timeUnixNano: "1734876925424574000" + name: genre.imdb + scope: + name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlqueryreceiver \ No newline at end of file diff --git a/receiver/sqlserverreceiver/go.mod b/receiver/sqlserverreceiver/go.mod index b87a2e98a44ee..517c9b514d490 100644 --- a/receiver/sqlserverreceiver/go.mod +++ b/receiver/sqlserverreceiver/go.mod @@ -98,6 +98,7 @@ require ( github.com/sirupsen/logrus v1.9.3 // indirect github.com/snowflakedb/gosnowflake v1.12.0 // indirect github.com/stretchr/objx v0.5.2 // indirect + github.com/thda/tds v0.1.7 // indirect github.com/zeebo/xxh3 v1.0.2 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/collector/consumer/consumererror v0.120.1-0.20250219144032-c2af75d88e89 // indirect diff --git a/receiver/sqlserverreceiver/go.sum b/receiver/sqlserverreceiver/go.sum index 35d9081863bd9..2a53e942f12c5 100644 --- a/receiver/sqlserverreceiver/go.sum +++ b/receiver/sqlserverreceiver/go.sum @@ -66,6 +66,9 @@ github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -154,6 +157,7 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/microsoft/go-mssqldb v1.8.0 h1:7cyZ/AT7ycDsEoWPIXibd+aVKFtteUNhDGf3aobP+tw= github.com/microsoft/go-mssqldb v1.8.0/go.mod h1:6znkekS3T2vp0waiMhen4GPU1BiAsrP+iXHcE7a7rFo= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= @@ -195,6 +199,9 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/thda/tds v0.1.7 h1:s29kbnJK0agL3ps85A/sb9XS2uxgKF5UJ6AZjbyqXX4= +github.com/thda/tds v0.1.7/go.mod h1:isLIF1oZdXfkqVMJM8RyNrsjlHPlTKnPlnsBs7ngZcM= +github.com/xo/tblfmt v0.0.0-20190609041254-28c54ec42ce8/go.mod h1:3U5kKQdIhwACye7ml3acccHmjGExY9WmUGU7rnDWgv0= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -259,6 +266,7 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -274,6 +282,7 @@ golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -291,6 +300,7 @@ golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -308,12 +318,14 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190802003818-e9bb7d36c060/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= From 4c45287ffbf92bc46b5acce6fdd6d6a0c4a16626 Mon Sep 17 00:00:00 2001 From: Michal Grandys Date: Wed, 12 Feb 2025 08:25:41 +0100 Subject: [PATCH 2/4] Update .chloggen/feat-sqlqueryreciver-sap-ase.yaml Co-authored-by: Curtis Robert --- .chloggen/feat-sqlqueryreciver-sap-ase.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/feat-sqlqueryreciver-sap-ase.yaml b/.chloggen/feat-sqlqueryreciver-sap-ase.yaml index b909e76834089..e4195491f0767 100644 --- a/.chloggen/feat-sqlqueryreciver-sap-ase.yaml +++ b/.chloggen/feat-sqlqueryreciver-sap-ase.yaml @@ -4,7 +4,7 @@ change_type: enhancement # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) -component: receiver/sqlqueryreceiver +component: receiver/sqlquery # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). note: Add support for SapASE (sybase) database connections From 1f3bdafdb5bbbfb6669fc1098bc11c968c88dfed Mon Sep 17 00:00:00 2001 From: Michal Grandys Date: Wed, 12 Feb 2025 12:49:53 +0100 Subject: [PATCH 3/4] do not skip SapASE integration test --- receiver/sqlqueryreceiver/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/receiver/sqlqueryreceiver/integration_test.go b/receiver/sqlqueryreceiver/integration_test.go index 0b1addf58ea88..6ef08cffce05a 100644 --- a/receiver/sqlqueryreceiver/integration_test.go +++ b/receiver/sqlqueryreceiver/integration_test.go @@ -179,8 +179,8 @@ var ( SQLParameter: func(_ int) string { return "?" }, - CheckCompatibility: func(t *testing.T) { - t.Skip("Skipping the test until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27577 is fixed") + CheckCompatibility: func(_ *testing.T) { + // t.Skip("Skipping the test until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27577 is fixed") }, ConnectionString: func(host string, externalPort nat.Port) string { return fmt.Sprintf("tds://otel:otel1234@%s:%s/otel", host, externalPort.Port()) From 4e051b1f9661b1e0f4fe22867997a078f84cf9db Mon Sep 17 00:00:00 2001 From: Michal Grandys Date: Wed, 12 Feb 2025 13:41:03 +0100 Subject: [PATCH 4/4] Revert "do not skip SapASE integration test" This reverts commit 1008b6cb54da13308a30e44aed433eb08de8b6bc. --- receiver/sqlqueryreceiver/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/receiver/sqlqueryreceiver/integration_test.go b/receiver/sqlqueryreceiver/integration_test.go index 6ef08cffce05a..0b1addf58ea88 100644 --- a/receiver/sqlqueryreceiver/integration_test.go +++ b/receiver/sqlqueryreceiver/integration_test.go @@ -179,8 +179,8 @@ var ( SQLParameter: func(_ int) string { return "?" }, - CheckCompatibility: func(_ *testing.T) { - // t.Skip("Skipping the test until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27577 is fixed") + CheckCompatibility: func(t *testing.T) { + t.Skip("Skipping the test until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27577 is fixed") }, ConnectionString: func(host string, externalPort nat.Port) string { return fmt.Sprintf("tds://otel:otel1234@%s:%s/otel", host, externalPort.Port())