Project: EaseMesh (Orchestration & Management / Service Mesh)
File: sidecar-protocol.md

EaseMesh uses Easegress-based sidecar inside Kubernetes Pod for traffic hosting* and EaseAgent for metrics reporting and RESTful-API-based RPC enhancement. EaseMesh only supports Java SpringCloud ecosystem's application natively currently. There are three types of traffic that are managed by EaseMesh. First, the RESTful-API HTTP traffic* for RPC inside the mesh. This traffic is invoked by Java applications with popular RPC frameworks, such as Feign, RestTemplate, and so on. EaseAgent will enhance this traffic by adding the target RPC server's name inside the HTTP header for telling the sidecar of the real handler. The traffic must satisfy at least one way of: Headers: `X-Mesh-Rpc-Service: {destinationservicename}` Headers: `Host: {destinationservicename}` or `Host: ^(\w+\.)*{destinationservicename}\.(\w+)\.svc\..+` Second, the Health-checking HTTP traffic*. This traffic is sent from the sidecar to the Java application's additional port opened by EaseAgent. The complete URI is `http://localhost:9900/health` by default. This `9900` port is opened by EaseAgent, sidecar will query this URI period for checking the liveness of the Java application. After successfully deployed, sidecar will registry this instance into EaseMesh automatically after confirming the HTTP 200 success return by this URI. Third, the Service-discovery traffic*. This traffic is invoked by the Java spring cloud application's RPC framework. During the lifetime of the Java application, sidecar will work as the Java application's service registry and discovery center. EaseMesh sidecar implements Eureka/Consul/Naocs APIs for hosting the Java application's registry and discovery requests. To make the sidecar server the registry and discovery center, value it with `http://localhost:13009` inside the Java application's XML. The port `13009` is listened by sidecar for handling Eureka/Consul/Nacos

The ports used by EaseMesh sidecar+agent system | Role | Port | Description | |-|-|--| | Sidecar | 13001 | The default Ingress port listened by sidecar for handing over traffic to local Java application | | Sidecar | 13002 | The default egress port listened by sidecar for routing local Java applications RPC request to another Java application | | Sidecar | 13009 | The default registry and discovery port listened by sidecar, for handling local Java application's Eureka/Conslu/Nacos APIs | | Agent | 9900 | The default health port listened by Agent queried by sidecar for checking the liveness of Java application | | Application | customized port | The port listened by the user application. The sidecar routes ingress traffic to it | Figuring out the standard for supporting multiple-language programs running inside EaseMesh. To support the none-Java-spring-cloud-based RESTful-API application, we had demoed a DNS-enhancement way for supporting Java spring boot application. Can we reuse this way to support Golang-based or RUST-based RESTful-API applications? ](https://mermaid-js.github.io/mermaid-live-editor/edit/#eyJjb2RlIjoic2VxdWVuY2VEaWFncmFtXG4gICAgSmF2YUFQUCAtPj4gK2NvcmVETlMgOiBhc2tpbmcgdGhlIGRvbWFpbiBhbmFseXNpc1xuICAgIGNvcmVETlMgLT4-ICtFdGNkIDogc2VhcmNoIHNlcnZpY2UgaW4gRWFzZU1lc2ggRXRjZFxuICAgIEV0Y2QgLT4-IC1jb3JlRE5TIDogcmV0dXJuIGxvY2FsIHNpZGVjYXIgYWRkcmVzcyBpZiBpdCdzIGEgbWVzaCBzZXJ2aWNlc1xuICAgIGNvcmVETlMgLT4-ICAtSmF2YUFQUCA6IHJldHVybiB0aGUgbG9jYWwgc2lkZWNhciBhZGRyXG4gICAgSmF2YUFQUCAtPj4gK2xvY2FsU2lkZWNhciA6IFJFU1RmdWwgcmVxdWVzdFxuICAgIGxvY2FsU2lkZWNhciAtPj4gK3RhcmdldFNpZGVjYXIgOiByb3V0aW5nIHRvIHRhcmdldCBzZXJ2ZXIncyBzaWRlY2FyXG4gICAgdGFyZ2V0U2lkZWNhciAtPj4gK3RhcmdldEphdmFBUFA6IHJvdXRpbmcgdG8gdGhlIHJlYWwgaGFuZGxlclxuICAgIHRhcmdldEphdmFBUFAgLT4-IC10YXJnZXRTaWRlY2FyOiByZXR1cm4gdGhlIHJlc3VsdFxuICAgIHRhcmdldFNpZGVjYXIgLT4-IC1sb2NhbFNpZGVjYXI6IHJldHVybiB0aGUgcmVzdWx0XG4gICAgbG9jYWxTaWRlY2FyIC0-PiAtSmF2YUFQUCA6IHJldHVybiB0aGUgcmVzc3VsdCIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJ1cGRhdGVFZGl0b3IiOmZhbHNlLCJhdXRvU3luYyI6dHJ1ZSwidXBkYXRlRGlhZ3JhbSI6ZmFsc2V9) To support non-registry-discovery dependent on Java spring boot application, EaseMesh enhances Kubernetes' coreDNS with add a plugin for finding services inside EaseMesh's Etcd. We can reuse this method for none-Java-based programs. EaseAgent uses Java Byte Buddy-based technology for collecting several application metrics. This requires a JVM-liked software architecture. This observability will be sacrificed for the none-Java-spring-cloud-based RESTful-API application. To support the none-Java-spring-cloud-based RESTful-API application, regardless of which programming is used. The application must follow the protocol below It must serve as standard RESTful-API for handling requesting or invoking RPC. It must use a domain for discovering in RESTful-API RPC. ```plain Requirement: Use coreDNS with easemesh specific plugin Valid domain formats: Service name, e.g. `vet-services` Service name with more subdomains, e.g. `_tcp.vet-services.easemesh.svc.cluster.local` `vet-services.easemesh.svc.cluster.local` `zip.tcp.vet-services.easemesh.svc.com` ``` It must serve the `http://localhost:9900/health` URI for EaseMesh health checking. (Only HTTP 200 return is required, regardless of the body content) It must reserve ports `13001` , `13002` and `13009` for local sidecar usage. It should specify the application port in Kubernetes deployment's `mesh.megaease.com/application-port` annotation for sidecar routing the ingress traffic. If it is omitted, the first port of the first container will be regarded as the application port. The sidecar periodically post agent config to `http://localhost:9900/config` to notify the latest config. The config body is like(some fields are ommitted) ```json { "easeagent.progress.forwarded.headers": "X-Location,X-Mesh-Service-Canary,X-Phone-Os", "loadBalance.policy": "random", "name": "service-001", "registerTenant": "mesh-tenant", "sidecar.address": "127.0.0.1", "sidecar.discoveryType": "consul", "sidecar.egressPort": "13002", "sidecar.egressProtocol": "http", "sidecar.ingressPort": "13001", "sidecar.ingressProtocol": "http" } ``` For example, we extract the value of `easeagent.progress.forwarded.headers` to get the canary headers needed to transmit across the chain. If an application obeys the protocol above, then EaseMesh can run it inside with sacrificed observability regardless of the implements programming language.