Skip to content

Commit 3ebb88f

Browse files
author
agopala95
committed
added review changes for route monitor data
1 parent 62ad655 commit 3ebb88f

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

pkg/e2e/routemonitors/routemonitors.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ type RouteMonitors struct {
3535
Plots map[string]*plot.Plot
3636
targeters map[string]vegeta.Targeter
3737
attackers []*vegeta.Attacker
38-
ReportData map[string][][]float64
38+
ReportData map[string][]RouteMonData
3939
}
4040

4141
// Frequency of requests per second (per route)
4242
const pollFrequency = 3
4343
const timeoutSeconds = 3 * time.Second
4444

45+
// Data Structure used to store time-value values of Route Monitor Data
46+
type RouteMonData struct {
47+
Time, Value float64
48+
}
49+
4550
// Detects the available routes in the cluster and initializes monitors for their availability
4651
func Create() (*RouteMonitors, error) {
4752
h := helper.NewOutsideGinkgo()
@@ -139,11 +144,11 @@ func Create() (*RouteMonitors, error) {
139144
}
140145

141146
return &RouteMonitors{
142-
Monitors: make(map[string]<-chan *vegeta.Result, 0),
143-
Metrics: make(map[string]*vegeta.Metrics, 0),
144-
Plots: make(map[string]*plot.Plot, 0),
147+
Monitors: make(map[string]<-chan *vegeta.Result),
148+
Metrics: make(map[string]*vegeta.Metrics),
149+
Plots: make(map[string]*plot.Plot),
145150
targeters: targeters,
146-
ReportData: make(map[string][][]float64, 0),
151+
ReportData: make(map[string][]RouteMonData),
147152
}, nil
148153
}
149154

@@ -248,14 +253,12 @@ func createPlot(title string) *plot.Plot {
248253
func (rm *RouteMonitors) ExtractData(baseDir string) error {
249254
outputDirectory := filepath.Join(baseDir, "route-monitors")
250255
if _, err := os.Stat(outputDirectory); os.IsNotExist(err) {
251-
if err := os.Mkdir(outputDirectory, os.FileMode(0755)); err != nil {
256+
if err := os.MkdirAll(outputDirectory, os.FileMode(0755)); err != nil {
252257
return fmt.Errorf("error while creating route monitor report directory %s: %v", outputDirectory, err)
253258
}
254259
}
255260

256-
for title, pl := range rm.Plots {
257-
_ = pl
258-
261+
for title := range rm.Plots {
259262
// Open the plot file
260263
htmlfilePath := filepath.Join(outputDirectory, fmt.Sprintf("%s.html", title))
261264
file, err := os.Open(htmlfilePath)
@@ -271,7 +274,8 @@ func (rm *RouteMonitors) ExtractData(baseDir string) error {
271274
readdata := false
272275

273276
// This list stores the numbers
274-
datalist := make([][]float64, 0)
277+
278+
datalist := make([]RouteMonData, 0)
275279

276280
// Scan each line in the html file to extract data
277281
scanner := bufio.NewReader(file)
@@ -286,15 +290,15 @@ func (rm *RouteMonitors) ExtractData(baseDir string) error {
286290
if readdata {
287291
if datanum_regex.FindString(line) != "" {
288292
num_str := strings.Split(start_regex.FindString(line), ",")
289-
time_num, err := strconv.ParseFloat(num_str[0], 64)
293+
num_data := RouteMonData{}
294+
num_data.Time, err = strconv.ParseFloat(num_str[0], 64)
290295
if err != nil {
291296
log.Printf("Error while parsing route monitor data values - %v", err)
292297
}
293-
value_num, err := strconv.ParseFloat(num_str[1], 64)
298+
num_data.Value, err = strconv.ParseFloat(num_str[1], 64)
294299
if err != nil {
295300
log.Printf("Error while parsing route monitor data values - %v", err)
296301
}
297-
num_data := []float64{time_num, value_num}
298302
datalist = append(datalist, num_data)
299303
}
300304
}

0 commit comments

Comments
 (0)