OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Dispatcher usage: | 5 // Dispatcher usage: |
6 // go run infra/monitoring/dispatcher | 6 // go run infra/monitoring/dispatcher |
7 // Expects gatekeeper.json to be in the current directory. | 7 // Expects gatekeeper.json to be in the current directory. |
8 // Runs a single check, prints out diagnosis and exits. | 8 // Runs a single check, prints out diagnosis and exits. |
9 // TODO(seanmccullough): Run continuously. Also, consider renaming to 'patrol' | 9 // TODO(seanmccullough): Run continuously. Also, consider renaming to 'patrol' |
10 // or 'scanner' because that's really what this thing does. | 10 // or 'scanner' because that's really what this thing does. |
11 | 11 |
12 package main | 12 package main |
13 | 13 |
14 import ( | 14 import ( |
15 "encoding/json" | 15 "encoding/json" |
16 "flag" | 16 "flag" |
17 "fmt" | 17 "fmt" |
18 "io/ioutil" | 18 "io/ioutil" |
19 "os" | 19 "os" |
20 "strings" | 20 "strings" |
21 "time" | 21 "time" |
22 | 22 |
23 » "github.com/Sirupsen/logrus" | 23 » "infra/libs/logging" |
24 | 24 |
25 "infra/monitoring/analyzer" | 25 "infra/monitoring/analyzer" |
26 "infra/monitoring/messages" | 26 "infra/monitoring/messages" |
27 ) | 27 ) |
28 | 28 |
29 var ( | 29 var ( |
30 dataURL = flag.String("data_url", "", "Url where alerts are
stored") | 30 dataURL = flag.String("data_url", "", "Url where alerts are
stored") |
31 masterFilter = flag.String("master-filter", "", "Filter out maste
rs that contain this string") | 31 masterFilter = flag.String("master-filter", "", "Filter out maste
rs that contain this string") |
32 masterOnly = flag.String("master", "", "Only check this master"
) | 32 masterOnly = flag.String("master", "", "Only check this master"
) |
33 mastersOnly = flag.Bool("masters-only", false, "Just check for m
aster alerts, not builders") | 33 mastersOnly = flag.Bool("masters-only", false, "Just check for m
aster alerts, not builders") |
34 gatekeeperJSON = flag.String("gatekeeper", "gatekeeper.json", "Loca
tion of gatekeeper json file") | 34 gatekeeperJSON = flag.String("gatekeeper", "gatekeeper.json", "Loca
tion of gatekeeper json file") |
35 gatekeeperTreesJSON = flag.String("gatekeeper-trees", "gatekeeper_trees.
json", "Location of gatekeeper json file") | 35 gatekeeperTreesJSON = flag.String("gatekeeper-trees", "gatekeeper_trees.
json", "Location of gatekeeper json file") |
36 treeOnly = flag.String("tree", "", "Only check this tree") | 36 treeOnly = flag.String("tree", "", "Only check this tree") |
37 builderOnly = flag.String("builder", "", "Only check this builde
r") | 37 builderOnly = flag.String("builder", "", "Only check this builde
r") |
38 buildOnly = flag.Int64("build", 0, "Only check this build") | 38 buildOnly = flag.Int64("build", 0, "Only check this build") |
39 | 39 |
40 » log = logrus.New() | 40 » log = logging.DefaultLogger |
41 | 41 |
42 // gk is the gatekeeper config. | 42 // gk is the gatekeeper config. |
43 gk = &struct { | 43 gk = &struct { |
44 // Weird. Are there ever multiple configs per master key? | 44 // Weird. Are there ever multiple configs per master key? |
45 Masters map[string][]messages.MasterConfig `json:"masters"` | 45 Masters map[string][]messages.MasterConfig `json:"masters"` |
46 }{} | 46 }{} |
47 // gkt is the gatekeeper trees config. | 47 // gkt is the gatekeeper trees config. |
48 gkt = map[string]messages.TreeMasterConfig{} | 48 gkt = map[string]messages.TreeMasterConfig{} |
49 filteredFailures = uint64(0) | 49 filteredFailures = uint64(0) |
50 ) | 50 ) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 start := time.Now() | 87 start := time.Now() |
88 flag.Parse() | 88 flag.Parse() |
89 | 89 |
90 masterNames := []string{} | 90 masterNames := []string{} |
91 if *masterOnly != "" { | 91 if *masterOnly != "" { |
92 masterNames = append(masterNames, *masterOnly) | 92 masterNames = append(masterNames, *masterOnly) |
93 } | 93 } |
94 | 94 |
95 err := readJSONFile(*gatekeeperJSON, &gk) | 95 err := readJSONFile(*gatekeeperJSON, &gk) |
96 if err != nil { | 96 if err != nil { |
97 » » log.Fatalf("Error reading gatekeeper json: %v", err) | 97 » » log.Errorf("Error reading gatekeeper json: %v", err) |
| 98 » » os.Exit(1) |
98 } | 99 } |
99 | 100 |
100 err = readJSONFile(*gatekeeperTreesJSON, &gkt) | 101 err = readJSONFile(*gatekeeperTreesJSON, &gkt) |
101 if err != nil { | 102 if err != nil { |
102 » » log.Fatalf("Error reading gatekeeper json: %v", err) | 103 » » log.Errorf("Error reading gatekeeper json: %v", err) |
| 104 » » os.Exit(1) |
103 } | 105 } |
104 | 106 |
105 a := analyzer.New(nil, 2, 5) | 107 a := analyzer.New(nil, 2, 5) |
106 | 108 |
107 for masterURL, masterCfgs := range gk.Masters { | 109 for masterURL, masterCfgs := range gk.Masters { |
108 if len(masterCfgs) != 1 { | 110 if len(masterCfgs) != 1 { |
109 » » » log.Fatalf("Multiple configs for master: %s", masterURL) | 111 » » » log.Errorf("Multiple configs for master: %s", masterURL) |
| 112 » » » os.Exit(1) |
110 } | 113 } |
111 masterName := masterFromURL(masterURL) | 114 masterName := masterFromURL(masterURL) |
112 a.MasterCfgs[masterName] = masterCfgs[0] | 115 a.MasterCfgs[masterName] = masterCfgs[0] |
113 } | 116 } |
114 | 117 |
115 a.TreeOnly = *treeOnly | 118 a.TreeOnly = *treeOnly |
116 a.MasterOnly = *masterOnly | 119 a.MasterOnly = *masterOnly |
117 a.BuilderOnly = *builderOnly | 120 a.BuilderOnly = *builderOnly |
118 a.BuildOnly = *buildOnly | 121 a.BuildOnly = *buildOnly |
119 | 122 |
120 if *treeOnly != "" { | 123 if *treeOnly != "" { |
121 if t, ok := gkt[*treeOnly]; ok { | 124 if t, ok := gkt[*treeOnly]; ok { |
122 for _, url := range t.Masters { | 125 for _, url := range t.Masters { |
123 masterNames = append(masterNames, masterFromURL(
url)) | 126 masterNames = append(masterNames, masterFromURL(
url)) |
124 } | 127 } |
125 } else { | 128 } else { |
126 » » » log.Fatalf("Unrecoginzed tree: %s", *treeOnly) | 129 » » » log.Errorf("Unrecoginzed tree: %s", *treeOnly) |
| 130 » » » os.Exit(1) |
127 } | 131 } |
128 } | 132 } |
129 | 133 |
130 bes, errs := a.Client.BuildExtracts(masterNames) | 134 bes, errs := a.Client.BuildExtracts(masterNames) |
131 log.Infof("Build Extracts read: %d", len(bes)) | 135 log.Infof("Build Extracts read: %d", len(bes)) |
132 log.Infof("Errors: %d", len(errs)) | 136 log.Infof("Errors: %d", len(errs)) |
133 for url, err := range errs { | 137 for url, err := range errs { |
134 log.Errorf("Error reading build extract from %s : %s", url, err) | 138 log.Errorf("Error reading build extract from %s : %s", url, err) |
135 } | 139 } |
136 | 140 |
(...skipping 19 matching lines...) Expand all Loading... |
156 } | 160 } |
157 } | 161 } |
158 | 162 |
159 log.Infof("Filtered failures: %v", filteredFailures) | 163 log.Infof("Filtered failures: %v", filteredFailures) |
160 a.Client.DumpStats() | 164 a.Client.DumpStats() |
161 log.Infof("Elapsed time: %v", time.Since(start)) | 165 log.Infof("Elapsed time: %v", time.Since(start)) |
162 if len(errs) > 0 { | 166 if len(errs) > 0 { |
163 os.Exit(1) | 167 os.Exit(1) |
164 } | 168 } |
165 } | 169 } |
OLD | NEW |