Skip to content

Fix download serialization to JSON to be a float in bps instead of a string with unit#216

Merged
nchaulet merged 3 commits intomainfrom
fix-upgrade-details-json
Jul 11, 2024
Merged

Fix download serialization to JSON to be a float in bps instead of a string with unit#216
nchaulet merged 3 commits intomainfrom
fix-upgrade-details-json

Conversation

@nchaulet
Copy link
Copy Markdown
Member

@nchaulet nchaulet commented Jul 4, 2024

Description

Related to https://github.com/elastic/ingest-dev/issues/3446

Fix DownloadRate serialization to JSON to be a float in bps instead of a string with unit.

as serializing Inf to json is not possible, I fallback to the max float value, I think it's probably better than crashing for that.

@nchaulet nchaulet self-assigned this Jul 5, 2024
@nchaulet nchaulet added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Jul 5, 2024
@nchaulet nchaulet marked this pull request as ready for review July 5, 2024 13:02
@nchaulet nchaulet requested a review from a team as a code owner July 5, 2024 13:02
@nchaulet nchaulet requested review from belimawr and rdner and removed request for a team July 5, 2024 13:02
@elasticmachine
Copy link
Copy Markdown
Collaborator

💚 Build Succeeded

History

cc @nchaulet

@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Jul 5, 2024
@ycombinator ycombinator removed the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Jul 9, 2024
@ycombinator ycombinator requested review from blakerouse and michel-laterman and removed request for belimawr and rdner July 9, 2024 20:41
downloadRateBytesPerSecond := float64(*dr)
if math.IsInf(downloadRateBytesPerSecond, 0) {
return json.Marshal("+Inf bps")
return json.Marshal(math.MaxFloat64)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I fear that this could be misleading, especially if we use this value to get metrics or averages in ES/Kibana...

I get that having the unit is causing problems, but how often is this value actually Inf? Is it because the download rate is too slow or too fast?

I believe a custom marshal/unmarshal here and on Fleet-Server could more accurately handle those situations.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@belimawr actually I am not sure we ever encounter the Inf issue ever, as with the max float 64 value we could support 1.798e+284YBps,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Then I believe the best is to encode as +Inf/-Inf and deal with that on the Fleet side as well. Or even not send this value/piece of data as we know it is due to some issue.

The key thing on my mind is that if we show this to our users, it needs to be accurate, or clearly state we can't get this metric for some reason.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ycombinator I am curious to have your thoughts on that one as you did the original implementation, does the Inf scenario something that already happens/could happens when computing the download rate in the agent? otherwise it seems we may be able to use the default serialization and do not really care about Inf value no?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, IIRC, we have occasionally seen +Inf when the download happens really fast, almost instantaneously. But, stepping back and taking a look at the end-goal here, it is to let the user know how fast a download is proceeding. For really fast downloads, a user is not going to care if we report that as +Inf bps (which, of course, has proven problematic being a string) or some really large number like math.MaxFloat64. In some ways, the latter is a bit more realistic even. So I'm +1 for going with math.MaxFloat64 here as the fix.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you two agree with math.MaxFloat64 I'm not opposed to it. I'd just make sure we get the correct signal to differentiate between +Inf and -Inf.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, thanks @belimawr. I should've clarified that -Inf should never happen with the download rate so it's really a question of how we want to represent the +Inf situation as a numeric value.

@nchaulet nchaulet merged commit 1160ccd into main Jul 11, 2024
@nchaulet nchaulet deleted the fix-upgrade-details-json branch July 11, 2024 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants