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

Enable direct connection to SQL Server instance #30297

Closed
crobert-1 opened this issue Jan 4, 2024 · 4 comments · Fixed by #31915
Closed

Enable direct connection to SQL Server instance #30297

crobert-1 opened this issue Jan 4, 2024 · 4 comments · Fixed by #31915
Assignees
Labels
enhancement New feature or request receiver/sqlquery SQL query receiver receiver/sqlserver

Comments

@crobert-1
Copy link
Member

crobert-1 commented Jan 4, 2024

Component(s)

receiver/sqlserver

Is your feature request related to a problem? Please describe.

The existing implementation of the SQL Server receiver only collects information from Windows Performance counters. This was by design with the introduction of the receiver, as this solution provided good value for the amount of effort required (source). The main limitation was noted in the proposal as there would be metrics not covered by this solution, but it was acceptable at the time (source).

At this time there are two main drawbacks with the receiver's functionality:

  1. As noted, there are useful metrics that can not be gathered by this solution. I've received customer requests for some of these recently, as described in [receiver/sqlserver] Request to add support for more metrics #29865.
  2. SQL Server can be installed in Windows, Linux, and Docker environments, but the receiver can only be run in Windows.

Describe the solution you'd like

I want the sqlserver receiver to be able to run in all environments supported by SQL server itself, as well as scraping more metrics that can help users understand the status of the SQL server instances.

My proposed solution would be to add the sqlquery receiver as an internal dependency of the sqlserver receiver. The sqlserver receiver could expose metrics to the user as it does now, but internally rely on the sqlquery receiver to send the queries that would give metrics we want. This would require the addition of more configuration options for connection to the DB, as well as defining the metrics and queries we want.

Adding a receiver as a dependency of another may not be the best design, so a possible answer to this may also involve moving some sqlquery receiver logic into a central package as suggested here. This would allow re-using the same logic in multiple places without duplicating code.

Describe alternatives you've considered

  1. Require users to manually provide all relevant queries, and use the sqlquery receiver directly. This is a poor UX experience and very liable to misconfigurations. It also doesn't provide metric naming semantics, or re-usability for different users.
  2. Directly rely on the Telegraf SQL Server Plugin Input. This would change the receiver's configuration, as more options would be required to interface with Telegraf and to directly connect to a running SQL Server instance.There has been some discussion historically around directly using Telegraf plugins. This has been suggested in core, and here's an article of a working (at the time) implementation.This would allow us to leverage existing connection logic, as well as existing queries. Potential drawbacks may be relying on the Telegraf plugin itself, or potentially performance concerns around converting metrics received from telegraf into Otel's format. This would also be a bit more complex to implement.
  3. Rely on Telegraf's OpenTelemetry output plugin to send data to the collector, then use the influxdb receiver to ingest it. This works but is definitely a more complicated running environment for users.

Additional context

No response

@crobert-1 crobert-1 added enhancement New feature or request needs triage New item requiring triage labels Jan 4, 2024
Copy link
Contributor

github-actions bot commented Jan 4, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@crobert-1 crobert-1 added the receiver/sqlquery SQL query receiver label Jan 4, 2024
Copy link
Contributor

github-actions bot commented Jan 4, 2024

Pinging code owners for receiver/sqlquery: @dmitryax @pmcollins. See Adding Labels via Comments if you do not have permissions to add labels yourself.

@djaglowski djaglowski removed the needs triage New item requiring triage label Jan 9, 2024
@djaglowski
Copy link
Member

This makes sense to me. I would prefer that we not depend directly on another receiver though, and instead take the approach where we move common code to a shared package.

@crobert-1 crobert-1 self-assigned this Jan 11, 2024
dmitryax pushed a commit that referenced this issue Feb 2, 2024
…30709)

**Description:** 
As noted in the related issues, a lot of the logic in the sqlquery
receiver can be moved to a central package to be used by other
receivers. I realize this appears to be a large change, but it's purely
a re-organization PR, there's no functional changes. GitHub is not
recognizing moved files, so please refer to new file names and their
deleted counterparts. A lot of members are now public in the internal
package that were private in the receiver which is likely what's causing
GitHub to miss that they're just moved files.

This doesn't require a changelog (in my mind) because all things moving
were originally private to the receiver. They're now still purely
internal, so they won't be published.

