Skip to content

Commit

Permalink
Make users know about telemetry via startupWarnings (#1336)
Browse files Browse the repository at this point in the history
Closes #1328.
  • Loading branch information
Elena Grahovac authored Nov 2, 2022
1 parent 5c242d0 commit be83096
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 20 deletions.
4 changes: 2 additions & 2 deletions integration/setup/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func SkipForPostgresWithReason(tb testing.TB, reason string) {

// setupListener starts in-process FerretDB server that runs until ctx is done,
// and returns listening port number.
func setupListener(tb testing.TB, ctx context.Context, logger *zap.Logger) int {
func setupListener(tb testing.TB, ctx context.Context, logger *zap.Logger) (*state.Provider, int) {
tb.Helper()

p, err := state.NewProvider("")
Expand Down Expand Up @@ -153,7 +153,7 @@ func setupListener(tb testing.TB, ctx context.Context, logger *zap.Logger) int {
port := l.Addr().(*net.TCPAddr).Port
logger.Info("Listener started", zap.String("handler", *handlerF), zap.Int("port", port))

return port
return p, port
}

// setupClient returns MongoDB client for database on 127.0.0.1:port.
Expand Down
18 changes: 11 additions & 7 deletions integration/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"golang.org/x/exp/slices"

"github.com/FerretDB/FerretDB/integration/shareddata"
"github.com/FerretDB/FerretDB/internal/util/state"
"github.com/FerretDB/FerretDB/internal/util/testutil"
)

Expand All @@ -46,9 +47,10 @@ type SetupOpts struct {

// SetupResult represents setup results.
type SetupResult struct {
Ctx context.Context
Collection *mongo.Collection
Port uint16
Ctx context.Context
Collection *mongo.Collection
Port uint16
StateProvider *state.Provider
}

// SetupWithOpts setups the test according to given options.
Expand All @@ -69,12 +71,13 @@ func SetupWithOpts(tb testing.TB, opts *SetupOpts) *SetupResult {
}
logger := testutil.Logger(tb, level)

var stateProvider *state.Provider
port := *targetPortF
if port == 0 {
// TODO check targetUnixSocketF, setup Unix socket-only listener if true.
// TODO https://github.com/FerretDB/FerretDB/issues/1295
_ = *targetUnixSocketF
port = setupListener(tb, ctx, logger)
stateProvider, port = setupListener(tb, ctx, logger)
}

// register cleanup function after setupListener registers its own to preserve full logs
Expand All @@ -85,9 +88,10 @@ func SetupWithOpts(tb testing.TB, opts *SetupOpts) *SetupResult {
level.SetLevel(*logLevelF)

return &SetupResult{
Ctx: ctx,
Collection: collection,
Port: uint16(port),
Ctx: ctx,
Collection: collection,
Port: uint16(port),
StateProvider: stateProvider,
}
}

Expand Down
6 changes: 5 additions & 1 deletion integration/setup/setup_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"golang.org/x/exp/slices"

"github.com/FerretDB/FerretDB/integration/shareddata"
"github.com/FerretDB/FerretDB/internal/util/state"
"github.com/FerretDB/FerretDB/internal/util/testutil"
)

Expand All @@ -54,6 +55,7 @@ type SetupCompatResult struct {
TargetPort uint16
CompatCollections []*mongo.Collection
CompatPort uint16
StateProvider *state.Provider
}

// SetupCompatWithOpts setups the compatibility test according to given options.
Expand Down Expand Up @@ -93,9 +95,10 @@ func SetupCompatWithOpts(tb testing.TB, opts *SetupCompatOpts) *SetupCompatResul
}
logger := testutil.Logger(tb, level)

var stateProvider *state.Provider
targetPort := *targetPortF
if targetPort == 0 {
targetPort = setupListener(tb, ctx, logger)
stateProvider, targetPort = setupListener(tb, ctx, logger)
}

// register cleanup function after setupListener registers its own to preserve full logs
Expand All @@ -112,6 +115,7 @@ func SetupCompatWithOpts(tb testing.TB, opts *SetupCompatOpts) *SetupCompatResul
TargetPort: uint16(targetPort),
CompatCollections: compatCollections,
CompatPort: uint16(compatPort),
StateProvider: stateProvider,
}
}

Expand Down
20 changes: 16 additions & 4 deletions internal/handlers/pg/msg_getlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,23 @@ func (h *Handler) MsgGetLog(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg,
pv, _, _ := strings.Cut(h.StateProvider.Get().HandlerVersion, " ")
mv := version.Get()

startupWarnings := []string{
"Powered by FerretDB " + mv.Version + " and PostgreSQL " + pv + ".",
"Please star us on GitHub: https://github.com/FerretDB/FerretDB.",
}

state := h.StateProvider.Get()
if state.Telemetry == nil {
startupWarnings = append(
startupWarnings,
"The telemetry state is undecided; the first report will be sent soon. "+
"Read more about FerretDB telemetry and how to opt out at https://beacon.ferretdb.io.",
)
}

var log types.Array
for _, line := range []string{
"Powered by 🥭 FerretDB " + mv.Version + " and PostgreSQL " + pv + ".",
"Please star us on GitHub: https://github.com/FerretDB/FerretDB",
} {

for _, line := range startupWarnings {
b, err := json.Marshal(map[string]any{
"msg": line,
"tags": []string{"startupWarnings"},
Expand Down
20 changes: 16 additions & 4 deletions internal/handlers/tigris/msg_getlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,23 @@ func (h *Handler) MsgGetLog(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg,
return nil, lazyerrors.Error(err)
}

var log types.Array
for _, line := range []string{
startupWarnings := []string{
"Powered by FerretDB " + version.Get().Version + " and Tigris " + info.ServerVersion + ".",
"Please star us on GitHub: https://github.com/FerretDB/FerretDB and https://github.com/tigrisdata/tigris",
} {
"Please star us on GitHub: https://github.com/FerretDB/FerretDB and https://github.com/tigrisdata/tigris.",
}

state := h.StateProvider.Get()
if state.Telemetry == nil {
startupWarnings = append(
startupWarnings,
"The telemetry state is undecided; the first report will be sent soon. "+
"Read more about FerretDB telemetry and how to opt out at https://beacon.ferretdb.io.",
)
}

var log types.Array

for _, line := range startupWarnings {
b, err := json.Marshal(map[string]any{
"msg": line,
"tags": []string{"startupWarnings"},
Expand Down
4 changes: 2 additions & 2 deletions internal/util/telemetry/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (r *Reporter) firstReportDelay(ctx context.Context, ch <-chan struct{}) {
}

msg := fmt.Sprintf(
"Telemetry state undecided, waiting %s before the first report. "+
"Read more about FerretDB telemetry at https://beacon.ferretdb.io",
"The telemetry state is undecided; the first report will be sent in %s. "+
"Read more about FerretDB telemetry and how to opt out at https://beacon.ferretdb.io.",
r.UndecidedDelay,
)
r.L.Info(msg)
Expand Down

1 comment on commit be83096

@vercel
Copy link

@vercel vercel bot commented on be83096 Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ferret-db – ./

ferret-db.vercel.app
ferret-db-ferretdb.vercel.app
ferret-db-git-main-ferretdb.vercel.app

Please sign in to comment.