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

datasource int overflow #507

Merged

Conversation

danielnachtrub
Copy link
Contributor

@danielnachtrub danielnachtrub commented Jul 10, 2024

Fixes an issue on datasource types that export counters that can reach values larger than an int32. Switched to TypeFloat because it's underlying type is float64.

@danielnachtrub danielnachtrub requested a review from a team as a code owner July 10, 2024 09:33
@dokmic
Copy link
Contributor

dokmic commented Jul 11, 2024

Hey @danielnachtrub,

Thanks for the contribution - that's a great job. But could you please share some examples of the numbers that cause fields to overflow on your end?

I quickly checked both our implementation and terraform-plugin-sdk. And they both use strconv underneath, so that the numbers should be converted to int64 and not int32.

To be honest, I don't think it's correct to use TypeFloat here, as those numbers cannot be fractional. It would probably be more correct to use TypeString or just get rid of the counters at all, as in #299.

@danielnachtrub
Copy link
Contributor Author

Technically float is for sure not the right type because numbers are integers - just not int32.

Here's what we've seen in the logs:

│ Error: strconv.Atoi: parsing "2618960812": value out of range for 'rx_byte' field
│
│   with module.routeros_interface_bond[0].data.routeros_interfaces.existing_interfaces,
│   on .terraform\modules\routeros_interface_bond\main.tf line 45, in data "routeros_interfaces" "existing_interfaces":
│   45: data "routeros_interfaces" "existing_interfaces" {}
│
╵
╷
│ Error: strconv.Atoi: parsing "2772712184": value out of range for 'rx_byte' field
│
│   with module.routeros_interface_bond[0].data.routeros_interfaces.existing_interfaces,
│   on .terraform\modules\routeros_interface_bond\main.tf line 45, in data "routeros_interfaces" "existing_interfaces":
│   45: data "routeros_interfaces" "existing_interfaces" {}
│
╵
╷
│ Error: strconv.Atoi: parsing "2621148278": value out of range for 'rx_byte' field
│
│   with module.routeros_interface_bond[0].data.routeros_interfaces.existing_interfaces,
│   on .terraform\modules\routeros_interface_bond\main.tf line 45, in data "routeros_interfaces" "existing_interfaces":
│   45: data "routeros_interfaces" "existing_interfaces" {}

@vaerh
Copy link
Collaborator

vaerh commented Jul 22, 2024

@danielnachtrub @dokmic
Greetings, friends!
It is impossible to convert counters from int32 to int64 directly. This is an old problem related to building modules for x32 architecture. I think Michael pointed out the right option earlier - to make these fields string or remove them from the schemа if they are counters.

@danielnachtrub
Copy link
Contributor Author

@vaerh @dokmic Okay, i can update it in this regard. As these fields are generating constantly changes and probably no deployment should rely on counters like this - do we need to expose them at all?

@vaerh
Copy link
Collaborator

vaerh commented Jul 22, 2024

I can't think of a case where full use of counters is possible within a deployment scenario.
I would ignore them.

@danielnachtrub
Copy link
Contributor Author

I agree on this one. So, should I prepare a PR that removes them instead of adjusting the value types?

@vaerh
Copy link
Collaborator

vaerh commented Jul 22, 2024

Sure, I don't mind.

@vaerh
Copy link
Collaborator

vaerh commented Aug 8, 2024

@danielnachtrub

Hi!

I'll leave a link to a similar change I made yesterday.

MetaSkipFields: PropSkipFields(
// Generic
"since", "status", "done_tests", "failed_tests",
// ICMP
"sent_count", "response_count", "loss_count", "loss_percent", "rtt_avg", "rtt_min", "rtt_max", "rtt_jitter",
"rtt_stdev",
// TCP
"tcp_connect_time",
// HTTP, HTTPS
"http_status_code",
// DNS
"ip", "ip6", "mail_servers", "name_servers",
),

#535

We can't just remove unnecessary attributes, as the user will get warnings about fields missing in the schema.

@danielnachtrub
Copy link
Contributor Author

@vaerh better now?

@vaerh
Copy link
Collaborator

vaerh commented Aug 12, 2024

@danielnachtrub

better now?

Yes!

I have one questions: ingress_priority & random these two metrics, based on MT's description, are meaningful and should not change over time. Does it make sense to reduce them?

@vaerh vaerh merged commit aea6028 into terraform-routeros:main Aug 13, 2024
3 checks passed
@vaerh
Copy link
Collaborator

vaerh commented Aug 13, 2024

🎉 This PR is included in version 1.59.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@vaerh vaerh added the released label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants