Skip to content

Commit 1160ccd

Browse files
authored
Fix download serialization to JSON to be a float in bps instead of a string with unit (#216)
1 parent e6c17c1 commit 1160ccd

File tree

5 files changed

+4
-234
lines changed

5 files changed

+4
-234
lines changed

NOTICE.txt

Lines changed: 0 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -41,207 +41,6 @@ SOFTWARE.
4141

4242

4343

44-
--------------------------------------------------------------------------------
45-
Dependency : github.com/docker/go-units
46-
Version: v0.5.0
47-
Licence type (autodetected): Apache-2.0
48-
--------------------------------------------------------------------------------
49-
50-
Contents of probable licence file $GOMODCACHE/github.com/docker/[email protected]/LICENSE:
51-
52-
53-
Apache License
54-
Version 2.0, January 2004
55-
https://www.apache.org/licenses/
56-
57-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
58-
59-
1. Definitions.
60-
61-
"License" shall mean the terms and conditions for use, reproduction,
62-
and distribution as defined by Sections 1 through 9 of this document.
63-
64-
"Licensor" shall mean the copyright owner or entity authorized by
65-
the copyright owner that is granting the License.
66-
67-
"Legal Entity" shall mean the union of the acting entity and all
68-
other entities that control, are controlled by, or are under common
69-
control with that entity. For the purposes of this definition,
70-
"control" means (i) the power, direct or indirect, to cause the
71-
direction or management of such entity, whether by contract or
72-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
73-
outstanding shares, or (iii) beneficial ownership of such entity.
74-
75-
"You" (or "Your") shall mean an individual or Legal Entity
76-
exercising permissions granted by this License.
77-
78-
"Source" form shall mean the preferred form for making modifications,
79-
including but not limited to software source code, documentation
80-
source, and configuration files.
81-
82-
"Object" form shall mean any form resulting from mechanical
83-
transformation or translation of a Source form, including but
84-
not limited to compiled object code, generated documentation,
85-
and conversions to other media types.
86-
87-
"Work" shall mean the work of authorship, whether in Source or
88-
Object form, made available under the License, as indicated by a
89-
copyright notice that is included in or attached to the work
90-
(an example is provided in the Appendix below).
91-
92-
"Derivative Works" shall mean any work, whether in Source or Object
93-
form, that is based on (or derived from) the Work and for which the
94-
editorial revisions, annotations, elaborations, or other modifications
95-
represent, as a whole, an original work of authorship. For the purposes
96-
of this License, Derivative Works shall not include works that remain
97-
separable from, or merely link (or bind by name) to the interfaces of,
98-
the Work and Derivative Works thereof.
99-
100-
"Contribution" shall mean any work of authorship, including
101-
the original version of the Work and any modifications or additions
102-
to that Work or Derivative Works thereof, that is intentionally
103-
submitted to Licensor for inclusion in the Work by the copyright owner
104-
or by an individual or Legal Entity authorized to submit on behalf of
105-
the copyright owner. For the purposes of this definition, "submitted"
106-
means any form of electronic, verbal, or written communication sent
107-
to the Licensor or its representatives, including but not limited to
108-
communication on electronic mailing lists, source code control systems,
109-
and issue tracking systems that are managed by, or on behalf of, the
110-
Licensor for the purpose of discussing and improving the Work, but
111-
excluding communication that is conspicuously marked or otherwise
112-
designated in writing by the copyright owner as "Not a Contribution."
113-
114-
"Contributor" shall mean Licensor and any individual or Legal Entity
115-
on behalf of whom a Contribution has been received by Licensor and
116-
subsequently incorporated within the Work.
117-
118-
2. Grant of Copyright License. Subject to the terms and conditions of
119-
this License, each Contributor hereby grants to You a perpetual,
120-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
121-
copyright license to reproduce, prepare Derivative Works of,
122-
publicly display, publicly perform, sublicense, and distribute the
123-
Work and such Derivative Works in Source or Object form.
124-
125-
3. Grant of Patent License. Subject to the terms and conditions of
126-
this License, each Contributor hereby grants to You a perpetual,
127-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
128-
(except as stated in this section) patent license to make, have made,
129-
use, offer to sell, sell, import, and otherwise transfer the Work,
130-
where such license applies only to those patent claims licensable
131-
by such Contributor that are necessarily infringed by their
132-
Contribution(s) alone or by combination of their Contribution(s)
133-
with the Work to which such Contribution(s) was submitted. If You
134-
institute patent litigation against any entity (including a
135-
cross-claim or counterclaim in a lawsuit) alleging that the Work
136-
or a Contribution incorporated within the Work constitutes direct
137-
or contributory patent infringement, then any patent licenses
138-
granted to You under this License for that Work shall terminate
139-
as of the date such litigation is filed.
140-
141-
4. Redistribution. You may reproduce and distribute copies of the
142-
Work or Derivative Works thereof in any medium, with or without
143-
modifications, and in Source or Object form, provided that You
144-
meet the following conditions:
145-
146-
(a) You must give any other recipients of the Work or
147-
Derivative Works a copy of this License; and
148-
149-
(b) You must cause any modified files to carry prominent notices
150-
stating that You changed the files; and
151-
152-
(c) You must retain, in the Source form of any Derivative Works
153-
that You distribute, all copyright, patent, trademark, and
154-
attribution notices from the Source form of the Work,
155-
excluding those notices that do not pertain to any part of
156-
the Derivative Works; and
157-
158-
(d) If the Work includes a "NOTICE" text file as part of its
159-
distribution, then any Derivative Works that You distribute must
160-
include a readable copy of the attribution notices contained
161-
within such NOTICE file, excluding those notices that do not
162-
pertain to any part of the Derivative Works, in at least one
163-
of the following places: within a NOTICE text file distributed
164-
as part of the Derivative Works; within the Source form or
165-
documentation, if provided along with the Derivative Works; or,
166-
within a display generated by the Derivative Works, if and
167-
wherever such third-party notices normally appear. The contents
168-
of the NOTICE file are for informational purposes only and
169-
do not modify the License. You may add Your own attribution
170-
notices within Derivative Works that You distribute, alongside
171-
or as an addendum to the NOTICE text from the Work, provided
172-
that such additional attribution notices cannot be construed
173-
as modifying the License.
174-
175-
You may add Your own copyright statement to Your modifications and
176-
may provide additional or different license terms and conditions
177-
for use, reproduction, or distribution of Your modifications, or
178-
for any such Derivative Works as a whole, provided Your use,
179-
reproduction, and distribution of the Work otherwise complies with
180-
the conditions stated in this License.
181-
182-
5. Submission of Contributions. Unless You explicitly state otherwise,
183-
any Contribution intentionally submitted for inclusion in the Work
184-
by You to the Licensor shall be under the terms and conditions of
185-
this License, without any additional terms or conditions.
186-
Notwithstanding the above, nothing herein shall supersede or modify
187-
the terms of any separate license agreement you may have executed
188-
with Licensor regarding such Contributions.
189-
190-
6. Trademarks. This License does not grant permission to use the trade
191-
names, trademarks, service marks, or product names of the Licensor,
192-
except as required for reasonable and customary use in describing the
193-
origin of the Work and reproducing the content of the NOTICE file.
194-
195-
7. Disclaimer of Warranty. Unless required by applicable law or
196-
agreed to in writing, Licensor provides the Work (and each
197-
Contributor provides its Contributions) on an "AS IS" BASIS,
198-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
199-
implied, including, without limitation, any warranties or conditions
200-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
201-
PARTICULAR PURPOSE. You are solely responsible for determining the
202-
appropriateness of using or redistributing the Work and assume any
203-
risks associated with Your exercise of permissions under this License.
204-
205-
8. Limitation of Liability. In no event and under no legal theory,
206-
whether in tort (including negligence), contract, or otherwise,
207-
unless required by applicable law (such as deliberate and grossly
208-
negligent acts) or agreed to in writing, shall any Contributor be
209-
liable to You for damages, including any direct, indirect, special,
210-
incidental, or consequential damages of any character arising as a
211-
result of this License or out of the use or inability to use the
212-
Work (including but not limited to damages for loss of goodwill,
213-
work stoppage, computer failure or malfunction, or any and all
214-
other commercial damages or losses), even if such Contributor
215-
has been advised of the possibility of such damages.
216-
217-
9. Accepting Warranty or Additional Liability. While redistributing
218-
the Work or Derivative Works thereof, You may choose to offer,
219-
and charge a fee for, acceptance of support, warranty, indemnity,
220-
or other liability obligations and/or rights consistent with this
221-
License. However, in accepting such obligations, You may act only
222-
on Your own behalf and on Your sole responsibility, not on behalf
223-
of any other Contributor, and only if You agree to indemnify,
224-
defend, and hold each Contributor harmless for any liability
225-
incurred by, or claims asserted against, such Contributor by reason
226-
of your accepting any such warranty or additional liability.
227-
228-
END OF TERMS AND CONDITIONS
229-
230-
Copyright 2015 Docker, Inc.
231-
232-
Licensed under the Apache License, Version 2.0 (the "License");
233-
you may not use this file except in compliance with the License.
234-
You may obtain a copy of the License at
235-
236-
https://www.apache.org/licenses/LICENSE-2.0
237-
238-
Unless required by applicable law or agreed to in writing, software
239-
distributed under the License is distributed on an "AS IS" BASIS,
240-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
241-
See the License for the specific language governing permissions and
242-
limitations under the License.
243-
244-
24544
--------------------------------------------------------------------------------
24645
Dependency : github.com/elastic/go-structform
24746
Version: v0.0.9

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.21
44

55
require (
66
github.com/Microsoft/go-winio v0.5.2
7-
github.com/docker/go-units v0.5.0
87
github.com/elastic/go-structform v0.0.9
98
github.com/elastic/go-ucfg v0.8.5
109
github.com/elastic/pkcs8 v1.0.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG
1010
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1111
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1212
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13-
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
14-
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
1513
github.com/elastic/go-structform v0.0.9 h1:HpcS7xljL4kSyUfDJ8cXTJC6rU5ChL1wYb6cx3HLD+o=
1614
github.com/elastic/go-structform v0.0.9/go.mod h1:CZWf9aIRYY5SuKSmOhtXScE5uQiLZNqAFnwKR4OrIM4=
1715
github.com/elastic/go-sysinfo v1.14.0 h1:dQRtiqLycoOOla7IflZg3aN213vqJmP0lpVpKQ9lUEY=

upgrade/details/details.go

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ package details
1919

2020
import (
2121
"encoding/json"
22-
"fmt"
2322
"math"
24-
"strings"
25-
26-
"github.com/docker/go-units"
2723
)
2824

2925
// DownloadRate is a float64 that can be safely marshalled to JSON
@@ -33,32 +29,10 @@ type DownloadRate float64
3329
func (dr *DownloadRate) MarshalJSON() ([]byte, error) {
3430
downloadRateBytesPerSecond := float64(*dr)
3531
if math.IsInf(downloadRateBytesPerSecond, 0) {
36-
return json.Marshal("+Inf bps")
32+
return json.Marshal(math.MaxFloat64)
3733
}
3834

3935
return json.Marshal(
40-
fmt.Sprintf("%sps", units.HumanSizeWithPrecision(downloadRateBytesPerSecond, 10)),
36+
downloadRateBytesPerSecond,
4137
)
4238
}
43-
44-
func (dr *DownloadRate) UnmarshalJSON(data []byte) error {
45-
var downloadRateStr string
46-
err := json.Unmarshal(data, &downloadRateStr)
47-
if err != nil {
48-
return err
49-
}
50-
51-
if downloadRateStr == "+Inf bps" {
52-
*dr = DownloadRate(math.Inf(1))
53-
return nil
54-
}
55-
56-
downloadRateStr = strings.TrimSuffix(downloadRateStr, "ps")
57-
downloadRateBytesPerSecond, err := units.FromHumanSize(downloadRateStr)
58-
if err != nil {
59-
return err
60-
}
61-
62-
*dr = DownloadRate(downloadRateBytesPerSecond)
63-
return nil
64-
}

upgrade/details/details_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestDownloadRateJSON(t *testing.T) {
3636
var unmarshalledDownloadRate DownloadRate
3737
err = json.Unmarshal(data, &unmarshalledDownloadRate)
3838
require.NoError(t, err)
39-
require.Equal(t, float64(1794), float64(unmarshalledDownloadRate))
39+
require.Equal(t, float64(1794.7), float64(unmarshalledDownloadRate))
4040
})
4141

4242
// Infinity download rate
@@ -49,6 +49,6 @@ func TestDownloadRateJSON(t *testing.T) {
4949
var unmarshalledDownloadRate DownloadRate
5050
err = json.Unmarshal(data, &unmarshalledDownloadRate)
5151
require.NoError(t, err)
52-
require.Equal(t, math.Inf(1), float64(unmarshalledDownloadRate))
52+
require.Equal(t, math.MaxFloat64, float64(unmarshalledDownloadRate))
5353
})
5454
}

0 commit comments

Comments
 (0)