Skip to content

Commit

Permalink
Merge branch 'alert-metrics-averages' of github.com:target/goalert in…
Browse files Browse the repository at this point in the history
…to alert-metrics-averages
  • Loading branch information
KatieMSB committed May 5, 2022
2 parents 977bdab + 8150490 commit b8d1b48
Show file tree
Hide file tree
Showing 62 changed files with 1,810 additions and 3,056 deletions.
38 changes: 29 additions & 9 deletions Makefile.binaries.mk
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ container-demo: container-demo-amd64 container-demo-arm container-demo-arm64
container-goalert: container-goalert-amd64 container-goalert-arm container-goalert-arm64

$(BIN_DIR)/build/integration/cypress.json: web/src/cypress.json
sed 's/\.ts/\.js/' web/src/cypress.json >$@
cp web/src/cypress.json $@

$(BIN_DIR)/build/integration/cypress: node_modules web/src/webpack.cypress.js $(BIN_DIR)/build/integration/cypress.json $(shell find ./web/src/cypress)
$(BIN_DIR)/build/integration/cypress: node_modules $(BIN_DIR)/build/integration/cypress.json web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
rm -rf $@
yarn workspace goalert-web webpack --config webpack.cypress.js
cp -r web/src/cypress/fixtures $@/
yarn workspace goalert-web esbuild-cy
mkdir -p $@/plugins
cp web/src/cypress/plugins/index.js $@/plugins/index.js
touch $@


Expand Down Expand Up @@ -363,6 +364,25 @@ $(BIN_DIR)/windows-amd64/simpleproxy.exe: $(GO_DEPS)
GOOS=windows GOARCH=amd64 go build -trimpath -o $@ ./devtools/simpleproxy


$(BIN_DIR)/slowproxy: $(GO_DEPS)
go build -o $@ ./devtools/slowproxy

$(BIN_DIR)/darwin-amd64/slowproxy: $(GO_DEPS)
GOOS=darwin GOARCH=amd64 go build -trimpath -o $@ ./devtools/slowproxy

$(BIN_DIR)/linux-amd64/slowproxy: $(GO_DEPS)
GOOS=linux GOARCH=amd64 go build -trimpath -o $@ ./devtools/slowproxy

$(BIN_DIR)/linux-arm/slowproxy: $(GO_DEPS)
GOOS=linux GOARCH=arm GOARM=7 go build -trimpath -o $@ ./devtools/slowproxy

$(BIN_DIR)/linux-arm64/slowproxy: $(GO_DEPS)
GOOS=linux GOARCH=arm64 go build -trimpath -o $@ ./devtools/slowproxy

$(BIN_DIR)/windows-amd64/slowproxy.exe: $(GO_DEPS)
GOOS=windows GOARCH=amd64 go build -trimpath -o $@ ./devtools/slowproxy


$(BIN_DIR)/waitfor: $(GO_DEPS)
go build -o $@ ./devtools/waitfor

Expand All @@ -384,27 +404,27 @@ $(BIN_DIR)/windows-amd64/waitfor.exe: $(GO_DEPS)



$(BIN_DIR)/darwin-amd64/_all: $(BIN_DIR)/darwin-amd64/goalert-smoketest $(BIN_DIR)/darwin-amd64/goalert $(BIN_DIR)/darwin-amd64/goalert-slack-email-sync $(BIN_DIR)/darwin-amd64/mockslack $(BIN_DIR)/darwin-amd64/pgdump-lite $(BIN_DIR)/darwin-amd64/procwrap $(BIN_DIR)/darwin-amd64/psql-lite $(BIN_DIR)/darwin-amd64/resetdb $(BIN_DIR)/darwin-amd64/runproc $(BIN_DIR)/darwin-amd64/sendit $(BIN_DIR)/darwin-amd64/sendit-server $(BIN_DIR)/darwin-amd64/sendit-token $(BIN_DIR)/darwin-amd64/simpleproxy $(BIN_DIR)/darwin-amd64/waitfor
$(BIN_DIR)/darwin-amd64/_all: $(BIN_DIR)/darwin-amd64/goalert-smoketest $(BIN_DIR)/darwin-amd64/goalert $(BIN_DIR)/darwin-amd64/goalert-slack-email-sync $(BIN_DIR)/darwin-amd64/mockslack $(BIN_DIR)/darwin-amd64/pgdump-lite $(BIN_DIR)/darwin-amd64/procwrap $(BIN_DIR)/darwin-amd64/psql-lite $(BIN_DIR)/darwin-amd64/resetdb $(BIN_DIR)/darwin-amd64/runproc $(BIN_DIR)/darwin-amd64/sendit $(BIN_DIR)/darwin-amd64/sendit-server $(BIN_DIR)/darwin-amd64/sendit-token $(BIN_DIR)/darwin-amd64/simpleproxy $(BIN_DIR)/darwin-amd64/slowproxy $(BIN_DIR)/darwin-amd64/waitfor

$(BIN_DIR)/darwin-amd64/goalert-smoketest: $(GO_DEPS)
GOOS=darwin GOARCH=amd64 go test ./smoketest -c -o $@

$(BIN_DIR)/linux-amd64/_all: $(BIN_DIR)/linux-amd64/goalert-smoketest $(BIN_DIR)/linux-amd64/goalert $(BIN_DIR)/linux-amd64/goalert-slack-email-sync $(BIN_DIR)/linux-amd64/mockslack $(BIN_DIR)/linux-amd64/pgdump-lite $(BIN_DIR)/linux-amd64/procwrap $(BIN_DIR)/linux-amd64/psql-lite $(BIN_DIR)/linux-amd64/resetdb $(BIN_DIR)/linux-amd64/runproc $(BIN_DIR)/linux-amd64/sendit $(BIN_DIR)/linux-amd64/sendit-server $(BIN_DIR)/linux-amd64/sendit-token $(BIN_DIR)/linux-amd64/simpleproxy $(BIN_DIR)/linux-amd64/waitfor
$(BIN_DIR)/linux-amd64/_all: $(BIN_DIR)/linux-amd64/goalert-smoketest $(BIN_DIR)/linux-amd64/goalert $(BIN_DIR)/linux-amd64/goalert-slack-email-sync $(BIN_DIR)/linux-amd64/mockslack $(BIN_DIR)/linux-amd64/pgdump-lite $(BIN_DIR)/linux-amd64/procwrap $(BIN_DIR)/linux-amd64/psql-lite $(BIN_DIR)/linux-amd64/resetdb $(BIN_DIR)/linux-amd64/runproc $(BIN_DIR)/linux-amd64/sendit $(BIN_DIR)/linux-amd64/sendit-server $(BIN_DIR)/linux-amd64/sendit-token $(BIN_DIR)/linux-amd64/simpleproxy $(BIN_DIR)/linux-amd64/slowproxy $(BIN_DIR)/linux-amd64/waitfor

$(BIN_DIR)/linux-amd64/goalert-smoketest: $(GO_DEPS)
GOOS=linux GOARCH=amd64 go test ./smoketest -c -o $@

