Skip to content

[receiver/sqlserver] Properly parse scientific notation numbers to ints #39905

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

Merged

Conversation

crobert-1
Copy link
Member

@crobert-1 crobert-1 commented May 6, 2025

Description

SQL Server stores large integers in scientific e notation. strconv.ParseInt fails to parse this and raises an error, as seen in the original filed issue. For our use case, we still want these to be considered valid integers, so before failing entirely, attempt to parse to float and convert to integer.

This change also uses already existing methods, retrieveInt and retrieveFloat to be able to re-use the parsing functionality. The original issue was only for sqlserver.database.tempdb.space, but I believe this issue is relevant for all metrics of type int.

Link to tracking issue

Fixes #39124

Testing

Changed test values of a couple integers to ensure new functionality works. The changed values broke tests on main in the same way the filed bug shows, but tests are passing with this change.

@crobert-1 crobert-1 requested a review from a team as a code owner May 6, 2025 19:16
@crobert-1 crobert-1 requested a review from MovieStoreGuy May 6, 2025 19:16
@github-actions github-actions bot added receiver/sqlserver Run Windows Enable running windows test on a PR labels May 6, 2025
@github-actions github-actions bot requested review from sincejune and StefanKurek May 6, 2025 19:16
}
}
} else {
err = fmt.Errorf("no value found for column %s", columnName)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically in both retrieveInt and retrieveFloat I've added new potential errors scenarios, but both of these methods are only called currently from a select when a column name is seen in a row. I don't believe either of the new error cases are hit today, they're an attempt at future-proofing these methods.

Also, even if they're introducing new errors, the receiver is already failing to scrape the given metric or attribute, but it's just being hidden here and metrics are recorded as zero values. The proper behavior should be to notify users of errors.

@crobert-1 crobert-1 added ready to merge Code review completed; ready to merge by maintainers and removed waiting-for-code-owners labels May 7, 2025
@crobert-1 crobert-1 force-pushed the sqlserver_scientific_notation branch from 3576b7e to 4cf22c1 Compare May 7, 2025 16:55
@crobert-1 crobert-1 changed the title [reciver/sqlserver] Properly parse scientific notation numbers to ints [receiver/sqlserver] Properly parse scientific notation numbers to ints May 7, 2025
@atoulme atoulme merged commit d3f92cb into open-telemetry:main May 8, 2025
207 checks passed
@github-actions github-actions bot added this to the next release milestone May 8, 2025
dragonlord93 pushed a commit to dragonlord93/opentelemetry-collector-contrib that referenced this pull request May 23, 2025
…ts (open-telemetry#39905)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
SQL Server stores large integers in scientific e notation.
`strconv.ParseInt` fails to parse this and raises an error, as seen in
the original filed issue. For our use case, we still want these to be
considered valid integers, so before failing entirely, attempt to parse
to float and convert to integer.

This change also uses already existing methods, `retrieveInt` and
`retrieveFloat` to be able to re-use the parsing functionality. The
original issue was only for `sqlserver.database.tempdb.space`, but I
believe this issue is relevant for all metrics of type `int`.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#39124

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Changed test values of a couple integers to ensure new functionality
works. The changed values broke tests on `main` in the same way the
filed bug shows, but tests are passing with this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Code review completed; ready to merge by maintainers receiver/sqlserver Run Windows Enable running windows test on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[receiver/SQLServer] Error scraping metrics failed to parse valueKey
4 participants