Rename ALERTMANAGER_URI to ALERTMANAGER_URIS

This will make upgrade more explicit since there is a syntax change
This commit is contained in:
Łukasz Mierzwa
2017-06-28 19:49:00 -07:00
parent 0e9d9cee39
commit 612a0e817f
7 changed files with 28 additions and 24 deletions

View File

@@ -2,8 +2,8 @@ NAME := unsee
VERSION := $(shell git describe --tags --always --dirty='-dev')
# Alertmanager instance used when running locally, points to mock data
MOCK_PATH := $(CURDIR)/mock/0.7.1
ALERTMANAGER_URI := "localfs:file://$(MOCK_PATH) local2:file://$(CURDIR)/mock/0.7.0"
MOCK_PATH := $(CURDIR)/mock/0.7.1
ALERTMANAGER_URIS := mock:file://$(MOCK_PATH)
# Listen port when running locally
PORT := 8080
@@ -49,7 +49,7 @@ clean:
.PHONY: run
run: $(NAME)
ALERTMANAGER_URI=$(ALERTMANAGER_URI) \
ALERTMANAGER_URIS=$(ALERTMANAGER_URIS) \
COLOR_LABELS_UNIQUE="@receiver instance cluster" \
COLOR_LABELS_STATIC="job" \
DEBUG="$(GIN_DEBUG)" \
@@ -68,7 +68,7 @@ run-docker: docker-image
--name $(NAME) \
$(DOCKER_ARGS) \
-v $(MOCK_PATH):$(MOCK_PATH) \
-e ALERTMANAGER_URI=$(ALERTMANAGER_URI) \
-e ALERTMANAGER_URIS=$(ALERTMANAGER_URIS) \
-e COLOR_LABELS_UNIQUE="instance cluster" \
-e COLOR_LABELS_STATIC="job" \
-e DEBUG="$(GIN_DEBUG)" \

View File

@@ -63,22 +63,22 @@ To finally compile `unsee` the binary run:
## Running
`unsee` is configured via environment variables or command line flags.
Environment variable `ALERTMANAGER_URI` or cli flag `-alertmanager.uri` is the
Environment variable `ALERTMANAGER_URIS` or cli flag `-alertmanager.uris` is the
only option required to run. See [Environment variables](#environment-variables)
section below for the full list of supported environment variables. Examples:
ALERTMANAGER_URI=https://alertmanager.example.com unsee
unsee -alertmanager.uri https://alertmanager.example.com
ALERTMANAGER_URIS=default:https://alertmanager.example.com unsee
unsee -alertmanager.uris default:https://alertmanager.example.com
There is a make target which will compile and run unsee:
make run
By default it will listen on port `8080` and Alertmanager mock data will be
used, to override Alertmanager URI set `ALERTMANAGER_URI` and/or `PORT` make
used, to override Alertmanager URI set `ALERTMANAGER_URIS` and/or `PORT` make
variables. Example:
make PORT=5000 ALERTMANAGER_URI=https://alertmanager.example.com run
make PORT=5000 ALERTMANAGER_URIS=default:https://alertmanager.example.com run
## Docker
@@ -96,14 +96,14 @@ Images are built automatically for:
To start a release image run:
docker run -e ALERTMANAGER_URI=https://alertmanager.example.com cloudflare/unsee:vX.Y.Z
docker run -e ALERTMANAGER_URIS=default:https://alertmanager.example.com cloudflare/unsee:vX.Y.Z
Latest release details can be found on
[GitHub](https://github.com/cloudflare/unsee/releases).
To start docker image build from lastet master branch run:
docker run -e ALERTMANAGER_URI=https://alertmanager.example.com cloudflare/unsee:latest
docker run -e ALERTMANAGER_URIS=default:https://alertmanager.example.com cloudflare/unsee:latest
Note that latest master branch might have bugs or breaking changes. Using
release images is strongly recommended for any production use.
@@ -121,7 +121,7 @@ This will build a Docker image from sources.
Will run locally built Docker image. Same defaults and override variables
apply as with `make run`. Example:
make PORT=5000 ALERTMANAGER_URI=https://alertmanager.example.com run-docker
make PORT=5000 ALERTMANAGER_URIS=default:https://alertmanager.example.com run-docker
## Environment variables
@@ -159,14 +159,19 @@ The UI has a watchdog that tracks the timestamp of the last pull. If the UI
does not receive updates for more than 15 minutes it will print an error and
reload the page.
#### ALERTMANAGER_URI
#### ALERTMANAGER_URIS
URI of the Alertmanager instance, unsee will use it to pull alert groups and
silences. Endpoints in use:
List of Alertmanager instances URI, unsee will use it to pull alert groups and
silences from all defined instances and deduplicate all alerts.
API endpoints in use:
* ${ALERTMANAGER_URI}/api/v1/alerts/groups
* ${ALERTMANAGER_URI}/api/v1/silences
Expected syntax:
${name1}:${uri} ${name2}:{uri}
Supported URI schemes:
* http://
@@ -178,11 +183,11 @@ target.
Example:
ALERTMANAGER_URI=https://alertmanager.example.com
ALERTMANAGER_URIS="prod:https://prod.alertmanager.example.com staging:https://staging.alertmanager.example.com"
This option can also be set using `-alertmanager.uri` flag. Example:
This option can also be set using `-alertmanager.uris` flag. Example:
$ unsee -alertmanager.uri https://alertmanager.example.com
$ unsee -alertmanager.uris "prod:https://prod.alertmanager.example.com staging:https://staging.alertmanager.example.com"
This variable is required and there is no default value.

View File

@@ -3,7 +3,6 @@ package alertmanager
import (
"time"
"github.com/cloudflare/unsee/config"
"github.com/cloudflare/unsee/transport"
log "github.com/Sirupsen/logrus"
@@ -27,7 +26,7 @@ func GetVersion(uri string, timeout time.Duration) string {
url, err := transport.JoinURL(uri, "api/v1/status")
if err != nil {
log.Errorf("Failed to join url '%s' and path 'api/v1/status': %s", config.Config.AlertmanagerURI, err.Error())
log.Errorf("Failed to join url '%s' and path 'api/v1/status': %s", uri, err.Error())
return defaultVersion
}
ver := alertmanagerVersion{}

View File

@@ -25,7 +25,7 @@ func (mvd *spaceSeparatedList) Decode(value string) error {
type configEnvs struct {
AlertmanagerTimeout time.Duration `envconfig:"ALERTMANAGER_TIMEOUT" default:"40s" help:"Timeout for all request send to Alertmanager"`
AlertmanagerTTL time.Duration `envconfig:"ALERTMANAGER_TTL" default:"1m" help:"TTL for Alertmanager alerts and silences"`
AlertmanagerURI spaceSeparatedList `envconfig:"ALERTMANAGER_URI" required:"true" help:"Alertmanager URIs"`
AlertmanagerURIs spaceSeparatedList `envconfig:"ALERTMANAGER_URIS" required:"true" help:"List of Alertmanager URIs (name:uri)"`
ColorLabelsStatic spaceSeparatedList `envconfig:"COLOR_LABELS_STATIC" help:"List of label names that should have the same (but distinct) color"`
ColorLabelsUnique spaceSeparatedList `envconfig:"COLOR_LABELS_UNIQUE" help:"List of label names that should have unique color"`
Debug bool `envconfig:"DEBUG" default:"false" help:"Enable debug mode"`

View File

@@ -30,7 +30,7 @@ func TestMakeFlagName(t *testing.T) {
func TestReadConfig(t *testing.T) {
os.Setenv("ALERTMANAGER_TTL", "1s")
os.Setenv("ALERTMANAGER_URI", "http://localhost")
os.Setenv("ALERTMANAGER_URIS", "default:http://localhost")
os.Setenv("DEBUG", "true")
os.Setenv("COLOR_LABELS_STATIC", "a bb ccc")
Config.Read()

View File

@@ -53,7 +53,7 @@ func setupRouter(router *gin.Engine) {
}
func setupUpstreams() {
for _, s := range config.Config.AlertmanagerURI {
for _, s := range config.Config.AlertmanagerURIs {
z := strings.SplitN(s, ":", 2)
if len(z) != 2 {
log.Fatalf("Invalid Alertmanager URI '%s', expected format 'name:uri'", s)

View File

@@ -23,7 +23,7 @@ import (
func mockConfig() {
log.SetLevel(log.ErrorLevel)
os.Setenv("ALERTMANAGER_URI", "default:http://localhost")
os.Setenv("ALERTMANAGER_URIS", "default:http://localhost")
os.Setenv("COLOR_LABELS_UNIQUE", "alertname")
config.Config.Read()
setupUpstreams()