$(BIN_DIR)/linux-arm/_all: $(BIN_DIR)/linux-arm/goalert-smoketest $(BIN_DIR)/linux-arm/goalert $(BIN_DIR)/linux-arm/goalert-slack-email-sync $(BIN_DIR)/linux-arm/mockslack $(BIN_DIR)/linux-arm/pgdump-lite $(BIN_DIR)/linux-arm/procwrap $(BIN_DIR)/linux-arm/psql-lite $(BIN_DIR)/linux-arm/resetdb $(BIN_DIR)/linux-arm/runproc $(BIN_DIR)/linux-arm/sendit $(BIN_DIR)/linux-arm/sendit-server $(BIN_DIR)/linux-arm/sendit-token $(BIN_DIR)/linux-arm/simpleproxy $(BIN_DIR)/linux-arm/waitfor
$(BIN_DIR)/linux-arm/_all: $(BIN_DIR)/linux-arm/goalert-smoketest $(BIN_DIR)/linux-arm/goalert $(BIN_DIR)/linux-arm/goalert-slack-email-sync $(BIN_DIR)/linux-arm/mockslack $(BIN_DIR)/linux-arm/pgdump-lite $(BIN_DIR)/linux-arm/procwrap $(BIN_DIR)/linux-arm/psql-lite $(BIN_DIR)/linux-arm/resetdb $(BIN_DIR)/linux-arm/runproc $(BIN_DIR)/linux-arm/sendit $(BIN_DIR)/linux-arm/sendit-server $(BIN_DIR)/linux-arm/sendit-token $(BIN_DIR)/linux-arm/simpleproxy $(BIN_DIR)/linux-arm/slowproxy $(BIN_DIR)/linux-arm/waitfor

$(BIN_DIR)/linux-arm/goalert-smoketest: $(GO_DEPS)
GOOS=linux GOARCH=arm GOARM=7 go test ./smoketest -c -o $@

$(BIN_DIR)/linux-arm64/_all: $(BIN_DIR)/linux-arm64/goalert-smoketest $(BIN_DIR)/linux-arm64/goalert $(BIN_DIR)/linux-arm64/goalert-slack-email-sync $(BIN_DIR)/linux-arm64/mockslack $(BIN_DIR)/linux-arm64/pgdump-lite $(BIN_DIR)/linux-arm64/procwrap $(BIN_DIR)/linux-arm64/psql-lite $(BIN_DIR)/linux-arm64/resetdb $(BIN_DIR)/linux-arm64/runproc $(BIN_DIR)/linux-arm64/sendit $(BIN_DIR)/linux-arm64/sendit-server $(BIN_DIR)/linux-arm64/sendit-token $(BIN_DIR)/linux-arm64/simpleproxy $(BIN_DIR)/linux-arm64/waitfor
$(BIN_DIR)/linux-arm64/_all: $(BIN_DIR)/linux-arm64/goalert-smoketest $(BIN_DIR)/linux-arm64/goalert $(BIN_DIR)/linux-arm64/goalert-slack-email-sync $(BIN_DIR)/linux-arm64/mockslack $(BIN_DIR)/linux-arm64/pgdump-lite $(BIN_DIR)/linux-arm64/procwrap $(BIN_DIR)/linux-arm64/psql-lite $(BIN_DIR)/linux-arm64/resetdb $(BIN_DIR)/linux-arm64/runproc $(BIN_DIR)/linux-arm64/sendit $(BIN_DIR)/linux-arm64/sendit-server $(BIN_DIR)/linux-arm64/sendit-token $(BIN_DIR)/linux-arm64/simpleproxy $(BIN_DIR)/linux-arm64/slowproxy $(BIN_DIR)/linux-arm64/waitfor

$(BIN_DIR)/linux-arm64/goalert-smoketest: $(GO_DEPS)
GOOS=linux GOARCH=arm64 go test ./smoketest -c -o $@

$(BIN_DIR)/windows-amd64/_all: $(BIN_DIR)/windows-amd64/goalert-smoketest $(BIN_DIR)/windows-amd64/goalert.exe $(BIN_DIR)/windows-amd64/goalert-slack-email-sync.exe $(BIN_DIR)/windows-amd64/mockslack.exe $(BIN_DIR)/windows-amd64/pgdump-lite.exe $(BIN_DIR)/windows-amd64/procwrap.exe $(BIN_DIR)/windows-amd64/psql-lite.exe $(BIN_DIR)/windows-amd64/resetdb.exe $(BIN_DIR)/windows-amd64/runproc.exe $(BIN_DIR)/windows-amd64/sendit.exe $(BIN_DIR)/windows-amd64/sendit-server.exe $(BIN_DIR)/windows-amd64/sendit-token.exe $(BIN_DIR)/windows-amd64/simpleproxy.exe $(BIN_DIR)/windows-amd64/waitfor.exe
$(BIN_DIR)/windows-amd64/_all: $(BIN_DIR)/windows-amd64/goalert-smoketest $(BIN_DIR)/windows-amd64/goalert.exe $(BIN_DIR)/windows-amd64/goalert-slack-email-sync.exe $(BIN_DIR)/windows-amd64/mockslack.exe $(BIN_DIR)/windows-amd64/pgdump-lite.exe $(BIN_DIR)/windows-amd64/procwrap.exe $(BIN_DIR)/windows-amd64/psql-lite.exe $(BIN_DIR)/windows-amd64/resetdb.exe $(BIN_DIR)/windows-amd64/runproc.exe $(BIN_DIR)/windows-amd64/sendit.exe $(BIN_DIR)/windows-amd64/sendit-server.exe $(BIN_DIR)/windows-amd64/sendit-token.exe $(BIN_DIR)/windows-amd64/simpleproxy.exe $(BIN_DIR)/windows-amd64/slowproxy.exe $(BIN_DIR)/windows-amd64/waitfor.exe

$(BIN_DIR)/windows-amd64/goalert-smoketest: $(GO_DEPS)
GOOS=windows GOARCH=amd64 go test ./smoketest -c -o $@
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build: while true; do make -qs bin/goalert || make bin/goalert || (echo '\033[0;31mBuild Failure'; sleep 3); sleep 0.1; done

@watch-file=./bin/goalert
goalert: ./bin/goalert -l=localhost:3030 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5432/goalert?sslmode=disable --listen-sysapi=localhost:1234 --listen-prometheus=localhost:2112
goalert: ./bin/goalert -l=localhost:3030 --ui-dir=web/src/build --db-url=postgres://goalert@localhost --listen-sysapi=localhost:1234 --listen-prometheus=localhost:2112

smtp: go run github.com/mailhog/MailHog -ui-bind-addr=localhost:8025 -api-bind-addr=localhost:8025 -smtp-bind-addr=localhost:1025 | grep -v KEEPALIVE
prom: bin/tools/prometheus --log.level=warn --config.file=devtools/prometheus/prometheus.yml --storage.tsdb.path=bin/prom-data/ --web.listen-address=localhost:9090
Expand Down
5 changes: 4 additions & 1 deletion Procfile.cypress
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ goalert: go run ./devtools/waitfor postgres://postgres@localhost:5433 && go run
@watch-file=./web/src/esbuild.config.js
ui: yarn workspace goalert-web run esbuild --watch

@watch-file=./web/src/esbuild.cypress.js
build-cy: yarn workspace goalert-web run esbuild-cy --watch

slack: go run ./devtools/mockslack/cmd/mockslack -client-id=000000000000.000000000000 -client-secret=00000000000000000000000000000000 -access-token=xoxp-000000000000-000000000000-000000000000-00000000000000000000000000000000 -prefix=/slack -single-user=bob -addr=localhost:3046

proxy: go run ./devtools/simpleproxy -addr=localhost:3040 /slack/=http://localhost:3046 http://localhost:3042

cypress: go run ./devtools/waitfor http://localhost:3042 && CYPRESS_DB_URL=postgres://postgres@localhost:5433 yarn workspace goalert-web cypress open --config baseUrl=http://localhost:3040$GOALERT_HTTP_PREFIX
cypress: go run ./devtools/waitfor http://localhost:3042 && CYPRESS_DB_URL=postgres://postgres@localhost:5433 yarn workspace goalert-web --cwd=bin/build/integration cypress open --config baseUrl=http://localhost:3040$GOALERT_HTTP_PREFIX

db: $CONTAINER_TOOL rm -f smoketest-postgres || true; $CONTAINER_TOOL run -it --rm --name smoketest-postgres -p5433:5432 -e=POSTGRES_HOST_AUTH_METHOD=trust postgres:13-alpine
5 changes: 4 additions & 1 deletion Procfile.cypress.prod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ slack: go run ./devtools/mockslack/cmd/mockslack -client-id=000000000000.0000000

