Skip to content

Commit 94a1cf0

Browse files
Merge branch 'feature/release-2.0-RC6' into 'master'
Preparations for 2.0-RC6 See merge request lightmeter/controlcenter!956
2 parents ab7c65a + 9bf94c5 commit 94a1cf0

File tree

396 files changed

+51946
-30574
lines changed

Some content is hidden

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

396 files changed

+51946
-30574
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test:
9191
needs: []
9292
script:
9393
- make mocks
94-
- go test ./... -race -v -tags="sqlite_json" | go run github.com/jstemmer/go-junit-report > report.xml
94+
- go test ./... -race -v | go run github.com/jstemmer/go-junit-report > report.xml
9595
artifacts:
9696
reports:
9797
junit: report.xml
@@ -103,7 +103,7 @@ cover:
103103
needs: []
104104
script:
105105
- go get -u github.com/t-yuki/gocover-cobertura
106-
- ./tools/go_test.sh -tags sqlite_json -coverprofile=coverinfo_with_gen.txt
106+
- ./tools/go_test.sh -coverprofile=coverinfo_with_gen.txt
107107
- grep -v '.gen.go' < coverinfo_with_gen.txt > coverinfo.txt
108108
- go run github.com/t-yuki/gocover-cobertura < coverinfo.txt > cobertura.xml
109109
- go tool cover -html=coverinfo.txt -o coverage.html

Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,33 @@ all:
2222
$(error Use make (dev|release|static_release) instead)
2323

2424
race:
25-
./tools/go_test.sh -race -tags="sqlite_json"
25+
./tools/go_test.sh -race
2626

2727
BUILD_DEPENDENCIES = go gcc ragel npm vue
2828
$(foreach exec,$(BUILD_DEPENDENCIES),\
2929
$(if $(shell command -v $(exec) 2> /dev/null),$(info Found executable `$(exec)`),$(error "Build dependency program $(exec) could not be found in PATH. Check README.md for more info")))
3030

3131
dev_headless_pre_build: mocks translations swag static_www postfix_parser domain_mapping_list po2go www
3232

33+
pre_build: export SKIP_VUE_SOURCE_MAPS := false
3334
dev_pre_build: npminstall mocks translations frontend_root swag static_www postfix_parser domain_mapping_list po2go
3435

36+
pre_build: export SKIP_VUE_SOURCE_MAPS := true
3537
pre_build: npminstall translations frontend_root static_www postfix_parser domain_mapping_list po2go email_notification_template
3638

3739
pre_release: pre_build recommendation_release
3840

3941
dev_bin: dev_pre_build recommendation_dev
40-
go build -tags="dev include no_postgres no_mysql no_clickhouse no_mssql sqlite_json" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
42+
go build -tags="dev include no_postgres no_mysql no_clickhouse no_mssql" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
4143

4244
dev_headless_bin: dev_headless_pre_build recommendation_dev
43-
go build -tags="dev include no_postgres no_mysql no_clickhouse no_mssql sqlite_json" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
45+
go build -tags="dev include no_postgres no_mysql no_clickhouse no_mssql" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
4446

4547
release_bin: pre_release
46-
go build -tags="release include no_postgres no_mysql no_clickhouse no_mssql sqlite_json" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
48+
go build -tags="release include no_postgres no_mysql no_clickhouse no_mssql" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
4749

4850
static_release_bin: pre_release
49-
go build -tags="release include no_postgres no_mysql no_clickhouse no_mssql sqlite_json" -o "lightmeter" -ldflags \
51+
go build -tags="release include no_postgres no_mysql no_clickhouse no_mssql" -o "lightmeter" -ldflags \
5052
"${BUILD_INFO_FLAGS} -linkmode external -extldflags '-static' -s -w" -a -v
5153

5254
static_www:
@@ -81,7 +83,7 @@ timeutil_mock:
8183
go generate -tags="dev" gitlab.com/lightmeter/controlcenter/util/timeutil
8284

8385
detective_mock:
84-
go generate -tags="dev sqlite_json" gitlab.com/lightmeter/controlcenter/detective
86+
go generate -tags="dev" gitlab.com/lightmeter/controlcenter/detective
8587

8688
po2go:
8789
go generate -tags="dev" gitlab.com/lightmeter/controlcenter/po

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0-RC5
1+
2.0.0-RC6

acceptance_tests/specs/6_message_detective.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Search for messages
1111
* Click on "Search"
1212

1313
* Expect "1" detective results
14-
* Expect to see "Sent"
14+
* Expect to see "Received"
1515
* Expect to see "sender@sender.example.com"
1616
* Expect to see "user@recipient.example.com"
1717
* Expect to see "1F5A2194AA9"

api/detective_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ func TestDetectiveCheckMessageDeliveryHandler(t *testing.T) {
9696
testutil.MustParseTime(`2009-02-14 00:31:30 +0000`),
9797
detective.Status(parser.SentStatus),
9898
"2.0.0",
99+
[]string{"google.com"},
99100
nil,
100101
"user1@example.org",
101102
[]string{"user2@example.org"},
103+
nil,
102104
},
103105
},
104106
},

api/rawlogs_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"gitlab.com/lightmeter/controlcenter/httpauth"
1414
"gitlab.com/lightmeter/controlcenter/httpauth/auth"
1515
"gitlab.com/lightmeter/controlcenter/metadata"
16+
"gitlab.com/lightmeter/controlcenter/pkg/postfix"
1617
"gitlab.com/lightmeter/controlcenter/rawlogsdb"
1718
"gitlab.com/lightmeter/controlcenter/util/testutil"
1819
"gitlab.com/lightmeter/controlcenter/util/timeutil"
@@ -46,6 +47,10 @@ func (f *fakeRawLogsFetcher) CountLogLinesInInterval(context.Context, timeutil.T
4647
return 42, nil
4748
}
4849

