From ca4607225e3a251d83d2ff89d344680a84f8bebe Mon Sep 17 00:00:00 2001 From: vaibhavsawhney Date: Wed, 14 Aug 2019 09:44:32 +0530 Subject: [PATCH 1/5] Reverse proxy Deployment --- deployment/terraform/reverse-proxy/main.tf | 44 +++++++++++++ .../reverse-proxy/templates/deployment.yaml | 66 +++++++++++++++++++ .../terraform/reverse-proxy/variables.tf | 12 ++++ 3 files changed, 122 insertions(+) create mode 100644 deployment/terraform/reverse-proxy/main.tf create mode 100644 deployment/terraform/reverse-proxy/templates/deployment.yaml create mode 100644 deployment/terraform/reverse-proxy/variables.tf diff --git a/deployment/terraform/reverse-proxy/main.tf b/deployment/terraform/reverse-proxy/main.tf new file mode 100644 index 0000000..5282e48 --- /dev/null +++ b/deployment/terraform/reverse-proxy/main.tf @@ -0,0 +1,44 @@ +locals { + app_name = "blobs-http-reverse-proxy" + deployment_yaml_file_path = "${path.module}/templates/deployment.yaml" + count = "${var.reverse-proxy["enabled"]?1:0}" +} + +data "template_file" "deployment_yaml" { + template = "${file("${local.deployment_yaml_file_path}")}" + + vars { + app_name = "${local.app_name}" + node_selecter_label = "${var.node_selector_label}" + image = "expediadotcom/blobs-http-reverse-proxy:${var.reverse-proxy["version"]}" + replicas = "${var.reverse-proxy["proxy_instances"]}" + enabled = "${var.reverse-proxy["enabled"]}" + cpu_limit = "${var.reverse-proxy["proxy_cpu_limit"]}" + cpu_request = "${var.reverse-proxy["proxy_cpu_request"]}" + memory_limit = "${var.reverse-proxy["proxy_memory_limit"]}" + memory_request = "${var.reverse-proxy["proxy_memory_request"]}" + jvm_memory_limit = "${var.reverse-proxy["proxy_jvm_memory_limit"]}" + kubectl_context_name = "${var.kubectl_context_name}" + kubectl_executable_name = "${var.kubectl_executable_name}" + namespace = "${var.namespace}" + grpc_server_endpoint = "${var.reverse-proxy["grpc_server_endpoint"]}" + service_port = "${var.service_port}" + } +} + +resource "null_resource" "reverseproxy_addon" { + triggers { + template = "${data.template_file.deployment_yaml.rendered}" + } + + provisioner "local-exec" { + command = "echo '${data.template_file.deployment_yaml.rendered}' | ${var.kubectl_executable_name} apply -f - --context ${var.kubectl_context_name}" + } + + provisioner "local-exec" { + command = "echo '${data.template_file.deployment_yaml.rendered}' | ${var.kubectl_executable_name} delete -f - --context ${var.kubectl_context_name} || true" + when = "destroy" + } + + count = "${local.count}" +} diff --git a/deployment/terraform/reverse-proxy/templates/deployment.yaml b/deployment/terraform/reverse-proxy/templates/deployment.yaml new file mode 100644 index 0000000..4bca1f3 --- /dev/null +++ b/deployment/terraform/reverse-proxy/templates/deployment.yaml @@ -0,0 +1,66 @@ +# ------------------- Deployment ------------------- # + +kind: Deployment +apiVersion: apps/v1beta2 +metadata: + labels: + k8s-app: ${app_name} + name: ${app_name} + namespace: ${namespace} +spec: + replicas: ${replicas} + revisionHistoryLimit: 10 + selector: + matchLabels: + k8s-app: ${app_name} + template: + metadata: + labels: + k8s-app: ${app_name} + spec: + containers: + - name: ${app_name} + image: ${image} + resources: + limits: + cpu: ${cpu_limit} + memory: ${memory_limit}Mi + requests: + cpu: ${cpu_request} + memory: ${memory_request}Mi + env: + - name: "JAVA_XMS" + value: "${jvm_memory_limit}m" + - name: "JAVA_XMX" + value: "${jvm_memory_limit}m" + - name: "grpc-server-endpoint" + value: ${grpc_server_endpoint} + - name: "http-port" + value: ":${service_port}" +# livenessProbe: +# exec: +# command: +# - /bin/grpc_health_probe +# - "-addr=:${container_port}" +# initialDelaySeconds: 30 +# periodSeconds: 15 +# timeoutSeconds: 5 +# failureThreshold: 3 + nodeSelector: + ${node_selecter_label} + +# ------------------- Service ------------------- # +--- +apiVersion: v1 +kind: Service +metadata: + labels: + k8s-app: ${app_name} + name: ${app_name} + namespace: ${namespace} +spec: + ports: + - port: ${service_port} + targetPort: ${service_port} + selector: + k8s-app: ${app_name} \ No newline at end of file diff --git a/deployment/terraform/reverse-proxy/variables.tf b/deployment/terraform/reverse-proxy/variables.tf new file mode 100644 index 0000000..93ad290 --- /dev/null +++ b/deployment/terraform/reverse-proxy/variables.tf @@ -0,0 +1,12 @@ +variable "kubectl_context_name" {} +variable "kubectl_executable_name" {} +variable "namespace" {} +variable "node_selector_label"{} + +variable "reverse-proxy" { + type = "map" +} + +variable "service_port" { + default = 34002 +} \ No newline at end of file From a81cea0ed0da2f69fd1e6cf63ad61cb5503ac630 Mon Sep 17 00:00:00 2001 From: vaibhavsawhney Date: Wed, 14 Aug 2019 10:46:33 +0530 Subject: [PATCH 2/5] Ports changed from 34* series to 35* --- deployment/terraform/reverse-proxy/variables.tf | 2 +- haystack-blobs/README.md | 14 +++++++------- haystack-blobs/reverse-proxy/Dockerfile | 2 +- haystack-blobs/reverse-proxy/main.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/deployment/terraform/reverse-proxy/variables.tf b/deployment/terraform/reverse-proxy/variables.tf index 93ad290..86d2693 100644 --- a/deployment/terraform/reverse-proxy/variables.tf +++ b/deployment/terraform/reverse-proxy/variables.tf @@ -8,5 +8,5 @@ variable "reverse-proxy" { } variable "service_port" { - default = 34002 + default = 35002 } \ No newline at end of file diff --git a/haystack-blobs/README.md b/haystack-blobs/README.md index 47c4c4a..814428c 100644 --- a/haystack-blobs/README.md +++ b/haystack-blobs/README.md @@ -18,7 +18,7 @@ Below is a sample configuration for blobs in [Haystack-Agent](https://github.com agents { ossblobs { enabled = true - port = 34001 + port = 35001 max.blob.size.in.kb = 1536 dispatchers { s3 { @@ -44,7 +44,7 @@ This is a GRPC client that is used to send the blob to wherever the server resid The client is initiated using a builder which can either take a [ManagedChannel](https://grpc.github.io/grpc-java/javadoc/io/grpc/ManagedChannel.html) object or `address` and `port` of the server running. -The server in the haystack-agent is running at a default port 34001. +The server in the haystack-agent is running at a default port 35001. ### Agent Provider or Server We have one agent provider today that is loaded depending upon the configuration as above. @@ -93,11 +93,11 @@ To run the HTTP proxy to GRPC service locally please follow the below steps as w 1. Inside `reverse-proxy`, build using `go build` 2. You can add 2 optional environment variables using: - `$ export grpc-server-endpoint=localhost:34001` + `$ export grpc-server-endpoint=localhost:35001` - `$ export http-port=:34002` + `$ export http-port=:35002` - The default value of `http-port` is `:34002` and `grpc-server-endpoint` is `localhost:34001` + The default value of `http-port` is `:35002` and `grpc-server-endpoint` is `localhost:35001` 3. To run the server use `./main`. @@ -158,6 +158,6 @@ protoc -I/usr/local/include -I. \ 7. Inside `reverse-proxy` call `go build` -8. To run the server use `./main -http-port=:34002 -grpc-server-endpoint=localhost:34001`. +8. To run the server use `./main -http-port=:35002 -grpc-server-endpoint=localhost:35001`. - The command line arguments are optional with default value of `http-port` as `:34002` and `grpc-server-endpoint` as `localhost:34001` \ No newline at end of file + The command line arguments are optional with default value of `http-port` as `:35002` and `grpc-server-endpoint` as `localhost:35001` \ No newline at end of file diff --git a/haystack-blobs/reverse-proxy/Dockerfile b/haystack-blobs/reverse-proxy/Dockerfile index f10fdbf..37e5216 100644 --- a/haystack-blobs/reverse-proxy/Dockerfile +++ b/haystack-blobs/reverse-proxy/Dockerfile @@ -10,5 +10,5 @@ FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /root/ COPY --from=builder /work/app . -EXPOSE 34002 +EXPOSE 35002 CMD ["./app"] \ No newline at end of file diff --git a/haystack-blobs/reverse-proxy/main.go b/haystack-blobs/reverse-proxy/main.go index 89496c6..051a62b 100644 --- a/haystack-blobs/reverse-proxy/main.go +++ b/haystack-blobs/reverse-proxy/main.go @@ -14,9 +14,9 @@ import ( ) const GRPC_SERVER_ENDPOINT_ENV_VAR = "grpc-server-endpoint" -const DEFAULT_GRPC_SERVER_ENDPOINT = "haystack-agent:34001" +const DEFAULT_GRPC_SERVER_ENDPOINT = "haystack-agent:35001" const PROXY_SERVER_HTTP_PORT = "http-port" -const DEFAULT_PROXY_SERVER_HTTP_PORT = ":34002" +const DEFAULT_PROXY_SERVER_HTTP_PORT = ":35002" func getGrpcServerEndpoint() string { grpcServerEndpoint := os.Getenv(GRPC_SERVER_ENDPOINT_ENV_VAR) From ba2611d5d42e3d23a4097e08e336f9ab1d4536b3 Mon Sep 17 00:00:00 2001 From: vaibhavsawhney Date: Wed, 14 Aug 2019 10:47:05 +0530 Subject: [PATCH 3/5] Heath check for grpc added --- .../agent/blobs/server/api/GrpcHealthServer.java | 15 +++++++++++++++ .../agent/blobs/server/spi/BlobAgent.java | 6 ++++-- haystack-blobs/pom.xml | 6 ++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/api/GrpcHealthServer.java diff --git a/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/api/GrpcHealthServer.java b/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/api/GrpcHealthServer.java new file mode 100644 index 0000000..63f5685 --- /dev/null +++ b/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/api/GrpcHealthServer.java @@ -0,0 +1,15 @@ +package com.expedia.www.haystack.agent.blobs.server.api; + +import io.grpc.health.v1.HealthCheckRequest; +import io.grpc.health.v1.HealthCheckResponse; +import io.grpc.health.v1.HealthGrpc; +import io.grpc.stub.StreamObserver; + +public class GrpcHealthServer extends HealthGrpc.HealthImplBase { + + @Override + public void check(HealthCheckRequest request, StreamObserver responseObserver) { + responseObserver.onNext(HealthCheckResponse.newBuilder().setStatus(HealthCheckResponse.ServingStatus.SERVING).build()); + responseObserver.onCompleted(); + } +} diff --git a/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/spi/BlobAgent.java b/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/spi/BlobAgent.java index ac0672f..89637f0 100644 --- a/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/spi/BlobAgent.java +++ b/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/spi/BlobAgent.java @@ -2,6 +2,7 @@ import com.expedia.www.haystack.agent.blobs.dispatcher.core.BlobDispatcher; import com.expedia.www.haystack.agent.blobs.server.api.BlobAgentGrpcServer; +import com.expedia.www.haystack.agent.blobs.server.api.GrpcHealthServer; import com.expedia.www.haystack.agent.core.Agent; import com.google.common.annotations.VisibleForTesting; import com.typesafe.config.Config; @@ -31,7 +32,7 @@ public class BlobAgent implements Agent { this.server = server; } - public BlobAgent(){ + public BlobAgent() { } @@ -58,7 +59,8 @@ void _initialize(List dispatchers, Config config) throws IOExcep final NettyServerBuilder builder = NettyServerBuilder .forPort(port) .directExecutor() - .addService(new BlobAgentGrpcServer(dispatchers, maxBlobSizeInBytes)); + .addService(new BlobAgentGrpcServer(dispatchers, maxBlobSizeInBytes)) + .addService(new GrpcHealthServer()); // default max message size in grpc is 4MB. if our maxBlobSize is greater than 4MB then we should configure this // limit in the netty based grpc server. diff --git a/haystack-blobs/pom.xml b/haystack-blobs/pom.xml index 677e039..caa90d9 100644 --- a/haystack-blobs/pom.xml +++ b/haystack-blobs/pom.xml @@ -45,6 +45,12 @@ ${grpc.version} + + io.grpc + grpc-services + ${grpc.version} + + org.easymock easymock From 69da9f0afa06ab93ac21c3b6c0daa679879e5125 Mon Sep 17 00:00:00 2001 From: vaibhavsawhney Date: Wed, 14 Aug 2019 11:04:59 +0530 Subject: [PATCH 4/5] Excluded health check from jococo --- haystack-blobs/blobs-agent-server/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/haystack-blobs/blobs-agent-server/pom.xml b/haystack-blobs/blobs-agent-server/pom.xml index 8a13000..075567e 100644 --- a/haystack-blobs/blobs-agent-server/pom.xml +++ b/haystack-blobs/blobs-agent-server/pom.xml @@ -119,6 +119,11 @@ org.jacoco jacoco-maven-plugin + + + **/GrpcHealthServer.* + + From 786275f0574680983d012ce9ec4e7d9f8fb0fdcf Mon Sep 17 00:00:00 2001 From: vaibhavsawhney Date: Wed, 14 Aug 2019 11:11:32 +0530 Subject: [PATCH 5/5] Removal of unnecessary comments --- .../terraform/reverse-proxy/templates/deployment.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/deployment/terraform/reverse-proxy/templates/deployment.yaml b/deployment/terraform/reverse-proxy/templates/deployment.yaml index 4bca1f3..3f47d06 100644 --- a/deployment/terraform/reverse-proxy/templates/deployment.yaml +++ b/deployment/terraform/reverse-proxy/templates/deployment.yaml @@ -37,15 +37,6 @@ spec: value: ${grpc_server_endpoint} - name: "http-port" value: ":${service_port}" -# livenessProbe: -# exec: -# command: -# - /bin/grpc_health_probe -# - "-addr=:${container_port}" -# initialDelaySeconds: 30 -# periodSeconds: 15 -# timeoutSeconds: 5 -# failureThreshold: 3 nodeSelector: ${node_selecter_label}