diff --git a/.promu.yml b/.promu.yml index e2a28192..3b8cd4e4 100644 --- a/.promu.yml +++ b/.promu.yml @@ -2,6 +2,9 @@ go: 1.6.2 repository: path: github.com/prometheus/alertmanager build: + binaries: + - name: alertmanager + path: ./cmd/alertmanager flags: -a -tags netgo ldflags: | -X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}} diff --git a/api.go b/api/api.go similarity index 97% rename from api.go rename to api/api.go index fc8b6931..f17c2adb 100644 --- a/api.go +++ b/api/api.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package api import ( "encoding/json" @@ -28,6 +28,7 @@ import ( "github.com/satori/go.uuid" "golang.org/x/net/context" + "github.com/prometheus/alertmanager/dispatch" "github.com/prometheus/alertmanager/provider" "github.com/prometheus/alertmanager/types" ) @@ -59,15 +60,15 @@ type API struct { resolveTimeout time.Duration uptime time.Time - groups func() AlertOverview + groups func() dispatch.AlertOverview // context is an indirection for testing. context func(r *http.Request) context.Context mtx sync.RWMutex } -// NewAPI returns a new API. -func NewAPI(alerts provider.Alerts, silences provider.Silences, gf func() AlertOverview) *API { +// New returns a new API. +func New(alerts provider.Alerts, silences provider.Silences, gf func() dispatch.AlertOverview) *API { return &API{ context: route.Context, alerts: alerts, diff --git a/main.go b/cmd/alertmanager/main.go similarity index 93% rename from main.go rename to cmd/alertmanager/main.go index d3d2fb07..e7729882 100644 --- a/main.go +++ b/cmd/alertmanager/main.go @@ -38,12 +38,16 @@ import ( "github.com/prometheus/common/version" "github.com/weaveworks/mesh" + "github.com/prometheus/alertmanager/api" "github.com/prometheus/alertmanager/config" + "github.com/prometheus/alertmanager/dispatch" + "github.com/prometheus/alertmanager/inhibit" "github.com/prometheus/alertmanager/notify" "github.com/prometheus/alertmanager/provider/mem" meshprov "github.com/prometheus/alertmanager/provider/mesh" "github.com/prometheus/alertmanager/template" "github.com/prometheus/alertmanager/types" + "github.com/prometheus/alertmanager/ui" ) var ( @@ -144,13 +148,13 @@ func main() { defer alerts.Close() var ( - inhibitor *Inhibitor + inhibitor *inhibit.Inhibitor tmpl *template.Template - disp *Dispatcher + disp *dispatch.Dispatcher ) defer disp.Stop() - api := NewAPI(alerts, silences, func() AlertOverview { + apiv := api.New(alerts, silences, func() dispatch.AlertOverview { return disp.Groups() }) @@ -205,7 +209,7 @@ func main() { return err } - api.Update(conf.String(), time.Duration(conf.Global.ResolveTimeout)) + apiv.Update(conf.String(), time.Duration(conf.Global.ResolveTimeout)) tmpl, err = template.FromGlobs(conf.Templates...) if err != nil { @@ -216,8 +220,8 @@ func main() { inhibitor.Stop() disp.Stop() - inhibitor = NewInhibitor(alerts, conf.InhibitRules, marker) - disp = NewDispatcher(alerts, NewRoute(conf.Route, nil), build(conf.Receivers), marker) + inhibitor = inhibit.NewInhibitor(alerts, conf.InhibitRules, marker) + disp = dispatch.NewDispatcher(alerts, dispatch.NewRoute(conf.Route, nil), build(conf.Receivers), marker) go disp.Run() go inhibitor.Run() @@ -232,8 +236,8 @@ func main() { router := route.New() webReload := make(chan struct{}) - RegisterWeb(router.WithPrefix(amURL.Path), webReload) - api.Register(router.WithPrefix(path.Join(amURL.Path, "/api"))) + ui.Register(router.WithPrefix(amURL.Path), webReload) + apiv.Register(router.WithPrefix(path.Join(amURL.Path, "/api"))) log.Infoln("Listening on", *listenAddress) go listen(*listenAddress, router) diff --git a/dispatch.go b/dispatch/dispatch.go similarity index 99% rename from dispatch.go rename to dispatch/dispatch.go index 2a860bd9..5b3df009 100644 --- a/dispatch.go +++ b/dispatch/dispatch.go @@ -1,4 +1,4 @@ -package main +package dispatch import ( "fmt" diff --git a/dispatch_test.go b/dispatch/dispatch_test.go similarity index 99% rename from dispatch_test.go rename to dispatch/dispatch_test.go index 5c1279a0..ea57ff0f 100644 --- a/dispatch_test.go +++ b/dispatch/dispatch_test.go @@ -1,4 +1,4 @@ -package main +package dispatch import ( "reflect" diff --git a/route.go b/dispatch/route.go similarity index 99% rename from route.go rename to dispatch/route.go index 144e4db7..05081ced 100644 --- a/route.go +++ b/dispatch/route.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package dispatch import ( "encoding/json" diff --git a/route_test.go b/dispatch/route_test.go similarity index 99% rename from route_test.go rename to dispatch/route_test.go index 3578dfc0..850ae27a 100644 --- a/route_test.go +++ b/dispatch/route_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package dispatch import ( "reflect" diff --git a/inhibit.go b/inhibit/inhibit.go similarity index 99% rename from inhibit.go rename to inhibit/inhibit.go index 7f5a9cf6..0f5a936c 100644 --- a/inhibit.go +++ b/inhibit/inhibit.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package inhibit import ( "sync" diff --git a/inhibit_test.go b/inhibit/inhibit_test.go similarity index 99% rename from inhibit_test.go rename to inhibit/inhibit_test.go index f2acebfc..fee66a7d 100644 --- a/inhibit_test.go +++ b/inhibit/inhibit_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package inhibit import ( "reflect" diff --git a/web.go b/ui/web.go similarity index 89% rename from web.go rename to ui/web.go index 887b3c2a..fa8c799e 100644 --- a/web.go +++ b/ui/web.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package ui import ( "bytes" @@ -23,18 +23,16 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/log" "github.com/prometheus/common/route" - - "github.com/prometheus/alertmanager/ui" ) func serveAsset(w http.ResponseWriter, req *http.Request, fp string) { - info, err := ui.AssetInfo(fp) + info, err := AssetInfo(fp) if err != nil { log.Warn("Could not get file: ", err) w.WriteHeader(http.StatusNotFound) return } - file, err := ui.Asset(fp) + file, err := Asset(fp) if err != nil { if err != io.EOF { log.With("file", fp).Warn("Could not get file: ", err) @@ -46,8 +44,8 @@ func serveAsset(w http.ResponseWriter, req *http.Request, fp string) { http.ServeContent(w, req, info.Name(), info.ModTime(), bytes.NewReader(file)) } -// RegisterWeb registers handlers to serve files for the web interface. -func RegisterWeb(r *route.Router, reloadCh chan<- struct{}) { +// Register registers handlers to serve files for the web interface. +func Register(r *route.Router, reloadCh chan<- struct{}) { ihf := prometheus.InstrumentHandlerFunc r.Get("/app/*filepath", ihf("app_files",