50+
func (f *fakeRawLogsFetcher) FetchLogLine(context.Context, time.Time, postfix.Sum) (string, error) {
51+
return "", nil
52+
}
53+
4954
func TestFetchingRawLogs(t *testing.T) {
5055
Convey("Fetch Raw Logs", t, func() {
5156
registrar := &auth.FakeRegistrar{

cli_usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
```
2-
Lightmeter ControlCenter 2.0.0-RC4
2+
Lightmeter ControlCenter 2.0.0-RC6
33
44
Example call:
55

config/config.go

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99
"flag"
1010
"fmt"
1111
"os"
12-
"strconv"
1312
"strings"
1413
"time"
1514

1615
"github.com/rs/zerolog"
1716
"gitlab.com/lightmeter/controlcenter/metadata"
17+
"gitlab.com/lightmeter/controlcenter/util/envutil"
1818
"gitlab.com/lightmeter/controlcenter/util/errorutil"
1919
"gitlab.com/lightmeter/controlcenter/version"
2020
)
@@ -67,20 +67,20 @@ func ParseWithErrorHandling(cmdlineArgs []string, lookupenv func(string) (string
6767
fs.BoolVar(&conf.ShouldWatchFromStdin, "stdin", false, "Read log lines from stdin")
6868

6969
fs.StringVar(&conf.WorkspaceDirectory, "workspace",
70-
lookupEnvOrString("LIGHTMETER_WORKSPACE", "/var/lib/lightmeter_workspace", lookupenv),
70+
envutil.LookupEnvOrString("LIGHTMETER_WORKSPACE", "/var/lib/lightmeter_workspace", lookupenv),
7171
"Path to the directory to store all working data")
7272

7373
fs.BoolVar(&conf.ImportOnly, "importonly", false,
7474
"Only import existing logs, exiting immediately, without running the full application.")
7575

76-
b, err := lookupEnvOrBool("LIGHTMETER_LOGS_USE_RSYNC", false, lookupenv)
76+
b, err := envutil.LookupEnvOrBool("LIGHTMETER_LOGS_USE_RSYNC", false, lookupenv)
7777
if err != nil {
7878
return conf, err
7979
}
8080

8181
fs.BoolVar(&conf.RsyncedDir, "logs_use_rsync", b, "Log directory is updated by rsync")
8282

83-
logYear, err := lookupEnvOrInt("LIGHTMETER_LOGS_STARTING_YEAR", 0, lookupenv)
83+
logYear, err := envutil.LookupEnvOrInt("LIGHTMETER_LOGS_STARTING_YEAR", 0, lookupenv)
8484
if err != nil {
8585
return conf, err
8686
}
@@ -91,17 +91,17 @@ func ParseWithErrorHandling(cmdlineArgs []string, lookupenv func(string) (string
9191
fs.BoolVar(&conf.ShowVersion, "version", false, "Show Version Information")
9292

9393
fs.StringVar(&conf.DirToWatch, "watch_dir",
94-
lookupEnvOrString("LIGHTMETER_WATCH_DIR", "", lookupenv),
94+
envutil.LookupEnvOrString("LIGHTMETER_WATCH_DIR", "", lookupenv),
9595
"Path to the directory where postfix stores its log files, to be watched")
9696

9797
fs.StringVar(&conf.Address, "listen",
98-
lookupEnvOrString("LIGHTMETER_LISTEN", ":8080", lookupenv),
98+
envutil.LookupEnvOrString("LIGHTMETER_LISTEN", ":8080", lookupenv),
9999
"Network Address to listen to")
100100

101101
var stringLogLevel = "INFO"
102102

103103
fs.StringVar(&stringLogLevel, "log_level",
104-
lookupEnvOrString("LIGHTMETER_LOG_LEVEL", "INFO", lookupenv),
104+
envutil.LookupEnvOrString("LIGHTMETER_LOG_LEVEL", "INFO", lookupenv),
105105
"Log level (DEBUG, INFO, WARN, or ERROR. Default: INFO)")
106106

107107
fs.StringVar(&conf.EmailToChange, "email_reset", "", "Change user info (email, name or password; depends on -workspace)")
@@ -111,23 +111,23 @@ func ParseWithErrorHandling(cmdlineArgs []string, lookupenv func(string) (string
111111
fs.StringVar(&conf.ChangeUserInfoNewName, "new_user_name", "", "Update user name (depends on -email_reset)")
112112

113113
fs.StringVar(&conf.Socket, "logs_socket",
114-
lookupEnvOrString("LIGHTMETER_LOGS_SOCKET", "", lookupenv),
114+
envutil.LookupEnvOrString("LIGHTMETER_LOGS_SOCKET", "", lookupenv),
115115
"Receive logs via a Socket. E.g. unix=/tmp/lightemter.sock or tcp=localhost:9999")
116116

117117
fs.StringVar(&conf.LogFormat, "log_format",
118-
lookupEnvOrString("LIGHTMETER_LOG_FORMAT", "default", lookupenv),
118+
envutil.LookupEnvOrString("LIGHTMETER_LOG_FORMAT", "default", lookupenv),
119119
"Expected log format from external sources (like logstash, etc.)")
120120

121121
var unparsedDefaultSettings string
122122

123-
fs.StringVar(&unparsedDefaultSettings, "default_settings", lookupEnvOrString("LIGHTMETER_DEFAULT_SETTINGS", `{}`, lookupenv), "JSON string for default settings")
123+
fs.StringVar(&unparsedDefaultSettings, "default_settings", envutil.LookupEnvOrString("LIGHTMETER_DEFAULT_SETTINGS", `{}`, lookupenv), "JSON string for default settings")
124124

125125
var unparsedLogPatterns string
126126

127-
fs.StringVar(&unparsedLogPatterns, "log_file_patterns", lookupEnvOrString("LIGHTMETER_LOG_FILE_PATTERNS", "", lookupenv),
127+
fs.StringVar(&unparsedLogPatterns, "log_file_patterns", envutil.LookupEnvOrString("LIGHTMETER_LOG_FILE_PATTERNS", "", lookupenv),
128128
`An optional colon separated list of the base filenames for the Postfix log files. Example: "mail.log:mail.err:mail.log" or "maillog"`)
129129

130-
proxyConf, err := lookupEnvOrBool("LIGHTMETER_I_KNOW_WHAT_I_AM_DOING_NOT_USING_A_REVERSE_PROXY", false, lookupenv)
130+
proxyConf, err := envutil.LookupEnvOrBool("LIGHTMETER_I_KNOW_WHAT_I_AM_DOING_NOT_USING_A_REVERSE_PROXY", false, lookupenv)
131131
if err != nil {
132132
return conf, err
133133
}
@@ -136,9 +136,9 @@ func ParseWithErrorHandling(cmdlineArgs []string, lookupenv func(string) (string
136136
proxyConf, "Used when you are accessing the application without a reverse proxy (e.g. apache2, nginx or traefik), "+
137137
"which is unsupported by us at the moment and might lead to security issues")
138138

139-
fs.StringVar(&conf.RegisteredUserEmail, "registered_user_email", lookupEnvOrString("LIGHTMETER_REGISTERED_USER_EMAIL", "", lookupenv), "Experimental: static user e-mail")
140-
fs.StringVar(&conf.RegisteredUserName, "registered_user_name", lookupEnvOrString("LIGHTMETER_REGISTERED_USER_NAME", "", lookupenv), "Experimental: static user name")
141-
fs.StringVar(&conf.RegisteredUserPassword, "registered_user_password", lookupEnvOrString("LIGHTMETER_REGISTERED_USER_PASSWORD", "", lookupenv), "Experimental: static user password")
139+
fs.StringVar(&conf.RegisteredUserEmail, "registered_user_email", envutil.LookupEnvOrString("LIGHTMETER_REGISTERED_USER_EMAIL", "", lookupenv), "Experimental: static user e-mail")
140+
fs.StringVar(&conf.RegisteredUserName, "registered_user_name", envutil.LookupEnvOrString("LIGHTMETER_REGISTERED_USER_NAME", "", lookupenv), "Experimental: static user name")
141+
fs.StringVar(&conf.RegisteredUserPassword, "registered_user_password", envutil.LookupEnvOrString("LIGHTMETER_REGISTERED_USER_PASSWORD", "", lookupenv), "Experimental: static user password")
142142

143143
fs.BoolVar(&conf.GenerateDovecotConfig, "dovecot_conf_gen", false, "Generate Dovecot Configuration")
144144
fs.BoolVar(&conf.DovecotConfigIsOld, "dovecot_conf_is_old", false, "Requires -dovecot_conf_gen. Use if if you're using a Dovecot older than 2.3.1")
@@ -179,37 +179,3 @@ func ParseWithErrorHandling(cmdlineArgs []string, lookupenv func(string) (string
179179

180180
return conf, nil
181181
}
182-
183-
func lookupEnvOrString(key string, defaultVal string, loopkupenv func(string) (string, bool)) string {
184-
if val, ok := loopkupenv(key); ok {
185-
return val
186-
}
187-
188-
return defaultVal
189-
}
190-
191-
func lookupEnvOrBool(key string, defaultVal bool, loopkupenv func(string) (string, bool)) (bool, error) {
192-
if val, ok := loopkupenv(key); ok {
193-
v, err := strconv.ParseBool(val)
194-
if err != nil {
195-
return v, fmt.Errorf("Boolean env var %v boolean value could not be parsed: %w", key, err)
196-
}
197-
198-
return v, nil
199-
}
200-
201-
return defaultVal, nil
202-
}
203-
204-
func lookupEnvOrInt(key string, defaultVal int64, loopkupenv func(string) (string, bool)) (int64, error) {
205-
if val, ok := loopkupenv(key); ok {
206-
v, err := strconv.ParseInt(val, 10, 32)
207-
if err != nil {
208-
return v, fmt.Errorf("Integer env var %v integer value could not be parsed: %w", key, err)
209-
}
210-
211-
return v, nil
212-
}
213-
214-
return defaultVal, nil
215-
}

deliverydb/cleaning.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ func tryToDeleteDeliveryQueue(tx *sql.Tx, deliveryId int64, stmts dbconn.TxPrepa
108108
return nil
109109
}
110110

111+
func tryToDeleteLogLinesRefs(tx *sql.Tx, deliveryId int64, stmts dbconn.TxPreparedStmts) error {
112+
//nolint:sqlclosecheck
113+
if _, err := stmts.Get(deleteLogLinesRefsByDeliveryId).Exec(deliveryId); err != nil {
114+
return errorutil.Wrap(err)
115+
}
116+
117+
return nil
118+
}
119+
111120
func makeCleanAction(maxAge time.Duration, batchSize int) dbrunner.Action {
112121
return func(tx *sql.Tx, stmts dbconn.TxPreparedStmts) (err error) {
113122
// NOTE: the time in the database is in Seconds
@@ -144,6 +153,10 @@ func makeCleanAction(maxAge time.Duration, batchSize int) dbrunner.Action {
144153
return errorutil.Wrap(err)
145154
}
146155

156+
if err := tryToDeleteLogLinesRefs(tx, deliveryId, stmts); err != nil {
157+
return errorutil.Wrap(err)
158+
}
159+
147160
// TODO:
148161
// maybe delete sender and recipient and orig_recipient domain parts,
149162
// although they are very unlikely to grow too much over time

deliverydb/delivery.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const (
5858
countDeliveriesWithMessageId
5959
deleteMessageIdById
6060

61+
insertLogLineRef
62+
deleteLogLinesRefsByDeliveryId
63+
6164
lastStmtKey
6265
)
6366

@@ -129,12 +132,14 @@ from
129132
deliveries join delivery_queue on delivery_queue.delivery_id = deliveries.id
130133
where
131134
delivery_queue.queue_id = ?`,
132-
deleteDeliveryQueueById: `delete from delivery_queue where id = ?`,
133-
deleteExpiredQueuesByQueueId: `delete from expired_queues where queue_id = ?`,
134-
deleteQueueParentingByQueueId: `delete from queue_parenting where parent_queue_id = ? or child_queue_id = ?`,
135-
deleteQueueById: `delete from queues where id = ?`,
136-
countDeliveriesWithMessageId: `select count(*) from deliveries where message_id = ? and delivery_ts < ?`,
137-
deleteMessageIdById: `delete from messageids where id = ?`,
135+
deleteDeliveryQueueById: `delete from delivery_queue where id = ?`,
136+
deleteExpiredQueuesByQueueId: `delete from expired_queues where queue_id = ?`,
137+
deleteQueueParentingByQueueId: `delete from queue_parenting where parent_queue_id = ? or child_queue_id = ?`,
138+
deleteQueueById: `delete from queues where id = ?`,
139+
countDeliveriesWithMessageId: `select count(*) from deliveries where message_id = ? and delivery_ts < ?`,
140+
deleteMessageIdById: `delete from messageids where id = ?`,
141+
insertLogLineRef: `insert into log_lines_ref(delivery_id, ref_type, time, checksum) values(?, ?, ?, ?)`,
142+
deleteLogLinesRefsByDeliveryId: `delete from log_lines_ref where delivery_id = ?`,
138143
}
139144

140145
func setupDomainMapping(conn dbconn.RwConn, m *domainmapping.Mapper) error {
@@ -339,6 +344,16 @@ func insertMandatoryResultFields(tx *sql.Tx, stmts dbconn.TxPreparedStmts, tr tr
339344
return nil, errorutil.Wrap(err)
340345
}
341346

347+
deliveryId, err := result.LastInsertId()
348+
if err != nil {
349+
return nil, errorutil.Wrap(err)
350+
}
351+
352+
//nolint:sqlclosecheck
353+
if _, err := stmts.Get(insertLogLineRef).Exec(deliveryId, tracking.ResultDeliveryLineChecksum, tr[tracking.ResultDeliveryTimeKey].Int64(), tr[tracking.ResultDeliveryLineChecksum].Int64()); err != nil {
354+
return nil, errorutil.Wrap(err)
355+
}
356+
342357
return result, nil
343358
}
344359

0 commit comments

Comments
 (0)