Skip to content

Commit

Permalink
Merge branch 'master' into grpc-filter-example
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster authored Aug 29, 2024
2 parents 88ca66b + 52aa48a commit 365df61
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public class AccessLogGrpcFilter<R extends GeneratedMessageV3, S extends Generat

public AccessLogGrpcFilter() {
accessLogContextBuilder = AccessLogContext.builder();
accessLogContextBuilder.requestTime(System.currentTimeMillis());
startTime = System.currentTimeMillis();
accessLogContextBuilder.requestTime(startTime);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public class AccessLogHttpFilter extends HttpFilter implements Logging {

public AccessLogHttpFilter() {
accessLogContextBuilder = AccessLogContext.builder();
accessLogContextBuilder.requestTime(System.currentTimeMillis());
startTime = System.currentTimeMillis();
accessLogContextBuilder.requestTime(startTime);
}

public static void setFormat(String format) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public GreeterService(@Named("hw.greeting") String greeting, HelloBeanService he
@Override
@Api(deadlineConfig = "apiProperties.sayhello.deadline") // specify an API level Deadline that will cascade to all @ConcurrentTask invoked in serving this API
@Timed // the Timed annotation for publishing JMX metrics via MBean
@MethodFilters({LoggingFilter.class, CustomHeaderGRPCFilter.class}) // Method level filters
@Traced(withSamplingRate=0.0f) // Start a new Trace or participate in a Client-initiated distributed trace

@MethodFilters({LoggingFilter.class, AuthFilter.class, CustomHeaderGRPCFilter.class}) // Method level filters
@Traced(withSamplingRate=0.5f) // Start a new Trace or participate in a Client-initiated distributed trace
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {

info("Saying hello in Greeter service");
Expand Down
102 changes: 59 additions & 43 deletions grpc-jexpress-template/envoy.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,63 @@
admin:
access_log_path: /tmp/admin-access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
access_log_path: /tmp/admin-access.log
address:
socket_address:
address: 0.0.0.0
port_value: 9901

static_resources:
listeners:
- name: listener1
address:
socket_address: { address: 0.0.0.0, port_value: 51051 }
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
stat_prefix: grpc_json
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" , grpc: {}}
route: { cluster: grpc, timeout: { seconds: 60 } }
http_filters:
- name: envoy.grpc_json_transcoder
config:
proto_descriptor: "/tmp/sample_proto_descriptor_set.pb"
services: ["service.UserService"]
print_options:
add_whitespace: true
always_print_primitive_fields: true
always_print_enums_as_ints: false
preserve_proto_field_names: false
- name: envoy.router
listeners:
- name: listener1
address:
socket_address:
address: 0.0.0.0
port_value: 51051
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: grpc_json
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: grpc
timeout: { seconds: 60 }
http_filters:
- name: envoy.grpc_json_transcoder
typed_config:
'@type': type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder
proto_descriptor: "/tmp/sample_proto_descriptor_set.pb"
services: ["service.UserService"]
print_options:
add_whitespace: true
always_print_primitive_fields: true
always_print_enums_as_ints: false
preserve_proto_field_names: false
- name: envoy.router
typed_config:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

clusters:
- name: grpc
connect_timeout: 1.25s
type: logical_dns
lb_policy: round_robin
dns_lookup_family: V4_ONLY
http2_protocol_options: {}
hosts:
- socket_address:
address: docker.for.mac.localhost
port_value: 50051
clusters:
- name: grpc
connect_timeout: 1.25s
type: LOGICAL_DNS
lb_policy: ROUND_ROBIN
dns_lookup_family: V4_ONLY
http2_protocol_options: {}
load_assignment:
cluster_name: grpc
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: host.docker.internal
port_value: 50051
2 changes: 1 addition & 1 deletion grpc-jexpress-template/run_client.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

java -cp target/grpc-jexpress-template-1.0-SNAPSHOT.jar:target/lib/* com.flipkart.grpc.jexpress.SampleClient
exec java -cp target/grpc-jexpress-template-1.0-SNAPSHOT.jar:target/lib/* com.flipkart.grpc.jexpress.SampleClient
2 changes: 1 addition & 1 deletion grpc-jexpress-template/run_server.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

java -cp target/grpc-jexpress-template-1.0-SNAPSHOT.jar:target/lib/* --add-opens=java.base/java.lang=ALL-UNNAMED com.flipkart.grpc.jexpress.SampleApplication server src/main/resources/configuration.yml
exec java -cp target/grpc-jexpress-template-1.0-SNAPSHOT.jar:target/lib/* --add-opens=java.base/java.lang=ALL-UNNAMED com.flipkart.grpc.jexpress.SampleApplication server src/main/resources/configuration.yml
Binary file modified grpc-jexpress-template/sample_proto_descriptor_set.pb
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.flipkart.gjex.core.tracing.TracingSampler;
import com.flipkart.grpc.jexpress.filter.CreateLoggingFilter;
import com.flipkart.grpc.jexpress.filter.GetLoggingFilter;
import com.flipkart.grpc.jexpress.healthcheck.AllIsWellHealthCheck;
import com.flipkart.grpc.jexpress.service.SampleService;
import com.flipkart.grpc.jexpress.tracing.AllWhitelistTracingSampler;
import com.google.inject.AbstractModule;
Expand All @@ -17,7 +16,6 @@ public class SampleModule extends AbstractModule {
@Override
protected void configure() {
bind(BindableService.class).annotatedWith(Names.named("SampleService")).to(SampleService.class);
bind(HealthCheck.class).to(AllIsWellHealthCheck.class);
bind(GrpcFilter.class).annotatedWith(Names.named("GetLoggingFilter")).to(GetLoggingFilter.class);
bind(GrpcFilter.class).annotatedWith(Names.named("CreateLoggingFilter")).to(CreateLoggingFilter.class);
bind(TracingSampler.class).to(AllWhitelistTracingSampler.class);
Expand Down
4 changes: 4 additions & 0 deletions grpc-jexpress-template/src/main/resources/configuration.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Grpc:
server.port: 50051
server.executorThreads : 4
filterConfig:
enableAccessLogs: true

Dashboard:
service.port: 9999
Expand All @@ -14,6 +16,8 @@ Api:
service.selectors: 10
service.workers: 30
scheduledexecutor.threadpool.size: 1
filterConfig:
enableAccessLogs: true

ScheduledJobs.executorThreads: 5

Expand Down
3 changes: 2 additions & 1 deletion grpc-jexpress-template/start-envoy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash

sudo docker run -it --rm --name envoy -p 51051:51051 -p 9901:9901 -v "$(pwd)/sample_proto_descriptor_set.pb:/tmp/sample_proto_descriptor_set.pb:ro" -v "$(pwd)/envoy.yml:/etc/envoy/envoy.yaml:ro" envoyproxy/envoy
# envoy doesn't support a latest tag anymore, so find the latest version and use it accordingly
sudo docker run -it --rm --name envoy -p 51051:51051 -p 9901:9901 -v "$(pwd)/sample_proto_descriptor_set.pb:/tmp/sample_proto_descriptor_set.pb:ro" -v "$(pwd)/envoy.yml:/etc/envoy/envoy.yaml:ro" envoyproxy/envoy:v1.31-latest

0 comments on commit 365df61

Please sign in to comment.