Skip to content

Commit

Permalink
Save metrics to barrier without going through c.systemBarrierView (#884)
Browse files Browse the repository at this point in the history
* Don't bother trying to save metrics when we don't have a barrier.  Use stateLock.

* Use c.barrier instead of c.systemBarrierView, thus we don't need locking
and don't need to worry about race with mount setup.

* Remove unneccessary lock.
  • Loading branch information
ncabatoff authored and jefferai committed Apr 11, 2019
1 parent 6c49db3 commit ec9427c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions vault/counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const (
requestCounterDatePathFormat = "2006/01"
countersPath = systemBarrierPrefix + "counters"
requestCountersRelPath = "counters/requests/"
requestCountersPath = "sys/counters/requests/"
)

type counters struct {
Expand Down Expand Up @@ -51,7 +51,7 @@ type DatedRequestCounter struct {
// loadAllRequestCounters returns all request counters found in storage,
// ordered by time (oldest first.)
func (c *Core) loadAllRequestCounters(ctx context.Context, now time.Time) ([]DatedRequestCounter, error) {
view := c.systemBarrierView.SubView(requestCountersRelPath)
view := NewBarrierView(c.barrier, requestCountersPath)

datepaths, err := view.List(ctx, "")
if err != nil {
Expand Down Expand Up @@ -116,7 +116,7 @@ func (c *Core) loadCurrentRequestCounters(ctx context.Context, now time.Time) er
// If nothing is found at that path, that isn't an error: a reference to a zero
// RequestCounter is returned.
func (c *Core) loadRequestCounters(ctx context.Context, datepath string) (*RequestCounter, error) {
view := c.systemBarrierView.SubView(requestCountersRelPath)
view := NewBarrierView(c.barrier, requestCountersPath)

out, err := view.Get(ctx, datepath)
if err != nil {
Expand All @@ -140,7 +140,7 @@ func (c *Core) loadRequestCounters(ctx context.Context, datepath string) (*Reque
// we've entered a new month.
// now should be the current time; it is a parameter to facilitate testing.
func (c *Core) saveCurrentRequestCounters(ctx context.Context, now time.Time) error {
view := c.systemBarrierView.SubView(requestCountersRelPath)
view := NewBarrierView(c.barrier, requestCountersPath)
requests := atomic.LoadUint64(c.counters.requests)
curDatePath := now.Format(requestCounterDatePathFormat)

Expand Down

0 comments on commit ec9427c

Please sign in to comment.