How to use apiManagerStats method of main Package

Best Syzkaller code snippet using main.apiManagerStats

api.go

Source:api.go Github

copy

Full Screen

...39 "report_build_error": apiReportBuildError,40 "report_crash": apiReportCrash,41 "report_failed_repro": apiReportFailedRepro,42 "need_repro": apiNeedRepro,43 "manager_stats": apiManagerStats,44 "commit_poll": apiCommitPoll,45 "upload_commits": apiUploadCommits,46 "bug_list": apiBugList,47 "load_bug": apiLoadBug,48}49type JSONHandler func(c context.Context, r *http.Request) (interface{}, error)50type APIHandler func(c context.Context, r *http.Request, payload []byte) (interface{}, error)51type APINamespaceHandler func(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error)52const (53 maxReproPerBug = 1054 reproRetryPeriod = 24 * time.Hour // try 1 repro per day until we have at least syz repro55)56// Overridable for testing.57var timeNow = func(c context.Context) time.Time {58 return time.Now()59}60func timeSince(c context.Context, t time.Time) time.Duration {61 return timeNow(c).Sub(t)62}63func handleJSON(fn JSONHandler) http.Handler {64 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {65 c := appengine.NewContext(r)66 reply, err := fn(c, r)67 if err != nil {68 // ErrAccess is logged earlier.69 if err != ErrAccess {70 log.Errorf(c, "%v", err)71 }72 http.Error(w, err.Error(), http.StatusInternalServerError)73 return74 }75 w.Header().Set("Content-Type", "application/json")76 if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {77 w.Header().Set("Content-Encoding", "gzip")78 gz := gzip.NewWriter(w)79 if err := json.NewEncoder(gz).Encode(reply); err != nil {80 log.Errorf(c, "failed to encode reply: %v", err)81 }82 gz.Close()83 } else {84 if err := json.NewEncoder(w).Encode(reply); err != nil {85 log.Errorf(c, "failed to encode reply: %v", err)86 }87 }88 })89}90func handleAPI(c context.Context, r *http.Request) (reply interface{}, err error) {91 client := r.PostFormValue("client")92 method := r.PostFormValue("method")93 log.Infof(c, "api %q from %q", method, client)94 ns, err := checkClient(c, client, r.PostFormValue("key"))95 if err != nil {96 if client != "" {97 log.Errorf(c, "%v", err)98 } else {99 // Don't log as error if somebody just invokes /api.100 log.Infof(c, "%v", err)101 }102 return nil, err103 }104 var payload []byte105 if str := r.PostFormValue("payload"); str != "" {106 gr, err := gzip.NewReader(strings.NewReader(str))107 if err != nil {108 return nil, fmt.Errorf("failed to ungzip payload: %v", err)109 }110 payload, err = ioutil.ReadAll(gr)111 if err != nil {112 return nil, fmt.Errorf("failed to ungzip payload: %v", err)113 }114 if err := gr.Close(); err != nil {115 return nil, fmt.Errorf("failed to ungzip payload: %v", err)116 }117 }118 handler := apiHandlers[method]119 if handler != nil {120 return handler(c, r, payload)121 }122 nsHandler := apiNamespaceHandlers[method]123 if nsHandler == nil {124 return nil, fmt.Errorf("unknown api method %q", method)125 }126 if ns == "" {127 return nil, fmt.Errorf("method %q must be called within a namespace", method)128 }129 return nsHandler(c, ns, r, payload)130}131func checkClient(c context.Context, name0, key0 string) (string, error) {132 for name, key := range config.Clients {133 if name == name0 {134 if key != key0 {135 return "", ErrAccess136 }137 return "", nil138 }139 }140 for ns, cfg := range config.Namespaces {141 for name, key := range cfg.Clients {142 if name == name0 {143 if key != key0 {144 return "", ErrAccess145 }146 return ns, nil147 }148 }149 }150 return "", ErrAccess151}152func apiLogError(c context.Context, r *http.Request, payload []byte) (interface{}, error) {153 req := new(dashapi.LogEntry)154 if err := json.Unmarshal(payload, req); err != nil {155 return nil, fmt.Errorf("failed to unmarshal request: %v", err)156 }157 log.Errorf(c, "%v: %v", req.Name, req.Text)158 return nil, nil159}160func apiBuilderPoll(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {161 req := new(dashapi.BuilderPollReq)162 if err := json.Unmarshal(payload, req); err != nil {163 return nil, fmt.Errorf("failed to unmarshal request: %v", err)164 }165 bugs, _, err := loadAllBugs(c, func(query *db.Query) *db.Query {166 return query.Filter("Namespace=", ns).167 Filter("Status<", BugStatusFixed)168 })169 if err != nil {170 return nil, err171 }172 m := make(map[string]bool)173loop:174 for _, bug := range bugs {175 // TODO(dvyukov): include this condition into the query if possible.176 if len(bug.Commits) == 0 {177 continue178 }179 for _, mgr := range bug.PatchedOn {180 if mgr == req.Manager {181 continue loop182 }183 }184 for _, com := range bug.Commits {185 m[com] = true186 }187 }188 commits := make([]string, 0, len(m))189 for com := range m {190 commits = append(commits, com)191 }192 sort.Strings(commits)193 resp := &dashapi.BuilderPollResp{194 PendingCommits: commits,195 ReportEmail: reportEmail(c, ns),196 }197 return resp, nil198}199func reportEmail(c context.Context, ns string) string {200 for _, reporting := range config.Namespaces[ns].Reporting {201 if _, ok := reporting.Config.(*EmailConfig); ok {202 return ownEmail(c)203 }204 }205 return ""206}207func apiCommitPoll(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {208 resp := &dashapi.CommitPollResp{209 ReportEmail: reportEmail(c, ns),210 }211 for _, repo := range config.Namespaces[ns].Repos {212 resp.Repos = append(resp.Repos, dashapi.Repo{213 URL: repo.URL,214 Branch: repo.Branch,215 })216 }217 var bugs []*Bug218 _, err := db.NewQuery("Bug").219 Filter("Namespace=", ns).220 Filter("NeedCommitInfo=", true).221 Project("Commits").222 Limit(100).223 GetAll(c, &bugs)224 if err != nil {225 return nil, fmt.Errorf("failed to query bugs: %v", err)226 }227 commits := make(map[string]bool)228 for _, bug := range bugs {229 for _, com := range bug.Commits {230 commits[com] = true231 }232 }233 for com := range commits {234 resp.Commits = append(resp.Commits, com)235 }236 return resp, nil237}238func apiUploadCommits(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {239 req := new(dashapi.CommitPollResultReq)240 if err := json.Unmarshal(payload, req); err != nil {241 return nil, fmt.Errorf("failed to unmarshal request: %v", err)242 }243 // This adds fixing commits to bugs.244 err := addCommitsToBugs(c, ns, "", nil, req.Commits)245 if err != nil {246 return nil, err247 }248 // Now add commit info to commits.249 for _, com := range req.Commits {250 if com.Hash == "" {251 continue252 }253 if err := addCommitInfo(c, ns, com); err != nil {254 return nil, err255 }256 }257 return nil, nil258}259func addCommitInfo(c context.Context, ns string, com dashapi.Commit) error {260 var bugs []*Bug261 keys, err := db.NewQuery("Bug").262 Filter("Namespace=", ns).263 Filter("Commits=", com.Title).264 GetAll(c, &bugs)265 if err != nil {266 return fmt.Errorf("failed to query bugs: %v", err)267 }268 for i, bug := range bugs {269 if err := addCommitInfoToBug(c, bug, keys[i], com); err != nil {270 return err271 }272 }273 return nil274}275func addCommitInfoToBug(c context.Context, bug *Bug, bugKey *db.Key, com dashapi.Commit) error {276 if needUpdate, err := addCommitInfoToBugImpl(c, bug, com); err != nil {277 return err278 } else if !needUpdate {279 return nil280 }281 tx := func(c context.Context) error {282 bug := new(Bug)283 if err := db.Get(c, bugKey, bug); err != nil {284 return fmt.Errorf("failed to get bug %v: %v", bugKey.StringID(), err)285 }286 if needUpdate, err := addCommitInfoToBugImpl(c, bug, com); err != nil {287 return err288 } else if !needUpdate {289 return nil290 }291 if _, err := db.Put(c, bugKey, bug); err != nil {292 return fmt.Errorf("failed to put bug: %v", err)293 }294 return nil295 }296 return db.RunInTransaction(c, tx, nil)297}298func addCommitInfoToBugImpl(c context.Context, bug *Bug, com dashapi.Commit) (bool, error) {299 ci := -1300 for i, title := range bug.Commits {301 if title == com.Title {302 ci = i303 break304 }305 }306 if ci < 0 {307 return false, nil308 }309 for len(bug.CommitInfo) < len(bug.Commits) {310 bug.CommitInfo = append(bug.CommitInfo, Commit{})311 }312 hash0 := bug.CommitInfo[ci].Hash313 date0 := bug.CommitInfo[ci].Date314 author0 := bug.CommitInfo[ci].Author315 needCommitInfo0 := bug.NeedCommitInfo316 bug.CommitInfo[ci].Hash = com.Hash317 bug.CommitInfo[ci].Date = com.Date318 bug.CommitInfo[ci].Author = com.Author319 bug.NeedCommitInfo = false320 for i := range bug.CommitInfo {321 if bug.CommitInfo[i].Hash == "" {322 bug.NeedCommitInfo = true323 break324 }325 }326 changed := hash0 != bug.CommitInfo[ci].Hash ||327 date0 != bug.CommitInfo[ci].Date ||328 author0 != bug.CommitInfo[ci].Author ||329 needCommitInfo0 != bug.NeedCommitInfo330 return changed, nil331}332func apiJobPoll(c context.Context, r *http.Request, payload []byte) (interface{}, error) {333 req := new(dashapi.JobPollReq)334 if err := json.Unmarshal(payload, req); err != nil {335 return nil, fmt.Errorf("failed to unmarshal request: %v", err)336 }337 if len(req.Managers) == 0 {338 return nil, fmt.Errorf("no managers")339 }340 return pollPendingJobs(c, req.Managers)341}342func apiJobDone(c context.Context, r *http.Request, payload []byte) (interface{}, error) {343 req := new(dashapi.JobDoneReq)344 if err := json.Unmarshal(payload, req); err != nil {345 return nil, fmt.Errorf("failed to unmarshal request: %v", err)346 }347 err := doneJob(c, req)348 return nil, err349}350func apiUploadBuild(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {351 req := new(dashapi.Build)352 if err := json.Unmarshal(payload, req); err != nil {353 return nil, fmt.Errorf("failed to unmarshal request: %v", err)354 }355 now := timeNow(c)356 _, isNewBuild, err := uploadBuild(c, now, ns, req, BuildNormal)357 if err != nil {358 return nil, err359 }360 if isNewBuild {361 err := updateManager(c, ns, req.Manager, func(mgr *Manager, stats *ManagerStats) error {362 prevKernel, prevSyzkaller := "", ""363 if mgr.CurrentBuild != "" {364 prevBuild, err := loadBuild(c, ns, mgr.CurrentBuild)365 if err != nil {366 return err367 }368 prevKernel = prevBuild.KernelCommit369 prevSyzkaller = prevBuild.SyzkallerCommit370 }371 log.Infof(c, "new build on %v: kernel %v->%v syzkaller %v->%v",372 req.Manager, prevKernel, req.KernelCommit, prevSyzkaller, req.SyzkallerCommit)373 mgr.CurrentBuild = req.ID374 if req.KernelCommit != prevKernel {375 mgr.FailedBuildBug = ""376 }377 if req.SyzkallerCommit != prevSyzkaller {378 mgr.FailedSyzBuildBug = ""379 }380 return nil381 })382 if err != nil {383 return nil, err384 }385 }386 if len(req.Commits) != 0 || len(req.FixCommits) != 0 {387 for i := range req.FixCommits {388 // Reset hashes just to make sure,389 // the build does not necessary come from the master repo, so we must not remember hashes.390 req.FixCommits[i].Hash = ""391 }392 if err := addCommitsToBugs(c, ns, req.Manager, req.Commits, req.FixCommits); err != nil {393 // We've already uploaded the build successfully and manager can use it.394 // Moreover, addCommitsToBugs scans all bugs and can take long time.395 // So just log the error.396 log.Errorf(c, "failed to add commits to bugs: %v", err)397 }398 }399 return nil, nil400}401func uploadBuild(c context.Context, now time.Time, ns string, req *dashapi.Build, typ BuildType) (402 *Build, bool, error) {403 if build, err := loadBuild(c, ns, req.ID); err == nil {404 return build, false, nil405 }406 checkStrLen := func(str, name string, maxLen int) error {407 if str == "" {408 return fmt.Errorf("%v is empty", name)409 }410 if len(str) > maxLen {411 return fmt.Errorf("%v is too long (%v)", name, len(str))412 }413 return nil414 }415 if err := checkStrLen(req.Manager, "Build.Manager", MaxStringLen); err != nil {416 return nil, false, err417 }418 if err := checkStrLen(req.ID, "Build.ID", MaxStringLen); err != nil {419 return nil, false, err420 }421 if err := checkStrLen(req.KernelRepo, "Build.KernelRepo", MaxStringLen); err != nil {422 return nil, false, err423 }424 if len(req.KernelBranch) > MaxStringLen {425 return nil, false, fmt.Errorf("Build.KernelBranch is too long (%v)", len(req.KernelBranch))426 }427 if err := checkStrLen(req.SyzkallerCommit, "Build.SyzkallerCommit", MaxStringLen); err != nil {428 return nil, false, err429 }430 if len(req.CompilerID) > MaxStringLen {431 return nil, false, fmt.Errorf("Build.CompilerID is too long (%v)", len(req.CompilerID))432 }433 if len(req.KernelCommit) > MaxStringLen {434 return nil, false, fmt.Errorf("Build.KernelCommit is too long (%v)", len(req.KernelCommit))435 }436 configID, err := putText(c, ns, textKernelConfig, req.KernelConfig, true)437 if err != nil {438 return nil, false, err439 }440 build := &Build{441 Namespace: ns,442 Manager: req.Manager,443 ID: req.ID,444 Type: typ,445 Time: now,446 OS: req.OS,447 Arch: req.Arch,448 VMArch: req.VMArch,449 SyzkallerCommit: req.SyzkallerCommit,450 SyzkallerCommitDate: req.SyzkallerCommitDate,451 CompilerID: req.CompilerID,452 KernelRepo: req.KernelRepo,453 KernelBranch: req.KernelBranch,454 KernelCommit: req.KernelCommit,455 KernelCommitTitle: req.KernelCommitTitle,456 KernelCommitDate: req.KernelCommitDate,457 KernelConfig: configID,458 }459 if _, err := db.Put(c, buildKey(c, ns, req.ID), build); err != nil {460 return nil, false, err461 }462 return build, true, nil463}464func addCommitsToBugs(c context.Context, ns, manager string, titles []string, fixCommits []dashapi.Commit) error {465 presentCommits := make(map[string]bool)466 bugFixedBy := make(map[string][]string)467 for _, com := range titles {468 presentCommits[com] = true469 }470 for _, com := range fixCommits {471 presentCommits[com.Title] = true472 for _, bugID := range com.BugIDs {473 bugFixedBy[bugID] = append(bugFixedBy[bugID], com.Title)474 }475 }476 managers, err := managerList(c, ns)477 if err != nil {478 return err479 }480 // Fetching all bugs in a namespace can be slow, and there is no way to filter only Open/Dup statuses.481 // So we run a separate query for each status, this both avoids fetching unnecessary data482 // and splits a long query into two (two smaller queries have lower chances of trigerring483 // timeouts than one huge).484 for _, status := range []int{BugStatusOpen, BugStatusDup} {485 err := addCommitsToBugsInStatus(c, status, ns, manager, managers, presentCommits, bugFixedBy)486 if err != nil {487 return err488 }489 }490 return nil491}492func addCommitsToBugsInStatus(c context.Context, status int, ns, manager string, managers []string,493 presentCommits map[string]bool, bugFixedBy map[string][]string) error {494 bugs, _, err := loadAllBugs(c, func(query *db.Query) *db.Query {495 return query.Filter("Namespace=", ns).496 Filter("Status=", status)497 })498 if err != nil {499 return err500 }501 for _, bug := range bugs {502 var fixCommits []string503 for i := range bug.Reporting {504 fixCommits = append(fixCommits, bugFixedBy[bug.Reporting[i].ID]...)505 }506 sort.Strings(fixCommits)507 if err := addCommitsToBug(c, bug, manager, managers, fixCommits, presentCommits); err != nil {508 return err509 }510 if bug.Status == BugStatusDup {511 canon, err := canonicalBug(c, bug)512 if err != nil {513 return err514 }515 if canon.Status == BugStatusOpen && len(bug.Commits) == 0 {516 if err := addCommitsToBug(c, canon, manager, managers,517 fixCommits, presentCommits); err != nil {518 return err519 }520 }521 }522 }523 return nil524}525func addCommitsToBug(c context.Context, bug *Bug, manager string, managers []string,526 fixCommits []string, presentCommits map[string]bool) error {527 if !bugNeedsCommitUpdate(c, bug, manager, fixCommits, presentCommits, true) {528 return nil529 }530 now := timeNow(c)531 bugKey := bug.key(c)532 tx := func(c context.Context) error {533 bug := new(Bug)534 if err := db.Get(c, bugKey, bug); err != nil {535 return fmt.Errorf("failed to get bug %v: %v", bugKey.StringID(), err)536 }537 if !bugNeedsCommitUpdate(c, bug, manager, fixCommits, presentCommits, false) {538 return nil539 }540 if len(fixCommits) != 0 && !reflect.DeepEqual(bug.Commits, fixCommits) {541 bug.updateCommits(fixCommits, now)542 }543 if manager != "" {544 bug.PatchedOn = append(bug.PatchedOn, manager)545 if bug.Status == BugStatusOpen {546 fixed := true547 for _, mgr := range managers {548 if !stringInList(bug.PatchedOn, mgr) {549 fixed = false550 break551 }552 }553 if fixed {554 bug.Status = BugStatusFixed555 bug.Closed = now556 }557 }558 }559 if _, err := db.Put(c, bugKey, bug); err != nil {560 return fmt.Errorf("failed to put bug: %v", err)561 }562 return nil563 }564 return db.RunInTransaction(c, tx, nil)565}566func bugNeedsCommitUpdate(c context.Context, bug *Bug, manager string, fixCommits []string,567 presentCommits map[string]bool, dolog bool) bool {568 if len(fixCommits) != 0 && !reflect.DeepEqual(bug.Commits, fixCommits) {569 if dolog {570 log.Infof(c, "bug %q is fixed with %q", bug.Title, fixCommits)571 }572 return true573 }574 if len(bug.Commits) == 0 || manager == "" || stringInList(bug.PatchedOn, manager) {575 return false576 }577 for _, com := range bug.Commits {578 if !presentCommits[com] {579 return false580 }581 }582 return true583}584func managerList(c context.Context, ns string) ([]string, error) {585 var builds []*Build586 _, err := db.NewQuery("Build").587 Filter("Namespace=", ns).588 Project("Manager").589 Distinct().590 GetAll(c, &builds)591 if err != nil {592 return nil, fmt.Errorf("failed to query builds: %v", err)593 }594 configManagers := config.Namespaces[ns].Managers595 var managers []string596 for _, build := range builds {597 if configManagers[build.Manager].Decommissioned {598 continue599 }600 managers = append(managers, build.Manager)601 }602 return managers, nil603}604func stringInList(list []string, str string) bool {605 for _, s := range list {606 if s == str {607 return true608 }609 }610 return false611}612func apiReportBuildError(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {613 req := new(dashapi.BuildErrorReq)614 if err := json.Unmarshal(payload, req); err != nil {615 return nil, fmt.Errorf("failed to unmarshal request: %v", err)616 }617 now := timeNow(c)618 build, _, err := uploadBuild(c, now, ns, &req.Build, BuildFailed)619 if err != nil {620 return nil, err621 }622 req.Crash.BuildID = req.Build.ID623 bug, err := reportCrash(c, build, &req.Crash)624 if err != nil {625 return nil, err626 }627 if err := updateManager(c, ns, req.Build.Manager, func(mgr *Manager, stats *ManagerStats) error {628 log.Infof(c, "failed build on %v: kernel=%v", req.Build.Manager, req.Build.KernelCommit)629 if req.Build.KernelCommit != "" {630 mgr.FailedBuildBug = bug.keyHash()631 } else {632 mgr.FailedSyzBuildBug = bug.keyHash()633 }634 return nil635 }); err != nil {636 return nil, err637 }638 return nil, nil639}640const corruptedReportTitle = "corrupted report"641func apiReportCrash(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {642 req := new(dashapi.Crash)643 if err := json.Unmarshal(payload, req); err != nil {644 return nil, fmt.Errorf("failed to unmarshal request: %v", err)645 }646 build, err := loadBuild(c, ns, req.BuildID)647 if err != nil {648 return nil, err649 }650 if !config.Namespaces[ns].TransformCrash(build, req) {651 return new(dashapi.ReportCrashResp), nil652 }653 bug, err := reportCrash(c, build, req)654 if err != nil {655 return nil, err656 }657 resp := &dashapi.ReportCrashResp{658 NeedRepro: needRepro(c, bug),659 }660 return resp, nil661}662func reportCrash(c context.Context, build *Build, req *dashapi.Crash) (*Bug, error) {663 req.Title = limitLength(req.Title, maxTextLen)664 req.Maintainers = email.MergeEmailLists(req.Maintainers)665 if req.Corrupted {666 // The report is corrupted and the title is most likely invalid.667 // Such reports are usually unactionable and are discarded.668 // Collect them into a single bin.669 req.Title = corruptedReportTitle670 }671 ns := build.Namespace672 bug, bugKey, err := findBugForCrash(c, ns, req.Title)673 if err != nil {674 return nil, err675 }676 if active, err := isActiveBug(c, bug); err != nil {677 return nil, err678 } else if !active {679 bug, bugKey, err = createBugForCrash(c, ns, req)680 if err != nil {681 return nil, err682 }683 }684 now := timeNow(c)685 reproLevel := ReproLevelNone686 if len(req.ReproC) != 0 {687 reproLevel = ReproLevelC688 } else if len(req.ReproSyz) != 0 {689 reproLevel = ReproLevelSyz690 }691 save := reproLevel != ReproLevelNone ||692 bug.NumCrashes < maxCrashes ||693 now.Sub(bug.LastSavedCrash) > time.Hour ||694 bug.NumCrashes%20 == 0695 if save {696 if err := saveCrash(c, ns, req, bugKey, build); err != nil {697 return nil, err698 }699 } else {700 log.Infof(c, "not saving crash for %q", bug.Title)701 }702 tx := func(c context.Context) error {703 bug = new(Bug)704 if err := db.Get(c, bugKey, bug); err != nil {705 return fmt.Errorf("failed to get bug: %v", err)706 }707 bug.NumCrashes++708 bug.LastTime = now709 if save {710 bug.LastSavedCrash = now711 }712 if reproLevel != ReproLevelNone {713 bug.NumRepro++714 bug.LastReproTime = now715 }716 if bug.ReproLevel < reproLevel {717 bug.ReproLevel = reproLevel718 }719 if len(req.Report) != 0 {720 bug.HasReport = true721 }722 if !stringInList(bug.HappenedOn, build.Manager) {723 bug.HappenedOn = append(bug.HappenedOn, build.Manager)724 }725 if _, err = db.Put(c, bugKey, bug); err != nil {726 return fmt.Errorf("failed to put bug: %v", err)727 }728 return nil729 }730 if err := db.RunInTransaction(c, tx, &db.TransactionOptions{XG: true}); err != nil {731 return nil, err732 }733 if save {734 purgeOldCrashes(c, bug, bugKey)735 }736 return bug, nil737}738func saveCrash(c context.Context, ns string, req *dashapi.Crash, bugKey *db.Key, build *Build) error {739 // Reporting priority of this crash.740 prio := int64(kernelRepoInfo(build).ReportingPriority) * 1e6741 if len(req.ReproC) != 0 {742 prio += 4e12743 } else if len(req.ReproSyz) != 0 {744 prio += 2e12745 }746 if build.Arch == "amd64" {747 prio += 1e3748 }749 crash := &Crash{750 Manager: build.Manager,751 BuildID: req.BuildID,752 Time: timeNow(c),753 Maintainers: req.Maintainers,754 ReproOpts: req.ReproOpts,755 ReportLen: prio,756 }757 var err error758 if crash.Log, err = putText(c, ns, textCrashLog, req.Log, false); err != nil {759 return err760 }761 if crash.Report, err = putText(c, ns, textCrashReport, req.Report, false); err != nil {762 return err763 }764 if crash.ReproSyz, err = putText(c, ns, textReproSyz, req.ReproSyz, false); err != nil {765 return err766 }767 if crash.ReproC, err = putText(c, ns, textReproC, req.ReproC, false); err != nil {768 return err769 }770 crashKey := db.NewIncompleteKey(c, "Crash", bugKey)771 if _, err = db.Put(c, crashKey, crash); err != nil {772 return fmt.Errorf("failed to put crash: %v", err)773 }774 return nil775}776func purgeOldCrashes(c context.Context, bug *Bug, bugKey *db.Key) {777 const purgeEvery = 10778 if bug.NumCrashes <= 2*maxCrashes || (bug.NumCrashes-1)%purgeEvery != 0 {779 return780 }781 var crashes []*Crash782 keys, err := db.NewQuery("Crash").783 Ancestor(bugKey).784 Filter("Reported=", time.Time{}).785 GetAll(c, &crashes)786 if err != nil {787 log.Errorf(c, "failed to fetch purge crashes: %v", err)788 return789 }790 keyMap := make(map[*Crash]*db.Key)791 for i, crash := range crashes {792 keyMap[crash] = keys[i]793 }794 // Newest first.795 sort.Slice(crashes, func(i, j int) bool {796 return crashes[i].Time.After(crashes[j].Time)797 })798 var toDelete []*db.Key799 latestOnManager := make(map[string]bool)800 deleted, reproCount, noreproCount := 0, 0, 0801 for _, crash := range crashes {802 if !crash.Reported.IsZero() {803 log.Errorf(c, "purging reported crash?")804 continue805 }806 // Preserve latest crash on each manager.807 if !latestOnManager[crash.Manager] {808 latestOnManager[crash.Manager] = true809 continue810 }811 // Preserve maxCrashes latest crashes with repro and without repro.812 count := &noreproCount813 if crash.ReproSyz != 0 || crash.ReproC != 0 {814 count = &reproCount815 }816 if *count < maxCrashes {817 *count++818 continue819 }820 toDelete = append(toDelete, keyMap[crash])821 if crash.Log != 0 {822 toDelete = append(toDelete, db.NewKey(c, textCrashLog, "", crash.Log, nil))823 }824 if crash.Report != 0 {825 toDelete = append(toDelete, db.NewKey(c, textCrashReport, "", crash.Report, nil))826 }827 if crash.ReproSyz != 0 {828 toDelete = append(toDelete, db.NewKey(c, textReproSyz, "", crash.ReproSyz, nil))829 }830 if crash.ReproC != 0 {831 toDelete = append(toDelete, db.NewKey(c, textReproC, "", crash.ReproC, nil))832 }833 deleted++834 if deleted == 2*purgeEvery {835 break836 }837 }838 if len(toDelete) == 0 {839 return840 }841 if err := db.DeleteMulti(c, toDelete); err != nil {842 log.Errorf(c, "failed to delete old crashes: %v", err)843 return844 }845 log.Infof(c, "deleted %v crashes for bug %q", deleted, bug.Title)846}847func apiReportFailedRepro(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {848 req := new(dashapi.CrashID)849 if err := json.Unmarshal(payload, req); err != nil {850 return nil, fmt.Errorf("failed to unmarshal request: %v", err)851 }852 req.Title = limitLength(req.Title, maxTextLen)853 bug, bugKey, err := findBugForCrash(c, ns, req.Title)854 if err != nil {855 return nil, err856 }857 if bug == nil {858 return nil, fmt.Errorf("%v: can't find bug for crash %q", ns, req.Title)859 }860 now := timeNow(c)861 tx := func(c context.Context) error {862 bug := new(Bug)863 if err := db.Get(c, bugKey, bug); err != nil {864 return fmt.Errorf("failed to get bug: %v", err)865 }866 bug.NumRepro++867 bug.LastReproTime = now868 if _, err := db.Put(c, bugKey, bug); err != nil {869 return fmt.Errorf("failed to put bug: %v", err)870 }871 return nil872 }873 err = db.RunInTransaction(c, tx, &db.TransactionOptions{874 XG: true,875 Attempts: 30,876 })877 return nil, err878}879func apiNeedRepro(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {880 req := new(dashapi.CrashID)881 if err := json.Unmarshal(payload, req); err != nil {882 return nil, fmt.Errorf("failed to unmarshal request: %v", err)883 }884 if req.Corrupted {885 resp := &dashapi.NeedReproResp{886 NeedRepro: false,887 }888 return resp, nil889 }890 req.Title = limitLength(req.Title, maxTextLen)891 bug, _, err := findBugForCrash(c, ns, req.Title)892 if err != nil {893 return nil, err894 }895 if bug == nil {896 return nil, fmt.Errorf("%v: can't find bug for crash %q", ns, req.Title)897 }898 resp := &dashapi.NeedReproResp{899 NeedRepro: needRepro(c, bug),900 }901 return resp, nil902}903func apiManagerStats(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {904 req := new(dashapi.ManagerStatsReq)905 if err := json.Unmarshal(payload, req); err != nil {906 return nil, fmt.Errorf("failed to unmarshal request: %v", err)907 }908 now := timeNow(c)909 err := updateManager(c, ns, req.Name, func(mgr *Manager, stats *ManagerStats) error {910 mgr.Link = req.Addr911 mgr.LastAlive = now912 mgr.CurrentUpTime = req.UpTime913 if cur := int64(req.Corpus); cur > stats.MaxCorpus {914 stats.MaxCorpus = cur915 }916 if cur := int64(req.PCs); cur > stats.MaxPCs {917 stats.MaxPCs = cur...

Full Screen

Full Screen

apiManagerStats

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m.apiManagerStats()4}5import (6func main() {7 m.apiManagerStats()8}9import (10func main() {11 m.apiManagerStats()12}13import (14func main() {15 m.apiManagerStats()16}17import (18func main() {19 m.apiManagerStats()20}21import (22func main() {23 m.apiManagerStats()24}25import (26func main() {27 m.apiManagerStats()28}29import (30func main() {31 m.apiManagerStats()32}33import (34func main() {35 m.apiManagerStats()36}37import (38func main() {39 m.apiManagerStats()40}41import (42func main() {43 m.apiManagerStats()44}45import (46func main() {47 m.apiManagerStats()48}

Full Screen

Full Screen

apiManagerStats

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := &http.Client{4 }5 if err != nil {6 fmt.Println(err)7 }8 response, err := client.Do(request)9 if err != nil {10 fmt.Println(err)11 }12 defer response.Body.Close()13}14import (15func main() {16 client := &http.Client{17 }18 if err != nil {19 fmt.Println(err)20 }21 response, err := client.Do(request)22 if err != nil {23 fmt.Println(err)24 }25 defer response.Body.Close()26}27import (28func main() {29 client := &http.Client{30 }31 if err != nil {32 fmt.Println(err)33 }34 response, err := client.Do(request)35 if err != nil {36 fmt.Println(err)37 }38 defer response.Body.Close()39}40import (41func main() {42 client := &http.Client{43 }

Full Screen

Full Screen

apiManagerStats

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 beego.Run()4}5import (6func main() {7 beego.Run()8}9import (10func main() {11 beego.Run()12}13import (14func main() {15 beego.Run()16}17import (18func main() {19 beego.Run()20}21import (22func main() {23 beego.Run()24}25import (26func main() {27 beego.Run()28}29import (30func main() {

Full Screen

Full Screen

apiManagerStats

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 dir, err := filepath.Abs(filepath.Dir(os.Args[0]))5 if err != nil {6 log.Fatal(err)7 }8 fmt.Println("current working directory:", dir)9 dir, err = os.Getwd()10 if err != nil {11 log.Fatal(err)12 }13 fmt.Println("current working directory:", dir)14 dir, err = os.Getwd()15 if err != nil {16 log.Fatal(err)17 }18 fmt.Println("current working directory:", dir)19 dir, err = os.Getwd()20 if err != nil {21 log.Fatal(err)22 }23 fmt.Println("current working directory:", dir)24 dir, err = os.Getwd()25 if err != nil {26 log.Fatal(err)27 }28 fmt.Println("current working directory:", dir)29 dir, err = os.Getwd()30 if err != nil {31 log.Fatal(err)32 }33 fmt.Println("current working directory:", dir)34 dir, err = os.Getwd()35 if err != nil {36 log.Fatal(err)37 }38 fmt.Println("current working directory:", dir)39 dir, err = os.Getwd()40 if err != nil {41 log.Fatal(err)42 }43 fmt.Println("current working directory:", dir)44 dir, err = os.Getwd()45 if err != nil {46 log.Fatal(err)47 }48 fmt.Println("current working directory:", dir)49 dir, err = os.Getwd()50 if err != nil {51 log.Fatal(err)52 }53 fmt.Println("current working directory:", dir)54 dir, err = os.Getwd()55 if err != nil {56 log.Fatal(err)57 }58 fmt.Println("current working directory:", dir)59 dir, err = os.Getwd()60 if err != nil {61 log.Fatal(err)62 }63 fmt.Println("

Full Screen

Full Screen

apiManagerStats

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Welcome to API Manager Stats")4 fmt.Println("Total number of APIs: ", apiManagerStats())5}6import (7func apiManagerStats() int {8}9import (10func main() {11 fmt.Println("Welcome to API Manager Stats")12 fmt.Println("Total number of APIs: ", apiManagerStats())13}14func apiManagerStats() int {15}16import (17func main() {18 fmt.Println("Welcome to API Manager Stats")19 total, active := apiManagerStats()20 fmt.Println("Total number of APIs: ", total)21 fmt.Println("Active APIs: ", active)22}23func apiManagerStats() (int, int) {24}25import (26func main() {27 fmt.Println("Welcome to API Manager Stats")28 total, active := apiManagerStats()29 fmt.Println("Total number of APIs: ", total)30 fmt.Println("Active APIs: ", active)31}32func apiManagerStats() (total int, active int) {33}34import (35func main() {36 fmt.Println("Welcome to API Manager Stats")37 total, active := apiManagerStats()38 fmt.Println("Total number of

Full Screen

Full Screen

apiManagerStats

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 mainInstance := apiManager.GetMainClassInstance()5 mainInstance.apiManagerStats()6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful