sqlite: added pragma support for wal
This commit is contained in:
parent
9e1a192f93
commit
97341ec698
2
go/.gitignore
vendored
2
go/.gitignore
vendored
|
@ -1,4 +1,6 @@
|
||||||
models/
|
models/
|
||||||
*.db
|
*.db
|
||||||
|
*.db-shm
|
||||||
|
*.db-wal
|
||||||
gen/
|
gen/
|
||||||
.env
|
.env
|
||||||
|
|
|
@ -36,6 +36,8 @@ func init() {
|
||||||
flags.Float32(key, v, desc)
|
flags.Float32(key, v, desc)
|
||||||
case float64:
|
case float64:
|
||||||
flags.Float64(key, v, desc)
|
flags.Float64(key, v, desc)
|
||||||
|
case []string:
|
||||||
|
flags.StringSlice(key, v, desc)
|
||||||
default:
|
default:
|
||||||
flags.String(key, fmt.Sprintf("%v", v), desc)
|
flags.String(key, fmt.Sprintf("%v", v), desc)
|
||||||
}
|
}
|
||||||
|
@ -70,6 +72,7 @@ func main() {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ctx = config.WithContext(ctx, cfg)
|
ctx = config.WithContext(ctx, cfg)
|
||||||
if err := Cmd.ExecuteContext(ctx); err != nil {
|
if err := Cmd.ExecuteContext(ctx); err != nil {
|
||||||
|
slog.ErrorContext(ctx, err.Error(), "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"connectrpc.com/connect"
|
"connectrpc.com/connect"
|
||||||
|
@ -76,6 +77,25 @@ var Cmd = &cobra.Command{
|
||||||
"dsn", dsn,
|
"dsn", dsn,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
for i, pragma := range cfg.Strings("db.pragma") {
|
||||||
|
split := strings.SplitN(pragma, "=", 2)
|
||||||
|
if len(split) < 2 {
|
||||||
|
return errs.Failw("failed to parse db pragma. expected key=value format",
|
||||||
|
"index", i+1,
|
||||||
|
"pragma", pragma,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
key, value := split[0], split[1]
|
||||||
|
query := fmt.Sprintf("pragma %s = %s", key, value)
|
||||||
|
_, err = sqldb.Exec(query)
|
||||||
|
if err != nil {
|
||||||
|
return errs.Wrapw(err, "failed to execute pragma",
|
||||||
|
"index", i+1,
|
||||||
|
"pragma", pragma,
|
||||||
|
"query", query,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
cleanups = append(cleanups, sqldb.Close)
|
cleanups = append(cleanups, sqldb.Close)
|
||||||
if err := otelsql.RegisterDBStatsMetrics(sqldb, otelsql.WithAttributes(semconv.DBSystemSqlite)); err != nil {
|
if err := otelsql.RegisterDBStatsMetrics(sqldb, otelsql.WithAttributes(semconv.DBSystemSqlite)); err != nil {
|
||||||
return errs.Wrapw(
|
return errs.Wrapw(
|
||||||
|
|
|
@ -35,6 +35,7 @@ var DefaultConfig = Entries{
|
||||||
|
|
||||||
{"db.driver", "sqlite3", "Database driver", false},
|
{"db.driver", "sqlite3", "Database driver", false},
|
||||||
{"db.path", path.Join(xdg.Home, ".local", "share", "bluemage", "data.db"), "Database path", false},
|
{"db.path", path.Join(xdg.Home, ".local", "share", "bluemage", "data.db"), "Database path", false},
|
||||||
|
{"db.pragma", []string{"journal_mode=wal", "synchronous=normal", "temp_store=memory", "mmap_size=30000000000"}, `Database pragma options key=value comma separated values (or repeat). Example: '--db.pragma "journal_mode=wal,synchronous=normal"'`, false},
|
||||||
|
|
||||||
{"pubsub.db.path", path.Join(xdg.Home, ".local", "share", "bluemage", "pubsub.db"), "PubSub database path", false},
|
{"pubsub.db.path", path.Join(xdg.Home, ".local", "share", "bluemage", "pubsub.db"), "PubSub database path", false},
|
||||||
{"pubsub.db.timeout", "5s", "PubSub database timeout", false},
|
{"pubsub.db.timeout", "5s", "PubSub database timeout", false},
|
||||||
|
|
|
@ -44,5 +44,5 @@ func (SQLLogger) Log(ctx context.Context, level sqldblogger.Level, msg string, d
|
||||||
qc.Args = data["args"]
|
qc.Args = data["args"]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
slog.ErrorContext(ctx, strings.ReplaceAll(msg, "\n", " "), "lvl", level.String(), "data", data)
|
slog.DebugContext(ctx, strings.ReplaceAll(msg, "\n", " "), "lvl", level.String(), "data", data)
|
||||||
}
|
}
|
||||||
|
|
21
go/server/log_handlers.go
Normal file
21
go/server/log_handlers.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"connectrpc.com/connect"
|
||||||
|
logsv1 "github.com/tigorlazuardi/bluemage/go/gen/proto/logs/v1"
|
||||||
|
"github.com/tigorlazuardi/bluemage/go/gen/proto/logs/v1/logsv1connect"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LogHandlers struct {
|
||||||
|
logsv1connect.UnimplementedLogServiceHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lo *LogHandlers) Log(ctx context.Context, request *connect.Request[logsv1.LogRequest]) (*connect.Response[logsv1.LogResponse], error) {
|
||||||
|
panic("not implemented") // TODO: Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lo *LogHandlers) Tail(ctx context.Context, request *connect.Request[logsv1.TailRequest], response *connect.ServerStream[logsv1.TailResponse]) error {
|
||||||
|
panic("not implemented") // TODO: Implement
|
||||||
|
}
|
|
@ -4,3 +4,6 @@ deps:
|
||||||
- name: buf.build/bufbuild/protovalidate
|
- name: buf.build/bufbuild/protovalidate
|
||||||
commit: a6c49f84cc0f4e038680d390392e2ab0
|
commit: a6c49f84cc0f4e038680d390392e2ab0
|
||||||
digest: b5:e968392e88ff7915adcbd1635d670b45bff8836ec2415d81fc559ca5470a695dbdc30030bad8bc5764647c731079e9e7bba0023ea25c4e4a1672a7d2561d4a19
|
digest: b5:e968392e88ff7915adcbd1635d670b45bff8836ec2415d81fc559ca5470a695dbdc30030bad8bc5764647c731079e9e7bba0023ea25c4e4a1672a7d2561d4a19
|
||||||
|
- name: buf.build/protocolbuffers/wellknowntypes
|
||||||
|
commit: f17e05fe4a764a3482b8e033daec742e
|
||||||
|
digest: b5:405a06d8a554f01c830c643879f54feffe2087a6927643dc9418403653ff4033227a2ce9b2b19b8ad350a611ef6576b4df109c96e5dfb6164191eb73d779fb21
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
version: v2
|
version: v2
|
||||||
deps:
|
deps:
|
||||||
- buf.build/bufbuild/protovalidate
|
- buf.build/bufbuild/protovalidate
|
||||||
|
- buf.build/protocolbuffers/wellknowntypes:v21.12
|
||||||
|
|
54
schemas/proto/logs/v1/logs.proto
Normal file
54
schemas/proto/logs/v1/logs.proto
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package logs.v1;
|
||||||
|
|
||||||
|
service LogService {
|
||||||
|
rpc Log(LogRequest) returns (LogResponse) {}
|
||||||
|
rpc Tail(TailRequest) returns (stream TailResponse) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
message LogRequest {
|
||||||
|
Level level = 1;
|
||||||
|
string search = 2;
|
||||||
|
string trace_id = 3;
|
||||||
|
int64 from = 4;
|
||||||
|
int64 to = 5;
|
||||||
|
int64 limit = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message LogResponse {
|
||||||
|
repeated Log logs = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Log {
|
||||||
|
int64 timestamp = 1;
|
||||||
|
Level level = 2;
|
||||||
|
string message = 3;
|
||||||
|
Origin origin = 4;
|
||||||
|
string trace_id = 5;
|
||||||
|
string span_id = 6;
|
||||||
|
optional bytes details = 7;
|
||||||
|
optional bytes error = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Level {
|
||||||
|
LEVEL_UNSPECIFIED = 0;
|
||||||
|
LEVEL_DEBUG = 1;
|
||||||
|
LEVEL_INFO = 2;
|
||||||
|
LEVEL_WARN = 3;
|
||||||
|
LEVEL_ERROR = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Origin {
|
||||||
|
string file = 1;
|
||||||
|
int64 line = 2;
|
||||||
|
string function = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message TailRequest {
|
||||||
|
Level level = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message TailResponse {
|
||||||
|
Log log = 1;
|
||||||
|
}
|
Loading…
Reference in a new issue