| OLD | NEW |
| 1 package ignore | 1 package ignore |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "fmt" | 4 "fmt" |
| 5 "net/url" | 5 "net/url" |
| 6 "sync" | 6 "sync" |
| 7 "time" | 7 "time" |
| 8 | 8 |
| 9 "github.com/skia-dev/glog" | 9 "github.com/skia-dev/glog" |
| 10 | 10 |
| 11 "go.skia.org/infra/go/database" | 11 "go.skia.org/infra/go/database" |
| 12 "go.skia.org/infra/go/util" | 12 "go.skia.org/infra/go/util" |
| 13 "go.skia.org/infra/golden/go/expstorage" | 13 "go.skia.org/infra/golden/go/expstorage" |
| 14 "go.skia.org/infra/golden/go/types" | 14 "go.skia.org/infra/golden/go/types" |
| 15 ) | 15 ) |
| 16 | 16 |
| 17 type SQLIgnoreStore struct { | 17 type SQLIgnoreStore struct { |
| 18 » vdb *database.VersionedDB | 18 » vdb *database.VersionedDB |
| 19 » mutex sync.Mutex | 19 » mutex sync.Mutex |
| 20 » revision int64 | 20 » revision int64 |
| 21 » tileStream <-chan *types.TilePair | 21 » tileStream <-chan *types.TilePair |
| 22 » expStore expstorage.ExpectationsStore | 22 » lastTilePair *types.TilePair |
| 23 » expStore expstorage.ExpectationsStore |
| 23 } | 24 } |
| 24 | 25 |
| 25 // NewSQLIgnoreStore creates a new SQL based IgnoreStore. | 26 // NewSQLIgnoreStore creates a new SQL based IgnoreStore. |
| 26 // vdb - database to connect to. | 27 // vdb - database to connect to. |
| 27 // expStore - expectations store needed to cound the untriaged digests per rul
e. | 28 // expStore - expectations store needed to cound the untriaged digests per rul
e. |
| 28 // tileStream - continously provides an updated copy of the current tile. | 29 // tileStream - continously provides an updated copy of the current tile. |
| 29 func NewSQLIgnoreStore(vdb *database.VersionedDB, expStore expstorage.Expectatio
nsStore, tileStream <-chan *types.TilePair) IgnoreStore { | 30 func NewSQLIgnoreStore(vdb *database.VersionedDB, expStore expstorage.Expectatio
nsStore, tileStream <-chan *types.TilePair) IgnoreStore { |
| 30 ret := &SQLIgnoreStore{ | 31 ret := &SQLIgnoreStore{ |
| 31 vdb: vdb, | 32 vdb: vdb, |
| 32 tileStream: tileStream, | 33 tileStream: tileStream, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ignoreMatcher, err := m.BuildRuleMatcher() | 127 ignoreMatcher, err := m.BuildRuleMatcher() |
| 127 if err != nil { | 128 if err != nil { |
| 128 return err | 129 return err |
| 129 } | 130 } |
| 130 | 131 |
| 131 // Get the next tile. | 132 // Get the next tile. |
| 132 var tilePair *types.TilePair = nil | 133 var tilePair *types.TilePair = nil |
| 133 select { | 134 select { |
| 134 case tilePair = <-m.tileStream: | 135 case tilePair = <-m.tileStream: |
| 135 default: | 136 default: |
| 137 tilePair = m.lastTilePair |
| 136 } | 138 } |
| 137 if tilePair == nil { | 139 if tilePair == nil { |
| 138 return fmt.Errorf("No tile available to count ignores") | 140 return fmt.Errorf("No tile available to count ignores") |
| 139 } | 141 } |
| 142 m.lastTilePair = tilePair |
| 140 | 143 |
| 141 // Count the untriaged digests in HEAD. | 144 // Count the untriaged digests in HEAD. |
| 145 // matchingDigests[rule.ID]map[digest]bool |
| 142 matchingDigests := make(map[int]map[string]bool, len(rules)) | 146 matchingDigests := make(map[int]map[string]bool, len(rules)) |
| 147 rulesByDigest := map[string]map[int]bool{} |
| 143 for _, trace := range tilePair.TileWithIgnores.Traces { | 148 for _, trace := range tilePair.TileWithIgnores.Traces { |
| 144 gTrace := trace.(*types.GoldenTrace) | 149 gTrace := trace.(*types.GoldenTrace) |
| 145 if matchRules, ok := ignoreMatcher(gTrace.Params_); ok { | 150 if matchRules, ok := ignoreMatcher(gTrace.Params_); ok { |
| 146 testName := gTrace.Params_[types.PRIMARY_KEY_FIELD] | 151 testName := gTrace.Params_[types.PRIMARY_KEY_FIELD] |
| 147 » » » if digest := gTrace.LastDigest(); digest != "" && (exp.C
lassification(testName, digest) == types.UNTRIAGED) { | 152 » » » if digest := gTrace.LastDigest(); digest != types.MISSIN
G_DIGEST && (exp.Classification(testName, digest) == types.UNTRIAGED) { |
| 148 k := testName + ":" + digest | 153 k := testName + ":" + digest |
| 149 for _, r := range matchRules { | 154 for _, r := range matchRules { |
| 155 // Add the digest to all matching rules. |
| 150 if t, ok := matchingDigests[r.ID]; ok { | 156 if t, ok := matchingDigests[r.ID]; ok { |
| 151 t[k] = true | 157 t[k] = true |
| 152 } else { | 158 } else { |
| 153 matchingDigests[r.ID] = map[stri
ng]bool{k: true} | 159 matchingDigests[r.ID] = map[stri
ng]bool{k: true} |
| 154 } | 160 } |
| 161 |
| 162 // Add the rule to the test-digest. |
| 163 if t, ok := rulesByDigest[k]; ok { |
| 164 t[r.ID] = true |
| 165 } else { |
| 166 rulesByDigest[k] = map[int]bool{
r.ID: true} |
| 167 } |
| 155 } | 168 } |
| 156 } | 169 } |
| 157 } | 170 } |
| 158 } | 171 } |
| 159 | 172 |
| 160 for _, r := range rules { | 173 for _, r := range rules { |
| 161 r.Count = len(matchingDigests[r.ID]) | 174 r.Count = len(matchingDigests[r.ID]) |
| 175 r.ExclusiveCount = 0 |
| 176 for testDigestKey := range matchingDigests[r.ID] { |
| 177 // If exactly this one rule matches then account for it. |
| 178 if len(rulesByDigest[testDigestKey]) == 1 { |
| 179 r.ExclusiveCount++ |
| 180 } |
| 181 } |
| 162 } | 182 } |
| 163 return nil | 183 return nil |
| 164 } | 184 } |
| 165 | 185 |
| 166 // Delete, see IgnoreStore interface. | 186 // Delete, see IgnoreStore interface. |
| 167 func (m *SQLIgnoreStore) Delete(id int, userId string) (int, error) { | 187 func (m *SQLIgnoreStore) Delete(id int, userId string) (int, error) { |
| 168 stmt := "DELETE FROM ignorerule WHERE id=?" | 188 stmt := "DELETE FROM ignorerule WHERE id=?" |
| 169 ret, err := m.vdb.DB.Exec(stmt, id) | 189 ret, err := m.vdb.DB.Exec(stmt, id) |
| 170 if err != nil { | 190 if err != nil { |
| 171 return 0, err | 191 return 0, err |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 232 |
| 213 for ruleIdx, rule := range ignoreRules { | 233 for ruleIdx, rule := range ignoreRules { |
| 214 if rule.IsMatch(params) { | 234 if rule.IsMatch(params) { |
| 215 result = append(result, rulesList[ruleIdx]) | 235 result = append(result, rulesList[ruleIdx]) |
| 216 } | 236 } |
| 217 } | 237 } |
| 218 | 238 |
| 219 return result, len(result) > 0 | 239 return result, len(result) > 0 |
| 220 }, nil | 240 }, nil |
| 221 } | 241 } |
| OLD | NEW |