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

switch int64 to uint64 #90

Merged
merged 1 commit into from
May 11, 2024
Merged

switch int64 to uint64 #90

merged 1 commit into from
May 11, 2024

Conversation

copperlight
Copy link
Collaborator

@copperlight copperlight commented May 11, 2024

In a number of places throughout the code, we were using the int64 type, while performing checks to ensure that the values were non-negative. The better way to do this is to switch the type to uint64, which will call out those errors at compile time, and will help prevent integer overflow errors, when dealing with very large numbers, as may be the case with monotonic counters. Switching these types also allows us to delete a fair amount of code for checking and testing these values.

Of all the type swaps that occurred in this change, only the Counter and the MonotonicCounter wanted non-zero values. However, these values are not illegal to send to spectatord, so we are fine dropping that restriction.

Also, update the monotonic counter parameter name to reflect that it is recording a value, because spectatord is now responsible for calculating the delta.

Also, run go mod tidy to remove all of the unused dependency references.

In a number of places throughout the code, we were using the `int64` type,
while performing checks to ensure that the values were non-negative. The
better way to do this is to switch the type to `uint64`, which will call
out those errors at compile time, and will help prevent integer overflow
errors, when dealing with very large numbers, as may be the case with
monotonic counters. Switching these types also allows us to delete a fair
amount of code for checking and testing these values.

Of all the type swaps that occurred in this change, only the Counter and
the MonotonicCounter wanted non-zero values. However, these values are not
illegal to send to spectatord, so we are fine dropping that restriction.

Also, update the monotonic counter parameter name to reflect that it is
recording a value, because spectatord is now responsible for calculating
the delta.

Also, run `go mod tidy` to remove all of the unused dependency references.
@copperlight copperlight merged commit 8d0203b into Netflix:main May 11, 2024
2 checks passed
@copperlight copperlight deleted the fix-int64 branch May 11, 2024 01:18
copperlight added a commit that referenced this pull request May 11, 2024
This reverts commit 8d0203b.

There are two issues with this change: (1) it is a breaking API change, and
(2) it is a bit of an un-natural usage pattern, because you may need to cast
variables to `uint64` in order to use these functions. In Go, there are no
literals for `uint64`, so you need to declare that type up-front during the
construction of a variable. If you pass an int literal to the functions, they
will be accepted as long as they fit the parameters of `uint64`.

We should offer support for `uint64`, particularly for `MonotonicCounter`s,
which can grow large, but it should be done through additional methods such
as `AddUint`, much like was done for `float64` in the `AddFloat` functions.
This way, you can use `uint64`, if you need them, but common case of working
with `int` literals will behave as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant