Skip to content

Commit 1c07dce

Browse files
committed
feat grpc: move schemas to separate files for gRPC related libraries
Tests: протестировано CI commit_hash:96b2cf0fa44b0cb0fb50a7414200f3ca5071bf47
1 parent 54b56fc commit 1c07dce

File tree

9 files changed

+153
-134
lines changed

9 files changed

+153
-134
lines changed

.mapping.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,12 +2703,14 @@
27032703
"libraries/grpc-protovalidate/include/userver/grpc-protovalidate/validate.hpp":"taxi/uservices/userver/libraries/grpc-protovalidate/include/userver/grpc-protovalidate/validate.hpp",
27042704
"libraries/grpc-protovalidate/library.yaml":"taxi/uservices/userver/libraries/grpc-protovalidate/library.yaml",
27052705
"libraries/grpc-protovalidate/src/grpc-protovalidate/client/component.cpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/client/component.cpp",
2706+
"libraries/grpc-protovalidate/src/grpc-protovalidate/client/component.yaml":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/client/component.yaml",
27062707
"libraries/grpc-protovalidate/src/grpc-protovalidate/client/exceptions.cpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/client/exceptions.cpp",
27072708
"libraries/grpc-protovalidate/src/grpc-protovalidate/client/middleware.cpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/client/middleware.cpp",
27082709
"libraries/grpc-protovalidate/src/grpc-protovalidate/client/middleware.hpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/client/middleware.hpp",
27092710
"libraries/grpc-protovalidate/src/grpc-protovalidate/impl/utils.cpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/impl/utils.cpp",
27102711
"libraries/grpc-protovalidate/src/grpc-protovalidate/impl/utils.hpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/impl/utils.hpp",
27112712
"libraries/grpc-protovalidate/src/grpc-protovalidate/server/component.cpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/server/component.cpp",
2713+
"libraries/grpc-protovalidate/src/grpc-protovalidate/server/component.yaml":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/server/component.yaml",
27122714
"libraries/grpc-protovalidate/src/grpc-protovalidate/server/middleware.cpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/server/middleware.cpp",
27132715
"libraries/grpc-protovalidate/src/grpc-protovalidate/server/middleware.hpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/server/middleware.hpp",
27142716
"libraries/grpc-protovalidate/src/grpc-protovalidate/validate.cpp":"taxi/uservices/userver/libraries/grpc-protovalidate/src/grpc-protovalidate/validate.cpp",
@@ -3219,6 +3221,7 @@
32193221
"otlp/CMakeLists.txt":"taxi/uservices/userver/otlp/CMakeLists.txt",
32203222
"otlp/include/userver/otlp/logs/component.hpp":"taxi/uservices/userver/otlp/include/userver/otlp/logs/component.hpp",
32213223
"otlp/src/otlp/logs/component.cpp":"taxi/uservices/userver/otlp/src/otlp/logs/component.cpp",
3224+
"otlp/src/otlp/logs/component.yaml":"taxi/uservices/userver/otlp/src/otlp/logs/component.yaml",
32223225
"otlp/src/otlp/logs/logger.cpp":"taxi/uservices/userver/otlp/src/otlp/logs/logger.cpp",
32233226
"otlp/src/otlp/logs/logger.hpp":"taxi/uservices/userver/otlp/src/otlp/logs/logger.hpp",
32243227
"otlp/tests/service_test.cpp":"taxi/uservices/userver/otlp/tests/service_test.cpp",

libraries/grpc-protovalidate/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ userver_module(
1010
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
1111
LINK_LIBRARIES userver::grpc protovalidate_cc::protovalidate_cc
1212
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp"
13+
EMBED_FILES
14+
src/grpc-protovalidate/client/component.yaml
15+
src/grpc-protovalidate/server/component.yaml
1316
)

libraries/grpc-protovalidate/src/grpc-protovalidate/client/component.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
#include <grpc-protovalidate/client/middleware.hpp>
77

8+
#ifndef ARCADIA_ROOT
9+
#include "generated/src/grpc-protovalidate/client/component.yaml.hpp" // Y_IGNORE
10+
#endif
11+
812
USERVER_NAMESPACE_BEGIN
913

1014
namespace grpc_protovalidate::client {
@@ -42,28 +46,8 @@ std::shared_ptr<const ugrpc::client::MiddlewareBase> ValidatorComponent::CreateM
4246
yaml_config::Schema ValidatorComponent::GetMiddlewareConfigSchema() const { return GetStaticConfigSchema(); }
4347

4448
yaml_config::Schema ValidatorComponent::GetStaticConfigSchema() {
45-
return yaml_config::MergeSchemas<ugrpc::client::MiddlewareFactoryComponentBase>(R"(
46-
type: object
47-
description: gRPC response validator component
48-
additionalProperties: false
49-
properties:
50-
fail-fast:
51-
type: boolean
52-
description: do not check remaining constraints after first error is encountered
53-
defaultDescription: true
54-
methods:
55-
type: object
56-
description: per-method middleware options overrides
57-
properties: {}
58-
additionalProperties:
59-
type: object
60-
description: method options
61-
additionalProperties: false
62-
properties:
63-
fail-fast:
64-
type: boolean
65-
description: see 'fail-fast' global option
66-
)");
49+
return yaml_config::MergeSchemasFromResource<
50+
ugrpc::client::MiddlewareFactoryComponentBase>("src/grpc-protovalidate/client/component.yaml");
6751
}
6852

6953
} // namespace grpc_protovalidate::client
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
type: object
2+
description: gRPC response validator component
3+
additionalProperties: false
4+
properties:
5+
fail-fast:
6+
type: boolean
7+
description: do not check remaining constraints after first error is encountered
8+
defaultDescription: true
9+
methods:
10+
type: object
11+
description: per-method middleware options overrides
12+
properties: {}
13+
additionalProperties:
14+
type: object
15+
description: method options
16+
additionalProperties: false
17+
properties:
18+
fail-fast:
19+
type: boolean
20+
description: see 'fail-fast' global option

libraries/grpc-protovalidate/src/grpc-protovalidate/server/component.cpp

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
#include <grpc-protovalidate/server/middleware.hpp>
77

8+
#ifndef ARCADIA_ROOT
9+
#include "generated/src/grpc-protovalidate/server/component.yaml.hpp" // Y_IGNORE
10+
#endif
11+
812
USERVER_NAMESPACE_BEGIN
913

1014
namespace grpc_protovalidate::server {
@@ -46,35 +50,8 @@ std::shared_ptr<const ugrpc::server::MiddlewareBase> ValidatorComponent::CreateM
4650
yaml_config::Schema ValidatorComponent::GetMiddlewareConfigSchema() const { return GetStaticConfigSchema(); }
4751

4852
yaml_config::Schema ValidatorComponent::GetStaticConfigSchema() {
49-
return yaml_config::MergeSchemas<ugrpc::server::MiddlewareFactoryComponentBase>(R"(
50-
type: object
51-
description: gRPC request validator component
52-
additionalProperties: false
53-
properties:
54-
fail-fast:
55-
type: boolean
56-
description: do not check remaining constraints after first error is encountered
57-
defaultDescription: true
58-
send-violations:
59-
type: boolean
60-
description: send found constraint violations in grpc::Status
61-
defaultDescription: false
62-
methods:
63-
type: object
64-
description: per-method middleware options overrides
65-
properties: {}
66-
additionalProperties:
67-
type: object
68-
description: method options
69-
additionalProperties: false
70-
properties:
71-
fail-fast:
72-
type: boolean
73-
description: see 'fail-fast' global option
74-
send-violations:
75-
type: boolean
76-
description: see 'send-violations' global option
77-
)");
53+
return yaml_config::MergeSchemasFromResource<
54+
ugrpc::server::MiddlewareFactoryComponentBase>("src/grpc-protovalidate/server/component.yaml");
7855
}
7956

8057
} // namespace grpc_protovalidate::server
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
type: object
2+
description: gRPC request validator component
3+
additionalProperties: false
4+
properties:
5+
fail-fast:
6+
type: boolean
7+
description: do not check remaining constraints after first error is encountered
8+
defaultDescription: true
9+
send-violations:
10+
type: boolean
11+
description: send found constraint violations in grpc::Status
12+
defaultDescription: false
13+
methods:
14+
type: object
15+
description: per-method middleware options overrides
16+
properties: {}
17+
additionalProperties:
18+
type: object
19+
description: method options
20+
additionalProperties: false
21+
properties:
22+
fail-fast:
23+
type: boolean
24+
description: see 'fail-fast' global option
25+
send-violations:
26+
type: boolean
27+
description: see 'send-violations' global option

otlp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ userver_module(
1010
UTEST_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests"
1111
UTEST_LINK_LIBRARIES userver-grpc-utest
1212
DEPENDS grpc
13+
EMBED_FILES
14+
src/otlp/logs/component.yaml
1315
)
1416

1517
_userver_install_targets(COMPONENT otlp TARGETS userver-otlp-proto)

otlp/src/otlp/logs/component.cpp

Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#include <opentelemetry/proto/collector/logs/v1/logs_service_client.usrv.pb.hpp>
2121

22+
#ifndef ARCADIA_ROOT
23+
#include "generated/src/otlp/logs/component.yaml.hpp" // Y_IGNORE
24+
#endif
25+
2226
USERVER_NAMESPACE_BEGIN
2327

2428
namespace otlp {
@@ -126,89 +130,7 @@ LoggerComponent::~LoggerComponent() {
126130
}
127131

128132
yaml_config::Schema LoggerComponent::GetStaticConfigSchema() {
129-
return yaml_config::MergeSchemas<components::RawComponentBase>(R"(
130-
type: object
131-
description: >
132-
OpenTelemetry logger component
133-
additionalProperties: false
134-
properties:
135-
endpoint:
136-
type: string
137-
description: >
138-
Hostname:port of otel collector (gRPC). This endpoint is used
139-
both for logs and traces. If you want separate endpoints, then
140-
use "logs-endpoint" and "tracing-endpoint" members.
141-
Please note that "endpoint" is mutually exclusive with either
142-
"logs-endpoint" or "tracing-endpoint". Basically, you either have
143-
one endpoint for both, or you specify directly what goes where.
144-
logs-endpoint:
145-
type: string
146-
description: >
147-
Hostname:port of otel collector (gRPC). This endpoint is used
148-
only for logs.
149-
tracing-endpoint:
150-
type: string
151-
description: >
152-
Hostname:port of otel collector (gRPC). This endpoint is used
153-
only for traces.
154-
client-factory-name:
155-
type: string
156-
description: >
157-
This component needs ugrpc::client::ClientFactoryComponent to
158-
work and we will look for it with name given in this
159-
parameter.
160-
You need to set that component propertly, e.g. disable
161-
middlwares (otherwise it will be an infinite loop of client
162-
producing logs that go into otlp logger and back to client
163-
and that causes even more logs).
164-
165-
Although it is possible to omit this parameter and use
166-
default ClientFactoryComponent instance, it is not recommended
167-
and will cause severe problems in the long run.
168-
169-
log-level:
170-
type: string
171-
description: log level
172-
max-queue-size:
173-
type: integer
174-
description: max async queue size
175-
max-batch-delay:
176-
type: string
177-
description: max delay between send batches (e.g. 100ms or 1s)
178-
service-name:
179-
type: string
180-
description: service name
181-
sinks:
182-
type: object
183-
description: sinks to send logs/traces to
184-
additionalProperties: false
185-
properties:
186-
logs:
187-
type: string
188-
enum: [otlp, default, both]
189-
description: logs sink
190-
defaultDescription: otlp
191-
tracing:
192-
type: string
193-
enum: [otlp, default, both]
194-
description: tracing sink
195-
defaultDescription: otlp
196-
attributes-mapping:
197-
type: object
198-
description: rename rules for OTLP attributes
199-
properties: {}
200-
additionalProperties:
201-
type: string
202-
description: new attribute name
203-
extra-attributes:
204-
type: object
205-
description: extra OTLP attributes
206-
properties: {}
207-
additionalProperties:
208-
type: string
209-
description: attribute value
210-
211-
)");
133+
return yaml_config::MergeSchemasFromResource<components::RawComponentBase>("src/otlp/logs/component.yaml");
212134
}
213135

214136
} // namespace otlp

otlp/src/otlp/logs/component.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
type: object
2+
description: >
3+
OpenTelemetry logger component
4+
additionalProperties: false
5+
properties:
6+
endpoint:
7+
type: string
8+
description: >
9+
Hostname:port of otel collector (gRPC). This endpoint is used
10+
both for logs and traces. If you want separate endpoints, then
11+
use "logs-endpoint" and "tracing-endpoint" members.
12+
Please note that "endpoint" is mutually exclusive with either
13+
"logs-endpoint" or "tracing-endpoint". Basically, you either have
14+
one endpoint for both, or you specify directly what goes where.
15+
logs-endpoint:
16+
type: string
17+
description: >
18+
Hostname:port of otel collector (gRPC). This endpoint is used
19+
only for logs.
20+
tracing-endpoint:
21+
type: string
22+
description: >
23+
Hostname:port of otel collector (gRPC). This endpoint is used
24+
only for traces.
25+
client-factory-name:
26+
type: string
27+
description: >
28+
This component needs ugrpc::client::ClientFactoryComponent to
29+
work and we will look for it with name given in this
30+
parameter.
31+
You need to set that component propertly, e.g. disable
32+
middlwares (otherwise it will be an infinite loop of client
33+
producing logs that go into otlp logger and back to client
34+
and that causes even more logs).
35+
36+
Although it is possible to omit this parameter and use
37+
default ClientFactoryComponent instance, it is not recommended
38+
and will cause severe problems in the long run.
39+
40+
log-level:
41+
type: string
42+
description: log level
43+
max-queue-size:
44+
type: integer
45+
description: max async queue size
46+
max-batch-delay:
47+
type: string
48+
description: max delay between send batches (e.g. 100ms or 1s)
49+
service-name:
50+
type: string
51+
description: service name
52+
sinks:
53+
type: object
54+
description: sinks to send logs/traces to
55+
additionalProperties: false
56+
properties:
57+
logs:
58+
type: string
59+
enum: [otlp, default, both]
60+
description: logs sink
61+
defaultDescription: otlp
62+
tracing:
63+
type: string
64+
enum: [otlp, default, both]
65+
description: tracing sink
66+
defaultDescription: otlp
67+
attributes-mapping:
68+
type: object
69+
description: rename rules for OTLP attributes
70+
properties: {}
71+
additionalProperties:
72+
type: string
73+
description: new attribute name
74+
extra-attributes:
75+
type: object
76+
description: extra OTLP attributes
77+
properties: {}
78+
additionalProperties:
79+
type: string
80+
description: attribute value
81+

0 commit comments

Comments
 (0)