Skip to content

Commit

Permalink
Merge pull request #11 from ExpediaDotCom/deployment
Browse files Browse the repository at this point in the history
Reverse proxy Deployment
  • Loading branch information
keshavpeswani authored Aug 14, 2019
2 parents 38fadd4 + 786275f commit 91f0d76
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 12 deletions.
44 changes: 44 additions & 0 deletions deployment/terraform/reverse-proxy/main.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
57 changes: 57 additions & 0 deletions deployment/terraform/reverse-proxy/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# ------------------- 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}"
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}
12 changes: 12 additions & 0 deletions deployment/terraform/reverse-proxy/variables.tf
Original file line number Diff line number Diff line change
@@ -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 = 35002
}
14 changes: 7 additions & 7 deletions haystack-blobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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`.

Expand Down Expand Up @@ -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`
The command line arguments are optional with default value of `http-port` as `:35002` and `grpc-server-endpoint` as `localhost:35001`
5 changes: 5 additions & 0 deletions haystack-blobs/blobs-agent-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
**/GrpcHealthServer.*
</exclude>
</excludes>
<rules>
<rule>
<limits>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<HealthCheckResponse> responseObserver) {
responseObserver.onNext(HealthCheckResponse.newBuilder().setStatus(HealthCheckResponse.ServingStatus.SERVING).build());
responseObserver.onCompleted();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class BlobAgent implements Agent {
this.server = server;
}

public BlobAgent(){
public BlobAgent() {

}

Expand All @@ -58,7 +59,8 @@ void _initialize(List<BlobDispatcher> 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.
Expand Down
6 changes: 6 additions & 0 deletions haystack-blobs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
<version>${grpc.version}</version>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-services</artifactId>
<version>${grpc.version}</version>
</dependency>

<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion haystack-blobs/reverse-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 2 additions & 2 deletions haystack-blobs/reverse-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 91f0d76

Please sign in to comment.