Tuesday, May 12, 2020

Envoy with grpc Access logs

What is Envoy

Envoy is an L7 proxy and communication bus designed for large modern service oriented architectures. The project was born out of the belief that:

The network should be transparent to applications. When network and application problems do occur it should be easy to determine the source of the problem.

In practice, achieving the previously stated goal is incredibly difficult. Envoy attempts to do so by providing the following high level features:

More details about envoy documentation available at:  https://www.envoyproxy.io/docs/envoy/latest/about_docs

Now let's start implementing envoy as side-car along with our application containers and run it in a single pod:

This implementation is specific to kubernetes environment.

Envoy can be part of side car for any application and communication to application happens through envoy. Any inbound traffic will be done through envoy and envoy will have listeners , routing configured.

This can be done through grpcImplementations or with yaml configuration. These will be registered with envoy XDS Apis and envoy will know where to reach for communicating with application.

Here we will look at envoy yaml configuration:

envoy-grpcconfig.yaml

Here we have configured listeners , filters and routes.

Envoy Configuration:

Envoy is listening  at port 9902 in local host. This is where we can get /stats.

Application configuration:

In routes, we specified details of the cluster that matches with a pattern.

For each of the matching pattern envoy routes it to the cluster specified under virtual_hosts.Cluster details are specified under Clusters. The application will be served for this example with cluster name as service_c.

The host address and port details for service_c is where test application is served.

Grpc Access logs:

Under filters,we have specfied the configuration for access_log.

Here we are specifying it as envoy.http_grpc_access_log. Grpc Access logs details can. be found at

https://github.com/envoyproxy/envoy/blob/d90464cace696da61248d3999081c3c0d22a725b/api/envoy/data/accesslog/v2/accesslog.proto

More options on configuring access logs can be found at

https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/observability/access_logging

The yaml config emits access_logs for upstream systems.

Grpc AccessLogService Implementation:

For grpc we have to implement grpc server for AccessLogService.

Code is available at :https://github.com/sreesindhusruthiyadavalli/envoy-grpc/tree/master

Build the docker image and deploy it in a pod.

Please check kubernetes apply -f <deployment.yaml>/<service.yaml> for deployment and service configuration for any pod.I have given service name as 'envoy-grpc'.

Kubectl get services --> List of services available in kubernetes cluster.

It gives envoy-grpc as service name for grpc AccessLogService.

Now in envoy configuration we have to configure access logs which has to be communicated with the above service.

Under clusters give the service host address(envoy-grpc.default.svc.cluster.local) and add strict_dns to the access_log_cluster.

Build envoy with the yaml configuration and invoke an api inside the test application.

Enter into envoy pod: curl 127.0.0.1:8789/<resource>

This gives the response from the application.

Now check the logs of envoy-grpc pod.We will get to see the accesslog.

Sunday, March 10, 2019

The Concept of Overfitting in Machine learning





If you are taking any Machine learning courses or practising to solve some ML problems.You would have come across this term called “Overfitting”.

Let’s try to understand it with a simple example:

We are trying to come up with a generic size of a T-shirt that suits an average person.(not extreme tall/short and weights).

And for that we got certain sample measurements from the existing population.

Now we have come up with certain values for hands, neck, back etc and designed a shirt.

Now based on the feedback received from each individual , we keep changing the measurements such that it fits just fine for people in the sample. 

The adjustments we are trying to make doesn’t generalise much as we are trying to make sure that the shirt fits  perfectly for the people who’s measurements are known.

Friday, March 8, 2019

using regular expression in sublime Text Editor

Sublime Text editor provides an easy way of replacing text using regular expressions.

Let's take a simple regex examples and replacing it with the values that we would like to have.

one of the sample text is :

"CreateTime" : ISODate("2018-12-21T15:10:30.145Z")

This has to be replaced with the value in the quotes.

We can do this using any of the programming language and use grouping and replace with the value.

The same can be done in sublime editor as well:

Just select Edit-->Replace.

Choose Regex mode



Select Replace All will do the job.




Sunday, February 4, 2018

Intersection over union - Object detection



During object detection ,

When the image has more than one anchor box after filtering by thresholding over the classes scores , we use non-max suppression to get one anchor box for object detection.

Non-max suppression uses intersection over union.

Intersection over union calculates the intersection area of any two boxes by area of union of two boxes.

Here we have considered the  coordinates of each box which are diagonal like top left and bottom right

Our naming conventions here for each box  (x1,y1) – top left and (x2,y2) – bottom right.






Now for two boxes to calculate the intersection need to find the maximum for top left and minimum of bottom right.

X1_inter = max(box1(x1), box2(x1))
Y1_inter = max(box1(y1), box2(y1))
X2_inter = min(box1(x2), box2(x2))
Y2_inter = min(box1(y2), box2(y2))

Here is the code to implement iou: