Skip to content

Commit

Permalink
improve traces and http executions
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Nov 10, 2024
1 parent b5b189b commit 16b892a
Show file tree
Hide file tree
Showing 59 changed files with 2,638 additions and 264 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ go.work.sum

# Release directory
release/
_output/
_output/
schema.output.json
22 changes: 21 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,24 @@ ci-build-cli: clean
go run github.com/mitchellh/gox -ldflags '-X github.com/hasura/ndc-rest/ndc-rest-schema/version.BuildVersion=$(VERSION) -s -w -extldflags "-static"' \
-osarch="linux/amd64 darwin/amd64 windows/amd64 darwin/arm64 linux/arm64" \
-output="../$(OUTPUT_DIR)/ndc-rest-schema-{{.OS}}-{{.Arch}}" \
.
.

.PHONY: generate-test-config
generate-test-config:
go run ./ndc-rest-schema update -d ./tests/configuration

.PHONY: start-ddn
start-ddn:
HASURA_DDN_PAT=$$(ddn auth print-pat) docker compose --env-file tests/engine/.env up --build -d

.PHONY: stop-ddn
stop-ddn:
docker compose down --remove-orphans

.PHONY: build-supergraph-test
build-supergraph-test:
docker compose up -d --build ndc-rest
cd tests/engine && \
ddn connector-link update myapi --add-all-resources --subgraph ./app/subgraph.yaml && \
ddn supergraph build local
make start-ddn
68 changes: 54 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ files:
The config of each element follows the [config schema](https://github.com/hasura/ndc-rest/ndc-rest-schema/blob/main/config.example.yaml) of `ndc-rest-schema`.

You can add many OpenAPI files into the same connector.

> [!IMPORTANT]
> Conflicted object and scalar types will be ignored. Only the type of the first file is kept in the schema.

Expand All @@ -64,29 +66,67 @@ ndc-rest-schema convert -f ./rest/testdata/jsonplaceholder/swagger.json -o ./res
- `text/*`
- Upload file content types, e.g.`image/*` from `base64` arguments.

### Environment variable template
### Authentication

The connector can replaces `{{xxx}}` templates with environment variables. The converter automatically renders variables for API keys and tokens when converting OpenAPI documents. However, you can add your custom variables as well.
The current version supports API key and Auth token authentication schemes. The configuration is inspired from `securitySchemes` [with env variables](https://github.com/hasura/ndc-rest/ndc-rest-schema#authentication). The connector supports the following authentication strategies:

### Timeout and retry
- API Key
- Bearer Auth
- Cookies
- OAuth 2.0

The configuration automatically generates environment variables for the api key and Bearer token.

For Cookie authentication and OAuth 2.0, you need to enable headers forwarding from the Hasura engine to the connector.

The global timeout and retry strategy can be configured in the `settings` object.
### Header Forwarding

Enable `forwardHeaders` in the configuration file.

```yaml
settings:
timeout: 30
retry:
times: 2
# delay between each retry in milliseconds
delay: 1000
httpStatus: [429, 500, 502, 503]
# ...
forwardHeaders:
enabled: true
argumentField: headers
```

### Authentication
And configure in the connector link metadata.

```yaml
kind: DataConnectorLink
version: v1
definition:
name: my_api
# ...
argumentPresets:
- argument: headers
value:
httpHeaders:
forward:
- Cookie
additional: {}
```

See the configuration example in [Hasura docs](https://hasura.io/docs/3.0/recipes/business-logic/http-header-forwarding/#step-2-update-the-metadata-1).

### Timeout and retry

The current version supports API key and Auth token authentication schemes. The configuration is inspired from `securitySchemes` [with env variables](https://github.com/hasura/ndc-rest/ndc-rest-schema#authentication)
The global timeout and retry strategy can be configured in each file:

See [this example](rest/testdata/auth/schema.yaml) for more context.
```yaml
files:
- file: swagger.json
spec: oas2
timeout:
value: 30
retry:
times:
value: 1
delay:
# delay between each retry in milliseconds
value: 500
httpStatus: [429, 500, 502, 503]
```

## Distributed execution

Expand Down
15 changes: 15 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include:
- tests/engine/compose.yaml
services:
ndc-rest:
build:
context: .
ports:
- 8080:8080
volumes:
- ./tests/configuration:/etc/connector:ro
extra_hosts:
- local.hasura.dev=host-gateway
environment:
OTEL_EXPORTER_OTLP_ENDPOINT: http://local.hasura.dev:4317
HASURA_LOG_LEVEL: debug
2 changes: 1 addition & 1 deletion connector-definition/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
rest: 5
files:
- file: https://raw.githubusercontent.com/hasura/ndc-rest/main/connector/testdata/jsonplaceholder/swagger.json
spec: openapi2
spec: oas2
timeout:
value: 30
retry:
Expand Down
5 changes: 4 additions & 1 deletion connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ func (c *RESTConnector) ParseConfiguration(ctx context.Context, configurationDir
Query: schema.QueryCapabilities{
Variables: schema.LeafCapability{},
NestedFields: schema.NestedFieldCapabilities{},
Explain: schema.LeafCapability{},
},
Mutation: schema.MutationCapabilities{
Explain: schema.LeafCapability{},
},
Mutation: schema.MutationCapabilities{},
},
}
rawCapabilities, err := json.Marshal(restCapabilities)
Expand Down
Loading

0 comments on commit 16b892a

Please sign in to comment.