Fix golint warnings

This commit is contained in:
Fabian Reinartz 2015-11-05 10:49:32 +01:00
parent 5ce39632f8
commit 14001ebfa5
5 changed files with 32 additions and 0 deletions

5
api.go
View File

@ -31,6 +31,7 @@ import (
"github.com/prometheus/alertmanager/version"
)
// API provides registration of handlers for API routes.
type API struct {
alerts provider.Alerts
silences provider.Silences
@ -44,6 +45,7 @@ type API struct {
mtx sync.RWMutex
}
// NewAPI returns a new API.
func NewAPI(alerts provider.Alerts, silences provider.Silences, rf func() *UIRoute) *API {
return &API{
context: route.Context,
@ -54,6 +56,8 @@ func NewAPI(alerts provider.Alerts, silences provider.Silences, rf func() *UIRou
}
}
// Register regieters the API handlers under their correct routes
// in the given router.
func (api *API) Register(r *route.Router) {
// Register legacy forwarder for alert pushing.
r.Post("/alerts", api.legacyAddAlerts)
@ -75,6 +79,7 @@ func (api *API) Register(r *route.Router) {
r.Del("/silence/:sid", api.delSilence)
}
// Update sets the configuration string to a new value.
func (api *API) Update(config string) {
api.mtx.Lock()
defer api.mtx.Unlock()

View File

@ -14,6 +14,8 @@ import (
"github.com/prometheus/alertmanager/types"
)
// ResolveTimeout is the time after which an alert is declared resolved
// if it has not been updated.
const ResolveTimeout = 5 * time.Minute
// Dispatcher sorts incoming alerts into aggregation groups and
@ -54,6 +56,8 @@ func (d *Dispatcher) Run() {
close(d.done)
}
// UIRoute is the data representation of the routing tree as provided
// by the API.
type UIRoute struct {
RouteOpts *RouteOpts `json:"routeOpts"`
Matchers types.Matchers `json:"matchers"`
@ -61,11 +65,14 @@ type UIRoute struct {
Routes []*UIRoute `json:"routes"`
}
// UIGroup is the representation of a group of alerts as provided by
// the API.
type UIGroup struct {
Labels model.LabelSet `json:"labels"`
Alerts model.Alerts `json:"alerts"`
}
// Populate writes the dispatcher's internal state into the given UIRoute.
func (d *Dispatcher) Populate(r *UIRoute) {
for _, sr := range r.Routes {
d.Populate(sr)

View File

@ -24,6 +24,8 @@ import (
"github.com/prometheus/alertmanager/types"
)
// An Inhibitor determines whether a given label set is muted
// based on the currently active alerts and a set of inhibition rules.
type Inhibitor struct {
alerts provider.Alerts
rules []*InhibitRule
@ -31,6 +33,7 @@ type Inhibitor struct {
mtx sync.RWMutex
}
// NewInhibitor returns a new Inhibitor.
func NewInhibitor(ap provider.Alerts, rs []*config.InhibitRule) *Inhibitor {
ih := &Inhibitor{
alerts: ap,
@ -41,6 +44,7 @@ func NewInhibitor(ap provider.Alerts, rs []*config.InhibitRule) *Inhibitor {
return ih
}
// Mutes returns true iff the given label set is muted.
func (ih *Inhibitor) Mutes(lset model.LabelSet) bool {
alerts := ih.alerts.GetPending()
defer alerts.Close()
@ -82,6 +86,7 @@ type InhibitRule struct {
Equal map[model.LabelName]struct{}
}
// NewInhibitRule returns a new InihibtRule based on a configuration definition.
func NewInhibitRule(cr *config.InhibitRule) *InhibitRule {
var (
sourcem types.Matchers
@ -124,6 +129,8 @@ func NewInhibitRule(cr *config.InhibitRule) *InhibitRule {
}
}
// Mutes returns true iff the Inhibition rule applies for the given
// source and target label set.
func (r *InhibitRule) Mutes(source, target model.LabelSet) bool {
if !r.TargetMatchers.Match(target) || !r.SourceMatchers.Match(source) {
return false

View File

@ -24,6 +24,8 @@ import (
"github.com/prometheus/alertmanager/types"
)
// DefaultRouteOpts are the defaulting routing options which apply
// to the root route of a routing tree.
var DefaultRouteOpts = RouteOpts{
GroupWait: 30 * time.Second,
GroupInterval: 5 * time.Minute,
@ -52,6 +54,7 @@ type Route struct {
Routes []*Route
}
// NewRoute returns a new route.
func NewRoute(cr *config.Route, parent *Route) *Route {
// Create default and overwrite with configured settings.
opts := DefaultRouteOpts
@ -108,6 +111,7 @@ func NewRoute(cr *config.Route, parent *Route) *Route {
return route
}
// NewRoutes returns a slice of routes.
func NewRoutes(croutes []*config.Route, parent *Route) []*Route {
res := []*Route{}
for _, cr := range croutes {
@ -116,6 +120,7 @@ func NewRoutes(croutes []*config.Route, parent *Route) []*Route {
return res
}
// UIRoute returns the API data representation of a the route.
func (r *Route) UIRoute() *UIRoute {
var subs []*UIRoute
for _, sr := range r.Routes {
@ -158,6 +163,8 @@ func (r *Route) Match(lset model.LabelSet) []*RouteOpts {
return all
}
// SquashMatchers returns the total set of matchers on the path of the tree
// that have to apply to reach the route.
func (r *Route) SquashMatchers() types.Matchers {
var res types.Matchers
res = append(res, r.Matchers...)
@ -172,6 +179,8 @@ func (r *Route) SquashMatchers() types.Matchers {
return res
}
// Fingerprint returns a hash of the Route based on its grouping labels,
// routing options and the total set of matchers necessary to reach this route.
func (r *Route) Fingerprint() model.Fingerprint {
lset := make(model.LabelSet, len(r.RouteOpts.GroupBy))
@ -182,6 +191,8 @@ func (r *Route) Fingerprint() model.Fingerprint {
return r.SquashMatchers().Fingerprint() ^ lset.Fingerprint()
}
// RouteOpts holds various routing options necessary for processing alerts
// that match a given route.
type RouteOpts struct {
// The identifier of the associated notification configuration
SendTo string
@ -205,6 +216,7 @@ func (ro *RouteOpts) String() string {
return fmt.Sprintf("<RouteOpts send_to:%q group_by:%q timers:%q|%q>", ro.SendTo, labels, ro.GroupWait, ro.GroupInterval)
}
// MarshalJSON returns a JSON representation of the routing options.
func (ro *RouteOpts) MarshalJSON() ([]byte, error) {
v := struct {
SendTo string `json:"sendTo"`

1
web.go
View File

@ -21,6 +21,7 @@ import (
"github.com/prometheus/common/route"
)
// RegisterWeb registers handlers to serve files for the web interface.
func RegisterWeb(r *route.Router) {
r.Get("/app/*filepath", route.FileServe("ui/app/"))