---
# Source: social-network/charts/media-frontend/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: media-frontend
  labels:
    socialnetwork/service: media-frontend
data:
  nginx.conf: |    
    # Checklist: Make sure that worker_processes == #cores you gave to
    # nginx process
    worker_processes  16;
    
    # error_log  logs/error.log;
    
    # Checklist: Make sure that worker_connections * worker_processes
    # is greater than the total connections between the client and Nginx.
    events {
      worker_connections  1024;
    }
    
    env fqdn_suffix;
    
    http {
      include       mime.types;
      default_type  application/octet-stream;
    
      log_format main '$remote_addr - $remote_user [$time_local] "$request"'
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
      # access_log  logs/access.log  main;
    
      sendfile        on;
      tcp_nopush      on;
      tcp_nodelay     on;
    
      # Checklist: Make sure the keepalive_timeout is greateer than
      # the duration of your experiment and keepalive_requests
      # is greateer than the total number of requests sent from
      # the workload generator
      keepalive_timeout  120s;
      keepalive_requests 100000;
    
      # Docker default hostname resolver
      resolver kube-dns.kube-system.svc.cluster.local valid=10s ipv6=off;
    
      lua_package_path '/usr/local/openresty/nginx/lua-scripts/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;;';
    
      lua_shared_dict config 32k;
    
      init_by_lua_block {
        local upload = require "resty.upload"
        local memcached = require "resty.memcached"
        local mongo = require "resty-mongol"
      }
    
      server {
    
        # Checklist: Set up the port that nginx listens to.
        listen       8080 reuseport;
        server_name  localhost;
    
        # Checklist: Turn of the access_log and error_log if you
        # don't need them.
        access_log  off;
        # error_log off;
    
        client_max_body_size 100M;
        client_body_buffer_size 100M;
    
        # Checklist: Make sure that the location here is consistent
        # with the location you specified in wrk2.
        location /upload-media {
              if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain; charset=utf-8';
                add_header 'Content-Length' 0;
                return 204;
              }
              if ($request_method = 'POST') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
              }
              if ($request_method = 'GET') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
              }
          content_by_lua '
            local client = require "upload-media"
            client.UploadMedia();
          ';
        }
    
        # Checklist: Make sure that the location here is consistent
        # with the location you specified in wrk2.
        location /get-media {
              if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain; charset=utf-8';
                add_header 'Content-Length' 0;
                return 204;
              }
              if ($request_method = 'POST') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
              }
              if ($request_method = 'GET') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
              }
          content_by_lua '
            local client = require "get-media"
            client.GetMedia();
          ';
        }
    
      }
    }
  service-config.json: |    
    {
        "secret": "secret",
        "social-graph-service": {
          "addr": "social-graph-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "social-graph-mongodb": {
          "addr": "social-graph-mongodb",
          "port": 27017,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "social-graph-redis": {
          "addr": "social-graph-redis",
          "port": 6379,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "write-home-timeline-service": {
          "addr": "write-home-timeline-service",
          "port": 9090,
          "workers": 32,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "write-home-timeline-rabbitmq": {
          "addr": "write-home-timeline-rabbitmq",
          "port": 5672,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "home-timeline-redis": {
          "addr": "home-timeline-redis",
          "port": 6379,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "compose-post-service": {
          "addr": "compose-post-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "compose-post-redis": {
          "addr": "compose-post-redis",
          "port": 6379,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "user-timeline-service": {
          "addr": "user-timeline-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "user-timeline-mongodb": {
          "addr": "user-timeline-mongodb",
          "port": 27017,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "user-timeline-redis": {
          "addr": "user-timeline-redis",
          "port": 6379,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "post-storage-service": {
          "addr": "post-storage-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "post-storage-mongodb": {
          "addr": "post-storage-mongodb",
          "port": 27017,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "post-storage-memcached": {
          "addr": "post-storage-memcached",
          "port": 11211,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "unique-id-service": {
          "addr": "unique-id-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000,
          "netif": "eth0"
        },
        "media-service": {
          "addr": "media-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "media-mongodb": {
          "addr": "media-mongodb",
          "port": 27017,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "media-memcached": {
          "addr": "media-memcached",
          "port": 11211,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "media-frontend": {
          "addr": "media-frontend",
          "port": 8081,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "text-service": {
          "addr": "text-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "user-mention-service": {
          "addr": "user-mention-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "url-shorten-service": {
          "addr": "url-shorten-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "url-shorten-memcached": {
          "addr": "url-shorten-memcached",
          "port": 11211,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "url-shorten-mongodb": {
          "addr": "url-shorten-mongodb",
          "port": 27017,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "user-service": {
          "addr": "user-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000,
          "netif": "eth0"
        },
        "user-memcached": {
          "addr": "user-memcached",
          "port": 11211,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "user-mongodb": {
          "addr": "user-mongodb",
          "port": 27017,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "home-timeline-service": {
          "addr": "home-timeline-service",
          "port": 9090,
          "connections": 512,
          "timeout_ms": 10000,
          "keepalive_ms": 10000
        },
        "ssl": {
          "enabled": false,
          "caPath": "/keys/CA.pem",
          "ciphers": "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH",
          "serverKeyPath": "/keys/server.key",
          "serverCertPath": "/keys/server.crt"
        }
      }
