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

[Fleet] Support download rate in string with unit format #3677

Merged
merged 6 commits into from
Jul 4, 2024

Conversation

nchaulet
Copy link
Member

@nchaulet nchaulet commented Jul 3, 2024

Description

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

Elastic-agent are currently not sending download rate as a float but as a string with unit, while this is fixed on the agent side and for older agent, Fleet server should accept both format.

That PR does that, and return a 400 instead of a 500 when an error parsing meta happen.

Todo

  • Changelog

@nchaulet nchaulet added Team:Fleet Label for the Fleet team Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team labels Jul 3, 2024
@nchaulet nchaulet self-assigned this Jul 3, 2024
@nchaulet nchaulet marked this pull request as ready for review July 3, 2024 15:47
@nchaulet nchaulet requested a review from a team as a code owner July 3, 2024 15:47
"github.com/docker/go-units"
)

func parseDownloadRate(jsonDownloadRate json.RawMessage) (*float64, error) {
Copy link
Contributor

@michel-laterman michel-laterman Jul 3, 2024

Choose a reason for hiding this comment

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

We should adjust the openapi spec for the download rate to be:

oneOf:
  - type: string
  - type: float

Copy link
Member Author

@nchaulet nchaulet Jul 3, 2024

Choose a reason for hiding this comment

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

@michel-laterman I am wondering if we should really change the openAPISpec, as this mostly a temporary fix to support a client that did not sent the correct value.

Copy link
Member

Choose a reason for hiding this comment

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

Don't make the error an officially accepted value. Tolerate it but don't encourage it's use.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, can you add a line in the changelog and as a description to this function to indicate this
also can you add tests that just test a random string input, and another that tests "MBps"

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I will add one with a random string input already had one with MBps

changelog/fragments/1720021515-fix_download_rate.yaml Outdated Show resolved Hide resolved
"github.com/docker/go-units"
)

func parseDownloadRate(jsonDownloadRate json.RawMessage) (*float64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, can you add a line in the changelog and as a description to this function to indicate this
also can you add tests that just test a random string input, and another that tests "MBps"

changelog/fragments/1720021515-fix_download_rate.yaml Outdated Show resolved Hide resolved
@nchaulet
Copy link
Member Author

nchaulet commented Jul 4, 2024

@michel-laterman I think it will make sense to backport this 8.15 no?

Copy link
Contributor

@michel-laterman michel-laterman left a comment

Choose a reason for hiding this comment

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

Please backport and add a an additional test case

expectedValue: 1000000.00,
}, {
name: "download rate random string",
raw: json.RawMessage(`"toto"`),
Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion for an additional test case would be to include just the suffix that is checked:
json.RawMessage(`"MBps"`) as a test case

@nchaulet nchaulet merged commit b04157a into main Jul 4, 2024
8 checks passed
@nchaulet nchaulet deleted the feature-handle-parse-download-rate branch July 4, 2024 17:55
mergify bot pushed a commit that referenced this pull request Jul 4, 2024
pierrehilbert pushed a commit that referenced this pull request Jul 5, 2024
(cherry picked from commit b04157a)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.15.0 Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team Team:Fleet Label for the Fleet team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants