*: restructure package tree
This commit packages up individual modules and removes the top-level main package.
This commit is contained in:
parent
6a20296af4
commit
3931d4e64b
|
@ -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}}
|
||||
|
|
|
@ -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,
|
|
@ -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)
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"reflect"
|
|
@ -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"
|
|
@ -11,7 +11,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"reflect"
|
|
@ -11,7 +11,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
package inhibit
|
||||
|
||||
import (
|
||||
"sync"
|
|
@ -11,7 +11,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
package inhibit
|
||||
|
||||
import (
|
||||
"reflect"
|
|
@ -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",
|
Loading…
Reference in New Issue