Skip to content

Commit

Permalink
feat: support show growth within 7 days
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeProgrammer committed Oct 21, 2023
1 parent 8cdd860 commit 1d5d0db
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ testdata/docker-test/testout.json
testdata/docker-test/testout.html
./gopogh
cmd/gopogh-server/gopogh-server
.vscode
2 changes: 1 addition & 1 deletion pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Datab interface {

GetEnvCharts(string, int) (map[string]interface{}, error)

GetOverview() (map[string]interface{}, error)
GetOverview(dataRange int) (map[string]interface{}, error)

GetTestCharts(string, string) (map[string]interface{}, error)
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/db/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ func (m *Postgres) GetEnvCharts(env string, testsInTop int) (map[string]interfac
}

// GetOverview writes the overview charts to a map with the keys summaryAvgFail and summaryTable
func (m *Postgres) GetOverview() (map[string]interface{}, error) {
func (m *Postgres) GetOverview(dateRange int) (map[string]interface{}, error) {
// dateRange is the number of days to use to look for "flaky-est" envs.
start := time.Now()
// Filters out old data and calculates the average number of failures and average duration per day per environment
sqlQuery := `
Expand All @@ -442,9 +443,6 @@ func (m *Postgres) GetOverview() (map[string]interface{}, error) {
}
log.Printf("\nduration metric: took %f seconds to execute SQL query for summary duration and failure charts since start of handler", time.Since(start).Seconds())

// Number of days to use to look for "flaky-est" envs.
const dateRange = 15

// Filters out data from prior to 90 days
// Then computes average number of fails for each environment for each time frame
// Then calculates the change in the average number of fails between the time frames
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ func (m *sqlite) GetTestCharts(_ string, _ string) (map[string]interface{}, erro

// GetOverview writes the overview charts to a map with the keys summaryAvgFail and summaryTable
// This is not yet supported for sqlite
func (m *sqlite) GetOverview() (map[string]interface{}, error) {
func (m *sqlite) GetOverview(int) (map[string]interface{}, error) {
return nil, nil
}
42 changes: 37 additions & 5 deletions pkg/handler/flake_chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,38 @@
return [unescape(keyValue[0]), unescape(keyValue[1])];
}));
}

function createRecentNumberOfFailTable(summaryTable) {
function createDateRangeSelectForFailTable(table){
let tableCapturedByLambda = table
let dateSelect = document.createElement("select")
dateSelect.innerHTML = "<option value=3>3</option> <option value=7>7</option> <option value=15 selected='selected'>15</option>"
dateSelect.addEventListener('click', async function (event) {
// stop the onClick event from propagation to its parent
event.stopPropagation();
}, false);
dateSelect.addEventListener("change", async function(event){
// when a new date range is selected
// fetch new data and replace old table with new table
const parent = tableCapturedByLambda.parentElement
const dateRange = dateSelect.options[dateSelect.selectedIndex].value
const response = await fetch("/summary?date_range="+dateRange);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
let newTable = createRecentNumberOfFailTable(data.summaryTable, dateRange)
parent.replaceChild(newTable, tableCapturedByLambda)
tableCapturedByLambda = newTable
})
let wrapper = document.createElement("div")
wrapper.style.width = "100%"
wrapper.style.textAlign = "center"
wrapper.innerHTML = "Show Growth within "
wrapper.insertAdjacentElement("beforeend", dateSelect)
wrapper.insertAdjacentHTML("beforeend", " days")

return wrapper
}
function createRecentNumberOfFailTable(summaryTable, dateRange=15) {
const createCell = (elementType, text) => {
const element = document.createElement(elementType);
element.innerHTML = text;
Expand All @@ -50,7 +80,7 @@
tableHeaderRow.appendChild(createCell("th", "Rank"));
tableHeaderRow.appendChild(createCell("th", "Env Name")).style.textAlign = "left";
tableHeaderRow.appendChild(createCell("th", "Recent Number of Fails"));
tableHeaderRow.appendChild(createCell("th", "Growth (since last 15 days)"));
tableHeaderRow.appendChild(createCell("th", `Growth (since last ${dateRange} days)`));
table.appendChild(tableHeaderRow);
const tableBody = document.createElement("tbody");
for (let i = 0; i < summaryTable.length; i++) {
Expand Down Expand Up @@ -521,8 +551,10 @@
const durationChart = new google.visualization.LineChart(summaryDurContainer);
durationChart.draw(durChart, durOptions);


chartsContainer.appendChild(createRecentNumberOfFailTable(data.summaryTable))
const table=createRecentNumberOfFailTable(data.summaryTable)
const select=createDateRangeSelectForFailTable(table)
chartsContainer.appendChild(select)
chartsContainer.appendChild(table)
}

function displayEnvironmentChart(data, query) {
Expand Down
9 changes: 7 additions & 2 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ func (m *DB) ServeEnvCharts(w http.ResponseWriter, r *http.Request) {
}

// ServeOverview writes the overview chart for all of the environments to a JSON HTTP response
func (m *DB) ServeOverview(w http.ResponseWriter, _ *http.Request) {
data, err := m.Database.GetOverview()
func (m *DB) ServeOverview(w http.ResponseWriter, r *http.Request) {
dateRange, err := strconv.Atoi(r.URL.Query().Get("date_range"))
if err != nil {
dateRange = 15
}

data, err := m.Database.GetOverview(dateRange)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down

0 comments on commit 1d5d0db

Please sign in to comment.