Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switchover: refactor and move SWO toolset to UI #2523

Merged
merged 256 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
256 commits
Select commit Hold shift + click to select a range
c367ff3
simplify
mastercactapus Mar 16, 2022
efbf82b
don't use truncate
mastercactapus Mar 16, 2022
e6e25cc
describe values
mastercactapus Mar 16, 2022
e58bc24
Merge branch 'master' into swo-switchover-mk2
mastercactapus Mar 16, 2022
e0c2c39
state handling
mastercactapus Mar 21, 2022
8a34be3
add switchover route
Forfold Mar 21, 2022
cc33253
add switchover action buttons
Forfold Mar 21, 2022
f01fa4a
show the status
Forfold Mar 21, 2022
e269f24
add getActions wip
Forfold Mar 22, 2022
9eb22a4
fix event listener
mastercactapus Mar 22, 2022
5978021
remove old code
mastercactapus Mar 22, 2022
10c51d4
fix types
mastercactapus Mar 22, 2022
01e18c2
add trigger methods
mastercactapus Mar 22, 2022
e7189cf
Merge remote-tracking branch 'origin/swoui' into swo-switchover-mk2
mastercactapus Mar 22, 2022
d06d13c
add swo status query
mastercactapus Mar 22, 2022
555d262
add mutation
mastercactapus Mar 22, 2022
115cb33
add card title
Forfold Mar 22, 2022
b8a767a
concurrency fixes
mastercactapus Mar 22, 2022
6c2e120
add disabled functionality for actions
Forfold Mar 22, 2022
a476e64
add ack for reset action
mastercactapus Mar 22, 2022
3f03f2a
fix exec message flags
mastercactapus Mar 22, 2022
4e2ca83
Merge branch 'swo-switchover-mk2' of github.com:target/goalert into s…
mastercactapus Mar 22, 2022
00c8beb
add error status card, hookup with gql
Forfold Mar 22, 2022
be22c43
fix reset
mastercactapus Mar 22, 2022
5bc6e38
Merge branch 'swo-switchover-mk2' of github.com:target/goalert into s…
Forfold Mar 22, 2022
0945c5f
add error icon
Forfold Mar 22, 2022
f2474f9
fix mutations
mastercactapus Mar 22, 2022
4ffcb3e
fix exec test
mastercactapus Mar 22, 2022
83448d0
add exec mode
mastercactapus Mar 22, 2022
6eb9190
design improvements
Forfold Mar 22, 2022
c5c2906
Merge branch 'swo-switchover-mk2' of github.com:target/goalert into s…
Forfold Mar 22, 2022
2b8700a
work on mutation
Forfold Mar 22, 2022
b398012
fix locks
mastercactapus Mar 22, 2022
f22361c
defer constraints
mastercactapus Mar 22, 2022
1d5ed84
show notices
Forfold Mar 22, 2022
aaecf39
fix data
mastercactapus Mar 22, 2022
078798e
Merge branch 'swo-switchover-mk2' of github.com:target/goalert into s…
mastercactapus Mar 22, 2022
87bcefd
fix notice severity typing
Forfold Mar 22, 2022
de7f86d
Merge branch 'swo-switchover-mk2' of github.com:target/goalert into s…
Forfold Mar 22, 2022
04c96a0
check all nodes
mastercactapus Mar 22, 2022
5100927
render nodes
Forfold Mar 22, 2022
d61834d
remove notices on success
Forfold Mar 22, 2022
de78e8d
use lock to ensure log order
mastercactapus Mar 22, 2022
2175061
delete synced changes
mastercactapus Mar 22, 2022
3e44510
fix context cancel and add vacuum
mastercactapus Mar 23, 2022
a32caec
scan tables once
mastercactapus Mar 23, 2022
9a8c448
old query
mastercactapus Mar 23, 2022
8e11920
Merge remote-tracking branch 'origin/master' into swo-switchover-mk2
mastercactapus Mar 24, 2022
9ffe993
fix deps
mastercactapus Mar 24, 2022
52fdff0
wait for log poll before returning
mastercactapus Mar 24, 2022
5808ca4
fix reset state
mastercactapus Mar 24, 2022
592edcb
consistent language
mastercactapus Mar 24, 2022
2c4c534
consistent ui language
Forfold Mar 24, 2022
a7e5571
show db status idle/in prog/complete text in main card
Forfold Mar 24, 2022
7a47b4a
refactor layout
Forfold Mar 24, 2022
a60ae5a
reduce padding in main card
Forfold Mar 24, 2022
8cf2600
only sync final state
mastercactapus Mar 24, 2022
f48ae91
Merge branch 'swo-switchover-mk2' of github.com:target/goalert into s…
mastercactapus Mar 24, 2022
a96782d
put swonode into own component file, fix wording
Forfold Mar 24, 2022
20a5edc
fix primary card width on smaller screens
Forfold Mar 24, 2022
4f79b89
use loading button for swo actions
Forfold Mar 24, 2022
bfa6843
fix text
mastercactapus Mar 24, 2022
52939a5
Merge branch 'swo-switchover-mk2' of github.com:target/goalert into s…
mastercactapus Mar 24, 2022
2175578
fix sync
mastercactapus Mar 24, 2022
4821563
add isexec/reset
mastercactapus Mar 24, 2022
70e7cc0
persist spinners while action still in bg
mastercactapus Mar 24, 2022
c82aebe
tweak subheader
mastercactapus Mar 24, 2022
0c90638
non fatal sync error
mastercactapus Mar 24, 2022
5464b49
fix sort
mastercactapus Mar 24, 2022
041c6ff
better state display
mastercactapus Mar 25, 2022
a4880f6
add comment about friendly name
mastercactapus Mar 25, 2022
53ccf8a
fix a locking issue
mastercactapus Mar 25, 2022
c453fba
use methods to determine state
mastercactapus Mar 25, 2022
b865725
fix lock hang
mastercactapus Mar 25, 2022
e851505
fix missed rows
mastercactapus Mar 28, 2022
f0e6b36
refactor
mastercactapus Apr 6, 2022
5887afe
fix log
mastercactapus Apr 6, 2022
931e661
add skip support to pgdump-lite
mastercactapus Apr 6, 2022
a402b1b
rr support to simpleproxy
mastercactapus Apr 6, 2022
096b5b6
limit log cleanup num
mastercactapus Apr 6, 2022
7e0ed9e
don't log proc lock
mastercactapus Apr 6, 2022
46c6924
return not found if rotation no longer exists
mastercactapus Apr 6, 2022
10cde97
handle participant fkey
mastercactapus Apr 6, 2022
9dd346a
schema changes for swo
mastercactapus Apr 6, 2022
1fbcf94
Merge branch 'master' into swo-switchover-mk2
mastercactapus Apr 6, 2022
88043be
increase intervals
mastercactapus Apr 6, 2022
17f1cbc
lower delay
mastercactapus Apr 6, 2022
694c06f
add errors for swo ui
mastercactapus Apr 7, 2022
064922c
cleanup
mastercactapus Apr 7, 2022
91341e3
add page states for disabled and complete
mastercactapus Apr 7, 2022
a03e030
add connection list
mastercactapus Apr 7, 2022
23b3784
add connections to UI
mastercactapus Apr 7, 2022
5dafbca
fix switch
mastercactapus Apr 7, 2022
5342447
fix api change
mastercactapus Apr 7, 2022
aeb89ba
transition
mastercactapus Apr 7, 2022
0bc0e94
refactor
mastercactapus Apr 7, 2022
5083ebe
batch queries
mastercactapus Apr 7, 2022
d2304f7
add reset timeout
mastercactapus Apr 11, 2022
c1d1e23
add slowproxy tool
mastercactapus Apr 11, 2022
5e49955
fill bucket once per second
mastercactapus Apr 11, 2022
1565fea
fix jitter
mastercactapus Apr 11, 2022
651805d
batch change fetching
mastercactapus Apr 11, 2022
22688d6
increase timeout
mastercactapus Apr 12, 2022
88e93da
adjust layout
Forfold Apr 14, 2022
3440e40
add fallback for node status str
Forfold Apr 14, 2022
ea15b07
Merge branch 'master' into swo-switchover-mk2
mastercactapus Apr 18, 2022
707273e
Merge branch 'master' into swo-switchover-mk2
mastercactapus Jun 2, 2022
6e196f8
add switchover route
mastercactapus Jun 2, 2022
a185479
update disabled text
mastercactapus Jun 2, 2022
a49e969
fix spacing
mastercactapus Jun 2, 2022
9e3340a
add swo mode
mastercactapus Jun 3, 2022
a319a71
use sqlc
mastercactapus Jun 3, 2022
20e30c4
Merge branch 'master' into swo-switchover-mk2
mastercactapus Jun 28, 2022
051759c
update gen
mastercactapus Jun 28, 2022
793f727
fix startup
mastercactapus Jun 28, 2022
260ad7c
refactor sync logic to it's own package
mastercactapus Jul 1, 2022
7116da4
Merge branch 'master' into swo-switchover-mk2
mastercactapus Jul 1, 2022
826333c
sync tables in order
mastercactapus Jul 1, 2022
f76a072
use slow proxy to emulate db conditions
mastercactapus Jul 1, 2022
e6c764e
Merge branch 'master' into swo-switchover-mk2
mastercactapus Jul 7, 2022
ae89f92
Merge branch 'validation-fix' into swo-switchover-mk2
mastercactapus Jul 7, 2022
40f1d94
use prooxy for ui
mastercactapus Jul 11, 2022
8e27595
limit conn lifetime in pause mode
mastercactapus Jul 11, 2022
ba87e50
always exit on error
mastercactapus Jul 11, 2022
0018c09
check for missing override
mastercactapus Jul 11, 2022
9464407
commit changes before enabling triggers
mastercactapus Jul 11, 2022
c0f1127
increase pause time
mastercactapus Jul 11, 2022
1ed2321
add db versions to graphql query
mastercactapus Jul 11, 2022
0ef6b74
use SWO instead of S/O
mastercactapus Jul 11, 2022
21c2b8b
add db_id to switchover_state
mastercactapus Jul 11, 2022
3ebee78
push instead of pull for ratelimiter
mastercactapus Jul 13, 2022
bdb89df
don't display ... as number
mastercactapus Jul 13, 2022
04787bd
add data and use urql
mastercactapus Jul 13, 2022
a8499a9
simplify to single log
mastercactapus Jul 13, 2022
3599058
refactor cluster mgmt
mastercactapus Jul 20, 2022
771fd3a
Merge remote-tracking branch 'origin/master' into swo-switchover-mk2
mastercactapus Jul 20, 2022
cbe060e
fix nodes
mastercactapus Jul 20, 2022
62ffc63
increase interval
mastercactapus Jul 20, 2022
8311d00
wait for log echo
mastercactapus Jul 20, 2022
20466f2
increas max wait for heavy-load scenarios
mastercactapus Jul 20, 2022
5f97d13
always attempt to update log
mastercactapus Jul 21, 2022
701542b
only release the intended advisory lock
mastercactapus Jul 21, 2022
0f6c8f1
move app name change to swo code
mastercactapus Jul 21, 2022
562d2d0
Merge branch 'master' into swo-switchover-mk2
mastercactapus Jul 25, 2022
0e3cb62
fix swo error states
mastercactapus Jul 25, 2022
e6cfdac
fix stale UI issue on port 3030 in SWO mode
mastercactapus Jul 25, 2022
4e687a2
fix notice types
mastercactapus Jul 25, 2022
dd6d3c0
remove unused import
mastercactapus Jul 25, 2022
ef7b44b
ui updates
Forfold Jul 25, 2022
305f6fd
use warning icon for old DB
mastercactapus Jul 26, 2022
dff8794
remove unused test file
mastercactapus Jul 27, 2022
3f3cc26
ctx use
mastercactapus Jul 27, 2022
b221d4e
remove unused code
mastercactapus Jul 27, 2022
8b9a51c
remove duplicate case
mastercactapus Jul 27, 2022
5af9f7d
can't be 'done' due to previous check
mastercactapus Jul 27, 2022
6bd4cd0
remove unused import
mastercactapus Jul 27, 2022
35a626e
Merge remote-tracking branch 'origin/master' into swo-switchover-mk2
mastercactapus Jul 27, 2022
aff9702
add sqlc regen target
mastercactapus Jul 27, 2022
d95c340
Merge branch 'master' into swo-switchover-mk2
mastercactapus Aug 1, 2022
77f5c8f
spelling
mastercactapus Aug 1, 2022
40ce73c
document logical sync process
mastercactapus Aug 1, 2022
b570c97
update swosync docs
mastercactapus Aug 1, 2022
152c108
just use readme
mastercactapus Aug 1, 2022
5f4d954
more docs
mastercactapus Aug 1, 2022
c605c29
replace slowproxy with speedbump
mastercactapus Aug 8, 2022
1abd2cf
Merge remote-tracking branch 'origin/master' into swo-switchover-mk2
mastercactapus Aug 8, 2022
f25fc7f
copy Alert color for bad app config
mastercactapus Aug 8, 2022
73be9f8
update mk and increase max wait
mastercactapus Aug 8, 2022
f61a72a
don't use unlock all
mastercactapus Aug 8, 2022
8cc5caa
separate connection pools
mastercactapus Aug 8, 2022
95acd51
unexport conn method
mastercactapus Aug 8, 2022
6aca708
don't use snapshot isolation in final mode
mastercactapus Aug 8, 2022
8a7b7d8
fix imports
mastercactapus Aug 8, 2022
09b3ae3
use connection-based node list
mastercactapus Aug 10, 2022
4597115
remove unused imports
mastercactapus Aug 10, 2022
8ab8025
remove unused code/imports
mastercactapus Aug 10, 2022
1daa0c3
add error icon for non-swo GoAlert
mastercactapus Aug 11, 2022
5e9cc15
display reasons for invalid config
mastercactapus Aug 11, 2022
9be2495
Merge remote-tracking branch 'origin/master' into swo-switchover-mk2
mastercactapus Aug 11, 2022
c90b348
fix swo refetch
mastercactapus Aug 11, 2022
bbb545a
cleanup readme
mastercactapus Aug 15, 2022
735ee30
cleanup SWO readme
mastercactapus Aug 15, 2022
f9705b6
Merge remote-tracking branch 'origin/master' into swo-switchover-mk2
mastercactapus Aug 17, 2022
57ae9e4
fix nil pointer
mastercactapus Aug 17, 2022
7b8ed27
add failsafe reset timeout
mastercactapus Aug 17, 2022
5e0fff1
add uptime to UI
mastercactapus Aug 17, 2022
3144312
fix region id race
mastercactapus Aug 18, 2022
98f5571
fix shutdown race
mastercactapus Aug 18, 2022
9c893a4
resume after done
mastercactapus Aug 18, 2022
3f0a195
add err state for bad uptime
mastercactapus Aug 18, 2022
260953f
vacuum analyze after datagen
mastercactapus Aug 18, 2022
88d05ff
add prometheus to swo
mastercactapus Aug 18, 2022
3badad6
switch to upsert
mastercactapus Aug 18, 2022
290fb94
limit memory usage during initial sync
mastercactapus Aug 18, 2022
123841c
allow scaling regendb
mastercactapus Aug 18, 2022
b566d94
add WHERE to upsert
mastercactapus Aug 18, 2022
1711376
if ambiguous col name
mastercactapus Aug 18, 2022
2bfdaa2
solve duplicate row error
mastercactapus Aug 18, 2022
4768c25
sort oncall rows
mastercactapus Aug 18, 2022
1cf52ba
Merge branch 'master' into swo-switchover-mk2
mastercactapus Aug 24, 2022
1973561
fix mod
mastercactapus Aug 24, 2022
60116b2
Merge branch 'master' into swo-switchover-mk2
mastercactapus Sep 20, 2022
67dd47f
rename init method
mastercactapus Sep 20, 2022
0c81e4d
use q as receiver
mastercactapus Sep 22, 2022
adbea67
remove unused type
mastercactapus Sep 22, 2022
c2b64f6
add description for uptime field
mastercactapus Sep 22, 2022
8ec67e2
add conn info and tests
mastercactapus Sep 22, 2022
b3bff55
use ConnInfo for connection strings
mastercactapus Sep 22, 2022
b46cd12
add IsNext to ConnType
mastercactapus Sep 26, 2022
ae873c3
break out swo gql logic and test
mastercactapus Sep 26, 2022
3c34647
add test for node without connections
mastercactapus Sep 26, 2022
42e10ad
add comments to swo funcs
mastercactapus Sep 26, 2022
5ddd06d
be more explicit about sync operations
mastercactapus Sep 26, 2022
3318a28
document ConnInfo and ConnType better
mastercactapus Sep 26, 2022
3a31938
add comment for the Connector type
mastercactapus Sep 26, 2022
057be50
filename based on type
mastercactapus Sep 26, 2022
9dcd45e
add comment for the Executor type
mastercactapus Sep 26, 2022
2491e88
use more clear naming
mastercactapus Sep 27, 2022
74d07f0
add missing target deps
mastercactapus Sep 27, 2022
9d57137
add missing logger
mastercactapus Sep 30, 2022
d480a64
break apart exec logic from concurrency logic
mastercactapus Sep 30, 2022
87f2b86
wait during lock
mastercactapus Oct 6, 2022
cdeb900
add comment for WithFunc
mastercactapus Oct 6, 2022
b3085a6
add panic check for Begin
KatieMSB Oct 7, 2022
1ecb59d
add test withFunc
KatieMSB Oct 7, 2022
b4bb8fd
comments and cleanup
mastercactapus Oct 12, 2022
4817f71
add dev section to swo readme
mastercactapus Nov 7, 2022
5411722
do migrations in existing conditional block
mastercactapus Nov 7, 2022
86d649f
Merge branch 'master' into swo-switchover-mk2
mastercactapus Nov 7, 2022
1735515
Merge branch 'master' into swo-switchover-mk2
mastercactapus Nov 7, 2022
4026c58
Merge branch 'master' into swo-switchover-mk2
mastercactapus Nov 21, 2022
c43f96b
limit max conns during pause
mastercactapus Nov 21, 2022
83e2de6
retry on lock timeout
mastercactapus Nov 21, 2022
a87785b
retry deleteAll mutations
mastercactapus Nov 21, 2022
7fb3f64
Merge remote-tracking branch 'origin/master' into swo-switchover-mk2
mastercactapus Nov 29, 2022
00dbb77
fmt
mastercactapus Nov 29, 2022
6837f2b
fix migration test
mastercactapus Nov 29, 2022
7cc127b
Merge remote-tracking branch 'origin/master' into swo-switchover-mk2
mastercactapus Dec 1, 2022
9044250
fix flicker and error rendering in swo
mastercactapus Dec 1, 2022
17b72f7
add confirmation when errs found
mastercactapus Dec 1, 2022
9877170
break into separate components
mastercactapus Dec 1, 2022
e94e20e
add comment for use of useEffect
mastercactapus Dec 1, 2022
e1596c3
fix exec state on confirm
mastercactapus Dec 5, 2022
8494177
add missing type info
mastercactapus Dec 5, 2022
c0ca18b
render confirm errs as <li>
mastercactapus Dec 5, 2022
fde8671
fix function order
mastercactapus Dec 6, 2022
80e45cd
update sqlc and use gettool
mastercactapus Dec 6, 2022
0a1e93c
cleanup deps
mastercactapus Dec 6, 2022
ee20f05
re-add missing tools
mastercactapus Dec 6, 2022
b7398e5
listen on localhost
mastercactapus Dec 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ cy-wide-prod-run: web/src/build/static/app.js cypress
cy-mobile-prod-run: web/src/build/static/app.js cypress
$(MAKE) $(MFLAGS) cy-mobile-prod CY_ACTION=run CONTAINER_TOOL=$(CONTAINER_TOOL) BUNDLE=1

