Skip to content

Commit

Permalink
fix: merge master into v1 (#726)
Browse files Browse the repository at this point in the history
* patch: merge master into v1

* chore: run gofmt

* refactor: rename TOTPSecret->Secret

* fix: adjust application code to align with db schema

Co-authored-by: joel@joellee.org <joel@joellee.org>
  • Loading branch information
J0 and joel@joellee.org committed Oct 4, 2022
1 parent 9929b47 commit b27b85c
Show file tree
Hide file tree
Showing 100 changed files with 3,604 additions and 613 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Docs

on:
workflow_dispatch:

workflow_run:
workflows: [Test]
types: [completed]
branches:
- master

jobs:
docs:
name: Generate Swagger docs
runs-on: ubuntu-20.04
steps:
- name: Generate Swagger UI
uses: Legion2/swagger-ui-action@v1
with:
output: swagger-ui
spec-file: swagger.json

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: swagger-ui
6 changes: 1 addition & 5 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"branches": [
"master",
{
"name": "mfa_v1",
"prerelease": true
},
{
"name": "zerosessionidfix",
"name": "mfa",
"prerelease": true
}
],
Expand Down
22 changes: 13 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@ The following are some basic commands. A full and up to date list of commands ca

Start the containers as described above in an attached state with log output.

``` bash
```bash
make dev
```

### Running tests in the containers

Start the containers with a fresh database and run the project's tests.

``` bash
```bash
make docker-test
```

### Removing the containers

Remove both containers and their volumes. This removes any data associated with the containers.

``` bash
```bash
make docker-clean
```

### Rebuild the containers

Fully rebuild the containers without using any cached layers.

``` bash
```bash
make docker-build
```

Expand Down Expand Up @@ -118,7 +118,11 @@ To complete installation, you will:
2. To install the PostgreSQL Docker image, run:

```
./hack/postgresd.sh
# Builds the postgres image
docker-compose -f docker-compose-dev.yml build postgres
# Runs the postgres container
docker-compose -f docker-compose-dev.yml up postgres
```

You may see a message like:
Expand Down Expand Up @@ -433,7 +437,7 @@ The following commands should help in setting up a database and running the test

```sh
# Runs the database in a docker container
$ ./hack/postgresd.sh
$ docker-compose -f docker-compose-dev.yml up postgres

# Applies the migrations to the database (requires soda cli)
$ make migrate_test
Expand All @@ -452,9 +456,9 @@ In these examples, we change the port from 5432 to 7432.
> Note: This is not recommended, but if you do, please do not check in changes.
```
// file: postgresd.sh
docker run --name gotrue_postgresql
-p 7432:5432 \ 👈 set the first value to your external facing port
// file: docker-compose-dev.yml
ports:
- 7432:5432 \ 👈 set the first value to your external facing port
```

The port you customize here can them be used in the subsequent configuration:
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile.postgres.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM postgres:13
WORKDIR /
RUN pwd
COPY init_postgres.sh /docker-entrypoint-initdb.d/init.sh
RUN chmod +x /docker-entrypoint-initdb.d/init.sh
EXPOSE 5432

CMD ["postgres"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all build deps dev-deps image migrate test vet sec format unused
CHECK_FILES?=./...
FLAGS?=-ldflags "-X github.com/netlify/gotrue/cmd.Version=`git describe --tags`"
FLAGS?=-ldflags "-X github.com/netlify/gotrue/utilities.Version=`git describe --tags`" -buildvcs=false
DEV_DOCKER_COMPOSE:=docker-compose-dev.yml

help: ## Show this help.
Expand All @@ -9,8 +9,8 @@ help: ## Show this help.
all: vet sec static build ## Run the tests and build the binary.

build: deps ## Build the binary.
go build $(FLAGS)
GOOS=linux GOARCH=arm64 go build $(FLAGS) -o gotrue-arm64
CGO_ENABLED=0 go build $(FLAGS)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(FLAGS) -o gotrue-arm64

dev-deps: ## Install developer dependencies
@go install github.com/gobuffalo/pop/soda@latest
Expand Down
109 changes: 90 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ features and capabilities.

Create a `.env` file to store your own custom env vars. See [`example.env`](example.env)

1. Start the local postgres database in a postgres container: `./hack/postgresd.sh`
1. Start the local postgres database in a postgres container: `docker-compose -f docker-compose-dev.yml up postgres`
2. Build the gotrue binary: `make build` . You should see an output like this:

```
Expand Down Expand Up @@ -288,37 +288,108 @@ Controls what log levels are output. Choose from `panic`, `fatal`, `error`, `war

If you wish logs to be written to a file, set `log_file` to a valid file path.

### Opentracing
### Observability

Currently, only the Datadog tracer is supported.
GoTrue has basic observability built in. It is able to export
[OpenTelemetry](https://opentelemetry.io) metrics and traces to a collector.

```properties
GOTRUE_TRACING_ENABLED=true
GOTRUE_TRACING_HOST=127.0.0.1
GOTRUE_TRACING_PORT=8126
GOTRUE_TRACING_TAGS="tag1:value1,tag2:value2"
GOTRUE_SERVICE_NAME="gotrue"
#### Tracing

To enable tracing configure these variables:

`GOTRUE_TRACING_ENABLED` - `boolean`

`GOTRUE_TRACING_EXPORTER` - `string` only `opentracing` (deprecated) and
`opentelemetry` supported

Make sure you also configure the [OpenTelemetry
Exporter](https://opentelemetry.io/docs/reference/specification/protocol/exporter/)
configuration for your collector or service.

For example, if you use
[Honeycomb.io](https://docs.honeycomb.io/getting-data-in/opentelemetry/go-distro/#using-opentelemetry-without-the-honeycomb-distribution)
you should set these standard OpenTelemetry OTLP variables:

```
OTEL_SERVICE_NAME=gotrue
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
OTEL_EXPORTER_OTLP_ENDPOINT=https://api.honeycomb.io:443
OTEL_EXPORTER_OTLP_HEADERS="x-honeycomb-team=<API-KEY>,x-honeycomb-dataset=gotrue"
```

`TRACING_ENABLED` - `bool`
#### Metrics

Whether tracing is enabled or not. Defaults to `false`.
To enable metrics configure these variables:

`TRACING_HOST` - `bool`
`GOTRUE_METRICS_ENABLED` - `boolean`

The tracing destination.
`GOTRUE_METRICS_EXPORTER` - `string` only `opentelemetry` and `prometheus`
supported

`TRACING_PORT` - `bool`
Make sure you also configure the [OpenTelemetry
Exporter](https://opentelemetry.io/docs/reference/specification/protocol/exporter/)
configuration for your collector or service.

The port for the tracing host.
If you use the `prometheus` exporter, the server host and port can be
configured using these standard OpenTelemetry variables:

`TRACING_TAGS` - `string`
`OTEL_EXPORTER_PROMETHEUS_HOST` - IP address, default `0.0.0.0`

`OTEL_EXPORTER_PROMETHEUS_PORT` - port number, default `9100`

The metrics are exported on the `/` path on the server.

If you use the `opentelemetry` exporter, the metrics are pushed to the
collector.

For example, if you use
[Honeycomb.io](https://docs.honeycomb.io/getting-data-in/opentelemetry/go-distro/#using-opentelemetry-without-the-honeycomb-distribution)
you should set these standard OpenTelemetry OTLP variables:

```
OTEL_SERVICE_NAME=gotrue
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
OTEL_EXPORTER_OTLP_ENDPOINT=https://api.honeycomb.io:443
OTEL_EXPORTER_OTLP_HEADERS="x-honeycomb-team=<API-KEY>,x-honeycomb-dataset=gotrue"
```

A comma separated list of key:value pairs. These key value pairs will be added as tags to all opentracing spans.
Note that Honeycomb.io requires a paid plan to ingest metrics.

If you need to debug an issue with traces or metrics not being pushed, you can
set `DEBUG=true` to get more insights from the OpenTelemetry SDK.

#### Custom resource attributes

When using the OpenTelemetry tracing or metrics exporter you can define custom
resource attributes using the [standard `OTEL_RESOURCE_ATTRIBUTES` environment
variable](https://opentelemetry.io/docs/reference/specification/resource/sdk/#specifying-resource-information-via-an-environment-variable).

A default attribute `gotrue.version` is provided containing the build version.

#### Tracing HTTP routes

All HTTP calls to the GoTrue API are traced. Routes use the parametrized
version of the route, and the values for the route parameters can be found as
the `http.route.params.<route-key>` span attribute.

For example, the following request:

```
GET /admin/users/4acde936-82dc-4552-b851-831fb8ce0927/
```

will be traced as:

```
http.method = GET
http.route = /admin/users/{user_id}
http.route.params.user_id = 4acde936-82dc-4552-b851-831fb8ce0927
```

`SERVICE_NAME` - `string`
#### Go runtime and HTTP metrics

The name to use for the service.
All of the Go runtime metrics are exposed. Some HTTP metrics are also collected
by default.

### JSON Web Tokens (JWT)

Expand Down
Loading

0 comments on commit b27b85c

Please sign in to comment.