Skip to content

Commit d5e63f3

Browse files
committed
update Event Horizon, gokit, Go & buildkit-golang, build boilerplate
- gokit `logex` -> `log/slog` - gokit bump needed lots of small changes - go fix - fix lint nags (mainly initialisms)
1 parent f2ba138 commit d5e63f3

25 files changed

Lines changed: 404 additions & 632 deletions

.config/turbobob.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"for_description_of_this_file_see": "https://github.com/function61/turbobob",
3+
"version_major": 1,
4+
"project_name": "lambda-alertmanager",
5+
"builders": [
6+
{
7+
"name": "default",
8+
"uses": "docker://fn61/buildkit-golang:20260604_1344_ff654e98",
9+
"mount_source": "",
10+
"mount_destination": "/workspace",
11+
"workdir": "/workspace",
12+
"commands": {
13+
"build": ["build-go-project.sh", "--directory=cmd/alertmanager/", "--binary-basename=alertmanager", "--aws-lambda-zip"],
14+
"dev": ["bash"]
15+
}
16+
}
17+
],
18+
"os_arches": {
19+
"linux-amd64": true
20+
}
21+
}

.github/workflows/build.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ name: Build
22

33
on: [push]
44

5+
permissions:
6+
contents: read
7+
# push container images to GHCR
8+
packages: write
9+
510
jobs:
6-
build:
7-
runs-on: ubuntu-latest
8-
steps:
9-
- uses: actions/checkout@v2
10-
- name: Download Turbo Bob
11-
run: curl --fail --location --output bob https://dl.bintray.com/function61/dl/turbobob/20200220_1142_9c1ea959/bob_linux-amd64 && chmod +x bob
12-
- name: Build with Turbo Bob
13-
run: CI_REVISION_ID="$GITHUB_SHA" ./bob build --publish-artefacts
14-
# unfortunately there doesn't seem to be a way to "expose all secrets", so you must
15-
# list here each secret to pass on to the build
16-
env:
17-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18-
EVENTHORIZON: ${{ secrets.EVENTHORIZON }}
11+
reusable-build:
12+
# this basically just runs `$ bob build` (for details see https://github.com/function61/turbobob)
13+
uses: function61/turbobob-action/.github/workflows/build.yml@main
14+

bin/build.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

cmd/alertmanager/alerts.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import (
77
"time"
88

99
"github.com/function61/eventhorizon/pkg/ehevent"
10-
"github.com/function61/gokit/ossignal"
11-
"github.com/function61/gokit/stringutils"
10+
"github.com/function61/gokit/strings/stringutils"
1211
"github.com/function61/lambda-alertmanager/pkg/amdomain"
1312
"github.com/function61/lambda-alertmanager/pkg/amstate"
1413
"github.com/scylladb/termtables"
@@ -25,32 +24,29 @@ func alertEntry() *cobra.Command {
2524
Use: "mk [subject] [details]",
2625
Short: "Raise an alert",
2726
Args: cobra.ExactArgs(2),
28-
Run: func(cmd *cobra.Command, args []string) {
29-
exitIfError(alertRaise(
30-
ossignal.InterruptOrTerminateBackgroundCtx(nil),
27+
RunE: func(cmd *cobra.Command, args []string) error {
28+
return alertRaise(
29+
cmd.Context(),
3130
args[0],
32-
args[1]))
31+
args[1])
3332
},
3433
})
3534

3635
cmd.AddCommand(&cobra.Command{
3736
Use: "ls",
3837
Short: "List active alerts",
3938
Args: cobra.NoArgs,
40-
Run: func(cmd *cobra.Command, args []string) {
41-
exitIfError(alertList(
42-
ossignal.InterruptOrTerminateBackgroundCtx(nil)))
39+
RunE: func(cmd *cobra.Command, _ []string) error {
40+
return alertList(cmd.Context())
4341
},
4442
})
4543

4644
cmd.AddCommand(&cobra.Command{
4745
Use: "ack [id]",
4846
Short: "Acknowledge an alert",
4947
Args: cobra.ExactArgs(1),
50-
Run: func(cmd *cobra.Command, args []string) {
51-
exitIfError(alertAck(
52-
ossignal.InterruptOrTerminateBackgroundCtx(nil),
53-
args[0]))
48+
RunE: func(cmd *cobra.Command, args []string) error {
49+
return alertAck(cmd.Context(), args[0])
5450
},
5551
})
5652

@@ -64,7 +60,7 @@ func alertRaise(ctx context.Context, subject string, details string) error {
6460
}
6561

6662
raised := amdomain.NewAlertRaised(
67-
amstate.NewAlertId(),
63+
amstate.NewAlertID(),
6864
subject,
6965
details,
7066
ehevent.MetaSystemUser(time.Now()))
@@ -89,7 +85,7 @@ func alertList(ctx context.Context) error {
8985

9086
for _, alert := range app.State.ActiveAlerts() {
9187
view.AddRow(
92-
alert.Id,
88+
alert.ID,
9389
alert.Timestamp.Format(time.RFC3339),
9490
alert.Subject,
9591
stringutils.Truncate(removeLinebreaks(alert.Details), 50))
@@ -100,19 +96,19 @@ func alertList(ctx context.Context) error {
10096
return nil
10197
}
10298

103-
func alertAck(ctx context.Context, alertId string) error {
99+
func alertAck(ctx context.Context, alertID string) error {
104100
app, err := getApp(ctx)
105101
if err != nil {
106102
return err
107103
}
108104

109105
acked := amdomain.NewAlertAcknowledged(
110-
alertId,
106+
alertID,
111107
ehevent.MetaSystemUser(time.Now()))
112108

113109
return app.Reader.TransactWrite(ctx, func() error {
114-
if !amstate.HasAlertWithId(alertId, app.State.ActiveAlerts()) {
115-
return fmt.Errorf("no alert: %s", alertId)
110+
if !amstate.HasAlertWithID(alertID, app.State.ActiveAlerts()) {
111+
return fmt.Errorf("no alert: %s", alertID)
116112
}
117113

118114
return app.AppendAfter(ctx, app.State.Version(), acked)

cmd/alertmanager/deadmansswitches.go

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/function61/eventhorizon/pkg/ehevent"
9-
"github.com/function61/gokit/ossignal"
109
"github.com/function61/lambda-alertmanager/pkg/amdomain"
1110
"github.com/function61/lambda-alertmanager/pkg/amstate"
1211
"github.com/scylladb/termtables"
@@ -25,10 +24,8 @@ func deadMansSwitchEntry() *cobra.Command {
2524
Use: "ls",
2625
Short: "List dead man´s switches",
2726
Args: cobra.NoArgs,
28-
Run: func(cmd *cobra.Command, args []string) {
29-
exitIfError(deadmansswitchList(
30-
ossignal.InterruptOrTerminateBackgroundCtx(nil),
31-
expired))
27+
RunE: func(cmd *cobra.Command, _ []string) error {
28+
return deadmansswitchList(cmd.Context(), expired)
3229
},
3330
}
3431

@@ -40,33 +37,33 @@ func deadMansSwitchEntry() *cobra.Command {
4037
Use: "rm [id]",
4138
Short: "Remove a switch",
4239
Args: cobra.ExactArgs(1),
43-
Run: func(cmd *cobra.Command, args []string) {
44-
exitIfError(deadmansswitchRemove(
45-
ossignal.InterruptOrTerminateBackgroundCtx(nil),
46-
args[0]))
40+
RunE: func(cmd *cobra.Command, args []string) error {
41+
return deadmansswitchRemove(cmd.Context(), args[0])
4742
},
4843
})
4944

5045
cmd.AddCommand(&cobra.Command{
5146
Use: "checkin [subject] [ttl]",
5247
Short: "Make a checkin",
5348
Args: cobra.ExactArgs(2),
54-
Run: func(cmd *cobra.Command, args []string) {
55-
ctx := ossignal.InterruptOrTerminateBackgroundCtx(nil)
49+
RunE: func(cmd *cobra.Command, args []string) error {
50+
ttl, err := parseTTLSpec(args[1], time.Now())
51+
if err != nil {
52+
return err
53+
}
5654

57-
ttl, err := parseTtlSpec(args[1], time.Now())
58-
exitIfError(err)
59-
60-
app, err := getApp(ctx)
61-
exitIfError(err)
55+
app, err := getApp(cmd.Context())
56+
if err != nil {
57+
return err
58+
}
6259

6360
_, err = deadmansswitchCheckin(
64-
ctx,
61+
cmd.Context(),
6562
args[0],
6663
ttl,
6764
app,
6865
time.Now())
69-
exitIfError(err)
66+
return err
7067
},
7168
})
7269

@@ -88,7 +85,7 @@ func deadmansswitchList(ctx context.Context, expired bool) error {
8885
view.AddHeaders("Subject", "TTL")
8986

9087
for _, dms := range dmss {
91-
view.AddRow(dms.Subject, dms.Ttl.Format(time.RFC3339))
88+
view.AddRow(dms.Subject, dms.TTL.Format(time.RFC3339))
9289
}
9390

9491
fmt.Println(view.Render())
@@ -142,7 +139,7 @@ func deadmansswitchCheckin(
142139

143140
if alert := amstate.FindAlertWithSubject(subject, app.State.ActiveAlerts()); alert != nil {
144141
events = append(events, amdomain.NewAlertAcknowledged(
145-
alert.Id,
142+
alert.ID,
146143
ehevent.MetaSystemUser(now)))
147144

148145
alertAcked = true

cmd/alertmanager/deadmansswitches_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/function61/eventhorizon/pkg/ehevent"
1111
"github.com/function61/eventhorizon/pkg/ehreader"
1212
"github.com/function61/eventhorizon/pkg/ehreader/ehreadertest"
13-
"github.com/function61/gokit/assert"
13+
"github.com/function61/gokit/testing/assert"
1414
"github.com/function61/lambda-alertmanager/pkg/amdomain"
1515
"github.com/function61/lambda-alertmanager/pkg/amstate"
1616
)
@@ -45,11 +45,11 @@ func TestDeadmansswitchCheckin(t *testing.T) {
4545
app,
4646
t0)
4747
assert.Ok(t, err)
48-
assert.Assert(t, !alertAcked)
48+
assert.Equal(t, alertAcked, false)
4949

5050
dumper := newEventDumper(testStreamName, eventLog, amdomain.Types)
5151

52-
assert.EqualString(t, dumper.Dump(), `
52+
assert.Equal(t, dumper.Dump(), `
5353
2019-09-07T12:00:00.000Z UnnoticedAlertsNotified {"AlertIds":["dummyid"]}
5454
2019-09-07T12:00:00.000Z DeadMansSwitchCreated {"Subject":"My test switch","Ttl":"2019-09-07T13:00:00Z"}
5555
2019-09-07T12:00:00.000Z DeadMansSwitchCheckin {"Subject":"My test switch","Ttl":"2019-09-07T13:00:00Z"}`)
@@ -63,9 +63,9 @@ func TestDeadmansswitchCheckin(t *testing.T) {
6363
app,
6464
t0.Add(30*time.Minute))
6565
assert.Ok(t, err)
66-
assert.Assert(t, !alertAcked)
66+
assert.Equal(t, alertAcked, false)
6767

68-
assert.EqualString(t, dumper.Dump(), `
68+
assert.Equal(t, dumper.Dump(), `
6969
2019-09-07T12:00:00.000Z UnnoticedAlertsNotified {"AlertIds":["dummyid"]}
7070
2019-09-07T12:00:00.000Z DeadMansSwitchCreated {"Subject":"My test switch","Ttl":"2019-09-07T13:00:00Z"}
7171
2019-09-07T12:00:00.000Z DeadMansSwitchCheckin {"Subject":"My test switch","Ttl":"2019-09-07T13:00:00Z"}

0 commit comments

Comments
 (0)