-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b51c3b
commit ed544cd
Showing
6 changed files
with
97 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package gobrake | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type routes struct { | ||
filters []routeFilter | ||
|
||
stats *routeStats | ||
breakdowns *routeBreakdowns | ||
} | ||
|
||
func newRoutes(opt *NotifierOptions) *routes { | ||
return &routes{ | ||
stats: newRouteStats(opt), | ||
breakdowns: newRouteBreakdowns(opt), | ||
} | ||
} | ||
|
||
// AddFilter adds filter that can change route stat or ignore it by returning nil. | ||
func (rs *routes) AddFilter(fn func(*RouteMetric) *RouteMetric) { | ||
rs.filters = append(rs.filters, fn) | ||
} | ||
|
||
func (rs *routes) Flush() { | ||
rs.stats.Flush() | ||
rs.breakdowns.Flush() | ||
} | ||
|
||
func (rs *routes) Notify(c context.Context, metric *RouteMetric) error { | ||
metric.finish() | ||
|
||
for _, fn := range rs.filters { | ||
metric = fn(metric) | ||
if metric == nil { | ||
return nil | ||
} | ||
} | ||
|
||
err := rs.stats.Notify(c, metric) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = rs.breakdowns.Notify(c, metric) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters