Skip to content

Commit

Permalink
Log MongoDB URI and bump deps (#1060)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Oct 10, 2024
1 parent ad322f9 commit 8fe4f00
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
version: 1.72.1

- name: Run init
run: bin/task init
run: bin/task init build

- name: Dance!
run: bin/task dance CONFIG=${{ matrix.project }}.yml
Expand Down
6 changes: 2 additions & 4 deletions cmd/dance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func main() {
log.Fatal(err)
}

log.Printf("Waiting for port %d for %s / %s to be up...", port, db, uri)
log.Printf("Waiting for port %d for %s / %s to be up...", port, db, u.Redacted())

if err = waitForPort(ctx, port); err != nil {
log.Fatal(err)
Expand All @@ -155,10 +155,8 @@ func main() {
var pusherClient *pusher.Client

if cli.Push != "" {
log.Print("Connecting to MongoDB URI to push results...")

var err error
if pusherClient, err = pusher.New(cli.Push); err != nil {
if pusherClient, err = pusher.New(cli.Push, l.With(slog.String("name", "pusher"))); err != nil {
log.Fatal(err)
}

Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ module github.com/FerretDB/dance

go 1.23

toolchain go1.23.1
toolchain go1.23.2

require (
github.com/alecthomas/kong v1.2.1
github.com/pmezard/go-difflib v1.0.0
github.com/sethvargo/go-githubactions v1.3.0
github.com/stretchr/testify v1.9.0
go.mongodb.org/mongo-driver v1.16.1
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
golang.org/x/sys v0.25.0
go.mongodb.org/mongo-driver v1.17.1
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
golang.org/x/sys v0.26.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -23,8 +23,8 @@ require (
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.22.0 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/text v0.17.0 // indirect
)
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8=
go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand All @@ -52,16 +52,16 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down
4 changes: 2 additions & 2 deletions internal/configload/configload.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func loadContent(content, db string) (*config.Config, error) {
return nil, fmt.Errorf("no MongoDB URI for %q", db)
}

uri, err := url.Parse(mongodbURI)
u, err := url.Parse(mongodbURI)
if err != nil {
return nil, fmt.Errorf("failed to parse MongoDB URI %q for %q: %w", mongodbURI, db, err)
}
Expand All @@ -138,7 +138,7 @@ func loadContent(content, db string) (*config.Config, error) {
return nil, fmt.Errorf("failed to parse project config file template: %w", err)
}

data, err := templateData(*uri)
data, err := templateData(*u)
if err != nil {
return nil, err
}
Expand Down
49 changes: 49 additions & 0 deletions internal/pusher/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package pusher

import (
"io"
"log/slog"
"strings"
"testing"
)

// logWriter provides [io.Writer] for [testing.TB].
type logWriter struct {
tb testing.TB
}

// Write implements [io.Writer].
func (lw *logWriter) Write(p []byte) (int, error) {
// "logging.go:xx" is added by testing.TB.Log itself; there is nothing we can do about it.
// lw.tb.Helper() does not help. See:
// https://github.com/golang/go/issues/59928
// https://github.com/neilotoole/slogt/tree/v1.1.0?tab=readme-ov-file#deficiency
lw.tb.Log(strings.TrimSuffix(string(p), "\n"))
return len(p), nil
}

// Logger returns slog test logger.
func Logger(tb testing.TB) *slog.Logger {
return slog.New(slog.NewTextHandler(&logWriter{tb: tb}, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))
}

// check interfaces
var (
_ io.Writer = (*logWriter)(nil)
)
18 changes: 13 additions & 5 deletions internal/pusher/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package pusher

import (
"context"
"fmt"
"log/slog"
"net/url"
"os"
"strings"
Expand All @@ -31,6 +33,7 @@ import (

// Client represents a MongoDB client.
type Client struct {
l *slog.Logger
c *mongo.Client
database string
hostname string
Expand All @@ -39,20 +42,22 @@ type Client struct {
}

// New creates a new MongoDB client with given URI.
func New(uri string) (*Client, error) {
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
defer cancel()

func New(uri string, l *slog.Logger) (*Client, error) {
u, err := url.Parse(uri)
if err != nil {
return nil, err
}

database := strings.TrimPrefix(u.Path, "/")
if database == "" {
database = "dance"
return nil, fmt.Errorf("database name is empty in the URL")
}

ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
defer cancel()

l.InfoContext(ctx, "Connecting to MongoDB URI to push results...", slog.String("uri", u.Redacted()))

c, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))
if err != nil {
return nil, err
Expand All @@ -69,6 +74,7 @@ func New(uri string) (*Client, error) {
}

return &Client{
l: l,
c: c,
database: database,
hostname: hostname,
Expand Down Expand Up @@ -98,6 +104,8 @@ func (c *Client) Push(ctx context.Context, config, database string, res map[stri
{"passed", passed},
}

c.l.InfoContext(ctx, "Pushing results to MongoDB URI...", slog.Any("doc", doc))

_, err := c.c.Database(c.database).Collection("incoming").InsertOne(ctx, doc)

return err
Expand Down
2 changes: 1 addition & 1 deletion internal/pusher/pusher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
func TestPusher(t *testing.T) {
t.Parallel()

c, err := New("mongodb://localhost:27001/dance")
c, err := New("mongodb://localhost:27001/dance", Logger(t))
require.NoError(t, err)
t.Cleanup(c.Close)

Expand Down
2 changes: 1 addition & 1 deletion projects/enmeshed-runtime
Submodule enmeshed-runtime updated 137 files
2 changes: 1 addition & 1 deletion projects/mongo
Submodule mongo updated 110 files
2 changes: 1 addition & 1 deletion projects/mongo-go-driver
Submodule mongo-go-driver updated 168 files
2 changes: 1 addition & 1 deletion projects/restheart
Submodule restheart updated 33 files
+3 −21 GRAALVM.md
+2 −2 commons/src/main/java/org/restheart/utils/CleanerUtils.java
+30 −4 commons/src/main/java/org/restheart/utils/URLUtils.java
+5 −0 core/pom.xml
+12 −20 core/src/main/java/org/restheart/handlers/RequestLogger.java
+13 −0 core/src/main/resources/META-INF/native-image/org.restheart/restheart-core/reflect-config.json
+3 −0 core/src/main/resources/restheart-default-config-no-mongodb.yml
+12 −9 graphql/src/main/java/org/restheart/graphql/initializers/GraphAppsInitializer.java
+3 −2 mongodb/src/main/java/org/restheart/mongodb/db/Documents.java
+6 −7 mongodb/src/main/java/org/restheart/mongodb/handlers/bulk/BulkPostCollectionHandler.java
+3 −3 mongodb/src/main/java/org/restheart/mongodb/handlers/changestreams/ChangeStreamWorkerKey.java
+0 −227 polyglot/src/main/java/org/restheart/polyglot/AbstractJSPlugin.java
+103 −0 polyglot/src/main/java/org/restheart/polyglot/ContextQueue.java
+131 −0 polyglot/src/main/java/org/restheart/polyglot/JSPlugin.java
+56 −52 polyglot/src/main/java/org/restheart/polyglot/PolyglotDeployer.java
+5 −4 polyglot/src/main/java/org/restheart/polyglot/interceptors/BsonJSInterceptor.java
+5 −4 polyglot/src/main/java/org/restheart/polyglot/interceptors/ByteArrayJSInterceptor.java
+5 −4 polyglot/src/main/java/org/restheart/polyglot/interceptors/ByteArrayProxyJSInterceptor.java
+5 −4 polyglot/src/main/java/org/restheart/polyglot/interceptors/CsvJSInterceptor.java
+55 −39 polyglot/src/main/java/org/restheart/polyglot/interceptors/JSInterceptor.java
+58 −82 polyglot/src/main/java/org/restheart/polyglot/interceptors/JSInterceptorFactory.java
+5 −4 polyglot/src/main/java/org/restheart/polyglot/interceptors/JsonJSInterceptor.java
+5 −4 polyglot/src/main/java/org/restheart/polyglot/interceptors/JsonProxyJSInterceptor.java
+5 −4 polyglot/src/main/java/org/restheart/polyglot/interceptors/MongoJSInterceptor.java
+5 −4 polyglot/src/main/java/org/restheart/polyglot/interceptors/StringJSInterceptor.java
+81 −0 polyglot/src/main/java/org/restheart/polyglot/services/JSService.java
+47 −0 polyglot/src/main/java/org/restheart/polyglot/services/JSServiceArgs.java
+63 −99 polyglot/src/main/java/org/restheart/polyglot/services/JSStringService.java
+48 −41 polyglot/src/main/java/org/restheart/polyglot/services/NodeService.java
+1 −1 polyglot/src/main/resources/META-INF/native-image/org.restheart/restheart-polyglot/reflect-config.json
+6 −18 pom.xml
+72 −51 security/src/main/java/org/restheart/security/mechanisms/JwtAuthenticationMechanism.java
+14 −0 security/src/test/java/org/restheart/security/mechanisms/JwtAuthenticationMechanismTest.java
20 changes: 10 additions & 10 deletions tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module github.com/FerretDB/dance/tools

go 1.23

toolchain go1.23.1
toolchain go1.23.2

require (
github.com/go-task/task/v3 v3.39.0
github.com/go-task/task/v3 v3.39.2
github.com/pingcap/go-ycsb v1.0.1
github.com/quasilyte/go-consistent v0.6.1
golang.org/x/perf v0.0.0-20240910214617-f1a715d501dd
golang.org/x/pkgsite v0.0.0-20240913130837-7d0ea0a0e8cd
golang.org/x/tools v0.25.0
golang.org/x/perf v0.0.0-20241004173025-94b0db8a2472
golang.org/x/pkgsite v0.0.0-20241004190937-78391ec0fb95
golang.org/x/tools v0.26.0
golang.org/x/vuln v1.1.3
mvdan.cc/gofumpt v0.7.0
)
Expand Down Expand Up @@ -153,15 +153,15 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.20.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/telemetry v0.0.0-20240522233618-39ace7a40ae7 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
Loading

0 comments on commit 8fe4f00

Please sign in to comment.