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

Side by Side Diff: go/src/infra/monitoring/analyzer/gatekeeper.go

Issue 1874053002: [alerts-dispatcher] update to build again :) also fixes a concurrent map access (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: fix typo Created 4 years, 8 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 package analyzer
2
3 import (
4 "strings"
5
6 "infra/monitoring/messages"
7 )
8
9 // GatekeeperRules implements the rule checks that gatekeeper performs
10 // on failures to determine if the failure should close the tree.
11 type GatekeeperRules struct {
12 cfg messages.GatekeeperConfig
13 }
14
15 // NewGatekeeperRules returns a new instance of GatekeeperRules initialized
16 // with cfg.
17 func NewGatekeeperRules(cfg messages.GatekeeperConfig) *GatekeeperRules {
18 ret := &GatekeeperRules{cfg}
19 for masterURL, masterCfgs := range cfg.Masters {
20 if len(masterCfgs) != 1 {
21 log.Errorf("Multiple configs for master: %s", masterURL)
22 }
23 parts := strings.Split(masterURL, "/")
24 masterName := parts[len(parts)-1]
25 ret.cfg.Masters[masterName] = masterCfgs
26 }
27 return ret
28 }
29
30 // WouldCloseTree returns true if a step failure on given builder/master would
31 // cause it to close the tree.
32 func (r *GatekeeperRules) WouldCloseTree(master, builder, step string) bool {
33 mcs, ok := r.cfg.Masters[master]
34 if !ok {
35 log.Errorf("Missing master cfg: %s", master)
36 return false
37 }
38 mc := mcs[0]
39 bc, ok := mc.Builders[builder]
40 if !ok {
41 bc, ok = mc.Builders["*"]
42 if !ok {
43 return false
44 }
45 }
46
47 // TODO: Check for cfg.Categories
48 for _, xstep := range bc.ExcludedSteps {
49 if xstep == step {
50 return false
51 }
52 }
53
54 csteps := []string{}
55 csteps = append(csteps, bc.ClosingSteps...)
56 csteps = append(csteps, bc.ClosingOptional...)
57
58 for _, cs := range csteps {
59 if cs == "*" || cs == step {
60 return true
61 }
62 }
63
64 return false
65 }
66
67 // ExcludeFailure returns true if a step failure whould be ignored.
68 func (r *GatekeeperRules) ExcludeFailure(master, builder, step string) bool {
69 mcs, ok := r.cfg.Masters[master]
70 if !ok {
71 log.Errorf("Can't filter unknown master %s", master)
72 return false
73 }
74 mc := mcs[0]
martiniss 2016/04/12 22:02:54 it feels like we're doing something wrong if we ha
seanmccullough 2016/04/12 22:13:42 I agree, but this reflects what's in the config fi
75
76 for _, ebName := range mc.ExcludedBuilders {
77 if ebName == "*" || ebName == builder {
78 return true
79 }
80 }
81
82 // Not clear that builder_alerts even looks at the rest of these condtio ns
martiniss 2016/04/12 22:02:54 typo
seanmccullough 2016/04/12 22:13:42 Done.
83 // even though they're specified in gatekeeper.json
84 for _, s := range mc.ExcludedSteps {
85 if step == s {
86 return true
87 }
88 }
89
90 bc, ok := mc.Builders[builder]
91 if !ok {
92 if bc, ok = mc.Builders["*"]; !ok {
93 log.Warningf("Unknown %s builder %s", master, builder)
94 return true
95 }
96 }
97
98 for _, esName := range bc.ExcludedSteps {
99 if esName == step || esName == "*" {
100 return true
101 }
102 }
103
104 return false
105 }
OLDNEW
« no previous file with comments | « go/src/infra/monitoring/analyzer/analyzer_test.go ('k') | go/src/infra/monitoring/dispatcher/dispatcher.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698