| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package store | 5 package store |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "reflect" | 9 "reflect" |
| 10 "sync" | 10 "sync" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 data map[string]*metricData | 25 data map[string]*metricData |
| 26 dataLock sync.RWMutex | 26 dataLock sync.RWMutex |
| 27 } | 27 } |
| 28 | 28 |
| 29 type cellKey struct { | 29 type cellKey struct { |
| 30 fieldValuesHash, targetHash uint64 | 30 fieldValuesHash, targetHash uint64 |
| 31 } | 31 } |
| 32 | 32 |
| 33 type metricData struct { | 33 type metricData struct { |
| 34 types.MetricInfo | 34 types.MetricInfo |
| 35 types.MetricMetadata |
| 35 | 36 |
| 36 cells map[cellKey][]*types.CellData | 37 cells map[cellKey][]*types.CellData |
| 37 lock sync.Mutex | 38 lock sync.Mutex |
| 38 } | 39 } |
| 39 | 40 |
| 40 func (m *metricData) get(fieldVals []interface{}, t types.Target, resetTime time
.Time) (*types.CellData, error) { | 41 func (m *metricData) get(fieldVals []interface{}, t types.Target, resetTime time
.Time) (*types.CellData, error) { |
| 41 fieldVals, err := field.Canonicalize(m.Fields, fieldVals) | 42 fieldVals, err := field.Canonicalize(m.Fields, fieldVals) |
| 42 if err != nil { | 43 if err != nil { |
| 43 return nil, err | 44 return nil, err |
| 44 } | 45 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ret := []types.Cell{} | 244 ret := []types.Cell{} |
| 244 for _, m := range s.data { | 245 for _, m := range s.data { |
| 245 m.lock.Lock() | 246 m.lock.Lock() |
| 246 for _, cells := range m.cells { | 247 for _, cells := range m.cells { |
| 247 for _, cell := range cells { | 248 for _, cell := range cells { |
| 248 // Add the default target to the cell if it does
n't have one set. | 249 // Add the default target to the cell if it does
n't have one set. |
| 249 cellCopy := *cell | 250 cellCopy := *cell |
| 250 if cellCopy.Target == nil { | 251 if cellCopy.Target == nil { |
| 251 cellCopy.Target = defaultTarget | 252 cellCopy.Target = defaultTarget |
| 252 } | 253 } |
| 253 » » » » ret = append(ret, types.Cell{m.MetricInfo, cellC
opy}) | 254 » » » » ret = append(ret, types.Cell{m.MetricInfo, m.Met
ricMetadata, cellCopy}) |
| 254 } | 255 } |
| 255 } | 256 } |
| 256 m.lock.Unlock() | 257 m.lock.Unlock() |
| 257 } | 258 } |
| 258 return ret | 259 return ret |
| 259 } | 260 } |
| 260 | 261 |
| 261 func (s *inMemoryStore) Reset(ctx context.Context, h types.Metric) { | 262 func (s *inMemoryStore) Reset(ctx context.Context, h types.Metric) { |
| 262 m := s.getOrCreateData(h) | 263 m := s.getOrCreateData(h) |
| 263 | 264 |
| 264 m.lock.Lock() | 265 m.lock.Lock() |
| 265 m.cells = make(map[cellKey][]*types.CellData) | 266 m.cells = make(map[cellKey][]*types.CellData) |
| 266 m.lock.Unlock() | 267 m.lock.Unlock() |
| 267 } | 268 } |
| OLD | NEW |