I believe `internal` is the best destination for now as it allows us to
solidify the usage and interface before moving it to `pkg` to be
publicly available. There are still a lot of unknowns as far as how it
can be used by other receivers, so I fully expect "breaking changes" to
this. If we keep it internal we can update all usages with the changing
interface, so the changes won't be breaking.

**Link to tracking Issue:** 
#30297, #13546
anthoai97 pushed a commit to anthoai97/opentelemetry-collector-contrib that referenced this issue Feb 12, 2024
…pen-telemetry#30709)

**Description:** 
As noted in the related issues, a lot of the logic in the sqlquery
receiver can be moved to a central package to be used by other
receivers. I realize this appears to be a large change, but it's purely
a re-organization PR, there's no functional changes. GitHub is not
recognizing moved files, so please refer to new file names and their
deleted counterparts. A lot of members are now public in the internal
package that were private in the receiver which is likely what's causing
GitHub to miss that they're just moved files.

This doesn't require a changelog (in my mind) because all things moving
were originally private to the receiver. They're now still purely
internal, so they won't be published.

I believe `internal` is the best destination for now as it allows us to
solidify the usage and interface before moving it to `pkg` to be
publicly available. There are still a lot of unknowns as far as how it
can be used by other receivers, so I fully expect "breaking changes" to
this. If we keep it internal we can update all usages with the changing
interface, so the changes won't be breaking.

**Link to tracking Issue:** 
open-telemetry#30297, open-telemetry#13546
Copy link
Contributor

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the Stale label Mar 12, 2024
@crobert-1 crobert-1 removed the Stale label Mar 12, 2024
djaglowski pushed a commit that referenced this issue Apr 4, 2024
**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Add a query for the database IO metrics that SQL Server exposes. Read
more about available metrics
[here](https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-io-virtual-file-stats-transact-sql?view=sql-server-ver16).
This is a no-op update as this query will not be used until direct
connection to the SQL Server instance is fully implemented. This is
simply part of the effort.

**Note:** This code is currently not reached. This is on purpose.

**Link to tracking Issue:** <Issue number if applicable>
This was originally part of
#31915,
but I'm breaking this out to make the original PR a more manageable
size.


#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests and added tests are passing.

**Documentation:** <Describe the documentation added.>
Purposefully none: This is currently dead code until all of #31915 gets
merged, so it shouldn't be used.
ycombinator pushed a commit to ycombinator/opentelemetry-collector-contrib that referenced this issue Apr 9, 2024
…etry#32178)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Add a query for the database IO metrics that SQL Server exposes. Read
more about available metrics
[here](https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-io-virtual-file-stats-transact-sql?view=sql-server-ver16).
This is a no-op update as this query will not be used until direct
connection to the SQL Server instance is fully implemented. This is
simply part of the effort.

**Note:** This code is currently not reached. This is on purpose.

**Link to tracking Issue:** <Issue number if applicable>
This was originally part of
open-telemetry#31915,
but I'm breaking this out to make the original PR a more manageable
size.


open-telemetry#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests and added tests are passing.

**Documentation:** <Describe the documentation added.>
Purposefully none: This is currently dead code until all of open-telemetry#31915 gets
merged, so it shouldn't be used.
djaglowski pushed a commit that referenced this issue Apr 16, 2024
)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This adds config options for direct connection to a SQL server instance.
For the sake of PR size, this adds no functionality, it's simply config
options and validation.

**Link to tracking Issue:** <Issue number if applicable>
This was originally part of
#31915,
but I'm breaking this out to make the original PR a more manageable
size.


#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests and added tests are all passing.

**Documentation:** <Describe the documentation added.>
No documentation on purpose. The added config options currently have no
impact on functionality, so users shouldn't be aware of this, and
shouldn't try to use them yet.
djaglowski pushed a commit that referenced this issue Apr 17, 2024
…32471)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
A major part of
#31915
is adding support for other operating systems than Windows. This change
moves Windows-specific logic into files named as such, and renames some
specific functionality to match purpose, instead of generic names.

