diff options
| author | Taras Madan <tarasmadan@google.com> | 2024-08-30 12:02:30 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2024-09-16 12:31:08 +0000 |
| commit | c673ca06b23cea94091ab496ef62c3513e434585 (patch) | |
| tree | 417c77ae484cb6aa9e77ce45b1d6ead9d6768290 /pkg/covermerger | |
| parent | 49cf07733c7f8914ab688a3ff1effb82565030dd (diff) | |
dashboard/app: add file coverage page
It directly uses the coverage signals from BigQuery.
There is no need to wait for the coverage_batch cron jobs.
Looks good for debugging.
Limitations:
1. It is slow. I know how to speed up but want to stabilize the UI first.
2. It is expensive because of the direct BQ requests. Limited to admin only because of it.
3. It merges only the commits reachable on github because of the gitweb throttling.
After the UI stabilization I'll save all the required artifacts to spanner and make this page publicly available.
To merge all the commits, not the github reachable only, http git caching instance is needed.
Diffstat (limited to 'pkg/covermerger')
| -rw-r--r-- | pkg/covermerger/provider_web.go | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/pkg/covermerger/provider_web.go b/pkg/covermerger/provider_web.go index 6acb120ed..2a1bee85a 100644 --- a/pkg/covermerger/provider_web.go +++ b/pkg/covermerger/provider_web.go @@ -11,14 +11,17 @@ import ( "net/url" ) +type FuncProxyURI func(filePath string, rc RepoCommit) string + type webGit struct { + funcProxy FuncProxyURI } func (mr *webGit) GetFileVersions(targetFilePath string, repoCommits ...RepoCommit, ) (fileVersions, error) { res := make(fileVersions) for _, repoCommit := range repoCommits { - fileBytes, err := loadFile(targetFilePath, repoCommit.Repo, repoCommit.Commit) + fileBytes, err := mr.loadFile(targetFilePath, repoCommit.Repo, repoCommit.Commit) // It is ok if some file doesn't exist. It means we have repo FS diff. if err == errFileNotFound { continue @@ -33,10 +36,15 @@ func (mr *webGit) GetFileVersions(targetFilePath string, repoCommits ...RepoComm var errFileNotFound = errors.New("file not found") -func loadFile(filePath, repo, commit string) ([]byte, error) { - uri := fmt.Sprintf("%s/plain/%s", repo, filePath) - if commit != "latest" { - uri += "?id=" + commit +func (mr *webGit) loadFile(filePath, repo, commit string) ([]byte, error) { + var uri string + if mr.funcProxy != nil { + uri = mr.funcProxy(filePath, RepoCommit{Repo: repo, Commit: commit}) + } else { + uri = fmt.Sprintf("%s/plain/%s", repo, filePath) + if commit != "latest" { + uri += "?id=" + commit + } } u, err := url.Parse(uri) if err != nil { @@ -54,7 +62,7 @@ func loadFile(filePath, repo, commit string) ([]byte, error) { return nil, errFileNotFound } if res.StatusCode != 200 { - return nil, fmt.Errorf("error: status %d getting %s", res.StatusCode, uri) + return nil, fmt.Errorf("error: status %d getting '%s'", res.StatusCode, uri) } body, err := io.ReadAll(res.Body) if err != nil { @@ -63,13 +71,15 @@ func loadFile(filePath, repo, commit string) ([]byte, error) { return body, nil } -func MakeWebGit() FileVersProvider { - return &webGit{} +func MakeWebGit(funcProxy FuncProxyURI) FileVersProvider { + return &webGit{ + funcProxy: funcProxy, + } } func GetFileVersion(filePath, repo, commit string) (string, error) { repoCommit := RepoCommit{repo, commit} - files, err := MakeWebGit().GetFileVersions(filePath, repoCommit) + files, err := MakeWebGit(nil).GetFileVersions(filePath, repoCommit) if err != nil { return "", fmt.Errorf("failed to GetFileVersions: %w", err) } |
