Skip to content

Commit

Permalink
Resolve merge conflicts (#63)
Browse files Browse the repository at this point in the history
* Add tests for `sort` and `find` parameters type (FerretDB#544)

Refs #164.

* Prepare v0.2.0 release

* Bump go.mongodb.org/mongo-driver from 1.9.0 to 1.9.1 in /integration (FerretDB#555)

Bumps [go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/mongodb/mongo-go-driver/releases)
- [Commits](mongodb/mongo-go-driver@v1.9.0...v1.9.1)

---
updated-dependencies:
- dependency-name: go.mongodb.org/mongo-driver
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add missing `//nolint` (FerretDB#556)

* Set the handler to use via a command-line flag and remove debug handlers from interface (FerretDB#534)

Closes FerretDB#455.

* Add tests for `RemoveByPath` (FerretDB#549)

Closes FerretDB#479.

* Add `altMessage` to `AssertEqualError` (FerretDB#550)

* Add documentation for values comparision (FerretDB#559)

Refs FerretDB#457.

* Add `debug` and `panic` msg handlers to `Command` map (FerretDB#561)

Refs FerretDB#455.

* Add `RemoveByPath` for `Array` and `CompositeTypeInterface` (FerretDB#560)

Closes FerretDB#479.

* Bump docker/login-action from 1 to 2 (FerretDB#565)

Bumps [docker/login-action](https://github.com/docker/login-action) from 1 to 2.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](docker/login-action@v1...v2)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add conform CI workflow, improve docs (FerretDB#566)

Co-authored-by: Dmitry <dmitry.eremenko@ferretdb.io>
Co-authored-by: Alexey Palazhchenko <alexey.palazhchenko@ferretdb.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 9, 2022
2 parents 5b4719b + 63bd2ee commit 9443dc6
Show file tree
Hide file tree
Showing 46 changed files with 1,628 additions and 1,102 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/conform-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Conform PR
on:
pull_request:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
# List all types to make it easier to enable new ones when they are needed.
types:
# - assigned
# - unassigned
# - labeled
# - unlabeled
- opened
- edited
# - closed
- reopened
- synchronize
# - converted_to_draft
# - ready_for_review
# - locked
# - unlocked
# - review_requested
# - review_request_removed
# - auto_merge_enabled
# - auto_merge_disabled

# Stop pending and in-progress jobs of this workflow.
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-only-cancel-in-progress-jobs-or-runs-for-the-current-workflow
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
conform-pr:
name: Conform PR
runs-on: ubuntu-20.04

steps:
- name: Conform PR
uses: FerretDB/github-actions/conform-pr@main
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
uses: FerretDB/github-actions/extract-docker-tag@main

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand Down
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,61 @@
# Changelog

## [v0.2.0](https://github.com/FerretDB/FerretDB/releases/tag/v0.2.0) (2022-05-04)

### What's Changed

This release implements all required functionality to support [CLA Assistant](https://github.com/cla-assistant/cla-assistant).
More details will be available shortly in [our blog](https://www.ferretdb.io/blog/).

### New Features 🎉
* Add support for `$nin` operator by @ribaraka in https://github.com/FerretDB/FerretDB/pull/459
* Support querying with dot notation for documents by @GinGin3203 in https://github.com/FerretDB/FerretDB/pull/483
* Add support for `$ne` operator by @ribaraka in https://github.com/FerretDB/FerretDB/pull/464
* Add basic `findAndModify` implementation by @AlekSi in https://github.com/FerretDB/FerretDB/pull/501
* Add support for `$in` operator by @ribaraka in https://github.com/FerretDB/FerretDB/pull/499

### Fixed Bugs 🐛
* Fix large numbers comparision by @DoodgeMatvey in https://github.com/FerretDB/FerretDB/pull/466
* Fix panic on receiving a filter query with unknown operator by @GinGin3203 in https://github.com/FerretDB/FerretDB/pull/517
* Fix bitwise operators by @w84thesun in https://github.com/FerretDB/FerretDB/pull/488

### Enhancements 🛠
* Return better errors for unimplemented operations by @AlekSi in https://github.com/FerretDB/FerretDB/pull/504
* Implement `nameOnly` for `listDatabases` by @AlekSi in https://github.com/FerretDB/FerretDB/pull/524
* Improve `hostInfo` command's `os` response by @DoodgeMatvey in https://github.com/FerretDB/FerretDB/pull/509

### Documentation 📄
* Mention force pushes by @AlekSi in https://github.com/FerretDB/FerretDB/pull/500
* Update guidelines by @seeforschauer in https://github.com/FerretDB/FerretDB/pull/496
* Document `task env-pull` target by @AlekSi in https://github.com/FerretDB/FerretDB/pull/528

### Other Changes 🤖
* Stabilize tests by always sorting results by @AlekSi in https://github.com/FerretDB/FerretDB/pull/490
* Skip one test for now by @AlekSi in https://github.com/FerretDB/FerretDB/pull/494
* Bump MongoDB version by @AlekSi in https://github.com/FerretDB/FerretDB/pull/495
* Use `goimports` to group imports on `task fmt` by @AlekSi in https://github.com/FerretDB/FerretDB/pull/498
* Make default Docker arguments a bit more useful by @AlekSi in https://github.com/FerretDB/FerretDB/pull/502
* Export helpers that will be used in other package by @AlekSi in https://github.com/FerretDB/FerretDB/pull/505
* Correctly override `FUZZTIME` on CI by @AlekSi in https://github.com/FerretDB/FerretDB/pull/506
* Pass context to PostgreSQL pool by @AlekSi in https://github.com/FerretDB/FerretDB/pull/507
* Bump dependencies by @AlekSi in https://github.com/FerretDB/FerretDB/pull/514
* Remove `Array.Subslice` method by @AlekSi in https://github.com/FerretDB/FerretDB/pull/515
* Remove `types.CString` by @AlekSi in https://github.com/FerretDB/FerretDB/pull/529
* Make test helpers harder to misuse by @AlekSi in https://github.com/FerretDB/FerretDB/pull/530
* Move existing comparision code to `types` by @AlekSi in https://github.com/FerretDB/FerretDB/pull/531
* Extract common interface for handlers by @seeforschauer in https://github.com/FerretDB/FerretDB/pull/521
* Move all handler test to integration tests by @w84thesun in https://github.com/FerretDB/FerretDB/pull/523
* Use `nil` errors instead of empty values by @fenogentov in https://github.com/FerretDB/FerretDB/pull/542
* Delete old tests by @AlekSi in https://github.com/FerretDB/FerretDB/pull/543
* Add tests for `sort` and `find` parameters type by @w84thesun in https://github.com/FerretDB/FerretDB/pull/544

## New Contributors
* @DoodgeMatvey made their first contribution in https://github.com/FerretDB/FerretDB/pull/466

[All closed issues and pull requests](https://github.com/FerretDB/FerretDB/milestone/14?closed=1).
[All commits](https://github.com/FerretDB/FerretDB/compare/v0.1.1...v0.2.0).


## [v0.1.1](https://github.com/FerretDB/FerretDB/releases/tag/v0.1.1) (2022-04-19)

### New Features 🎉
Expand Down
96 changes: 78 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,33 @@

Thank you for your interest in making FerretDB better!

## Finding something to work on

We are interested in all contributions, big or small, in code or documentation.
But unless you are fixing a very small issue like a typo,
we kindly ask you first to [create an issue](https://github.com/FerretDB/FerretDB/issues/new/choose),
to leave a comment on an existing issue if you want to work on it,
or to [join our Slack chat](./README.md#community) and leave a message for us there.
This way, you will get help from us and avoid wasted efforts if something can't be worked on right now
or someone is already working on it.

You can find a list of good issues for first-time contributors [there](https://github.com/FerretDB/FerretDB/contribute).

## Contributing code

The supported way of developing FerretDB is to modify and run it on the host (Linux, macOS, or Windows with [WSL2](https://docs.microsoft.com/en-us/windows/wsl/)), with PostgreSQL and other dependencies running inside Docker Compose.
The supported way of developing FerretDB is to modify and run it on the host
(Linux, macOS, or Windows with [WSL2](https://docs.microsoft.com/en-us/windows/wsl/)),
with PostgreSQL and other dependencies running inside Docker Compose.

You will need Go 1.18 as FerretDB extensively uses ([fuzzing](https://go.dev/doc/tutorial/fuzz)) and [generics](https://go.dev/doc/tutorial/generics)).
If your package manager does not provide it yet, please install it from [go.dev](https://go.dev/dl/).
You will need Go 1.18 as FerretDB extensively uses ([fuzzing](https://go.dev/doc/tutorial/fuzz))
and [generics](https://go.dev/doc/tutorial/generics)).
If your package manager doesn't provide it yet,
please install it from [go.dev](https://go.dev/dl/).

### Cloning the Repository

After forking FerretDB on GitHub, you can clone the repository:
After [forking FerretDB on GitHub](https://github.com/FerretDB/FerretDB/fork),
you can clone the repository:

```sh
git clone git@github.com:<YOUR_GITHUB_USERNAME>/FerretDB.git
Expand All @@ -24,8 +41,11 @@ git remote add upstream https://github.com/FerretDB/FerretDB.git
To run development commands, you should first install the [`task`](https://taskfile.dev/) tool.
You can do this by changing the directory to `tools` (`cd tools`) and running `go generate -x`.
That will install `task` into the `bin` directory (`bin/task` on Linux and macOS, `bin\task.exe` on Windows).
You can then add `./bin` to `$PATH` either manually (`export PATH=./bin:$PATH` in `bash`) or using something like (`direnv` (`.envrc` files)[https://direnv.net], or replace every invocation of `task` with explicit `bin/task`.
You can also [install `task` globally](https://taskfile.dev/#/installation), but that might lead to the version skew.
You can then add `./bin` to `$PATH` either manually (`export PATH=./bin:$PATH` in `bash`)
or using something like (`direnv` (`.envrc` files)[https://direnv.net],
or replace every invocation of `task` with explicit `bin/task`.
You can also [install `task` globally](https://taskfile.dev/#/installation),
but that might lead to the version skew.

With `task` installed, you may do the following:

Expand All @@ -39,16 +59,14 @@ With `task` installed, you may do the following:
The differences in response are then logged and the FerretDB response is sent back to the client.
6. Run `mongosh` with `task mongosh`.
This allows you to run commands against FerretDB.
7. Change the code.
8. Run `task fmt` to format source code.
9. Run `task lint` to run linter checks.

You can see all available `task` tasks with `task -l`.

### Code Overview

Package `cmd` provides commands implementation. `ferretdb` is the main FerretDB binary; others are tools for development.

Package `cmd` provides commands implementation.
`ferretdb` is the main FerretDB binary; others are tools for development.
s
Package `tools` uses "tools.go" approach to fix tools versions.
They are installed into `bin/` by `cd tools; go generate -x`.

Expand All @@ -69,18 +87,60 @@ They are installed into `bin/` by `cd tools; go generate -x`.
all data is represented as built-in and `types` types.

Those packages are tested by "unit" tests that are placed inside those packages.
Some of them are truly hermetic and test only the package that contains them; you can run those "short" tests with `go test -short` or `task test-unit-short`, but that's typically not required.
Other unit tests use real databases; you can run those with `task test-unit` after starting the environment as described above.

We also have a set of "integration" tests in `integration` Go module that uses the Go MongoDB driver and tests either a running MongoDB-compatible database (such as FerretDB or MongoDB itself) or in-process FerretDB.
Some of them are truly hermetic and test only the package that contains them;
you can run those "short" tests with `go test -short` or `task test-unit-short`,
but that's typically not required.
Other unit tests use real databases;
you can run those with `task test-unit` after starting the environment as described above.

We also have a set of "integration" tests in `integration` Go module that uses the Go MongoDB driver
and tests either a running MongoDB-compatible database (such as FerretDB or MongoDB itself)
or in-process FerretDB.
They allow us to ensure compatibility between FerretDB and MongoDB.
You can run them with `task test-integration-ferretdb` for in-process FerretDB (meaning that integration tests start and stop FerretDB themselves), `task test-integration-mongodb` for MongoDB running on port 37017 (as in our development environment), or `task test-integration` to run both in parallel.
You can run them with `task test-integration-ferretdb` for in-process FerretDB
(meaning that integration tests start and stop FerretDB themselves),
`task test-integration-mongodb` for MongoDB running on port 37017 (as in our development environment),
or `task test-integration` to run both in parallel.

Finally, you may run all tests in parallel with `task test`.
If tests fail and the output is too confusing, try running them sequentially by using the commands above.

In general, we prefer integration tests over unit tests, tests using real databases over short tests and real objects over mocks.
In general, we prefer integration tests over unit tests,
tests using real databases over short tests
and real objects over mocks.

(You might disagree with our terminology for "unit" and "integration" tests; let's not fight over it.)
(You might disagree with our terminology for "unit" and "integration" tests;
let's not fight over it.)

We have an additional integration testing system in another repository: <https://github.com/FerretDB/dance>.

### Code style and conventions

Above everything else, we value consistency in the source code.
If you see some code that doesn't follow some best practice but is consistent,
please keep it that way;
but please also tell us about it, so we can improve all of it.
If, on the other hand, you see code that is inconsistent without apparent reason (or comment),
please improve it as you work on it.

Our code most of the standard Go conventions,
documented on [CodeReviewComments wiki page](https://github.com/golang/go/wiki/CodeReviewComments).
Some of our idiosyncrasies:

1. We use type switches over BSON types in many places in our code.
The order of `case`s follows this order: <https://pkg.go.dev/github.com/FerretDB/FerretDB/internal/types#hdr-Mapping>
It may seem random, but it is only pseudo-random and follows BSON spec: <https://bsonspec.org/spec.html>

### Submitting code changes

Before submitting a pull request, please make sure that:

1. Tests are added for new functionality or fixed bugs.
2. Code is regenerated if needed (`task gen`).
3. Code is formatted (`task fmt`).
4. Test pass (`task test`).
5. Linters pass (`task lint`).

## Contributing documentation

Please format documentation with `task docs-fmt`.
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
# FerretDB

[![Go](https://github.com/FerretDB/FerretDB/actions/workflows/go.yml/badge.svg)](https://github.com/FerretDB/FerretDB/actions/workflows/go.yml)
[![Integration](https://github.com/FerretDB/FerretDB/actions/workflows/integration.yml/badge.svg)](https://github.com/FerretDB/FerretDB/actions/workflows/integration.yml)
[![Docker](https://github.com/FerretDB/FerretDB/actions/workflows/docker.yml/badge.svg)](https://github.com/FerretDB/FerretDB/actions/workflows/docker.yml)
[![Go](https://github.com/FerretDB/FerretDB/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/FerretDB/FerretDB/actions/workflows/go.yml)
[![Integration](https://github.com/FerretDB/FerretDB/actions/workflows/integration.yml/badge.svg?branch=main)](https://github.com/FerretDB/FerretDB/actions/workflows/integration.yml)
[![Docker](https://github.com/FerretDB/FerretDB/actions/workflows/docker.yml/badge.svg?branch=main)](https://github.com/FerretDB/FerretDB/actions/workflows/docker.yml)
[![codecov](https://codecov.io/gh/FerretDB/FerretDB/branch/main/graph/badge.svg?token=JZ56XFT3DM)](https://codecov.io/gh/FerretDB/FerretDB)

FerretDB (previously MangoDB) was founded to become the de-facto open-source substitute to MongoDB.
FerretDB is an open-source proxy, converting the MongoDB wire protocol queries to SQL - using PostgreSQL as a database engine.

## Why do we need FerretDB?

MongoDB was originally an eye-opening technology for many of us developers, empowering us to build applications faster
than using relational databases. In its early days, its ease-to-use and well-documented drivers made MongoDB one of the
simplest database solutions available. However, as time passed, MongoDB abandoned its open-source roots; changing the
license to SSPL - making it unusable for many open source and early stage commercial projects.
MongoDB was originally an eye-opening technology for many of us developers,
empowering us to build applications faster than using relational databases.
In its early days, its ease-to-use and well-documented drivers made MongoDB one of the simplest database solutions available.
However, as time passed, MongoDB abandoned its open-source roots;
changing the license to SSPL - making it unusable for many open source and early-stage commercial projects.

Most MongoDB users are not in need of many advanced features offered by MongoDB; however, they are in need of an easy
to use open-source database solution. Recognizing this, FerretDB is here to fill that gap.
Most MongoDB users do not require any advanced features offered by MongoDB;
however, they need an easy-to-use open-source database solution.
Recognizing this, FerretDB is here to fill that gap.

## Scope
## Scope and current state

FerretDB will be compatible with MongoDB drivers and will strive to serve as a drop-in replacement for MongoDB.

## Current state
Currently, the project is in its early stages and welcomes all contributors.
See our [public roadmap](https://github.com/orgs/FerretDB/projects/2/views/1)
and [contributing guidelines](CONTRIBUTING.md).

What you see here is a tech demo - intended to show a proof of concept.
Over the next couple of months we will be adding more.
See [this example](https://github.com/FerretDB/example) for a short demonstration.
### Known differences

FerretDB is in its very early stages and welcomes all contributors.
See our [CONTRIBUTING.md](CONTRIBUTING.md).
1. FerretDB uses the same protocol error names and codes, but the exact error messages may be different in some cases.

If you encounter some other difference in behavior, please [join our community](#community) to report a problem.

## Quickstart

Expand Down
16 changes: 12 additions & 4 deletions cmd/envtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
"go.uber.org/zap"

"github.com/FerretDB/FerretDB/internal/clientconn"
"github.com/FerretDB/FerretDB/internal/handlers/common"
"github.com/FerretDB/FerretDB/internal/handlers/pg"
"github.com/FerretDB/FerretDB/internal/handlers/pg/pgdb"
"github.com/FerretDB/FerretDB/internal/util/debug"
"github.com/FerretDB/FerretDB/internal/util/logging"
Expand Down Expand Up @@ -158,7 +160,7 @@ func setupMongoDB(ctx context.Context) {
logger.Infof("Done in %s.", time.Since(start))
}

func setupMonilaAndValues(ctx context.Context, pgPool *pgdb.Pool) {
func setupMonilaAndValues(ctx context.Context, handler common.Handler) {
start := time.Now()
logger := zap.S().Named("postgres.monila_and_values")

Expand All @@ -171,10 +173,10 @@ func setupMonilaAndValues(ctx context.Context, pgPool *pgdb.Pool) {
addr = "127.0.0.1:27018"
}

l := clientconn.NewPgListener(&clientconn.NewListenerOpts{
l := clientconn.NewListener(&clientconn.NewListenerOpts{
ListenAddr: addr,
Mode: "normal",
PgPool: pgPool,
Handler: handler,
Logger: logger.Desugar(),
})

Expand Down Expand Up @@ -348,6 +350,12 @@ func run(ctx context.Context, logger *zap.SugaredLogger) error {
if err != nil {
return err
}
handlerOpts := &pg.NewOpts{
PgPool: pgPool,
L: logger.Desugar(),
StartTime: time.Now(),
}
h := pg.New(handlerOpts)

for _, db := range []string{`monila`, `values`, `test`} {
if err := pgPool.CreateSchema(ctx, db); err != nil {
Expand All @@ -364,7 +372,7 @@ func run(ctx context.Context, logger *zap.SugaredLogger) error {
wg.Add(1)
go func() {
defer wg.Done()
setupMonilaAndValues(ctx, pgPool)
setupMonilaAndValues(ctx, h)
}()

wg.Wait()
Expand Down
Loading

0 comments on commit 9443dc6

Please sign in to comment.