`newSQLServerScraper` -> `newSQLServerPCScraper` (PC in this context
stands for performance counters)
`sqlServerScraper` -> `sqlServerPCScraper``

This only renames internal functions and files, there's no user-facing
impact of this.

**Link to tracking Issue:** <Issue number if applicable>

#31915

#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests are passing.
djaglowski pushed a commit that referenced this issue Apr 19, 2024
…tems (#32542)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This change enables the SQL Server receiver to directly connect to SQL
Server instances, and to run on operating systems other than Windows.

This is part of
#31915,
but doesn't add any functionality for the end user. No metrics are
currently being gathered from SQL server instances, to make the PR
(hopefully) simpler to review.

**Link to tracking Issue:** <Issue number if applicable>

#31915

#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Tests added are passing.
djaglowski pushed a commit that referenced this issue Apr 23, 2024
…#31915)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This PR enables direct connection to SQL Server instances, and also
allows the SQL Server receiver to run on non-Windows platforms.

User-facing changes:
1. More (optional) configuration options. If the receiver wants to
connect directly to the SQL Server instance (rather than relying on
Windows Performance Counters), all of these options must be specified.
2. Add a new metric, `sqlserver.database_io.read_latency`. This is
disabled by default, and way randomly chosen as a single metric to try
to restrict this PR's size. I plan on following this PR up with more
metrics from the same query, as well as more queries and metrics.

Note: Existing users should see no change in functionality with this PR.
Using existing configurations with this PR should have no performance or
functional impact.

**Link to tracking Issue:** <Issue number if applicable>
Resolves
#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Tested on MacOS and Windows. Manual tested with direct connection to a
docker container on both platforms, as well as ran all tests in package.
Everything is passing.

**Working demo for testing:**
Docker container start command:
```
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=StrongPassw0rd" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest
```
Collector config:
```
sqlserver:
 password: "StrongPassw0rd"
 port: 1433
 server: 0.0.0.0
 username: sa
 resource_attributes:
   sqlserver.instance.name:
     enabled: true
   sqlserver.computer.name:
     enabled: true
 metrics:
   sqlserver.database_io.read_latency:
     enabled: true
```

**Documentation:** <Describe the documentation added.>
Updated README
djaglowski pushed a commit that referenced this issue May 8, 2024
… OS (#32878)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
With the enhancement in
#30297,
the SQL Server receiver can now run on MacOS and Linux, since it no
longer solely relies on Windows. The difference in functionality has
(hopefully) been documented clearly between the different platforms, so
the unsupported warning can be removed. I missed this in my previous
PRs.
rimitchell pushed a commit to rimitchell/opentelemetry-collector-contrib that referenced this issue May 8, 2024
…etry#32178)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Add a query for the database IO metrics that SQL Server exposes. Read
more about available metrics
[here](https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-io-virtual-file-stats-transact-sql?view=sql-server-ver16).
This is a no-op update as this query will not be used until direct
connection to the SQL Server instance is fully implemented. This is
simply part of the effort.

**Note:** This code is currently not reached. This is on purpose.

**Link to tracking Issue:** <Issue number if applicable>
This was originally part of
open-telemetry#31915,
but I'm breaking this out to make the original PR a more manageable
size.


open-telemetry#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests and added tests are passing.

**Documentation:** <Describe the documentation added.>
Purposefully none: This is currently dead code until all of open-telemetry#31915 gets
merged, so it shouldn't be used.
rimitchell pushed a commit to rimitchell/opentelemetry-collector-contrib that referenced this issue May 8, 2024
…n-telemetry#32176)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This adds config options for direct connection to a SQL server instance.
For the sake of PR size, this adds no functionality, it's simply config
options and validation.

**Link to tracking Issue:** <Issue number if applicable>
This was originally part of
open-telemetry#31915,
but I'm breaking this out to make the original PR a more manageable
size.


open-telemetry#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests and added tests are all passing.

**Documentation:** <Describe the documentation added.>
No documentation on purpose. The added config options currently have no
impact on functionality, so users shouldn't be aware of this, and
shouldn't try to use them yet.
rimitchell pushed a commit to rimitchell/opentelemetry-collector-contrib that referenced this issue May 8, 2024
…pen-telemetry#32471)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
A major part of
open-telemetry#31915
is adding support for other operating systems than Windows. This change
moves Windows-specific logic into files named as such, and renames some
specific functionality to match purpose, instead of generic names.

`newSQLServerScraper` -> `newSQLServerPCScraper` (PC in this context
stands for performance counters)
`sqlServerScraper` -> `sqlServerPCScraper``

This only renames internal functions and files, there's no user-facing
impact of this.

**Link to tracking Issue:** <Issue number if applicable>

open-telemetry#31915