proxy: go run ./devtools/simpleproxy -addr=localhost:3040 /slack/=http://localhost:3046 http://localhost:3042

cypress: go run ./devtools/waitfor http://localhost:3042 && CYPRESS_DB_URL=postgres://postgres@localhost:5433 yarn workspace goalert-web cypress $CY_ACTION --config baseUrl=http://localhost:3040$GOALERT_HTTP_PREFIX
cypress: go run ./devtools/waitfor http://localhost:3042 && CYPRESS_DB_URL=postgres://postgres@localhost:5433 yarn workspace goalert-web --cwd=bin/build/integration cypress $CY_ACTION --config baseUrl=http://localhost:3040$GOALERT_HTTP_PREFIX

db: $CONTAINER_TOOL rm -f smoketest-postgres || true; $CONTAINER_TOOL run -it --rm --name smoketest-postgres -p5433:5432 -e=POSTGRES_HOST_AUTH_METHOD=trust postgres:13-alpine


@watch-file=./web/src/esbuild.config.js
ui: yarn workspace goalert-web run esbuild --watch --prod

@watch-file=./web/src/esbuild.cypress.js
build-cy: yarn workspace goalert-web run esbuild-cy --watch
2 changes: 1 addition & 1 deletion Procfile.prod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build: while true; do make -qs bin/goalert BUNDLE=1 || make bin/goalert BUNDLE=1 || (echo '\033[0;31mBuild Failure'; sleep 3); sleep 0.1; done

@watch-file=./bin/goalert
goalert: ./bin/goalert -l=localhost:3030 --db-url=postgres://goalert@localhost:5432/goalert?sslmode=disable --listen-sysapi=localhost:1234 --listen-prometheus=localhost:2112
goalert: ./bin/goalert -l=localhost:3030 --db-url=postgres://goalert@localhost--listen-sysapi=localhost:1234 --listen-prometheus=localhost:2112

