Esempio n. 1
0
func fetchRunSetSummaries(database *pgx.Tx, machine string, config string) ([]RunSetSummary, *requestError) {
	rows, err := database.Query("queryRunSetSummaries", machine, config)
	if err != nil {
		return nil, internalServerError("Could not fetch run set summaries")
	}
	var summaries []RunSetSummary
	for rows.Next() {
		var rss RunSetSummary
		if err = rows.Scan(&rss.ID, &rss.MainProduct.Commit); err != nil {
			return nil, internalServerError("Could not scan run set summary")
		}
		summaries = append(summaries, rss)
	}
	return summaries, nil
}
Esempio n. 2
0
func insertResults(database *pgx.Tx, runID int32, results Results, update bool) *requestError {
	idByMetric := make(map[string]int32)
	if update {
		rows, err := database.Query("queryRunMetricsForRun", runID)
		if err != nil {
			return internalServerError("Could not query run metrics")
		}
		for rows.Next() {
			var runMetricID int32
			var metric string
			err = rows.Scan(&runMetricID, &metric)
			if err != nil {
				return internalServerError("Could not scan run metric")
			}
			idByMetric[metric] = runMetricID
		}
	}

	for m, v := range results {
		var err error
		runMetricID, exists := idByMetric[m]
		if metricIsArray(m) {
			var arr []float64
			for _, x := range v.([]interface{}) {
				arr = append(arr, x.(float64))
			}
			if exists {
				_, err = database.Exec("updateRunMetricArray", runMetricID, arr)
			} else {
				_, err = database.Exec("insertRunMetricArray", runID, m, arr)
			}
		} else {
			if exists {
				_, err = database.Exec("updateRunMetricNumber", runMetricID, v)
			} else {
				_, err = database.Exec("insertRunMetricNumber", runID, m, v)
			}
		}
		if err != nil {
			fmt.Printf("run metric insert error: %s\n", err)
			return internalServerError("Could not insert run metric")
		}
	}
	return nil
}
Esempio n. 3
0
func fetchBenchmarks(database *pgx.Tx) (map[string]bool, *requestError) {
	rows, err := database.Query("queryBenchmarks")
	if err != nil {
		return nil, internalServerError("Could not get benchmarks")
	}
	defer rows.Close()

	names := make(map[string]bool)
	for rows.Next() {
		var name string
		if err = rows.Scan(&name); err != nil {
			return nil, internalServerError("Could not scan benchmark name")
		}
		names[name] = true
	}

	return names, nil
}
Esempio n. 4
0
func fetchRunSet(database *pgx.Tx, id int32, withRuns bool) (*RunSet, *requestError) {
	var rs RunSet
	var secondaryCommits []string
	var pullRequestID *int32
	err := database.QueryRow("queryRunSet", id).Scan(&rs.StartedAt, &rs.FinishedAt,
		&rs.BuildURL, &rs.LogURLs,
		&rs.MainProduct.Commit, &secondaryCommits, &rs.Machine.Name, &rs.Config.Name,
		&rs.TimedOutBenchmarks, &rs.CrashedBenchmarks,
		&pullRequestID)
	if err == pgx.ErrNoRows {
		return nil, badRequestError("Run set does not exist")
	}
	if err != nil {
		fmt.Printf("run set query error: %s\n", err.Error())
		return nil, internalServerError("Could not get run set")
	}

	// FIXME: combine these two queries with the above one
	err = database.QueryRow("queryCommit", rs.MainProduct.Commit).Scan(&rs.MainProduct.Name)
	if err != nil {
		return nil, internalServerError("Could not get commit")
	}

	for _, c := range secondaryCommits {
		product := Product{Commit: c}
		err = database.QueryRow("queryCommit", c).Scan(&product.Name)
		if err != nil {
			return nil, internalServerError("Could not get commit")
		}

		rs.SecondaryProducts = append(rs.SecondaryProducts, product)
	}

	err = database.QueryRow("queryMachine", rs.Machine.Name).Scan(&rs.Machine.Architecture)
	if err != nil {
		return nil, internalServerError("Could not get machine")
	}

	config, reqErr := fetchConfig(database, rs.Config.Name)
	if reqErr != nil {
		return nil, nil
	}

	rs.Config = *config

	if withRuns {
		rows, err := database.Query("queryRunMetrics", id)
		if err != nil {
			return nil, internalServerError("Could not get run metrics")
		}
		defer rows.Close()

		runs := make(map[int32]*Run)

		for rows.Next() {
			var runID int32
			var benchmark string
			var metric string
			var resultNumber *float64
			var resultArray []float64

			if err = rows.Scan(&runID, &benchmark, &metric, &resultNumber, &resultArray); err != nil {
				return nil, internalServerError("Could not scan run metric: " + err.Error())
			}

			var resultValue interface{}
			if metricIsArray(metric) {
				resultValue = resultArray
			} else if resultNumber != nil {
				resultValue = *resultNumber
			} else {
				return nil, internalServerError("Run metric data is inconsistent")
			}

			run := runs[runID]
			if run == nil {
				run = &Run{Benchmark: benchmark, Results: make(map[string]interface{})}
				runs[runID] = run
			}

			run.Results[metric] = resultValue
		}

		for _, r := range runs {
			rs.Runs = append(rs.Runs, *r)
		}
	}

	return &rs, nil
}