open-telemetry#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Existing tests are passing.
rimitchell pushed a commit to rimitchell/opentelemetry-collector-contrib that referenced this issue May 8, 2024
…tems (open-telemetry#32542)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This change enables the SQL Server receiver to directly connect to SQL
Server instances, and to run on operating systems other than Windows.

This is part of
open-telemetry#31915,
but doesn't add any functionality for the end user. No metrics are
currently being gathered from SQL server instances, to make the PR
(hopefully) simpler to review.

**Link to tracking Issue:** <Issue number if applicable>

open-telemetry#31915

open-telemetry#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Tests added are passing.
rimitchell pushed a commit to rimitchell/opentelemetry-collector-contrib that referenced this issue May 8, 2024
…open-telemetry#31915)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This PR enables direct connection to SQL Server instances, and also
allows the SQL Server receiver to run on non-Windows platforms.

User-facing changes:
1. More (optional) configuration options. If the receiver wants to
connect directly to the SQL Server instance (rather than relying on
Windows Performance Counters), all of these options must be specified.
2. Add a new metric, `sqlserver.database_io.read_latency`. This is
disabled by default, and way randomly chosen as a single metric to try
to restrict this PR's size. I plan on following this PR up with more
metrics from the same query, as well as more queries and metrics.

Note: Existing users should see no change in functionality with this PR.
Using existing configurations with this PR should have no performance or
functional impact.

**Link to tracking Issue:** <Issue number if applicable>
Resolves
open-telemetry#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Tested on MacOS and Windows. Manual tested with direct connection to a
docker container on both platforms, as well as ran all tests in package.
Everything is passing.

**Working demo for testing:**
Docker container start command:
```
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=StrongPassw0rd" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest
```
Collector config:
```
sqlserver:
 password: "StrongPassw0rd"
 port: 1433
 server: 0.0.0.0
 username: sa
 resource_attributes:
   sqlserver.instance.name:
     enabled: true
   sqlserver.computer.name:
     enabled: true
 metrics:
   sqlserver.database_io.read_latency:
     enabled: true
```

**Documentation:** <Describe the documentation added.>
Updated README
rimitchell pushed a commit to rimitchell/opentelemetry-collector-contrib that referenced this issue May 8, 2024
… OS (open-telemetry#32878)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
With the enhancement in
open-telemetry#30297,
the SQL Server receiver can now run on MacOS and Linux, since it no
longer solely relies on Windows. The difference in functionality has
(hopefully) been documented clearly between the different platforms, so
the unsupported warning can be removed. I missed this in my previous
PRs.
jlg-io pushed a commit to jlg-io/opentelemetry-collector-contrib that referenced this issue May 14, 2024
…open-telemetry#31915)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This PR enables direct connection to SQL Server instances, and also
allows the SQL Server receiver to run on non-Windows platforms.

User-facing changes:
1. More (optional) configuration options. If the receiver wants to
connect directly to the SQL Server instance (rather than relying on
Windows Performance Counters), all of these options must be specified.
2. Add a new metric, `sqlserver.database_io.read_latency`. This is
disabled by default, and way randomly chosen as a single metric to try
to restrict this PR's size. I plan on following this PR up with more
metrics from the same query, as well as more queries and metrics.

Note: Existing users should see no change in functionality with this PR.
Using existing configurations with this PR should have no performance or
functional impact.

**Link to tracking Issue:** <Issue number if applicable>
Resolves
open-telemetry#30297

**Testing:** <Describe what testing was performed and which tests were
added.>
Tested on MacOS and Windows. Manual tested with direct connection to a
docker container on both platforms, as well as ran all tests in package.
Everything is passing.

**Working demo for testing:**
Docker container start command:
```
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=StrongPassw0rd" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest
```
Collector config:
```
sqlserver:
 password: "StrongPassw0rd"
 port: 1433
 server: 0.0.0.0
 username: sa
 resource_attributes:
   sqlserver.instance.name:
     enabled: true
   sqlserver.computer.name:
     enabled: true
 metrics:
   sqlserver.database_io.read_latency:
     enabled: true
```

**Documentation:** <Describe the documentation added.>
Updated README
jlg-io pushed a commit to jlg-io/opentelemetry-collector-contrib that referenced this issue May 14, 2024
… OS (open-telemetry#32878)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
With the enhancement in
open-telemetry#30297,
the SQL Server receiver can now run on MacOS and Linux, since it no
longer solely relies on Windows. The difference in functionality has
(hopefully) been documented clearly between the different platforms, so
the unsupported warning can be removed. I missed this in my previous
PRs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request receiver/sqlquery SQL query receiver receiver/sqlserver
Projects
None yet
2 participants