Skip to content

Instantly share code, notes, and snippets.

@strophy
Created May 23, 2022 14:20
Show Gist options
  • Save strophy/a6f4f6e30212e7cadcefb65b179c9bce to your computer and use it in GitHub Desktop.
Save strophy/a6f4f6e30212e7cadcefb65b179c9bce to your computer and use it in GitHub Desktop.
Dash Platform Monorepo Envoy gRPC configuration
static_resources:
listeners:
- name: web_grpc_gateweb
address:
socket_address: { address: 0.0.0.0, port_value: 10000 }
filter_chains:
- filters:
- name: envoy.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
http_filters:
- name: envoy.filters.http.local_ratelimit
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.local_ratelimit.v3.LocalRateLimit
stat_prefix: http_local_rate_limiter
# see documentation https://www.envoyproxy.io/docs/envoy/latest/api-v3/type/v3/token_bucket.proto#envoy-v3-api-msg-type-v3-tokenbucket
token_bucket:
max_tokens: 300
tokens_per_fill: 150
fill_interval: 60s
filter_enabled:
runtime_key: local_rate_limit_enabled
default_value:
numerator: 100
denominator: HUNDRED
filter_enforced:
runtime_key: local_rate_limit_enforced
default_value:
numerator: 100
denominator: HUNDRED
response_headers_to_add:
- append: false
header:
key: x-local-rate-limit
value: 'true'
- name: envoy.filters.http.cors
- name: envoy.filters.http.grpc_web
- name: envoy.filters.http.router
route_config:
name: local_route
virtual_hosts:
- name: dapi_services
domains: ["*"]
routes:
# tx subscription endpoint configuration
- match:
prefix: "/org.dash.platform.dapi.v0.Core/subscribeToTransactionsWithProofs"
headers:
- name: ":method"
safe_regex_match:
google_re2: {}
regex: "GET|POST|OPTIONS"
route:
cluster: tx_filter_stream
timeout: 0s
# block headers subscription endpoint configuration
- match:
prefix: "/org.dash.platform.dapi.v0.Core/subscribeToBlockHeadersWithChainLocks"
headers:
- name: ":method"
safe_regex_match:
google_re2: {}
regex: "GET|POST|OPTIONS"
route:
cluster: tx_filter_stream
timeout: 0s
# core endpoint configutration
- match:
prefix: "/org.dash.platform.dapi.v0.Core"
headers:
- name: ":method"
safe_regex_match:
google_re2: {}
regex: "GET|POST|OPTIONS"
route:
cluster: core_and_platform
# platform endpoint configutration
- match:
prefix: "/org.dash.platform.dapi.v0.Platform"
headers:
- name: ":method"
safe_regex_match:
google_re2: {}
regex: "GET|POST|OPTIONS"
route:
cluster: core_and_platform
# health-check endpoint configuration
- match:
prefix: "/grpc.health.v1.Health"
headers:
- name: ":method"
safe_regex_match:
google_re2: {}
regex: "GET|POST|OPTIONS"
route:
cluster: tx_filter_stream
# configuration of the static responses of unsupported api versions
# core static response
- match:
safe_regex:
google_re2: {}
regex: "\/org\\.dash\\.platform\\.dapi\\.v[1-9]+\\.Core"
response_headers_to_add:
- header:
key: "Content-Type"
value: "application/grpc-web+proto"
- header:
key: "grpc-status"
value: "12"
- header:
key: "grpc-message"
value: "Specified service version is not supported"
direct_response:
status: 204
# platform static respose
- match:
safe_regex:
google_re2: {}
regex: "\/org\\.dash\\.platform\\.dapi\\.v[1-9]+\\.Platform"
response_headers_to_add:
- header:
key: "Content-Type"
value: "application/grpc-web+proto"
- header:
key: "grpc-status"
value: "12"
- header:
key: "grpc-message"
value: "Specified service version is not supported"
direct_response:
status: 204
# root endpoint configuration
- match:
prefix: "/"
headers:
- name: ":method"
safe_regex_match:
google_re2: {}
regex: "GET|POST|OPTIONS"
route:
cluster: dapi_api_srv
# cors configuration
cors:
allow_origin_string_match:
- prefix: "*"
allow_methods: GET,POST,OPTIONS
allow_headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Transfer-Encoding,Custom-Header-1,X-Accept-Content-Transfer-Encoding,X-Accept-Response-Streaming,X-User-Agent,X-Grpc-Web
expose_headers: Content-Transfer-Encoding,Grpc-Message,Grpc-Status,Custom-Header-1
max_age: "1728000"
- name: native_grpc_gateway
address:
socket_address:
address: 0.0.0.0
port_value: 50051
filter_chains:
- filters:
- name: envoy.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
codec_type: HTTP2
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
log_format:
json_format:
timestamp: "%START_TIME%"
client: "%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%"
uri: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%"
upstream: "%UPSTREAM_HOST%"
"http-status": "%RESPONSE_CODE%"
"grpc-status": "%GRPC_STATUS%"
"rx-bytes": "%BYTES_RECEIVED%"
"tx-bytes": "%BYTES_SENT%"
http_filters:
- name: envoy.filters.http.local_ratelimit
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.local_ratelimit.v3.LocalRateLimit
stat_prefix: http_local_rate_limiter
token_bucket:
max_tokens: 300
tokens_per_fill: 150
fill_interval: 60s
filter_enabled:
runtime_key: local_rate_limit_enabled
default_value:
numerator: 100
denominator: HUNDRED
filter_enforced:
runtime_key: local_rate_limit_enforced
default_value:
numerator: 100
denominator: HUNDRED
response_headers_to_add:
- append: false
header:
key: x-local-rate-limit
value: 'true'
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
inline_code: |
function envoy_on_request(request_handle)
local max_bytes = 128 * 1024
local body_size = request_handle:body():length()
if body_size > max_bytes then
request_handle:respond({[":status"] = "413"})
end
end
- name: envoy.filters.http.router
route_config:
name: local_route
virtual_hosts:
- name: dapi_services
domains: ["*"]
routes:
# tx subscription endpoint configuration
- match:
prefix: "/org.dash.platform.dapi.v0.Core/subscribeToTransactionsWithProofs"
route:
cluster: tx_filter_stream
timeout: 0s
# block headers subscription endpoint configuration
- match:
prefix: "/org.dash.platform.dapi.v0.Core/subscribeToBlockHeadersWithChainLocks"
route:
cluster: tx_filter_stream
timeout: 0s
- match:
prefix: "/org.dash.platform.dapi.v0.Core"
route:
cluster: core_and_platform
- match:
prefix: "/org.dash.platform.dapi.v0.Platform"
route:
cluster: core_and_platform
- match:
prefix: "/grpc.health.v1.Health"
route:
cluster: tx_filter_stream
# configuration of the static responses of unsupported api versions
# core static response
- match:
safe_regex:
google_re2: {}
regex: "\/org\\.dash\\.platform\\.dapi\\.v[1-9]+\\.Core"
response_headers_to_add:
- header:
key: "Content-Type"
value: "application/grpc-web+proto"
- header:
key: "grpc-status"
value: "12"
- header:
key: "grpc-message"
value: "Specified service version is not supported"
direct_response:
status: 204
# platform static respose
- match:
safe_regex:
google_re2: {}
regex: "\/org\\.dash\\.platform\\.dapi\\.v[1-9]+\\.Platform"
response_headers_to_add:
- header:
key: "Content-Type"
value: "application/grpc-web+proto"
- header:
key: "grpc-status"
value: "12"
- header:
key: "grpc-message"
value: "Specified service version is not supported"
direct_response:
status: 204
clusters:
- name: core_and_platform
connect_timeout: 0.25s
type: logical_dns
http2_protocol_options: {}
lb_policy: round_robin
load_assignment:
cluster_name: core_and_platform
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: dapi_api
port_value: 3005
- name: tx_filter_stream
connect_timeout: 0.25s
type: logical_dns
http2_protocol_options: {}
lb_policy: round_robin
load_assignment:
cluster_name: core_and_platform
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: dapi_tx_filter_stream
port_value: 3006
- name: dapi_api_srv
connect_timeout: 30s
type: logical_dns
dns_lookup_family: V4_ONLY
lb_policy: round_robin
load_assignment:
cluster_name: core_and_platform
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: dapi_api
port_value: 3004
admin:
access_log_path: "/dev/null"
address:
socket_address:
address: 0.0.0.0
port_value: 8081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment