Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Wang committed Jun 23, 2017
1 parent 23934fa commit 3410a33
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion matcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (cfg *Configuration) NewNamespaces(
}

namespaces := NewNamespaces(opts.NamespacesKey(), opts)
return namespaces, namespaces.Open()
return namespaces, nil
}

// NewMatcher creates a Matcher.
Expand Down
35 changes: 18 additions & 17 deletions matcher/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ var (
// Namespaces manages runtime updates to registered namespaces and provides
// API to match metic ids against rules in the corresponding namespaces.
type Namespaces interface {
runtime.Value

// Open opens the namespaces and starts watching runtime rule updates
Open() error

Expand Down Expand Up @@ -128,23 +126,26 @@ func NewNamespaces(key string, opts Options) Namespaces {
}

func (n *namespaces) Open() error {
err := n.Watch()
if err == nil {
return nil
}

scope := n.opts.InstrumentOptions().MetricsScope()
if err := n.Watch(); err != nil {
errCreateWatch, ok := err.(runtime.CreateWatchError)
if ok {
scope.Counter("create-watch-errors").Inc(1)
return errCreateWatch
}
// NB(xichen): we managed to watch the key but weren't able
// to initialize the value. In this case, log the error instead
// to be more resilient to error conditions preventing process
// from starting up.
scope.Counter("init-watch-errors").Inc(1)
n.opts.InstrumentOptions().Logger().WithFields(
xlog.NewLogField("key", n.key),
xlog.NewLogErrField(err),
).Error("error initializing namespaces values")
errCreateWatch, ok := err.(runtime.CreateWatchError)
if ok {
scope.Counter("create-watch-errors").Inc(1)
return errCreateWatch
}
// NB(xichen): we managed to watch the key but weren't able
// to initialize the value. In this case, log the error instead
// to be more resilient to error conditions preventing process
// from starting up.
scope.Counter("init-watch-errors").Inc(1)
n.opts.InstrumentOptions().Logger().WithFields(
xlog.NewLogField("key", n.key),
xlog.NewLogErrField(err),
).Error("error initializing namespaces values, retrying in the background")
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions metric/id/m3/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ func IsRollupID(name []byte, tags []byte, iterPool id.SortedTagIteratorPool) boo
iter = iterPool.Get()
iter.Reset(tags)
}
defer iter.Close()

for iter.Next() {
name, val := iter.Current()
if bytes.Equal(name, rollupTagPair.Name) && bytes.Equal(val, rollupTagPair.Value) {
iter.Close()
return true
}
}
iter.Close()
return false
}

Expand Down

0 comments on commit 3410a33

Please sign in to comment.