smtp: go run github.com/mailhog/MailHog -ui-bind-addr=localhost:8025 -api-bind-addr=localhost:8025 -smtp-bind-addr=localhost:1025 | grep -v KEEPALIVE
prom: bin/tools/prometheus --log.level=warn --config.file=devtools/prometheus/prometheus.yml --storage.tsdb.path=bin/prom-data/ --web.listen-address=localhost:9090
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type App struct {
ScheduleRuleStore rule.Store
NotificationStore *notification.Store
ScheduleStore *schedule.Store
RotationStore rotation.Store
RotationStore *rotation.Store

CalSubStore *calsub.Store
OverrideStore *override.Store
Expand Down
2 changes: 1 addition & 1 deletion app/initstores.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (app *App) initStores(ctx context.Context) error {
}

if app.RotationStore == nil {
app.RotationStore, err = rotation.NewDB(ctx, app.db)
app.RotationStore, err = rotation.NewStore(ctx, app.db)
}
if err != nil {
return errors.Wrap(err, "init rotation store")
Expand Down
4 changes: 2 additions & 2 deletions dataloader/rotationloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

type RotationLoader struct {
*loader
store rotation.Store
store *rotation.Store
}

func NewRotationLoader(ctx context.Context, store rotation.Store) *RotationLoader {
func NewRotationLoader(ctx context.Context, store *rotation.Store) *RotationLoader {
p := &RotationLoader{
store: store,
}
Expand Down
2 changes: 1 addition & 1 deletion devtools/ci/dockerfiles/cypress-env/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/cypress/included:9.5.4
FROM docker.io/cypress/included:9.6.0
ENTRYPOINT []
RUN apt-get update && apt-get install -y --no-install-recommends postgresql postgresql-contrib && rm -rf /var/lib/apt/lists/*
ENV PGDATA=/var/lib/postgresql/data PGUSER=postgres DB_URL=postgresql://postgres@
Expand Down
2 changes: 1 addition & 1 deletion devtools/ci/tasks/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ outputs:
- name: debug
image_resource:
type: registry-image
source: { repository: goalert/cypress-env, tag: '9.5.4' }
source: { repository: goalert/cypress-env, tag: '9.6.0' }
run:
path: sh
dir: integration/goalert
Expand Down
9 changes: 5 additions & 4 deletions devtools/genmake/template.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ container-demo: {{range $.ContainerArch}} container-demo-{{.}}{{end}}
container-goalert: {{range $.ContainerArch}} container-goalert-{{.}}{{end}}

$(BIN_DIR)/build/integration/cypress.json: web/src/cypress.json
sed 's/\.ts/\.js/' web/src/cypress.json >$@
cp web/src/cypress.json $@

$(BIN_DIR)/build/integration/cypress: node_modules web/src/webpack.cypress.js $(BIN_DIR)/build/integration/cypress.json $(shell find ./web/src/cypress)
$(BIN_DIR)/build/integration/cypress: node_modules $(BIN_DIR)/build/integration/cypress.json web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
rm -rf $@
yarn workspace goalert-web webpack --config webpack.cypress.js
cp -r web/src/cypress/fixtures $@/
yarn workspace goalert-web esbuild-cy
mkdir -p $@/plugins
cp web/src/cypress/plugins/index.js $@/plugins/index.js
touch $@

{{range $.Builds}}
Expand Down
4 changes: 3 additions & 1 deletion devtools/pgdump-lite/cmd/pgdump-lite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"log"
"os"
"strings"

"github.com/jackc/pgx/v4"
"github.com/target/goalert/devtools/pgdump-lite"
Expand All @@ -15,6 +16,7 @@ func main() {
file := flag.String("f", "", "Output file (default is stdout).")
db := flag.String("d", os.Getenv("DBURL"), "DB URL") // use same env var as pg_dump
dataOnly := flag.Bool("a", false, "dump only the data, not the schema")
skip := flag.String("T", "", "skip tables")
flag.Parse()

out := os.Stdout
Expand All @@ -40,7 +42,7 @@ func main() {
}
defer conn.Close(ctx)

err = pgdump.DumpData(ctx, conn, out)
err = pgdump.DumpData(ctx, conn, out, strings.Split(*skip, ","))
if err != nil {
log.Fatalln("ERROR: dump data:", err)
}
Expand Down
16 changes: 15 additions & 1 deletion devtools/pgdump-lite/dumpdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func sortColumns(columns []string) {
return ci < cj
})
}

func quoteNames(names []string) {
for i, n := range names {
names[i] = pgx.Identifier{n}.Sanitize()
Expand Down Expand Up @@ -66,7 +67,16 @@ func (s *scannable) DecodeText(ci *pgtype.ConnInfo, src []byte) error {
return nil
}

func DumpData(ctx context.Context, conn *pgx.Conn, out io.Writer) error {
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

func DumpData(ctx context.Context, conn *pgx.Conn, out io.Writer, skip []string) error {
tx, err := conn.BeginTx(ctx, pgx.TxOptions{IsoLevel: pgx.RepeatableRead})
if err != nil {
return fmt.Errorf("begin tx: %w", err)
Expand All @@ -80,6 +90,10 @@ func DumpData(ctx context.Context, conn *pgx.Conn, out io.Writer) error {
sort.Strings(tables)

for _, table := range tables {
if contains(skip, table) {
continue
}

columns, err := queryStrings(ctx, tx, "select column_name from information_schema.columns where table_schema = 'public' and table_name = $1 order by ordinal_position", table)
if err != nil {
return fmt.Errorf("read columns for '%s': %w", table, err)
Expand Down
47 changes: 29 additions & 18 deletions devtools/resetdb/datagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import (
"github.com/target/goalert/util/timeutil"
)

var timeZones = []string{"America/Chicago", "Europe/Berlin", "UTC"}
var rotationTypes = []rotation.Type{rotation.TypeDaily, rotation.TypeHourly, rotation.TypeWeekly}
var (
timeZones = []string{"America/Chicago", "Europe/Berlin", "UTC"}
rotationTypes = []rotation.Type{rotation.TypeDaily, rotation.TypeHourly, rotation.TypeWeekly}
)

type AlertLog struct {
AlertID int
Expand Down Expand Up @@ -352,29 +354,39 @@ func (d *datagen) NewAlert(status alert.Status) {
}

// NewAlertLog will generate an alert log for the provided alert.
func (d *datagen) NewAlertLogs(alert alert.Alert) {

func (d *datagen) NewAlertLogs(alrt alert.Alert) {
// Add 'created' event log
d.AlertLogs = append(d.AlertLogs, AlertLog{
AlertID: alert.ID,
Timestamp: alert.CreatedAt,
AlertID: alrt.ID,
Timestamp: alrt.CreatedAt,
Event: "created",
Message: "",
})

// Add 'ack' event log
d.AlertLogs = append(d.AlertLogs, AlertLog{
AlertID: alert.ID,
Timestamp: gofakeit.DateRange(alert.CreatedAt, alert.CreatedAt.Add(10*time.Minute)),
Event: "acknowledged",
Message: "",
})
switch alrt.Status {
case alert.StatusActive:
d.AlertLogs = append(d.AlertLogs, AlertLog{
AlertID: alrt.ID,
Timestamp: gofakeit.DateRange(alrt.CreatedAt, alrt.CreatedAt.Add(30*time.Minute)),
Event: "acknowledged",
Message: "",
})
case alert.StatusClosed:
closeTime := gofakeit.DateRange(alrt.CreatedAt, alrt.CreatedAt.Add(30*time.Minute))

if gofakeit.Bool() {
// was acked
d.AlertLogs = append(d.AlertLogs, AlertLog{
AlertID: alrt.ID,
Timestamp: gofakeit.DateRange(alrt.CreatedAt, closeTime),
Event: "acknowledged",
Message: "",
})
}

// Add 'closed' event log
if alert.Status == "closed" {
d.AlertLogs = append(d.AlertLogs, AlertLog{
AlertID: alert.ID,
Timestamp: gofakeit.DateRange(alert.CreatedAt, alert.CreatedAt.Add(30*time.Minute)),
AlertID: alrt.ID,
Timestamp: closeTime,
Event: "closed",
Message: "",
})
Expand Down Expand Up @@ -405,7 +417,6 @@ func (d *datagen) NewFavorite(userID string) {

// Generate will produce a full random dataset based on the configuration.
func (cfg datagenConfig) Generate() datagen {

setDefault := func(val *int, def int) {
if *val != 0 {
return
Expand Down
17 changes: 11 additions & 6 deletions devtools/simpleproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ func main() {
parts = []string{"/", parts[0]}
}

u, err := url.Parse(parts[1])
if err != nil {
log.Fatalf("ERORR: parse %s: %v", parts[1], err)
}
var rr RR
hosts := strings.Split(parts[1], ",")
for _, host := range hosts {

u, err := url.Parse(host)
if err != nil {
log.Fatalf("ERORR: parse %s: %v", host, err)
}

p := httputil.NewSingleHostReverseProxy(u)
h := http.Handler(p)
rr.h = append(rr.h, httputil.NewSingleHostReverseProxy(u))
}
h := http.Handler(&rr)
if *trim {
h = http.StripPrefix(parts[0], h)
}
Expand Down
20 changes: 20 additions & 0 deletions devtools/simpleproxy/roundrobin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"net/http"
"sync"
)

type RR struct {
h []http.Handler
n int
mx sync.Mutex
}

func (r *RR) ServeHTTP(w http.ResponseWriter, req *http.Request) {
r.mx.Lock()
handler := r.h[r.n]
r.n = (r.n + 1) % len(r.h)
r.mx.Unlock()
handler.ServeHTTP(w, req)
}
Loading

0 comments on commit b8d1b48

Please sign in to comment.