Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat monitoring #33

Merged
merged 3 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
- [Use custom configuration inside service](#use-custom-configuration-inside-service)
- [Integration in an existing medusa project](#integration-in-an-existing-medusa-project)
- [Decorators API](#decorators-api)
- [Monitoring](#monitoring)

# Getting started

Expand Down Expand Up @@ -131,9 +132,14 @@ npm i medusa-extender

> Build a module, export it and share it with the community.

- :chart_with_upwards_trend: Monitor your app

> Using swagger stats you can access all the stats from the ui in your app or
> use the raw stats to show with grafana, elasticsearch or event kibana.

# Demo: Products scoped per store (Marketplace)

[![Video demo: scoped products per store](https://github.com/adrien2p/medusa-extender/blob/assets/assets/readme/store_scoped_demo_thumbnail.png?raw=true)](https://streamable.com/e/oel4vl)
[![Video demo: scoped products per store](https://raw.githubusercontent.com/adrien2p/medusa-extender/assets/assets/readme/store_scoped_demo_thumbnail.png)](https://streamable.com/e/oel4vl)

# Usage

Expand Down Expand Up @@ -587,7 +593,7 @@ medusa migrations run
npm run start
```

## Decorators API
# Decorators API

Here is the list of the provided decorators.

Expand All @@ -602,6 +608,55 @@ Here is the list of the provided decorators.
| `@Migration(/*...*/)` | Decorate a migration |
| `@OnMedusaEntityEvent.\*.\*(/*...*/)`| Can be used to send the right event type or register the handler to an event| `(entity: TEntity, { async? boolean; metatype?: Type<unknown> })`

# Monitoring

If you want to monitor whats going on on your app, you must specify the config
in your `medusa-config` file.

Here are the expected config

```typescript
interface MonitoringOptions {
version?: string;
hostname?: string;
ip?: string;
timelineBucketDuration?: number;
swaggerSpec?: string | OpenAPI.Document;
uriPath: string;
durationBuckets?: number[];
requestSizeBuckets?: number[];
responseSizeBuckets?: number[];
apdexThreshold?: number;
onResponseFinish?: (req: Request, res: Response, next: NextFunction) => void | Promise<void>;
authentication?: boolean;
sessionMaxAge?: number;
elasticsearch?: string;
onAuthenticate?: (req: Request, username: string, password: string) => boolean | Promise<boolean>;
}
```

so your `medusa-config` will looks like

```typescript
import { MonitoringOptions } from 'medusa-extender';

const config = {
/* ... */
monitoring: {
uriPath: '/monitoring'
} as MonitoringOptions,
/* ... */
};
```

Now, run your app and go to /monitoring url to get access to your dashboard.

For more information on the configuration, you can have a look at the [documentation](https://swaggerstats.io/guide/conf.html#options)

## Demo: Monitoring

[![Video demo: scoped products per store](https://raw.githubusercontent.com/adrien2p/medusa-extender/assets/assets/readme/monitoring-ss.png)](https://streamable.com/k3ivnk)

# Contribute :ballot_box:

Contributions are welcome! You can look at the contribution [guidelines](./CONTRIBUTING.md)
59 changes: 57 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ medusa-extender / [Exports](modules.md)
- [Use custom configuration inside service](#use-custom-configuration-inside-service)
- [Integration in an existing medusa project](#integration-in-an-existing-medusa-project)
- [Decorators API](#decorators-api)
- [Monitoring](#monitoring)

# Getting started

Expand Down Expand Up @@ -133,9 +134,14 @@ npm i medusa-extender

> Build a module, export it and share it with the community.

- :chart_with_upwards_trend: Monitor your app

> Using swagger stats you can access all the stats from the ui in your app or
> use the raw stats to show with grafana, elasticsearch or event kibana.

# Demo: Products scoped per store (Marketplace)

[![Video demo: scoped products per store](https://github.com/adrien2p/medusa-extender/blob/assets/assets/readme/store_scoped_demo_thumbnail.png?raw=true)](https://streamable.com/e/oel4vl)
[![Video demo: scoped products per store](https://raw.githubusercontent.com/adrien2p/medusa-extender/assets/assets/readme/store_scoped_demo_thumbnail.png)](https://streamable.com/e/oel4vl)

# Usage

Expand Down Expand Up @@ -589,7 +595,7 @@ medusa migrations run
npm run start
```

## Decorators API
# Decorators API

Here is the list of the provided decorators.

Expand All @@ -604,6 +610,55 @@ Here is the list of the provided decorators.
| `@Migration(/*...*/)` | Decorate a migration |
| `@OnMedusaEntityEvent.\*.\*(/*...*/)`| Can be used to send the right event type or register the handler to an event| `(entity: TEntity, { async? boolean; metatype?: Type<unknown> })`

# Monitoring

If you want to monitor whats going on on your app, you must specify the config
in your `medusa-config` file.

Here are the expected config

```typescript
interface MonitoringOptions {
version?: string;
hostname?: string;
ip?: string;
timelineBucketDuration?: number;
swaggerSpec?: string | OpenAPI.Document;
uriPath: string;
durationBuckets?: number[];
requestSizeBuckets?: number[];
responseSizeBuckets?: number[];
apdexThreshold?: number;
onResponseFinish?: (req: Request, res: Response, next: NextFunction) => void | Promise<void>;
authentication?: boolean;
sessionMaxAge?: number;
elasticsearch?: string;
onAuthenticate?: (req: Request, username: string, password: string) => boolean | Promise<boolean>;
}
```

so your `medusa-config` will looks like

```typescript
import { MonitoringOptions } from 'medusa-extender';

const config = {
/* ... */
monitoring: {
uriPath: '/monitoring'
} as MonitoringOptions,
/* ... */
};
```

Now, run your app and go to /monitoring url to get access to your dashboard.

For more information on the configuration, you can have a look at the [documentation](https://swaggerstats.io/guide/conf.html#options)

## Demo: Monitoring

[![Video demo: scoped products per store](https://raw.githubusercontent.com/adrien2p/medusa-extender/assets/assets/readme/monitoring-ss.png)](https://streamable.com/k3ivnk)

# Contribute :ballot_box:

Contributions are welcome! You can look at the contribution [guidelines](./CONTRIBUTING.md)
29 changes: 22 additions & 7 deletions docs/classes/Medusa.Medusa-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Load medusa and apply all components
### Methods

- [load](Medusa.Medusa-1.md#load)
- [loadMonitoringModuleIfNecessary](Medusa.Medusa-1.md#loadmonitoringmoduleifnecessary)

## Constructors

Expand All @@ -36,7 +37,7 @@ Load medusa and apply all components

#### Defined in

[src/Medusa.ts:36](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/Medusa.ts#L36)
[src/Medusa.ts:38](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/Medusa.ts#L38)

## Properties

Expand All @@ -46,7 +47,7 @@ Load medusa and apply all components

#### Defined in

[src/Medusa.ts:29](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/Medusa.ts#L29)
[src/Medusa.ts:31](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/Medusa.ts#L31)

___

Expand All @@ -56,7 +57,7 @@ ___

#### Defined in

[src/Medusa.ts:30](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/Medusa.ts#L30)
[src/Medusa.ts:32](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/Medusa.ts#L32)

## Methods

Expand All @@ -66,14 +67,28 @@ ___

#### Parameters

| Name | Type |
| :------ | :------ |
| `modules` | [`Constructor`](../modules/types.md#constructor)<`unknown`\>[] |
| Name | Type | Description |
| :------ | :------ | :------ |
| `modules` | [`Constructor`](../modules/types.md#constructor)<`unknown`\>[] | The modules to load into medusa |

#### Returns

`Promise`<`AwilixContainer`<`any`\>\>

#### Defined in

[src/Medusa.ts:44](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/Medusa.ts#L44)
[src/Medusa.ts:46](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/Medusa.ts#L46)

___

### loadMonitoringModuleIfNecessary

▸ `Private` **loadMonitoringModuleIfNecessary**(): `Promise`<`void`\>

#### Returns

`Promise`<`void`\>

#### Defined in

[src/Medusa.ts:76](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/Medusa.ts#L76)
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:42](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L42)
[src/decorators/onMedusaEntityEvent.decorator.ts:42](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L42)

## Properties

Expand All @@ -55,7 +55,7 @@

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:40](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L40)
[src/decorators/onMedusaEntityEvent.decorator.ts:40](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L40)

___

Expand All @@ -65,7 +65,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:39](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L39)
[src/decorators/onMedusaEntityEvent.decorator.ts:39](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L39)

## Accessors

Expand All @@ -79,7 +79,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:50](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L50)
[src/decorators/onMedusaEntityEvent.decorator.ts:50](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L50)

___

Expand All @@ -93,7 +93,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:46](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L46)
[src/decorators/onMedusaEntityEvent.decorator.ts:46](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L46)

## Methods

Expand All @@ -120,7 +120,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:70](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L70)
[src/decorators/onMedusaEntityEvent.decorator.ts:70](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L70)

___

Expand All @@ -146,7 +146,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:58](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L58)
[src/decorators/onMedusaEntityEvent.decorator.ts:58](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L58)

___

Expand All @@ -173,7 +173,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:84](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L84)
[src/decorators/onMedusaEntityEvent.decorator.ts:84](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L84)

___

Expand All @@ -199,7 +199,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:66](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L66)
[src/decorators/onMedusaEntityEvent.decorator.ts:66](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L66)

___

Expand All @@ -226,7 +226,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:77](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L77)
[src/decorators/onMedusaEntityEvent.decorator.ts:77](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L77)

___

Expand All @@ -252,7 +252,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:62](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L62)
[src/decorators/onMedusaEntityEvent.decorator.ts:62](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L62)

___

Expand Down Expand Up @@ -280,7 +280,7 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:91](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L91)
[src/decorators/onMedusaEntityEvent.decorator.ts:91](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L91)

___

Expand All @@ -300,4 +300,4 @@ ___

#### Defined in

[src/decorators/onMedusaEntityEvent.decorator.ts:54](https://github.com/adrien2p/medusa-extender/blob/56af3a5/src/decorators/onMedusaEntityEvent.decorator.ts#L54)
[src/decorators/onMedusaEntityEvent.decorator.ts:54](https://github.com/adrien2p/medusa-extender/blob/ea4bdcd/src/decorators/onMedusaEntityEvent.decorator.ts#L54)
Loading