Skip to content

Commit 77a3361

Browse files
committed
Logdb package and tests for sessions
1 parent 0d0f3d0 commit 77a3361

File tree

476 files changed

+26652
-14957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

476 files changed

+26652
-14957
lines changed

.golangci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ linters:
133133
# This file contains only configs which differ from defaults.
134134
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
135135
linters-settings:
136+
gosec:
137+
exclude-rules:
138+
- G404
136139
nestif:
137140
min-complexity: 8
138141
cyclop:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ vendor:
6464
## build/server: build cmd/server
6565
build/server:
6666
@echo 'Compiling server...'
67-
go build -ldflags="-X main.serverName=${SERVER_NAME} -X main.port=${PORT} -X main.uri=${URI} -X main.db=${DB}" -o=./bin/pulse-server ./cmd/server
67+
go build -o=./bin/pulse-server ./cmd/server
6868
.PHONY:build/server
6969

7070
## build/client: build cmd/client
7171
build/client:
7272
@echo 'Compiling client...'
73-
go build -ldflags="-X main.serverName=${SERVER_NAME} -X main.port=${PORT} -X main.hostname=${HOSTNAME}" -o=./bin/pulse-client ./cmd/client
73+
go build -o=./bin/pulse-client ./cmd/client
7474
.PHONY:build/client
7575

7676
## build: builds the server and client applications

go.mod

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
module github.com/creativecreature/pulse
22

3-
go 1.21.3
3+
go 1.22.5
44

55
require (
6-
github.com/charmbracelet/lipgloss v0.10.0
6+
github.com/charmbracelet/lipgloss v0.12.1
77
github.com/charmbracelet/log v0.4.0
88
github.com/neovim/go-client v1.2.1
99
github.com/spf13/viper v1.19.0
10-
go.mongodb.org/mongo-driver v1.11.7
11-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
10+
go.mongodb.org/mongo-driver v1.16.0
11+
golang.org/x/exp v0.0.0-20240707233637-46b078467d37
1212
)
1313

1414
require (
1515
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
16+
github.com/charmbracelet/x/ansi v0.1.4 // indirect
1617
github.com/fsnotify/fsnotify v1.7.0 // indirect
1718
github.com/go-logfmt/logfmt v0.6.0 // indirect
1819
github.com/golang/snappy v0.0.4 // indirect
19-
github.com/google/go-cmp v0.6.0 // indirect
2020
github.com/hashicorp/hcl v1.0.0 // indirect
21-
github.com/klauspost/compress v1.17.2 // indirect
21+
github.com/klauspost/compress v1.17.9 // indirect
2222
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
2323
github.com/magiconair/properties v1.8.7 // indirect
24-
github.com/mattn/go-isatty v0.0.18 // indirect
24+
github.com/mattn/go-isatty v0.0.20 // indirect
2525
github.com/mattn/go-runewidth v0.0.15 // indirect
2626
github.com/mitchellh/mapstructure v1.5.0 // indirect
2727
github.com/montanaflynn/stats v0.7.1 // indirect
28-
github.com/muesli/reflow v0.3.0 // indirect
2928
github.com/muesli/termenv v0.15.2 // indirect
3029
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
31-
github.com/pkg/errors v0.9.1 // indirect
3230
github.com/rivo/uniseg v0.4.7 // indirect
33-
github.com/sagikazarmark/locafero v0.4.0 // indirect
31+
github.com/sagikazarmark/locafero v0.6.0 // indirect
3432
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
3533
github.com/sourcegraph/conc v0.3.0 // indirect
3634
github.com/spf13/afero v1.11.0 // indirect
@@ -40,13 +38,12 @@ require (
4038
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
4139
github.com/xdg-go/scram v1.1.2 // indirect
4240
github.com/xdg-go/stringprep v1.0.4 // indirect
43-
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
44-
go.uber.org/atomic v1.9.0 // indirect
45-
go.uber.org/multierr v1.9.0 // indirect
46-
golang.org/x/crypto v0.21.0 // indirect
47-
golang.org/x/sync v0.6.0 // indirect
48-
golang.org/x/sys v0.18.0 // indirect
49-
golang.org/x/text v0.14.0 // indirect
41+
github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 // indirect
42+
go.uber.org/multierr v1.11.0 // indirect
43+
golang.org/x/crypto v0.25.0 // indirect
44+
golang.org/x/sync v0.7.0 // indirect
45+
golang.org/x/sys v0.22.0 // indirect
46+
golang.org/x/text v0.16.0 // indirect
5047
gopkg.in/ini.v1 v1.67.0 // indirect
5148
gopkg.in/yaml.v3 v3.0.1 // indirect
5249
)

go.sum

Lines changed: 26 additions & 56 deletions
Large diffs are not rendered by default.

filename.go renamed to logdb/filename.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pulse
1+
package logdb
22

33
import "strings"
44

filename_test.go renamed to logdb/filename_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package pulse_test
1+
package logdb_test
22

33
import (
44
"testing"
55

6-
"github.com/creativecreature/pulse"
6+
"github.com/creativecreature/pulse/logdb"
77
)
88

99
type filenameTest struct {
@@ -28,7 +28,7 @@ func TestFilename(t *testing.T) {
2828
tc := tc
2929
t.Run(tc.expected, func(t *testing.T) {
3030
t.Parallel()
31-
actual := pulse.Filename(tc.index)
31+
actual := logdb.Filename(tc.index)
3232
if actual != tc.expected {
3333
t.Errorf("expected %s, got %s", tc.expected, actual)
3434
}
@@ -58,7 +58,7 @@ func TestIndex(t *testing.T) {
5858
tc := tc
5959
t.Run(tc.filename, func(t *testing.T) {
6060
t.Parallel()
61-
actual := pulse.Index(tc.filename)
61+
actual := logdb.Index(tc.filename)
6262
if actual != tc.expected {
6363
t.Errorf("expected %d, got %d", tc.expected, actual)
6464
}

logdb.go renamed to logdb/logdb.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pulse
1+
package logdb
22

33
import (
44
"context"
@@ -8,6 +8,7 @@ import (
88

99
"github.com/charmbracelet/log"
1010
"github.com/creativecreature/pulse/clock"
11+
"github.com/creativecreature/pulse/logger"
1112
)
1213

1314
// Record represents a key-value pair in our database.
@@ -29,7 +30,7 @@ type LogDB struct {
2930

3031
// NewDB creates a new log database.
3132
func NewDB(dirPath string, segmentSizeKB int, c clock.Clock) *LogDB {
32-
log := NewLogger()
33+
log := logger.New()
3334

3435
// Create the directory if it doesn't exist.
3536
if err := os.MkdirAll(dirPath, 0o755); err != nil {

logdb_test.go renamed to logdb/logdb_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pulse_test
1+
package logdb_test
22

33
import (
44
"context"
@@ -11,8 +11,8 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/creativecreature/pulse"
1514
"github.com/creativecreature/pulse/clock"
15+
"github.com/creativecreature/pulse/logdb"
1616
)
1717

1818
func copyFile(src, dst string) error {
@@ -72,7 +72,7 @@ func TestConcurrentGetSet(t *testing.T) {
7272
cpus := runtime.NumCPU()
7373
writeCPUs, readCPUs := cpus/2, cpus/2
7474
numIterations := 10_000
75-
db := pulse.NewDB(t.TempDir(), 10, clock.New())
75+
db := logdb.NewDB(t.TempDir(), 10, clock.New())
7676

7777
wg := sync.WaitGroup{}
7878
wg.Add(numIterations * (writeCPUs + readCPUs))
@@ -108,7 +108,7 @@ func TestUniqueValues(t *testing.T) {
108108
}
109109

110110
mockClock := clock.NewMock(time.Now())
111-
db := pulse.NewDB(path, 10, mockClock)
111+
db := logdb.NewDB(path, 10, mockClock)
112112

113113
ctx, cancel := context.WithCancel(context.Background())
114114
defer cancel()
@@ -130,7 +130,7 @@ func TestAggregation(t *testing.T) {
130130
}
131131

132132
mockClock := clock.NewMock(time.Now())
133-
db := pulse.NewDB(path, 10, mockClock)
133+
db := logdb.NewDB(path, 10, mockClock)
134134

135135
ctx, cancel := context.WithCancel(context.Background())
136136
defer cancel()
@@ -157,7 +157,7 @@ func TestCompaction(t *testing.T) {
157157
}
158158

159159
mockClock := clock.NewMock(time.Now())
160-
db := pulse.NewDB(path, 10, mockClock)
160+
db := logdb.NewDB(path, 10, mockClock)
161161

162162
ctx, cancel := context.WithCancel(context.Background())
163163
defer cancel()
@@ -187,7 +187,7 @@ func TestAggregationAfterCompaction(t *testing.T) {
187187
}
188188

189189
mockClock := clock.NewMock(time.Now())
190-
db := pulse.NewDB(path, 10, mockClock)
190+
db := logdb.NewDB(path, 10, mockClock)
191191

192192
ctx, cancel := context.WithCancel(context.Background())
193193
defer cancel()
@@ -222,7 +222,7 @@ func TestCompactionWritesAggregation(t *testing.T) {
222222
}
223223

224224
mockClock := clock.NewMock(time.Now())
225-
db := pulse.NewDB(path, 10, mockClock)
225+
db := logdb.NewDB(path, 10, mockClock)
226226

227227
ctx, cancel := context.WithCancel(context.Background())
228228
defer cancel()
@@ -282,7 +282,7 @@ func TestAppendingCompactingWritesAggregation(t *testing.T) {
282282
}
283283

284284
mockClock := clock.NewMock(time.Now())
285-
db := pulse.NewDB(path, 10, mockClock)
285+
db := logdb.NewDB(path, 10, mockClock)
286286

287287
ctx, cancel := context.WithCancel(context.Background())
288288
defer cancel()
@@ -337,7 +337,7 @@ func TestWritesCompacting(t *testing.T) {
337337
t.Parallel()
338338

339339
mockClock := clock.NewMock(time.Now())
340-
db := pulse.NewDB(t.TempDir(), 10, mockClock)
340+
db := logdb.NewDB(t.TempDir(), 10, mockClock)
341341

342342
ctx, cancel := context.WithCancel(context.Background())
343343
defer cancel()

restore.go renamed to logdb/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pulse
1+
package logdb
22

33
import (
44
"os"

scan.go renamed to logdb/scan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pulse
1+
package logdb
22

33
import (
44
"bufio"

0 commit comments

Comments
 (0)