swo/swodb/queries.sql.go: bin/tools/sqlc sqlc.yaml swo/*/*.sql migrate/migrations/*.sql
./bin/tools/sqlc generate

web/src/schema.d.ts: graphql2/schema.graphql node_modules web/src/genschema.go
go generate ./web/src

Expand All @@ -114,6 +117,14 @@ start-prod: web/src/build/static/app.js $(BIN_DIR)/tools/prometheus ## Start the
$(MAKE) $(MFLAGS) bin/goalert BUNDLE=1
go run ./devtools/runproc -f Procfile.prod -l Procfile.local


start-swo: bin/psql-lite bin/goalert bin/waitfor bin/runproc node_modules web/src/schema.d.ts $(BIN_DIR)/tools/prometheus ## Start the developer version of the application in switchover mode (SWO)
./bin/waitfor -timeout 1s "$(DB_URL)" || make postgres
./bin/goalert migrate --db-url=postgres://goalert@localhost/goalert
./bin/psql-lite -d postgres://goalert@localhost -c "update switchover_state set current_state = 'idle'; truncate table switchover_log; drop database if exists goalert2; create database goalert2;"
./bin/goalert migrate --db-url=postgres://goalert@localhost/goalert2
GOALERT_VERSION=$(GIT_VERSION) ./bin/runproc -f Procfile.swo -l Procfile.local

start-integration: web/src/build/static/app.js bin/goalert bin/psql-lite bin/waitfor bin/runproc $(BIN_DIR)/tools/prometheus
./bin/waitfor -timeout 1s "$(DB_URL)" || make postgres
./bin/psql-lite -d "$(DB_URL)" -c 'DROP DATABASE IF EXISTS $(INT_DB); CREATE DATABASE $(INT_DB);'
Expand Down Expand Up @@ -164,7 +175,11 @@ pkg/sysapi/sysapi_grpc.pb.go: pkg/sysapi/sysapi.proto $(BIN_DIR)/tools/protoc-ge
pkg/sysapi/sysapi.pb.go: pkg/sysapi/sysapi.proto $(BIN_DIR)/tools/protoc-gen-go $(BIN_DIR)/tools/protoc
PATH="$(BIN_DIR)/tools" protoc --go_out=. --go_opt=paths=source_relative pkg/sysapi/sysapi.proto

generate: node_modules pkg/sysapi/sysapi.pb.go pkg/sysapi/sysapi_grpc.pb.go
bin/tools/sqlc: go.mod go.sum
CGO_ENABLED=1 go build -o bin/tools/sqlc github.com/kyleconroy/sqlc/cmd/sqlc

generate: node_modules pkg/sysapi/sysapi.pb.go pkg/sysapi/sysapi_grpc.pb.go bin/tools/sqlc
./bin/tools/sqlc generate
go generate ./...


Expand Down Expand Up @@ -228,6 +243,7 @@ postgres: bin/waitfor
-e POSTGRES_USER=goalert \
-e POSTGRES_HOST_AUTH_METHOD=trust \
--name goalert-postgres \
--shm-size 1g \
-p 5432:5432 \
docker.io/library/postgres:13-alpine && ./bin/waitfor "$(DB_URL)" && make regendb) || ($(CONTAINER_TOOL) start goalert-postgres && ./bin/waitfor "$(DB_URL)")

Expand Down
2 changes: 1 addition & 1 deletion Makefile.binaries.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

BIN_DIR=bin
GO_DEPS := Makefile.binaries.mk $(shell find . -path ./web/src -prune -o -path ./vendor -prune -o -path ./.git -prune -o -type f -name "*.go" -print) go.sum
GO_DEPS += migrate/migrations/ migrate/migrations/*.sql web/index.html graphql2/graphqlapp/slack.manifest.yaml
GO_DEPS += migrate/migrations/ migrate/migrations/*.sql web/index.html graphql2/graphqlapp/slack.manifest.yaml swo/*/*.sql
GO_DEPS += graphql2/mapconfig.go graphql2/maplimit.go graphql2/generated.go graphql2/models_gen.go
GO_DEPS += web/explore.html web/live.js

Expand Down
39 changes: 39 additions & 0 deletions Procfile.swo
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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:3040 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435 --listen-sysapi=localhost:1234 --listen-prometheus=localhost:2112 --db-url-next=postgres://goalert@localhost:5435/goalert2

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-swo.yml --storage.tsdb.path=bin/prom-data/ --web.listen-address=localhost:9090

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

@watch-file=./bin/goalert
ga2: ./bin/goalert -l=localhost:3050 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435/goalert?sslmode=disable --listen-prometheus=localhost:2113 --db-url-next=postgres://goalert@localhost:5435/goalert2 --api-only

@watch-file=./bin/goalert
ga3: ./bin/goalert -l=localhost:3051 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435/goalert?sslmode=disable --listen-prometheus=localhost:2114 --db-url-next=postgres://goalert@localhost:5435/goalert2 --api-only

@watch-file=./bin/goalert
ga4: ./bin/goalert -l=localhost:3052 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435/goalert?sslmode=disable --listen-prometheus=localhost:2115 --db-url-next=postgres://goalert@localhost:5435/goalert2 --api-only

@watch-file=./bin/goalert
ga5: ./bin/goalert -l=localhost:3053 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435/goalert?sslmode=disable --listen-prometheus=localhost:2116 --db-url-next=postgres://goalert@localhost:5435/goalert2 --api-only

@watch-file=./bin/goalert
ga6: ./bin/goalert -l=localhost:3054 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435/goalert?sslmode=disable --listen-prometheus=localhost:2117 --db-url-next=postgres://goalert@localhost:5435/goalert2 --api-only

@watch-file=./bin/goalert
ga7: ./bin/goalert -l=localhost:3055 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435/goalert?sslmode=disable --listen-prometheus=localhost:2118 --db-url-next=postgres://goalert@localhost:5435/goalert2

@watch-file=./bin/goalert
ga8: ./bin/goalert -l=localhost:3056 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435/goalert?sslmode=disable --listen-prometheus=localhost:2119 --db-url-next=postgres://goalert@localhost:5435/goalert2

@watch-file=./bin/goalert
ga9: ./bin/goalert -l=localhost:3057 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435/goalert?sslmode=disable --listen-prometheus=localhost:2120 --db-url-next=postgres://goalert@localhost:5435/goalert2

proxy: go run ./devtools/simpleproxy -addr localhost:3030 /=http://localhost:3040,http://localhost:3050,http://localhost:3051,http://localhost:3052,http://localhost:3053,http://localhost:3054,http://localhost:3055,http://localhost:3056,http://localhost:3057

slow: go run github.com/kffl/speedbump --port=5435 --latency=10ms --saw-amplitude=25ms --saw-period=1s localhost:5432
13 changes: 2 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ type App struct {
sysAPISrv *grpc.Server
hSrv *health.Server

srv *http.Server
requestLock *contextLocker
startupErr error
srv *http.Server
startupErr error

notificationManager *notification.Manager
Engine *engine.Engine
Expand Down Expand Up @@ -183,8 +182,6 @@ func NewApp(c Config, db *sql.DB) (*App, error) {
db: db,
cfg: c,
doneCh: make(chan struct{}),

requestLock: newContextLocker(),
}

gCfg := &gorm.Config{
Expand Down Expand Up @@ -263,9 +260,3 @@ func (a *App) URL() string {
func (a *App) Status() lifecycle.Status {
return a.mgr.Status()
}

// ActiveRequests returns the current number of active
// requests, not including pending ones during pause.
func (a *App) ActiveRequests() int {
return a.requestLock.RLockCount()
}
97 changes: 27 additions & 70 deletions app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"strings"
"time"

"github.com/jackc/pgx/v4/stdlib"
toml "github.com/pelletier/go-toml"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -24,8 +23,7 @@ import (
"github.com/target/goalert/migrate"
"github.com/target/goalert/permission"
"github.com/target/goalert/remotemonitor"
"github.com/target/goalert/switchover"
"github.com/target/goalert/switchover/dbsync"
"github.com/target/goalert/swo"
"github.com/target/goalert/user"
"github.com/target/goalert/util"
"github.com/target/goalert/util/log"
Expand Down Expand Up @@ -85,82 +83,58 @@ var RootCmd = &cobra.Command{
return err
}

wrappedDriver := sqldrv.NewRetryDriver(&stdlib.Driver{}, 10)

u, err := url.Parse(cfg.DBURL)
if err != nil {
return errors.Wrap(err, "parse old URL")
}
q := u.Query()
if cfg.DBURLNext != "" {
q.Set("application_name", fmt.Sprintf("GoAlert %s (S/O Mode)", version.GitVersion()))
} else {
q.Set("application_name", fmt.Sprintf("GoAlert %s", version.GitVersion()))
}
q.Set("enable_seqscan", "off")
u.RawQuery = q.Encode()
cfg.DBURL = u.String()

if cfg.APIOnly {
err = migrate.VerifyAll(log.WithDebug(ctx), cfg.DBURL)
if err != nil {
return errors.Wrap(err, "verify migrations")
doMigrations := func(url string) error {
if cfg.APIOnly {
err = migrate.VerifyAll(log.WithDebug(ctx), url)
if err != nil {
return errors.Wrap(err, "verify migrations")
}
return nil
}
} else {

s := time.Now()
n, err := migrate.ApplyAll(log.WithDebug(ctx), cfg.DBURL)
n, err := migrate.ApplyAll(log.WithDebug(ctx), url)
if err != nil {
return errors.Wrap(err, "apply migrations")
}
if n > 0 {
log.Logf(ctx, "Applied %d migrations in %s.", n, time.Since(s))
}

return nil
}

dbc, err := wrappedDriver.OpenConnector(cfg.DBURL)
err = doMigrations(cfg.DBURL)
if err != nil {
return errors.Wrap(err, "connect to postgres")
return err
}

var db *sql.DB
var h *switchover.Handler
if cfg.DBURLNext != "" {
u, err := url.Parse(cfg.DBURLNext)
err = doMigrations(cfg.DBURLNext)
if err != nil {
return errors.Wrap(err, "parse next URL")
return errors.Wrap(err, "nextdb")
}
q := u.Query()
q.Set("application_name", fmt.Sprintf("GoAlert %s (S/O Mode)", version.GitVersion()))
q.Set("enable_seqscan", "off")
u.RawQuery = q.Encode()
cfg.DBURLNext = u.String()

dbcNext, err := wrappedDriver.OpenConnector(cfg.DBURLNext)
mgr, err := swo.NewManager(swo.Config{OldDBURL: cfg.DBURL, NewDBURL: cfg.DBURLNext, CanExec: !cfg.APIOnly, Logger: cfg.Logger})
if err != nil {
return errors.Wrap(err, "connect to postres (next)")
return errors.Wrap(err, "init switchover handler")
}
h, err = switchover.NewHandler(ctx, l, dbc, dbcNext, cfg.DBURL, cfg.DBURLNext)
db = mgr.DB()
cfg.SWO = mgr
} else {
db, err = sqldrv.NewDB(cfg.DBURL, fmt.Sprintf("GoAlert %s", version.GitVersion()))
if err != nil {
return errors.Wrap(err, "init changeover handler")
return errors.Wrap(err, "connect to postgres")
}
db = h.DB()
} else {
db = sql.OpenDB(dbc)
}

app, err := NewApp(cfg, db)
if err != nil {
return errors.Wrap(err, "init app")
}
if h != nil {
h.SetApp(app)
}

go handleShutdown(ctx, func(ctx context.Context) error {
if h != nil {
h.Abort()
}
return app.Shutdown(ctx)
})
go handleShutdown(ctx, app.Shutdown)

// trigger engine cycles by process signal
trigCh := make(chan os.Signal, 1)
Expand Down Expand Up @@ -351,23 +325,6 @@ Migration: %s (#%d)
},
}

switchCmd = &cobra.Command{
Use: "switchover-shell",
Short: "Start a the switchover shell, used to initiate, control, and monitor a DB switchover operation.",
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := getConfig(cmd.Context())
if err != nil {
return err
}

if cfg.DBURLNext == "" {
return validation.NewFieldError("DBURLNext", "must not be empty for switchover")
}

return dbsync.RunShell(log.FromContext(cmd.Context()), cfg.DBURL, cfg.DBURLNext)
},
}

monitorCmd = &cobra.Command{
Use: "monitor",
Short: "Start a remote-monitoring process that functionally tests alerts.",
Expand Down Expand Up @@ -731,7 +688,7 @@ func init() {
RootCmd.Flags().String("region-name", def.RegionName, "Name of region for message processing (case sensitive). Only one instance per-region-name will process outgoing messages.")

RootCmd.PersistentFlags().String("db-url", def.DBURL, "Connection string for Postgres.")
RootCmd.PersistentFlags().String("db-url-next", def.DBURLNext, "Connection string for the *next* Postgres server (enables DB switch-over mode).")
RootCmd.PersistentFlags().String("db-url-next", def.DBURLNext, "Connection string for the *next* Postgres server (enables DB switchover mode).")

RootCmd.Flags().String("jaeger-endpoint", "", "Jaeger HTTP Thrift endpoint")
RootCmd.Flags().String("jaeger-agent-endpoint", "", "Instructs Jaeger exporter to send spans to jaeger-agent at this address.")
Expand Down Expand Up @@ -788,7 +745,7 @@ func init() {

monitorCmd.Flags().StringP("config-file", "f", "", "Configuration file for monitoring (required).")
initCertCommands()
RootCmd.AddCommand(versionCmd, testCmd, migrateCmd, exportCmd, monitorCmd, switchCmd, addUserCmd, getConfigCmd, setConfigCmd, genCerts)
RootCmd.AddCommand(versionCmd, testCmd, migrateCmd, exportCmd, monitorCmd, addUserCmd, getConfigCmd, setConfigCmd, genCerts)

err := viper.BindPFlags(RootCmd.Flags())
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/target/goalert/config"
"github.com/target/goalert/keyring"
"github.com/target/goalert/swo"
"github.com/target/goalert/util/log"
)

Expand Down Expand Up @@ -61,4 +62,7 @@ type Config struct {
// InitialConfig will be pushed into the config store
// if specified before the engine is started.
InitialConfig *config.Config

// SWO should be set to operate in switchover mode.
SWO *swo.Manager
}
Loading