Skip to content

Commit 965c8da

Browse files
committed
ci fixes
Signed-off-by: kumarabd <[email protected]>
1 parent fb7e794 commit 965c8da

File tree

4 files changed

+112
-97
lines changed

4 files changed

+112
-97
lines changed

pkg/client/error.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
const (
88
ErrGRPCDialCode = "1000"
99
ErrInvalidEndpointCode = "1001"
10+
ErrResponseNilCode = "1002"
1011
)
1112

1213
var (
1314
ErrInvalidEndpoint = errors.NewDefault(ErrInvalidEndpointCode, "Endpoint not reachable")
15+
ErrResponseNil = errors.NewDefault(ErrResponseNilCode, "Response is nil from the generator")
1416
)
1517

1618
func ErrGRPCDial(err error) error {

pkg/client/nighthawk.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@ type Client struct {
2323

2424
// New creates a new instance of the nighthawk client connection
2525
func New(opts Options) (*Client, error) {
26-
2726
if !utils.TcpCheck(&utils.HostPort{
2827
Address: opts.ServerHost,
2928
Port: opts.ServerPort,
3029
}, nil) {
3130
return nil, ErrInvalidEndpoint
3231
}
3332

34-
var dial_options []grpc.DialOption
35-
dial_options = append(dial_options, grpc.WithInsecure())
33+
var dialOptions []grpc.DialOption
34+
dialOptions = append(dialOptions, grpc.WithInsecure())
3635

37-
conn, err := grpc.Dial(fmt.Sprintf("%s:%d", opts.ServerHost, opts.ServerPort), dial_options...)
36+
conn, err := grpc.Dial(fmt.Sprintf("%s:%d", opts.ServerHost, opts.ServerPort), dialOptions...)
3837
if err != nil {
3938
return nil, ErrGRPCDial(err)
4039
}

pkg/client/nighthawk_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestNew(t *testing.T) {
2929
},
3030
}
3131
for _, tt := range tests {
32+
tt := tt
3233
t.Run(tt.name, func(t *testing.T) {
3334
got, err := New(tt.args.opts)
3435
if (err != nil) != tt.wantErr {

pkg/client/transform.go

Lines changed: 106 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -121,64 +121,9 @@ type TransformResult struct {
121121
}
122122

123123
func Transform(res *nighthawk_client.ExecutionResponse, typ string) ([]byte, error) {
124-
125-
//dur, err := time.ParseDuration(fmt.Sprintf("%ds%dµs", res.Output.Timestamp.Seconds, res.Output.Timestamp.Nanos))
126-
//if err != nil {
127-
// return nil, err
128-
//}
129-
130-
results := make([]Result, 0)
131-
132-
for _, r := range res.Output.Results {
133-
statistics := make([]Statistic, 0)
134-
counters := make([]Counter, 0)
135-
for _, c := range r.Counters {
136-
counters = append(counters, Counter{
137-
Name: c.Name,
138-
Value: strconv.Itoa(int(c.Value)),
139-
})
140-
}
141-
142-
for _, s := range r.Statistics {
143-
percentiles := make([]Percentile, 0)
144-
for _, p := range s.Percentiles {
145-
percentiles = append(percentiles, Percentile{
146-
Percentile: int(p.Percentile),
147-
Count: strconv.Itoa(int(p.Count)),
148-
Duration: formatToNs(p.GetDuration()),
149-
})
150-
}
151-
152-
sts := Statistic{
153-
Count: strconv.Itoa(int(s.Count)),
154-
ID: s.Id,
155-
Percentiles: percentiles,
156-
Mean: formatToNs(s.GetMean()),
157-
Pstdev: formatToNs(s.GetPstdev()),
158-
Min: formatToNs(s.GetMin()),
159-
Max: formatToNs(s.GetMax()),
160-
}
161-
if sts.Mean == "" {
162-
sts.RawMean = int(s.GetRawMean())
163-
}
164-
if sts.Pstdev == "" {
165-
sts.RawPstdev = int(s.GetRawPstdev())
166-
}
167-
if sts.Min == "" {
168-
sts.RawMin = strconv.Itoa(int(s.GetRawMin()))
169-
}
170-
if sts.Max == "" {
171-
sts.RawMax = strconv.Itoa(int(s.GetRawMax()))
172-
}
173-
statistics = append(statistics, sts)
174-
}
175-
results = append(results, Result{
176-
Name: r.Name,
177-
ExecutionStart: r.ExecutionStart.AsTime(),
178-
ExecutionDuration: formatToNs(r.ExecutionDuration),
179-
Statistics: statistics,
180-
Counters: counters,
181-
})
124+
results, err := constructResults(res)
125+
if err != nil {
126+
return nil, err
182127
}
183128

184129
expStrategy := res.Output.Options.ExperimentalH1ConnectionReuseStrategy.String()
@@ -241,20 +186,118 @@ func Transform(res *nighthawk_client.ExecutionResponse, typ string) ([]byte, err
241186
if err != nil {
242187
return nil, err
243188
}
244-
fmt.Println("input: ", input)
245189

246-
command := "/private/var/tmp/_bazel_abishekk/eaf1167d72f4772496616c435b301da8/execroot/nighthawk/bazel-out/darwin-opt/bin/nighthawk_output_transform"
190+
command := "./nighthawk_output_transform"
247191
cmd := exec.Command(command, "--output-format", "fortio")
248192
cmd.Stdin = strings.NewReader(input)
249193
out, err := cmd.Output()
250194
if err != nil {
251195
return nil, err
252196
}
253-
fmt.Println("output: ", string(out))
254197

255198
// Hack due to bug in nighthawk
199+
outputFinal, err := hackFormat(out)
200+
if err != nil {
201+
return nil, err
202+
}
203+
204+
return outputFinal, nil
205+
}
206+
207+
func constructResults(res *nighthawk_client.ExecutionResponse) ([]Result, error) {
208+
results := make([]Result, 0)
209+
if res == nil {
210+
return nil, ErrResponseNil
211+
}
212+
213+
for _, r := range res.Output.Results {
214+
statistics := make([]Statistic, 0)
215+
counters := make([]Counter, 0)
216+
for _, c := range r.Counters {
217+
counters = append(counters, Counter{
218+
Name: c.Name,
219+
Value: strconv.Itoa(int(c.Value)),
220+
})
221+
}
222+
223+
for _, s := range r.Statistics {
224+
percentiles := make([]Percentile, 0)
225+
for _, p := range s.Percentiles {
226+
percentiles = append(percentiles, Percentile{
227+
Percentile: int(p.Percentile),
228+
Count: strconv.Itoa(int(p.Count)),
229+
Duration: formatToNs(p.GetDuration()),
230+
})
231+
}
232+
233+
sts := Statistic{
234+
Count: strconv.Itoa(int(s.Count)),
235+
ID: s.Id,
236+
Percentiles: percentiles,
237+
Mean: formatToNs(s.GetMean()),
238+
Pstdev: formatToNs(s.GetPstdev()),
239+
Min: formatToNs(s.GetMin()),
240+
Max: formatToNs(s.GetMax()),
241+
}
242+
if sts.Mean == "" {
243+
sts.RawMean = int(s.GetRawMean())
244+
}
245+
if sts.Pstdev == "" {
246+
sts.RawPstdev = int(s.GetRawPstdev())
247+
}
248+
if sts.Min == "" {
249+
sts.RawMin = strconv.Itoa(int(s.GetRawMin()))
250+
}
251+
if sts.Max == "" {
252+
sts.RawMax = strconv.Itoa(int(s.GetRawMax()))
253+
}
254+
statistics = append(statistics, sts)
255+
}
256+
results = append(results, Result{
257+
Name: r.Name,
258+
ExecutionStart: r.ExecutionStart.AsTime(),
259+
ExecutionDuration: formatToNs(r.ExecutionDuration),
260+
Statistics: statistics,
261+
Counters: counters,
262+
})
263+
}
264+
return results, nil
265+
}
266+
267+
func formatToNs(s *duration.Duration) string {
268+
ss := s.AsDuration().String()
269+
if strings.Contains(ss, "ms") {
270+
sep := strings.Split(ss, "m")
271+
f, _ := strconv.ParseFloat(sep[0], 64)
272+
f /= 1000
273+
st := fmt.Sprintf("%f", f)
274+
sep[0] = st
275+
ss = strings.Join(sep, "")
276+
} else if strings.Contains(ss, "µs") {
277+
sep := strings.Split(ss, "µ")
278+
f, _ := strconv.ParseFloat(sep[0], 64)
279+
f /= 1000000
280+
st := fmt.Sprintf("%f", f)
281+
sep[0] = st
282+
ss = strings.Join(sep, "")
283+
} else if strings.Contains(ss, "ns") {
284+
sep := strings.Split(ss, "n")
285+
f, _ := strconv.ParseFloat(sep[0], 64)
286+
f /= 10000000
287+
st := fmt.Sprintf("%f", f)
288+
sep[0] = st
289+
ss = strings.Join(sep, "")
290+
}
291+
return ss
292+
}
293+
294+
func hackFormat(out []byte) ([]byte, error) {
256295
m := map[string]interface{}{}
257-
err = json.Unmarshal(out, &m)
296+
err := json.Unmarshal(out, &m)
297+
if err != nil {
298+
return nil, err
299+
}
300+
258301
m["RequestedQPS"] = fmt.Sprint(m["RequestedQPS"].(float64))
259302

260303
if m["DurationHistogram"] != nil {
@@ -298,35 +341,5 @@ func Transform(res *nighthawk_client.ExecutionResponse, typ string) ([]byte, err
298341
}
299342
m["Sizes"].(map[string]interface{})["Count"] = h
300343
}
301-
302-
outTemp, _ := json.Marshal(m)
303-
304-
return outTemp, nil
305-
}
306-
307-
func formatToNs(s *duration.Duration) string {
308-
ss := s.AsDuration().String()
309-
if strings.Contains(ss, "ms") {
310-
sep := strings.Split(ss, "m")
311-
f, _ := strconv.ParseFloat(sep[0], 64)
312-
f = f / 1000
313-
st := fmt.Sprintf("%f", f)
314-
sep[0] = st
315-
ss = strings.Join(sep, "")
316-
} else if strings.Contains(ss, "µs") {
317-
sep := strings.Split(ss, "µ")
318-
f, _ := strconv.ParseFloat(sep[0], 64)
319-
f = f / 1000000
320-
st := fmt.Sprintf("%f", f)
321-
sep[0] = st
322-
ss = strings.Join(sep, "")
323-
} else if strings.Contains(ss, "ns") {
324-
sep := strings.Split(ss, "n")
325-
f, _ := strconv.ParseFloat(sep[0], 64)
326-
f = f / 10000000
327-
st := fmt.Sprintf("%f", f)
328-
sep[0] = st
329-
ss = strings.Join(sep, "")
330-
}
331-
return ss
344+
return json.Marshal(m)
332345
}

0 commit comments

Comments
 (0)