Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1451)

Unified Diff: monitoring/go/alertserver/main.go

Issue 784103004: Improvements to commits page (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Hopefully fix missing commits in commit_cache Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | monitoring/go/commit_cache/commit_cache.go » ('j') | monitoring/res/imp/commits-sk.html » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: monitoring/go/alertserver/main.go
diff --git a/monitoring/go/alertserver/main.go b/monitoring/go/alertserver/main.go
index 7939e45a7c753b6bd7e63276503ed3990d08a72d..d9bc235cf61ad6f3ed49c85d3d18038c3a753fbb 100644
--- a/monitoring/go/alertserver/main.go
+++ b/monitoring/go/alertserver/main.go
@@ -14,6 +14,7 @@ import (
"os/user"
"path/filepath"
"runtime"
+ "strconv"
"strings"
"time"
)
@@ -33,12 +34,14 @@ import (
"skia.googlesource.com/buildbot.git/go/skiaversion"
"skia.googlesource.com/buildbot.git/go/util"
"skia.googlesource.com/buildbot.git/monitoring/go/alerting"
+ "skia.googlesource.com/buildbot.git/monitoring/go/commit_cache"
)
const (
COOKIESALT_METADATA_KEY = "cookiesalt"
CLIENT_ID_METADATA_KEY = "client_id"
CLIENT_SECRET_METADATA_KEY = "client_secret"
+ DEFAULT_COMMITS_TO_LOAD = 35
INFLUXDB_NAME_METADATA_KEY = "influxdb_name"
INFLUXDB_PASSWORD_METADATA_KEY = "influxdb_password"
GMAIL_CLIENT_ID_METADATA_KEY = "gmail_clientid"
@@ -48,8 +51,9 @@ const (
)
var (
- alertManager *alerting.AlertManager = nil
- gitInfo *gitinfo.GitInfo = nil
+ alertManager *alerting.AlertManager = nil
+ gitInfo *gitinfo.GitInfo = nil
+ commitCache *commit_cache.CommitCache = nil
)
// flags
@@ -174,31 +178,42 @@ func makeResourceHandler() func(http.ResponseWriter, *http.Request) {
func commitsJsonHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
- gitInfo.Update(true, true)
- commitHashes := gitInfo.From(time.Now().AddDate(0, 0, -45))
- branchHeads, err := gitInfo.GetBranches()
- if err != nil {
- util.ReportError(w, r, err, fmt.Sprintf("Failed to read branch information from the repo: %s", err))
+ q := r.URL.Query()
+ // Case 1: Requesting specific commit range by index.
+ if start, ok := q["start"]; ok {
+ startInt, err := strconv.ParseInt(start[0], 10, 32)
+ if err != nil {
+ util.ReportError(w, r, err, fmt.Sprintf("Invalid value for parameter 'start' (%s): %v", start, err))
+ return
+ }
+ startIdx := int(startInt)
+ endIdx := commitCache.NumCommits()
+ if end, ok := q["end"]; ok {
jcgregorio 2014/12/09 16:30:05 This seems like a repeated pattern: if end, ok :
borenet 2014/12/09 20:17:12 Done.
+ endInt, err := strconv.ParseInt(end[0], 10, 32)
+ if err != nil {
+ util.ReportError(w, r, err, fmt.Sprintf("Invalid value for parameter 'end' (%s): %v", end, err))
+ return
+ }
+ endIdx = int(endInt)
+ }
+ if err := commitCache.RangeAsJson(w, startIdx, endIdx); err != nil {
+ util.ReportError(w, r, err, fmt.Sprintf("Failed to load commit range from cache: %v", err))
+ return
+ }
return
}
- commits := make([]*gitinfo.LongCommit, len(commitHashes))
- for i, h := range commitHashes {
- c, err := gitInfo.Details(h)
+ // Case 2: Requesting N (or the default number) commits.
+ commitsToLoad := DEFAULT_COMMITS_TO_LOAD
+ if n, ok := q["n"]; ok {
+ intN, err := strconv.ParseInt(n[0], 10, 32)
if err != nil {
- util.ReportError(w, r, err, fmt.Sprintf("Failed to obtain commit details for %s: %s", h, err))
+ util.ReportError(w, r, err, fmt.Sprintf("Invalid value for parameter 'n' (%s): %v", n, err))
return
}
- commits[i] = c
- }
- data := struct {
- Commits []*gitinfo.LongCommit `json:"commits"`
- BranchHeads []*gitinfo.GitBranch `json:"branch_heads"`
- }{
- Commits: commits,
- BranchHeads: branchHeads,
+ commitsToLoad = int(intN)
}
- if err := json.NewEncoder(w).Encode(data); err != nil {
- util.ReportError(w, r, err, fmt.Sprintf("Failed to encode commit data as JSON: %s", err))
+ if err := commitCache.LastNAsJson(w, commitsToLoad); err != nil {
+ util.ReportError(w, r, err, fmt.Sprintf("Failed to load commits from cache: %v", err))
return
}
}
@@ -300,5 +315,16 @@ func main() {
if err != nil {
glog.Fatalf("Failed to check out Skia: %v", err)
}
+ commitCache, err = commit_cache.New(gitInfo)
+ if err != nil {
+ glog.Fatalf("Failed to create commit cache: %v", err)
+ }
+ go func() {
+ for _ = range time.Tick(time.Minute) {
+ if err := commitCache.Update(); err != nil {
+ glog.Errorf("Failed to update commit cache: %v", err)
+ }
+ }
+ }()
runServer(serverURL)
}
« no previous file with comments | « no previous file | monitoring/go/commit_cache/commit_cache.go » ('j') | monitoring/res/imp/commits-sk.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698