Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
Signed-off-by: Povilas Versockas <[email protected]>
  • Loading branch information
povilasv committed Aug 21, 2018
1 parent 79ff4ad commit 6e5e827
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 53 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

* [CHANGE] Revert Alertmanager working directory changes in Docker image back to `/alertmanager` (#1435)

## 0.15.2 / 2018-08-14

* [ENHANCEMENT] [amtool] Add support for stdin to check-config (#1431)
* [ENHANCEMENT] Log PagerDuty v1 response on BadRequest (#1481)
* [BUGFIX] Correctly encode query strings in notifiers (#1516)
* [BUGFIX] Add cache control headers to the API responses to avoid IE caching (#1500)
* [BUGFIX] Avoid listener blocking on unsubscribe (#1482)
* [BUGFIX] Fix a bunch of unhandled errors (#1501)
* [BUGFIX] Update PagerDuty API V2 to send full details on resolve (#1483)
* [BUGFIX] Validate URLs at config load time (#1468)
* [BUGFIX] Fix Settle() interval (#1478)
* [BUGFIX] Fix email to be green if only none firing (#1475)
* [BUGFIX] Handle errors in notify (#1474)
* [BUGFIX] Fix templating of hipchat room id (#1463)

## 0.15.1 / 2018-07-10

* [BUGFIX] Fix email template typo in alert-warning style (#1421)
Expand Down
1 change: 1 addition & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Stuart Nelson <[email protected]>
* Max Inden <[email protected]>
69 changes: 44 additions & 25 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,28 @@ pkgs = ./...
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
DOCKER_REPO ?= prom

.PHONY: all
all: style staticcheck unused build test

.PHONY: style
style:
@echo ">> checking code style"
! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
# This rule is used to forward a target like "build" to "common-build". This
# allows a new "build" target to be defined in a Makefile which includes this
# one and override "common-build" without override warnings.
%: common-% ;

.PHONY: check_license
check_license:
.PHONY: common-style
common-style:
@echo ">> checking code style"
@fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
if [ -n "$${fmtRes}" ]; then \
echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
echo "Please ensure you are using $$($(GO) version) for formatting code."; \
exit 1; \
fi

.PHONY: common-check_license
common-check_license:
@echo ">> checking license header"
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
Expand All @@ -56,49 +67,57 @@ check_license:
exit 1; \
fi

.PHONY: test-short
test-short:
.PHONY: common-test-short
common-test-short:
@echo ">> running short tests"
$(GO) test -short $(pkgs)

.PHONY: test
test:
.PHONY: common-test
common-test:
@echo ">> running all tests"
$(GO) test -race $(pkgs)

.PHONY: format
format:
.PHONY: common-format
common-format:
@echo ">> formatting code"
$(GO) fmt $(pkgs)

.PHONY: vet
vet:
.PHONY: common-vet
common-vet:
@echo ">> vetting code"
$(GO) vet $(pkgs)

.PHONY: staticcheck
staticcheck: $(STATICCHECK)
.PHONY: common-staticcheck
common-staticcheck: $(STATICCHECK)
@echo ">> running staticcheck"
$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)

.PHONY: unused
unused: $(GOVENDOR)
.PHONY: common-unused
common-unused: $(GOVENDOR)
@echo ">> running check for unused packages"
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'

.PHONY: build
build: promu
.PHONY: common-build
common-build: promu
@echo ">> building binaries"
$(PROMU) build --prefix $(PREFIX)

.PHONY: tarball
tarball: promu
.PHONY: common-tarball
common-tarball: promu
@echo ">> building release tarball"
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)

.PHONY: docker
docker:
docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
.PHONY: common-docker
common-docker:
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .

.PHONY: common-docker-publish
common-docker-publish:
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"

.PHONY: common-docker-tag-latest
common-docker-tag-latest:
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):latest"

.PHONY: promu
promu:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.15.1
0.15.2
2 changes: 2 additions & 0 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ type SlackConfig struct {
Fallback string `yaml:"fallback,omitempty" json:"fallback,omitempty"`
IconEmoji string `yaml:"icon_emoji,omitempty" json:"icon_emoji,omitempty"`
IconURL string `yaml:"icon_url,omitempty" json:"icon_url,omitempty"`
ImageURL string `yaml:"image_url,omitempty" json:"image_url,omitempty"`
ThumbURL string `yaml:"thumb_url,omitempty" json:"thumb_url,omitempty"`
LinkNames bool `yaml:"link_names,omitempty" json:"link_names,omitempty"`
Actions []*SlackAction `yaml:"actions,omitempty" json:"actions,omitempty"`
}
Expand Down
19 changes: 16 additions & 3 deletions notify/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ type slackAttachment struct {
Fallback string `json:"fallback"`
Fields []config.SlackField `json:"fields,omitempty"`
Actions []config.SlackAction `json:"actions,omitempty"`
ImageURL string `json:"image_url,omitempty"`
ThumbURL string `json:"thumb_url,omitempty"`
Footer string `json:"footer"`

Color string `json:"color,omitempty"`
Expand All @@ -687,6 +689,8 @@ func (n *Slack) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
Pretext: tmplText(n.conf.Pretext),
Text: tmplText(n.conf.Text),
Fallback: tmplText(n.conf.Fallback),
ImageURL: tmplText(n.conf.ImageURL),
ThumbURL: tmplText(n.conf.ThumbURL),
Footer: tmplText(n.conf.Footer),
Color: tmplText(n.conf.Color),
MrkdwnIn: []string{"fallback", "pretext", "text"},
Expand Down Expand Up @@ -805,7 +809,10 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
roomid = tmplText(n.conf.RoomID)
apiURL = n.conf.APIURL.Copy()
)
apiURL.Path += fmt.Sprintf("v2/room/%s/notification?auth_token=%s", roomid, n.conf.AuthToken)
apiURL.Path += fmt.Sprintf("v2/room/%s/notification", roomid)
q := apiURL.Query()
q.Set("auth_token", fmt.Sprintf("%s", n.conf.AuthToken))
apiURL.RawQuery = q.Encode()

if n.conf.MessageFormat == "html" {
msg = tmplHTML(n.conf.Message)
Expand Down Expand Up @@ -976,7 +983,10 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
}

postMessageURL := n.conf.APIURL.Copy()
postMessageURL.Path += "message/send?access_token=" + n.accessToken
postMessageURL.Path += "message/send"
q := postMessageURL.Query()
q.Set("access_token", n.accessToken)
postMessageURL.RawQuery = q.Encode()

req, err := http.NewRequest(http.MethodPost, postMessageURL.String(), &buf)
if err != nil {
Expand Down Expand Up @@ -1106,7 +1116,10 @@ func (n *OpsGenie) createRequest(ctx context.Context, as ...*types.Alert) (*http
)
switch alerts.Status() {
case model.AlertResolved:
apiURL.Path += fmt.Sprintf("v2/alerts/%s/close?identifierType=alias", alias)
apiURL.Path += fmt.Sprintf("v2/alerts/%s/close", alias)
q := apiURL.Query()
q.Set("identifierType", "alias")
apiURL.RawQuery = q.Encode()
msg = &opsGenieCloseMessage{Source: tmpl(n.conf.Source)}
default:
message := tmpl(n.conf.Message)
Expand Down
45 changes: 24 additions & 21 deletions provider/mem/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func (a *Alerts) runGC() {
}
}

for i, l := range a.listeners {
select {
case <-l.done:
delete(a.listeners, i)
close(l.alerts)
default:
// listener is not closed yet, hence proceed.
}
}

a.mtx.Unlock()
}
}
Expand All @@ -85,41 +95,34 @@ func (a *Alerts) Close() error {
return nil
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

// Subscribe returns an iterator over active alerts that have not been
// resolved and successfully notified about.
// They are not guaranteed to be in chronological order.
func (a *Alerts) Subscribe() provider.AlertIterator {
alerts, err := a.getPending()

var (
ch = make(chan *types.Alert, alertChannelLength)
ch = make(chan *types.Alert, max(len(alerts), alertChannelLength))
done = make(chan struct{})
)
alerts, err := a.getPending()

for _, a := range alerts {
ch <- a
}

a.mtx.Lock()
i := a.next
a.next++
a.listeners[i] = listeningAlerts{alerts: ch, done: done}
a.mtx.Unlock()

go func() {
defer func() {
a.mtx.Lock()
delete(a.listeners, i)
close(ch)
a.mtx.Unlock()
}()

for _, a := range alerts {
select {
case ch <- a:
case <-done:
return
}
}

<-done
}()

return provider.NewAlertIterator(ch, done, err)
}

Expand Down
7 changes: 6 additions & 1 deletion ui/app/src/Views/NavBar/Types.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ statusTab =
{ link = "#/status", name = "Status" }


helpTab : Tab
helpTab =
{ link = "https://prometheus.io/docs/alerting/alertmanager/", name = "Help" }


noneTab : Tab
noneTab =
{ link = "", name = "" }


tabs : List Tab
tabs =
[ alertsTab, silencesTab, statusTab ]
[ alertsTab, silencesTab, statusTab, helpTab ]
4 changes: 2 additions & 2 deletions ui/bindata.go

Large diffs are not rendered by default.

0 comments on commit 6e5e827

Please sign in to comment.