Skip to content

Commit

Permalink
Merge branch 'main' into allow-dashes-coll-1280
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Oct 25, 2022
2 parents 49e1770 + 1df8ad6 commit 03bd269
Show file tree
Hide file tree
Showing 14 changed files with 421 additions and 196 deletions.
11 changes: 9 additions & 2 deletions .golangci-new.yml
Expand Up @@ -10,7 +10,15 @@ linters-settings:
errorf: false
asserts: true
comparison: true

revive:
ignore-generated-header: true
severity: warning
# TODO enable-all-rules: true
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
- name: exported
arguments: [checkPrivateReceivers]
- name: package-comments
staticcheck:
checks: ["all"]
wsl:
Expand Down Expand Up @@ -48,7 +56,6 @@ linters:
- lll
- misspell
- nolintlint
- revive
- unused
- whitespace

Expand Down
8 changes: 0 additions & 8 deletions .golangci.yml
Expand Up @@ -86,13 +86,6 @@ linters-settings:
allow-no-explanation: []
require-explanation: true
require-specific: true
revive:
ignore-generated-header: true
severity: warning
# TODO enable-all-rules: true
rules:
- name: exported
# TODO arguments: [checkPrivateReceivers]
staticcheck:
checks:
- all
Expand Down Expand Up @@ -122,7 +115,6 @@ linters:
- lll
- misspell
- nolintlint
- revive
- staticcheck
- unused
- whitespace
Expand Down
16 changes: 12 additions & 4 deletions Taskfile.yml
Expand Up @@ -234,23 +234,31 @@ tasks:
desc: "Run FerretDB"
deps: [build-testcover]
cmds:
- bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt -- --test-records-dir=records --mode=diff-normal --listen-addr=:27017
- >
bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt -- --test-records-dir=records
--mode=diff-normal --listen-addr=:27017
run-tigris:
deps: [build-testcover]
cmds:
- bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt -- --test-records-dir=records --mode=diff-normal --listen-addr=:27017 --handler=tigris
- >
bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt -- --test-records-dir=records
--mode=diff-normal --listen-addr=:27017 --handler=tigris
run-cockroach:
deps: [build-testcover]
cmds:
- bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt -- --test-records-dir=records --mode=diff-normal --listen-addr=:27017 --postgresql-url=postgres://cockroach@127.0.0.1:26257/ferretdb
- >
bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt -- --test-records-dir=records
--mode=diff-normal --listen-addr=:27017 --postgresql-url=postgres://cockroach@127.0.0.1:26257/ferretdb
run-proxy:
desc: "Run FerretDB in diff-proxy mode"
deps: [build-testcover]
cmds:
- bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt -- --test-records-dir=records --mode=diff-proxy --listen-addr=:27017
- >
bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt -- --test-records-dir=records
--mode=diff-proxy --listen-addr=:27017
lint:
desc: "Run linters"
Expand Down
15 changes: 6 additions & 9 deletions cmd/ferretdb/main.go
Expand Up @@ -26,7 +26,6 @@ import (
"sync"
"time"

"github.com/AlekSi/pointer"
"github.com/alecthomas/kong"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/expfmt"
Expand Down Expand Up @@ -62,8 +61,7 @@ var cli struct {

MetricsUUID bool `default:"false" help:"Add instance UUID to all metrics."`

// TODO switch to string for 3 states
Telemetry bool `default:"false" help:"Enable basic telemetry. See https://beacon.ferretdb.io."`
Telemetry telemetry.Flag `default:"" help:"Enable or disable basic telemetry. See https://beacon.ferretdb.io."`

Handler string `default:"pg" help:"${help_handler}"`

Expand Down Expand Up @@ -199,13 +197,10 @@ func setupLogger(stateProvider *state.Provider) *zap.Logger {
}

// runTelemetryReporter runs telemetry reporter until ctx is canceled.
func runTelemetryReporter(ctx context.Context, enabled bool, opts *telemetry.NewReporterOpts) {
// TODO probably move out of this function
opts.P.Update(func(s *state.State) { s.Telemetry = pointer.ToBool(enabled) })

func runTelemetryReporter(ctx context.Context, opts *telemetry.NewReporterOpts) {
r, err := telemetry.NewReporter(opts)
if err != nil {
opts.L.Fatal("Failed to create telemetry reporter.", zap.Error(err))
opts.L.Sugar().Fatalf("Failed to create telemetry reporter: %s.", err)
}

r.Run(ctx)
Expand Down Expand Up @@ -253,9 +248,11 @@ func run() {
defer wg.Done()
runTelemetryReporter(
ctx,
cli.Telemetry,
&telemetry.NewReporterOpts{
URL: cli.Test.Telemetry.URL,
F: &cli.Telemetry,
DNT: os.Getenv("DO_NOT_TRACK"),
ExecName: os.Args[0],
P: stateProvider,
L: logger.Named("telemetry"),
UndecidedDelay: cli.Test.Telemetry.UndecidedDelay,
Expand Down
3 changes: 1 addition & 2 deletions integration/setup/setup.go
Expand Up @@ -23,7 +23,6 @@ import (
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"golang.org/x/exp/slices"

"github.com/FerretDB/FerretDB/integration/shareddata"
Expand Down Expand Up @@ -68,7 +67,7 @@ func SetupWithOpts(tb testing.TB, opts *SetupOpts) *SetupResult {
if *debugSetupF {
level = zap.NewAtomicLevelAt(zap.DebugLevel)
}
logger := zaptest.NewLogger(tb, zaptest.Level(level), zaptest.WrapOptions(zap.AddCaller(), zap.Development()))
logger := testutil.Logger(tb, level)

port := *targetPortF
if port == 0 {
Expand Down
3 changes: 1 addition & 2 deletions integration/setup/setup_compat.go
Expand Up @@ -25,7 +25,6 @@ import (
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"golang.org/x/exp/slices"

"github.com/FerretDB/FerretDB/integration/shareddata"
Expand Down Expand Up @@ -92,7 +91,7 @@ func SetupCompatWithOpts(tb testing.TB, opts *SetupCompatOpts) *SetupCompatResul
if *debugSetupF {
level = zap.NewAtomicLevelAt(zap.DebugLevel)
}
logger := zaptest.NewLogger(tb, zaptest.Level(level), zaptest.WrapOptions(zap.AddCaller(), zap.Development()))
logger := testutil.Logger(tb, level)

targetPort := *targetPortF
if targetPort == 0 {
Expand Down
5 changes: 2 additions & 3 deletions internal/handlers/pg/pgdb/pgdb_test.go
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"

"github.com/FerretDB/FerretDB/internal/util/testutil"
)
Expand All @@ -31,8 +30,8 @@ import (
func getPool(ctx context.Context, tb testing.TB) *Pool {
tb.Helper()

l := zaptest.NewLogger(tb, zaptest.WrapOptions(zap.AddCaller(), zap.Development()))
pool, err := NewPool(ctx, testutil.PostgreSQLURL(tb, nil), l, false)
logger := testutil.Logger(tb, zap.NewAtomicLevelAt(zap.DebugLevel))
pool, err := NewPool(ctx, testutil.PostgreSQLURL(tb, nil), logger, false)
require.NoError(tb, err)
tb.Cleanup(pool.Close)

Expand Down
3 changes: 1 addition & 2 deletions internal/handlers/tigris/tigrisdb/tigrisdb_test.go
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/tigrisdata/tigris-client-go/config"
"github.com/tigrisdata/tigris-client-go/driver"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"

"github.com/FerretDB/FerretDB/internal/util/testutil"
)
Expand All @@ -37,7 +36,7 @@ func TestCreateCollectionIfNotExist(t *testing.T) {
URL: testutil.TigrisURL(t),
}

logger := zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller(), zap.Development()))
logger := testutil.Logger(t, zap.NewAtomicLevelAt(zap.DebugLevel))
tdb, err := New(cfg, logger)
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions internal/util/debug/debug.go
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package debug provides debug facilities.
package debug

import (
Expand Down
1 change: 1 addition & 0 deletions internal/util/hex/hex.go
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package hex provides helpers for working with hex dumps.
package hex

import (
Expand Down

0 comments on commit 03bd269

Please sign in to comment.