Skip to content

Commit a7eb802

Browse files
committed
add by month test chart
1 parent 36b5c49 commit a7eb802

File tree

2 files changed

+114
-2
lines changed

2 files changed

+114
-2
lines changed

cmd/gopogh-server/flake_chart.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,98 @@ function displayTestAndEnvironmentChart(data, query) {
279279
chartsContainer.appendChild(flakeRateWeekContainer);
280280
const wChart = new google.visualization.LineChart(flakeRateWeekContainer);
281281
wChart.draw(weekChart, weekOptions);
282+
283+
const monthData = data.flakeByMonth
284+
const monthChart = new google.visualization.DataTable();
285+
monthChart.addColumn('date', 'Date');
286+
monthChart.addColumn('number', 'Flake Percentage');
287+
monthChart.addColumn({
288+
type: 'string',
289+
role: 'tooltip',
290+
'p': {
291+
'html': true
292+
}
293+
});
294+
monthChart.addColumn('number', 'Duration');
295+
monthChart.addColumn({
296+
type: 'string',
297+
role: 'tooltip',
298+
'p': {
299+
'html': true
300+
}
301+
});
302+
303+
console.log(monthChart)
304+
monthChart.addRows(
305+
monthData
306+
.map(groupData => {
307+
let dataArr = groupData.commitResultsAndDurations.split(',')
308+
dataArr = dataArr.map((commit) => commit.split(":"))
309+
const resultArr = dataArr.map((commit) => ({
310+
id: commit[commit.length - 3],
311+
status: (commit[commit.length - 2]).trim()
312+
}))
313+
const durationArr = dataArr.map((commit) => ({
314+
id: commit[commit.length - 3],
315+
status: (commit[commit.length - 2]).trim(),
316+
duration: (commit[commit.length - 1]).trim()
317+
}))
318+
319+
return [
320+
new Date(groupData.startOfDate),
321+
groupData.flakePercentage,
322+
`<div style="padding: 1rem; font-family: 'Arial'; font-size: 14">
323+
<b>Date:</b> ${groupData.startOfDate.toLocaleString([], {dateStyle: 'medium'})}<br>
324+
<b>Flake Percentage:</b> ${groupData.flakePercentage.toFixed(2)}%<br>
325+
<b>Jobs:</b><br>
326+
${resultArr.map(({ id, status }) => ` - <a href="${testGopoghLink(id, query.env, query.test, status)}">${id}</a> (${status})`).join("<br>")}
327+
</div>`,
328+
groupData.avgDuration,
329+
`<div style="padding: 1rem; font-family: 'Arial'; font-size: 14">
330+
<b>Date:</b> ${groupData.startOfDate.toLocaleString([], {dateStyle: 'medium'})}<br>
331+
<b>Average Duration:</b> ${groupData.avgDuration.toFixed(2)}s<br>
332+
<b>Jobs:</b><br>
333+
${durationArr.map(({ id, duration, status }) => ` - <a href="${testGopoghLink(id, query.env, query.test, status)}">${id}</a> (${duration}s)`).join("<br>")}
334+
</div>`,
335+
]
336+
})
337+
);
338+
const monthOptions = {
339+
title: `Flake rate and duration by month of ${query.test} on ${query.env}`,
340+
width: window.innerWidth,
341+
height: window.innerHeight,
342+
pointSize: 10,
343+
pointShape: "circle",
344+
series: {
345+
0: {
346+
targetAxisIndex: 0
347+
},
348+
1: {
349+
targetAxisIndex: 1
350+
},
351+
},
352+
vAxes: {
353+
0: {
354+
title: "Flake rate",
355+
minValue: 0,
356+
maxValue: 100
357+
},
358+
1: {
359+
title: "Duration (seconds)"
360+
},
361+
},
362+
colors: ['#dc3912', '#3366cc'],
363+
tooltip: {
364+
trigger: "selection",
365+
isHtml: true
366+
}
367+
};
368+
const flakeRateMonthContainer = document.createElement("div");
369+
flakeRateMonthContainer.style.width = "100vw";
370+
flakeRateMonthContainer.style.height = "100vh";
371+
chartsContainer.appendChild(flakeRateMonthContainer);
372+
const mChart = new google.visualization.LineChart(flakeRateMonthContainer);
373+
mChart.draw(monthChart, monthOptions);
282374
}
283375

284376
function displaySummaryChart(data) {

pkg/db/postgres.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,29 @@ func (m *Postgres) GetTestCharts(env string, test string) (map[string]interface{
221221
}
222222
log.Printf("\nduration metric: took %f seconds to execute SQL query for flake rate and duration by week chart since start of handler", time.Since(start).Seconds())
223223

224+
// Groups the datetimes together by month, calculating flake percentage and aggregating the individual results/durations for each date
225+
sqlQuery = fmt.Sprintf(`
226+
SELECT
227+
DATE_TRUNC('month', TestTime) AS StartOfDate,
228+
AVG(Duration) AS AvgDuration,
229+
ROUND(COALESCE(AVG(CASE WHEN Result = 'fail' THEN 1 ELSE 0 END) * 100, 0), 2) AS FlakePercentage,
230+
STRING_AGG(CommitID || ': ' || Result || ': ' || Duration, ', ') AS CommitResultsAndDurations
231+
FROM %s
232+
WHERE TestName = $1
233+
GROUP BY StartOfDate
234+
ORDER BY StartOfDate DESC
235+
`, viewName)
236+
var flakeByMonth []models.DBTestRateAndDuration
237+
err = m.db.Select(&flakeByMonth, sqlQuery, test)
238+
if err != nil {
239+
return nil, fmt.Errorf("failed to execute SQL query for flake rate and duration by month chart: %v", err)
240+
}
241+
log.Printf("\nduration metric: took %f seconds to execute SQL query for flake rate and duration by month chart since start of handler", time.Since(start).Seconds())
242+
224243
data := map[string]interface{}{
225-
"flakeByDay": flakeByDay,
226-
"flakeByWeek": flakeByWeek,
244+
"flakeByDay": flakeByDay,
245+
"flakeByWeek": flakeByWeek,
246+
"flakeByMonth": flakeByMonth,
227247
}
228248
log.Printf("\nduration metric: took %f seconds to gather individual test chart data since start of handler\n\n", time.Since(start).Seconds())
229249
return data, nil

0 commit comments

Comments
 (0)