Skip to content

Commit 0c64d2a

Browse files
authored
Merge pull request #3 from bobturanov/feature/task-3
Feature/task 3
2 parents 2feaafa + 1ffabe6 commit 0c64d2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+8371
-314
lines changed

DOCS.md

-143
This file was deleted.

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ deps-go:
7878
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@latest
7979

8080
.deps-python:
81-
python -m pip install grpcio-tools grpclib protobuf
81+
python3 -m pip install grpcio-tools grpclib protobuf # python3 for my machine
8282

8383
.PHONY: build
8484
build: generate .build

README.md

+134-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,143 @@
1-
### Задание 2
1+
# Ozon Marketplace Verification API
22

3-
1. Создать репозиторий именование которого указано в таблице прогресса ✅
3+
---
44

5-
2. Описать сущность `{domain}.{Subdomain}` и `{domain}.{Subdomain}Event` в **internal/model/{subdomain}.go**
5+
## Build project
66

7-
3. Реализовать паттерн consumer-producer из **db** в **kafka** на основе интерфейсов [EventRepo](https://github.com/ozonmp/omp-demo-api/blob/b847b3ae4a3c9e1d25e31e077c847a22f8b7aa99/internal/app/repo/event.go#L7) и [EventSender](https://github.com/ozonmp/omp-demo-api/blob/b847b3ae4a3c9e1d25e31e077c847a22f8b7aa99/internal/app/sender/event.go#L7) для одного типа события **Created**
7+
### Local
88

9-
4. Написать тесты ✅
9+
For local assembly you need to perform
1010

11-
5. Синхронизацию работы потоков сделать через `context` 💎 ⌛️
11+
```zsh
12+
$ make deps # Installation of dependencies
13+
$ make build # Build project
14+
```
15+
## Running
1216

13-
6. Создавать задачи у workerpool по обработке батчевых идентификаторов записей событий 💎 ⌛️
17+
### For local development
1418

15-
7. Поддержать несколько типов событий учитывая корректный порядок 💎 🤔
19+
```zsh
20+
$ docker-compose up -d
21+
```
1622

17-
8. Реализовать гарантию доставки **At-least-once** 💎 🤔
23+
---
1824

19-
9. Найти скрытые ошибки в коде 💎 🤔
25+
## Services
26+
27+
### Swagger UI
28+
29+
The Swagger UI is an open source project to visually render documentation for an API defined with the OpenAPI (Swagger) Specification
30+
31+
- http://localhost:8080/swagger
32+
33+
### Grafana:
34+
35+
- http://localhost:3000
36+
- - login `admin`
37+
- - password `MYPASSWORT`
38+
39+
### gRPC:
40+
41+
- http://localhost:8082
42+
43+
```sh
44+
[I] ➜ grpc_cli call localhost:8082 DescribeVerificationV1 "id: 1"
45+
connecting to localhost:8082
46+
Rpc failed with status code 5, error message: verification not found
47+
```
48+
49+
### Gateway:
50+
51+
It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC
52+
53+
- http://localhost:8080/api'
54+
55+
```sh
56+
[I] ➜ curl -s -X 'POST' \
57+
'http://localhost:8080/api/v1/verifications'' \
58+
-H 'accept: application/json' \
59+
-H 'Content-Type: application/json' \
60+
-d '{
61+
"id": "1"
62+
}' | jq .
63+
{
64+
"code": 5,
65+
"message": "verification not found",
66+
"details": []
67+
}
68+
```
69+
70+
### Metrics:
71+
72+
Metrics GRPC Server
73+
74+
- http://localhost:9100/metrics
75+
76+
### Status:
77+
78+
Service condition and its information
79+
80+
- http://localhost:8000
81+
- - `/live`- Layed whether the server is running
82+
- - `/ready` - Is it ready to accept requests
83+
- - `/version` - Version and assembly information
84+
85+
### Prometheus:
86+
87+
Prometheus is an open-source systems monitoring and alerting toolkit
88+
89+
- http://localhost:9090
90+
91+
### Kafka
92+
93+
Apache Kafka is an open-source distributed event streaming platform used by thousands of companies for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications.
94+
95+
- http://localhost:9094
96+
97+
### Kafka UI
98+
99+
UI for Apache Kafka is a simple tool that makes your data flows observable, helps find and troubleshoot issues faster and deliver optimal performance. Its lightweight dashboard makes it easy to track key metrics of your Kafka clusters - Brokers, Topics, Partitions, Production, and Consumption.
100+
101+
- http://localhost:9001
102+
103+
### Jaeger UI
104+
105+
Monitor and troubleshoot transactions in complex distributed systems.
106+
107+
- http://localhost:16686
108+
109+
### Graylog
110+
111+
Graylog is a leading centralized log management solution for capturing, storing, and enabling real-time analysis of terabytes of machine data.
112+
113+
- http://localhost:9000
114+
- - login `admin`
115+
- - password `admin`
116+
117+
### PostgreSQL
118+
119+
For the convenience of working with the database, you can use the [pgcli](https://github.com/dbcli/pgcli) utility. Migrations are rolled out when the service starts. migrations are located in the **./migrations** directory and are created using the [goose](https://github.com/pressly/goose) tool.
120+
121+
```sh
122+
$ pgcli "postgresql://docker:docker@localhost:5432/srv_verification_api"
123+
```
124+
125+
### Python client
126+
127+
```shell
128+
$ python -m venv .venv
129+
$ . .venv/bin/activate
130+
$ make deps
131+
$ make generate
132+
$ cd pypkg/srv-verification-api
133+
$ python setup.py install
134+
$ cd ../..
135+
$ docker-compose up -d
136+
$ python scripts/grpc_client.py
137+
```
138+
139+
140+
### Thanks
141+
142+
- [Evald Smalyakov](https://github.com/evald24)
143+
- [Michael Morgoev](https://github.com/zerospiel)

api/ozonmp/srv_verification_api/v1/srv_verification_api.proto

+41-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package ozonmp.srv_verification_api.v1;
44

55
import "validate/validate.proto";
66
import "google/api/annotations.proto";
7-
import "google/protobuf/timestamp.proto";
87

98
option go_package = "github.com/ozonmp/srv-verification-api/pkg/srv-verification-api;srv_verification_api";
109

@@ -16,12 +15,27 @@ service SrvVerificationApiService {
1615
get: "/v1/verifications/{verification_id}"
1716
};
1817
}
18+
rpc CreateVerificationV1(CreateVerificationV1Request) returns (CreateVerificationV1Response) {
19+
option (google.api.http) = {
20+
post: "/v1/verifications/create"
21+
body: "*"
22+
};
23+
}
24+
rpc ListVerificationV1(ListVerificationV1Request) returns (ListVerificationV1Response) {
25+
option (google.api.http) = {
26+
get: "/v1/verifications/list"
27+
};
28+
}
29+
rpc RemoveVerificationV1(RemoveVerificationV1Request) returns (RemoveVerificationV1Response) {
30+
option (google.api.http) = {
31+
delete: "/v1/verifications/remove/{verification_id}"
32+
};
33+
}
1934
}
2035

2136
message Verification {
2237
uint64 id = 1;
23-
uint64 foo = 2;
24-
google.protobuf.Timestamp created = 3;
38+
string name = 2;
2539
}
2640

2741
message DescribeVerificationV1Request {
@@ -31,3 +45,27 @@ message DescribeVerificationV1Request {
3145
message DescribeVerificationV1Response {
3246
Verification value = 1;
3347
}
48+
49+
message CreateVerificationV1Request {
50+
string verification_name = 2 [(validate.rules).string.min_len = 2];
51+
}
52+
53+
message CreateVerificationV1Response {
54+
uint64 verification_id = 1 [(validate.rules).uint64.gt = 0];
55+
}
56+
57+
message ListVerificationV1Request {
58+
}
59+
60+
message ListVerificationV1Response {
61+
repeated Verification verification = 1;
62+
}
63+
64+
message RemoveVerificationV1Request {
65+
uint64 verification_id = 1 [(validate.rules).uint64.gt = 0];
66+
}
67+
68+
message RemoveVerificationV1Response {
69+
bool result = 1;
70+
}
71+

0 commit comments

Comments
 (0)