Skip to content

Commit

Permalink
[automated commit] Bump docs to version 1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
leorossi authored and github-actions[bot] committed Oct 25, 2023
1 parent 3705db4 commit 7dc48c2
Show file tree
Hide file tree
Showing 145 changed files with 271 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ We'll see that this has generated a new directory, `clients/people/`, which cont
}
```

This configuration will make the People service client available as `request.people` inside any plugins that we create for our Media service.
This configuration will make the People service client available as `app.people` inside any plugins that we create for our Media service.

To create the skeleton structure for our plugin, let's create a new file, `services/media-service/plugin.js`, and add the following code:

Expand Down Expand Up @@ -904,7 +904,7 @@ function buildOnComposerResponseCallback (peopleProps) {
}
}

const people = await request.people.getPeople({ "where.id.in": peopleIds.join(',') })
const people = await app.people.getPeople({ "where.id.in": peopleIds.join(',') })

const getPersonNameById = (id) => {
const person = people.find(person => person.id === id)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions versioned_docs/version-1.6.1/guides/logging-to-elasticsearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logging to ElasticSearch (or any other destination)

This guide shows how to configure a Platformatic application to
deliver logs to [ElasticSearch](https://www.elastic.co/elasticsearch/)
or via any other supported [transports](https://getpino.io/#/docs/transports).
The logs will then be visualized via [Kibana](https://www.elastic.co/kibana).

## Create a platformatic application

Create a platformatic application using `npx create-platformatic@latest`.

## Setup ElasticSearch and Kibana

If you are logging to ElasticSearch and visualizing with Kibana,
you might want to set it up using [Docker Compose](https://docs.docker.com/compose/)
for local testing.

Write the following as `docker-compose.yml`:

```yaml
---
version: '3.8'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.3.3
environment:
- discovery.type=single-node
# Elasticsearch 8.x has HTTPS and auth on by default. This option is
# needed to use HTTP and no auth (as used in the tests).
- xpack.security.enabled=false
container_name: elasticsearch
ports: ['9200:9200']

kibana:
image: docker.elastic.co/kibana/kibana:8.3.3
container_name: kibana
ports: ['5601:5601']
depends_on: ['elasticsearch']
```
Then, start ElasticSearch and Kibana with `docker-compose -f docker-compose.yml up`.

## Install transport

```bash
npm i pino-elasticsearch
```

## Configure Logger Transport

Configuring your platformatic application to log to ElasticSearch is straighforward,
you just have to configure it like the following:

```json
{
...
"server": {
"hostname": "{PLT_SERVER_HOSTNAME}",
"port": "{PORT}",
"logger": {
"level": "{PLT_SERVER_LOGGER_LEVEL}",
"transport": {
"targets": [{
"target": "pino-elasticsearch",
"options": {
"node": "http://127.0.0.1:9200"
}
}, {
"target": "pino-pretty"
}]
}
}
}
}
```

This snippet can be applied either to the `platformatic.runtime.json` config
for Platformatic Runtime applications, or as part of the applicaiton configuration
for any other application.

This setup will allow you to log both to the terminal (TTY)
and to ElasticSearch at the same time.

Start your server with `platformatic start`, and navigate across
its API.

## Configure Kibana

1. Open `http://localhost:5601` in your browser
2. Click on the hamburger menu on top left, and then "Discover"

![Kibana start page](./images/kibana-1.png)

3. Click on the "Create Data View"

![Create a Data View](./images/kibana-2.png)

4. Write `pino*` as `name` and select `time` as timestamp field

![Select an index](./images/kibana-3.png)

5. Enjoy your logs

![Browse logs](./images/kibana-4.png)
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,47 @@ Edit your app's `platformatic.service.json` to load your root plugin:
"paths": [{
"path": "./root-plugin.js",
"encapsulate": false
}],
"hotReload": false
},
"watch": false
}]
}
}
```

These settings are important when using `@fastify/express` in a Platformatic Service app:

- `encapsulate` — You'll need to disable encapsulation for any Fastify plugin which mounts Express routes. This is due to the way that `@fastify/express` works.
- `hotReload` and `watch` — You'll need to disable hot reloading and watching for your app, as they don't currently work when using `@fastify/express`. This is a known issue that we're working to fix.

### Using @fastify/express with Platformatic Runtime

If you are using [Platformatic Runtime](/reference/runtime/introduction.md), you must configure your other services to connect to this one using an actual TCP socket
instead of the virtual network.

Edit your app's `platformatic.runtime.json` and add the `useHttp` option:

```json
{
"$schema": "https://platformatic.dev/schemas/v1.3.0/runtime",
"entrypoint": "b",
"autoload": {
"path": "./services",
"mappings": {
"myexpressservice": {
"id": "a",
"config": "platformatic.service.json",
"useHttp": true
}
}
},
"server": {
"hostname": "127.0.0.1",
"port": 3000,
"logger": {
"level": "info"
}
}
}
```

Where the Platformatic Service using express is located at `./services/myexpressservice`.

## Wrapping up

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,47 @@ Options:
> :information_source:
>
> When deploying an application to a ***dynamic workspace***, specify the deploy `--label` option. You can find it on your cloud dashboard or you can specify a new one.
>
> If you do not specify an environment file to use with the `-e` flag, **ensure that a default environment file named `.env` exists**.
Deploy a **static** Platformatic Cloud application.

```bash
platformatic deploy \
-t static \
-c platformatic.db.json \
-e .env.prototype \
--workspace-id=00000000-0000-0000-0000-000000000000 \
--workspace-key=11111111111111111111111111111111
```

Deploy a **static** Platformatic Cloud application with a workspace keys file. The keys file can be downloaded from the Platformatic Console when generating a new API key.

```bash
platformatic deploy \
-t static \
-c platformatic.db.json \
-k foo.plt.txt
```

The `foo.plt.txt` must contain two variables for the workspace id and workspace API key.

```
# Contents of foo.plt.txt
PLATFORMATIC_STATIC_WORKSPACE_ID=00000000-0000-0000-0000-000000000000
PLATFORMATIC_STATIC_WORKSPACE_API_KEY=11111111111111111111111111111111
```

Deploy a **dynamic** Platformatic Cloud application.

```bash
platformatic deploy \
-t dynamic \
-c platformatic.db.json \
-l dev \
--workspace-id=00000000-0000-0000-0000-000000000000 \
--workspace-key=11111111111111111111111111111111
```


#### gh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can use the client in your application in Javascript, calling a GraphQL endp
/** @type {import('fastify').FastifyPluginAsync<{} */
module.exports = async function (app, opts) {
app.post('/', async (request, reply) => {
const res = await app.myclient.graphql({
const res = await request.myclient.graphql({
query: 'query { movies { title } }'
})
return res
Expand All @@ -48,8 +48,8 @@ import { FastifyInstance } from 'fastify'
/// <reference path="./myclient" />

export default async function (app: FastifyInstance) {
app.get('/', async () => {
return app.myclient.get({})
app.get('/', async (request, reply) => {
return requests.myclient.get({})
})
}
```
Expand Down Expand Up @@ -323,7 +323,7 @@ module.exports = async function (app, opts) {
})

app.post('/', async (request, reply) => {
const res = await app.myclient.graphql({
const res = await request.myclient.graphql({
query: 'query { movies { title } }'
})
return res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,18 @@ that presented the `adminSecret` to perform any operation on any entity:
"save": false
}
```

## Custom authorization strategies

You can create your own authorization strategy using a `addAuthStrategy` function. `addAuthStrategy` accepts a strategy `name` and a `createSession` function as a params. `createSession` function should set `request.user` object. All custom strategies will be executed after `jwt` and `webhook` default strategies.

_Example_

```js
app.addAuthStrategy({
name: 'custom-auth-strategy',
createSession: async (req, reply) => {
req.user = { id: 42, role: 'admin' }
}
})
```
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ A **required** object with the following settings:
}
```

Enables GraphQL support with the `enabled` option

```json
{
"db": {
...
"graphql": {
...
"enabled": true
}
}
}
```

Enables GraphQL support with GraphiQL

```json
Expand Down Expand Up @@ -165,6 +179,20 @@ A **required** object with the following settings:
}
```

Enables OpenAPI using the `enabled` option

```json
{
"db": {
...
"openapi": {
...
"enabled": true
}
}
}
```

Enables OpenAPI with prefix

```json
Expand Down Expand Up @@ -295,6 +323,20 @@ A **required** object with the following settings:

_Examples_

Enable events using the `enabled` option.

```json
{
"db": {
...
"events": {
...
"enabled": true
}
}
}
```

```json
{
"db": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ these default values.
microservice ID.
- **`config` (**required**, `string`) - The overridden configuration file
name. This is the file that will be used when starting the microservice.
- **`useHttp`** (`boolean`) - The service will be started on a random HTTP port
on `127.0.0.1`, and exposed to the other services via that port; set it to `true`
if you are using [@fastify/express](https://github.com/fastify/fastify-express).
Default: `false`.

### `services`

Expand All @@ -83,6 +87,10 @@ property or the `name` field in the client's `package.json` file if a
the microservice.
- **`config`** (**required**, `string`) - The configuration file used to start
the microservice.
- **`useHttp`** (`boolean`) - The service will be started on a random HTTP port
on `127.0.0.1`, and exposed to the other services via that port; set it to `true`
if you are using [@fastify/express](https://github.com/fastify/fastify-express).
Default: `false`.

### `entrypoint`

Expand All @@ -103,6 +111,8 @@ While hot reloading is useful for development, it is not recommended for use in
production.
:::

Note that `watch` should be enabled for each individual service in the runtime.

### `allowCycles`

An optional boolean, defaulting to `false`, indicating if dependency cycles
Expand Down
Loading

0 comments on commit 7dc48c2

Please sign in to comment.