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. | 9 // TODO(seanmccullough): Run continuously. Also, consider renaming to 'patrol' |
| 10 // or 'scanner' because that's really what this thing does. |
10 | 11 |
11 package main | 12 package main |
12 | 13 |
13 import ( | 14 import ( |
14 "encoding/json" | 15 "encoding/json" |
15 "flag" | 16 "flag" |
16 "fmt" | 17 "fmt" |
17 "io/ioutil" | 18 "io/ioutil" |
18 "os" | 19 "os" |
19 "time" | 20 "time" |
20 | 21 |
21 "github.com/Sirupsen/logrus" | 22 "github.com/Sirupsen/logrus" |
22 | 23 |
23 "infra/monitoring/analyzer" | 24 "infra/monitoring/analyzer" |
24 "infra/monitoring/messages" | 25 "infra/monitoring/messages" |
25 ) | 26 ) |
26 | 27 |
27 var ( | 28 var ( |
28 dataURL = flag.String("data_url", "", "Url where alerts are
stored") | 29 dataURL = flag.String("data_url", "", "Url where alerts are
stored") |
29 masterFilter = flag.String("master-filter", "", "Filter out maste
rs that contain this string") | 30 masterFilter = flag.String("master-filter", "", "Filter out maste
rs that contain this string") |
30 masterOnly = flag.String("master", "", "Only check this master"
) | 31 masterOnly = flag.String("master", "", "Only check this master"
) |
31 mastersOnly = flag.Bool("masters-only", false, "Just check for m
aster alerts, not builders") | 32 mastersOnly = flag.Bool("masters-only", false, "Just check for m
aster alerts, not builders") |
32 gatekeeperJSON = flag.String("gatekeeper", "gatekeeper.json", "Loca
tion of gatekeeper json file") | 33 gatekeeperJSON = flag.String("gatekeeper", "gatekeeper.json", "Loca
tion of gatekeeper json file") |
33 gatekeeperTreesJSON = flag.String("gatekeeper-trees", "gatekeeper_trees.
json", "Location of gatekeeper json file") | 34 gatekeeperTreesJSON = flag.String("gatekeeper-trees", "gatekeeper_trees.
json", "Location of gatekeeper json file") |
| 35 treeOnly = flag.String("tree", "", "Only check this tree") |
| 36 builderOnly = flag.String("builder", "", "Only check this builde
r") |
| 37 buildOnly = flag.Int64("build", 0, "Only check this build") |
34 | 38 |
35 log = logrus.New() | 39 log = logrus.New() |
36 | 40 |
37 // gk is the gatekeeper config. | 41 // gk is the gatekeeper config. |
38 gk = &struct { | 42 gk = &struct { |
39 // Weird. Are there ever multiple configs per master key? | 43 // Weird. Are there ever multiple configs per master key? |
40 Masters map[string][]messages.MasterConfig `json:"masters"` | 44 Masters map[string][]messages.MasterConfig `json:"masters"` |
41 }{} | 45 }{} |
| 46 // gkt is the gatekeeper trees config. |
| 47 gkt = map[string]messages.TreeMasterConfig{} |
42 filteredFailures = uint64(0) | 48 filteredFailures = uint64(0) |
43 ) | 49 ) |
44 | 50 |
45 func init() { | 51 func init() { |
46 flag.Usage = func() { | 52 flag.Usage = func() { |
47 fmt.Printf("Runs a single check, prints out diagnosis and exits.
\n") | 53 fmt.Printf("Runs a single check, prints out diagnosis and exits.
\n") |
48 flag.PrintDefaults() | 54 flag.PrintDefaults() |
49 } | 55 } |
50 } | 56 } |
51 | 57 |
(...skipping 26 matching lines...) Expand all Loading... |
78 mURLs := []string{} | 84 mURLs := []string{} |
79 if *masterOnly != "" { | 85 if *masterOnly != "" { |
80 mURLs = append(mURLs, *masterOnly) | 86 mURLs = append(mURLs, *masterOnly) |
81 } | 87 } |
82 | 88 |
83 err := readJSONFile(*gatekeeperJSON, &gk) | 89 err := readJSONFile(*gatekeeperJSON, &gk) |
84 if err != nil { | 90 if err != nil { |
85 log.Fatalf("Error reading gatekeeper json: %v", err) | 91 log.Fatalf("Error reading gatekeeper json: %v", err) |
86 } | 92 } |
87 | 93 |
88 » // Use a direct reference to the client implementation so we can | 94 » err = readJSONFile(*gatekeeperTreesJSON, &gkt) |
89 » // report request processing stats. | 95 » if err != nil { |
90 » a := analyzer.New(nil, 10) | 96 » » log.Fatalf("Error reading gatekeeper json: %v", err) |
| 97 » } |
| 98 |
| 99 » a := analyzer.New(nil, 2, 5) |
| 100 |
| 101 » a.TreeOnly = *treeOnly |
| 102 » a.MasterOnly = *masterOnly |
| 103 » a.BuilderOnly = *builderOnly |
| 104 » a.BuildOnly = *buildOnly |
| 105 |
| 106 » if *treeOnly != "" { |
| 107 » » if t, ok := gkt[*treeOnly]; ok { |
| 108 » » » for _, url := range t.Masters { |
| 109 » » » » mURLs = append(mURLs, fmt.Sprintf("%s/json", url
)) |
| 110 » » » } |
| 111 » » } else { |
| 112 » » » log.Fatalf("Unrecoginzed tree: %s", *treeOnly) |
| 113 » » } |
| 114 » } |
91 | 115 |
92 bes, errs := a.Client.BuildExtracts(mURLs) | 116 bes, errs := a.Client.BuildExtracts(mURLs) |
93 log.Infof("Build Extracts read: %d", len(bes)) | 117 log.Infof("Build Extracts read: %d", len(bes)) |
94 log.Infof("Errors: %d", len(errs)) | 118 log.Infof("Errors: %d", len(errs)) |
95 for url, err := range errs { | 119 for url, err := range errs { |
96 log.Errorf("Error reading build extract from %s : %s", url, err) | 120 log.Errorf("Error reading build extract from %s : %s", url, err) |
97 } | 121 } |
98 | 122 |
99 alerts := &messages.Alerts{} | 123 alerts := &messages.Alerts{} |
100 | 124 |
(...skipping 17 matching lines...) Expand all Loading... |
118 } | 142 } |
119 } | 143 } |
120 | 144 |
121 log.Infof("Filtered failures: %v", filteredFailures) | 145 log.Infof("Filtered failures: %v", filteredFailures) |
122 a.Client.DumpStats() | 146 a.Client.DumpStats() |
123 log.Infof("Elapsed time: %v", time.Since(start)) | 147 log.Infof("Elapsed time: %v", time.Since(start)) |
124 if len(errs) > 0 { | 148 if len(errs) > 0 { |
125 os.Exit(1) | 149 os.Exit(1) |
126 } | 150 } |
127 } | 151 } |
OLD | NEW |