Skip to content

Commit

Permalink
[ISSUE #113] Optimize Webhook doc and add updateWebHookConfig endpoint (
Browse files Browse the repository at this point in the history
#118)

* Remove redundant zh doc files.

* Fix webhook zh doc not displayed (need translation)

* Optimize Webhook zh doc format and typos

* Optimize Webhook en doc

* Add updateWebHookConfig endpoint and optimize en titles
  • Loading branch information
Pil0tXia committed Aug 28, 2023
1 parent fec7ea7 commit a334001
Show file tree
Hide file tree
Showing 5 changed files with 366 additions and 388 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Use Webhook to subscribe events

## Webhook usage process
#### The first step: Configure webhook related information in eventmesh and start

##### Configuration
### The first step: Configure Webhook related information in eventmesh and start

Configuration:

```
# Whether to start the webhook admin service
# Whether to start the Webhook admin service
eventMesh.webHook.admin.start=true
# webhook event configuration storage mode. But currently only supports file and nacos
# Webhook event configuration storage mode. But currently only supports file and nacos
eventMesh.webHook.operationMode=file
# The file path of fileMode. If you write #{eventMeshHome}, in the eventMesh root directory
Expand All @@ -17,13 +20,13 @@ eventMesh.webHook.fileMode.filePath= #{eventMeshHome}/webhook
## address of nacos
eventMesh.webHook.nacosMode.serverAddr=127.0.0.1:8848
# webhook eventcloud send mode. Same as eventMesh.connector.plugin.type configuration
# Webhook CloudEvent sending mode. This property is the same as the eventMesh.storage.plugin.type configuration.
eventMesh.webHook.producer.connector=standalone
```

#### The second step: Add webhook configuration information
### The second step: Add Webhook configuration information

Configuration information description
Configuration information description:

```java
/**
Expand All @@ -44,7 +47,7 @@ Configuration information description
private String manufacturerDomain;

/**
* webhook event name, like rep-push
* Webhook event name, like rep-push
*/
private String manufacturerEventName;

Expand Down Expand Up @@ -92,10 +95,12 @@ Configuration information description

```

##### Add WebHook config
#### Add WebHook config

path: /webhook/insertWebHookConfig

method: POST

contentType: application/json

input params:
Expand Down Expand Up @@ -128,9 +133,12 @@ E.g:

Output params: 1 for success, 0 for failure

##### Query WebHook config by callback path
#### Query WebHook config by callback path

path: /webhook/queryWebHookConfigById

method: POST

contentType: application/json

input params:
Expand Down Expand Up @@ -165,10 +173,12 @@ Output params:
| cloudEventName | cloudEvent name | string | Y | null |
| cloudEventIdGenerateMode | cloudEvent event object identification method, uuid or event id | string | N | manufacturerEventId |

#### Query WebHook config by manufacturer

##### Query WebHook config by manufacturer
path: /webhook/queryWebHookConfigByManufacturer

method: POST

contentType: application/json

input params:
Expand All @@ -179,7 +189,6 @@ input params:
| pageNum | page number of paging query | string | Y | null |
| pageSize | page size of each page | string | Y | null |


E.g:

```json
Expand All @@ -206,10 +215,50 @@ Output params:
| cloudEventName | cloudEvent name | string | Y | null |
| cloudEventIdGenerateMode | cloudEvent event object identification method, uuid or event id | string | N | manufacturerEventId |

##### Delete WebHook config
#### Update WebHook config

path: /webhook/updateWebHookConfig

method: POST

contentType: application/json

input params:

| field | desc | type | necessary | default |
| ------------------------ | ------------------------------------------------------------ | ------ | --------- | ------------------- |
| callbackPath | call address, unique address | string | Y | null |
| manufacturerName | manufacturer name | string | Y | null |
| manufacturerDomain | manufacturer domain name | string | Y | null |
| manufacturerEventName | manufacturer event name | string | Y | null |
| contentType | http connettype | string | N | application/json |
| description | configuration instructions | string | N | null |
| secret | signature string | string | N | null |
| userName | username | string | N | null |
| password | password | string | N | null |
| cloudEventName | cloudEvent name | string | Y | null |
| cloudEventIdGenerateMode | cloudEvent event object identification method, uuid or event id | string | N | manufacturerEventId |

E.g:

```json
{
"callbackPath":"/webhook/github/eventmesh/all",
"manufacturerName":"github",
"manufacturerDomain":"www.github.com",
"manufacturerEventName":"all",
"cloudEventName":"github-eventmesh"
}
```

Output params: 1 for success, 0 for failure

#### Delete WebHook config

path: /webhook/deleteWebHookConfig

method: POST

contentType: application/json

input params:
Expand All @@ -219,7 +268,6 @@ input params:
| callbackPath | call address, unique address | string | Y | null |
| manufacturerName | the caller of this callbackPath belongs to | string | Y | null |


E.g:

```json
Expand All @@ -231,19 +279,18 @@ E.g:

Output params: 1 for success, 0 for failure

#### The third step: Check if the configuration is successful

1. file storage mode. Please go to the eventMesh.webHook.fileMode.filePath directory to view. filename callbackPath.
### The third step: Check if the configuration is successful

2. nacos storage mode. Please go to the nacos service configured by eventMesh.webHook.nacosMode.serverAddr to see.
1. file storage mode. Please go to the eventMesh.webHook.fileMode.filePath directory to view. The Filename is callbackPath.
2. nacos storage mode. Please go to the nacos service configured by eventMesh.webHook.nacosMode.serverAddr to see this.

#### The fourth step: Configure the consumer of cloudevent
### The fourth step: Configure the consumer of cloudevent

#### The fifth step: Configure webhook related information in the manufacturer
### The fifth step: Configure Webhook related information in the manufacturer

> For manufacturer's operation, please refer to [Manufacturer's webhook operation instructions] .
> For manufacturer's operation, please refer to [Manufacturer's Webhook operation instructions](#Manufacturer's-Webhook-operation-instructions).
## Manufacturer's webhook operation instructions
## Manufacturer's Webhook operation instructions

### github sign up

Expand All @@ -257,17 +304,21 @@ Output params: 1 for success, 0 for failure

![](/images/design-document/webhook/webhook-github-webhooks.png)

#### The fourth step: Click on Add webhook
#### The fourth step: Click on Add Webhook

![](/images/design-document/webhook/webhook-github-add.png)

#### The fifth step: Fill in the webhook information
#### The fifth step: Fill in the Webhook information

![](/images/design-document/webhook/webhook-github-info.png)

Payload URL: Service address and pahts. [http or https]://[domain or IP]:[port]/webhook/[callbackPath]
Payload URL: EventMesh service address and callbackPath, which must include the protocol header. For example, when the callback address `callbackPath` is `/webhook/github/eventmesh/all`, the Payload URL is `http://www.example.com:10105/webhook/github/eventmesh/all`.

[http or https]://[domain or IP]:[port]/webhook/[callbackPath]

Content type: http header content type
secret: signature string

Secret: signature string



Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# EventMesh Schema Registry (OpenSchema)

## Overview of Schema and Schema Registry

### Schema

A Schema stands for the description of serialization instances(string/stream/file/...) and has two properties. First, it is also in the format of serialization type. Second, it defines what requirements such serialized instances should satisfy.

Besides describing a serialization instance, a Schema may also be used for validating whether an instance is legitimate. The reason is that it defines the ```type```(and other properties) of a serialized instance and inside keys. Taking JSON Schema for example, it could not only be referred when describing a JSON string, but also be used for validating whether a string satisfies properties defined in the schema[[1]](#References).

Commonly, there are JSON Schema, Protobuf Schema, and Avro Schema.

### Schema Registry

Schema Registry is a server provides RESTful interfaces. It could receive and store Schemas from clients, as well as provide intrefaces for other clients to retrieve Schemas from it.

It could be applied to validation process and (de-)serialization process.

### Comparison of Schema Registry in Different Projects

Project | Application
:---: | :---
EMQ[[2]](#References) | Mainly in (de-)serialization process. Use "Schema Registry" and "Rule Matching" to transfer a message from one serialization format to another.
Pulsar[[3]](#References) | Mainly in validation process. Use "Schema Registry" to validate a message.
Confluentinc[[4]](#References) | In both validation and (de-)serialization process.

## Overview of OpenSchema

OpenSchema[[5]](#References) proposes a specification for data schema when exchanging the message and event in more and more modern cloud-native applications. It designs a RESTful interface for storing and retrieving such as Avro, JSON Schema, and Protobuf3 schemas from three aspects(subject/schema/compatibility).

## Requirements(Goals)

| Requirement ID | Requirement Description | Comments |
| :------------- | ------------------------------------------------------------ | ------------- |
| F-1 | In transmission, no message needs to contain schema information which bring efficiency. | Functionality |
| F-2 | The message content from producer could be validated whether serialized correctly according to schema. | Functionality |

## Design Details

### Architecture

![OpenSchema](/images/design-document/schema-registry-architecture.png)

### Process of Transferring Messages under Schema Registry

![Process](/images/design-document/schema-registry-process.jpg)

The highlevel process of messages transmission contains 10 steps as follows:

- 1: Consumer subscribes "TOPIC" messages from EventMesh.
- 2: Producer registers a schema to EventMesh.
- 3: EventMesh registers a schema to Schema Registry.
- 4: Schema Registry returns the id of newly created schema; EventMesh caches such id and schema.
- 5: EventMesh returns the id of schema to Producer.
- 6: Producer patches the id in front of messages and send messages to EventMesh.
- 7: EventMesh validates the messages in the entry port and send it to EventStore; EventMesh retrieves messages from EventStore.
- 8: EventMesh unpatches the id and send it to Schema Registry(if such `<id, schema>` does not exists in local cache).
- 9: Schema Registry returns schema and EventMesh caches it.
- 10: EventMesh patches schema in front of messages and push it to consumer.

## Current Progress

### Status

**Current state**: Developing

**Discussion thread**: ISSUE #339

### Proposed Changes

The proposal has two aspects.

First is a separated Open Schema Registry, which includes storage and compatibility check for schema.
This proposal is under developing.

Second is the integration of Open Schema in Eventmesh, which includes validation for schema. This proposal is to be developed.

As for the first proposal, some developing statuses are as follows.

#### Status Code and Exception Code

No. | Status Code | Exception Code | Description | status
--- | :---: | :---: | :---: | :---:
1 | 401 | 40101 | Unauthorized Exception | ✔
2 | 404 | 40401 | Schema Non- Exception | ✔
3 | ^ | 40402 | Subject Non-exist Exception | ✔
4 | ^ | 40403 | Version Non-exist Exception | ✔
5 | 409 | 40901 | Compatibility Exception | ✔
6 | 422 | 42201 | Schema Format Exception | ✔
7 | ^ | 42202 | Subject Format Exception | ✔
8 | ^ | 42203 | Version Format Exception | ✔
9 | ^ | 42204 | Compatibility Format Exception | ✔
10 | 500 | 50001 | Storage Service Exception | ✔
11 | ^ | 50002 | Timeout Exception | ✔

#### API Development Status

No. | Type | URL | response | exception | code | test
--- | --- | --- | --- | --- | --- | ---
1 | GET | /schemas/ids/{string: id} | `Schema.class` | 40101\40401\50001 | ✔ | ❌
2 | GET | /schemas/ids/{string: id}/subjects | `SubjectAndVersion.class` | 40101\40401\50001 | ✔ | ❌
3 | GET | /subjects | `List\<String>` | 40101\50001 | ✔ | ❌
4 | GET | /subjects/{string: subject}/versions | `List\<Integer>` | 40101\40402\50001 | ✔ | ❌
5 | DELETE | /subjects/(string: subject) | `List\<Integer>` | 40101\40402\50001 | ✔ | ❌
6 | GET | /subjects/(string: subject) | `Subject.class` | 40101\40402\50001 | ✔ | ❌
7 | GET | /subjects/(string: subject)/versions/(version: version)/schema | `SubjectWithSchema.class` | 40101\40402\40403\50001 | ✔ | ❌
8 | POST | /subjects/(string: subject)/versions | `SchemaIdResponse.class` | 40101\40901\42201\50001\50002 | - | ❌
9 | POST | /subjects/(string: subject)/ | `Subject.class` | 40101\40901\42202\50001\50002 | ✔ | ❌
10 | DELETE | /subjects/(string: subject)/versions/(version: version) | `int` | 40101\40402\40403\40901\50001| - | ❌
11 | POST | /compatibility/subjects/(string: subject)/versions/(version: version) | `CompatibilityResultResponse.class` | 40101\40402\40403\42201\42203\50001| - | ❌
12 | GET | /compatibility/(string: subject) | `Compatibility.class` | 40101\40402\50001 | ✔ | ❌
13 | PUT | /compatibility/(string: subject) | `Compatibility.class` | 40101\40402\40901\42204\50001 | - | ❌

#### Overall Project Structure

```SchemaController.java```+```SchemaService.java``` : ```OpenSchema 7.1.1~7.1.2 (API 1~2)```

```SubjectController.java```+```SubjectService.java``` : ```OpenSchema 7.2.1~7.2.8 (API 3~10)```

```CompatibilityController.java```+```CompatibilityService.java``` : ```OpenSchema 7.3.1~7.3.3 (API 11~13)``` + ```Check for Compatibility```

![Project Structure](/images/design-document/schema-registry-project-structure.png)

## References

[1] [schema validator (github.com)](https://github.com/search?q=schema+validator)

[2] [EMQ: Schema Registry](https://www.jianshu.com/p/33e0655c642b)

[3] [Pulsar: Schema Registry](https://mp.weixin.qq.com/s/PaB66-Si00cX80py5ig5Mw)

[4] [confluentinc/schema-registry](https://github.com/confluentinc/schema-registry)

[5] [openmessaging/openschema](https://github.com/openmessaging/openschema)
Loading

0 comments on commit a334001

Please sign in to comment.