From 3cbe98ff4a691bccdd779b9c18841c1fdbfcd30a Mon Sep 17 00:00:00 2001 From: Fernandez Feijoo Date: Tue, 8 Oct 2019 19:42:16 -0300 Subject: [PATCH 1/8] fix for backend get calls --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1807ae0..04480f9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,7 +10,7 @@ class ApplicationController < ActionController::Base # Example endpoint that calls the backend nodejs api def index begin - req = Net::HTTP::Get.new(nodejs_uri.to_s) + req = Net::HTTP::Get.new(nodejs_uri.path) res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 @@ -30,7 +30,7 @@ def index end begin - crystalreq = Net::HTTP::Get.new(crystal_uri.to_s) + crystalreq = Net::HTTP::Get.new(crystal_uri.path) crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 From 8d24ab18eaad360606528a1de1797da9fa3bde9c Mon Sep 17 00:00:00 2001 From: Fernandez Feijoo Date: Sat, 12 Oct 2019 10:52:09 -0300 Subject: [PATCH 2/8] new behavior for app mesh workshop runs --- app/controllers/application_controller.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 04480f9..82765f6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,7 +10,8 @@ class ApplicationController < ActionController::Base # Example endpoint that calls the backend nodejs api def index begin - req = Net::HTTP::Get.new(nodejs_uri.path) + # req = Net::HTTP::Get.new(nodejs_uri.path.presence || "/") + req = Net::HTTP::Get.new(nodejs_uri.request_uri) res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 @@ -30,7 +31,8 @@ def index end begin - crystalreq = Net::HTTP::Get.new(crystal_uri.path) + # crystalreq = Net::HTTP::Get.new(crystal_uri.path.presence || "/") + crystalreq = Net::HTTP::Get.new(crystal_uri.request_uri) crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 @@ -56,11 +58,19 @@ def health end def crystal_uri - expand_url ENV["CRYSTAL_URL"] + if ENV['MESH_RUN'].present? && ENV['MESH_RUN'] == 'true' + uri = URI(ENV["CRYSTAL_URL"]) + else + expand_url ENV["CRYSTAL_URL"] + end end def nodejs_uri - expand_url ENV["NODEJS_URL"] + if ENV['MESH_RUN'].present? && ENV['MESH_RUN'] == 'true' + uri = URI(ENV["NODEJS_URL"]) + else + expand_url ENV["NODEJS_URL"] + end end # Resolve the SRV records for the hostname in the URL @@ -104,4 +114,4 @@ def code_hash def custom_header response.headers['Cache-Control'] = 'max-age=86400, public' end -end +end \ No newline at end of file From cde3f47923d4b7308ef62d52d7e9974a5b038812 Mon Sep 17 00:00:00 2001 From: Fernandez Feijoo Date: Sat, 12 Oct 2019 16:54:25 -0300 Subject: [PATCH 3/8] formatting --- app/controllers/application_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 82765f6..ae1fa95 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -114,4 +114,5 @@ def code_hash def custom_header response.headers['Cache-Control'] = 'max-age=86400, public' end + end \ No newline at end of file From 4bf192ea97b24b85af1c8152c1b16b477b03629a Mon Sep 17 00:00:00 2001 From: Fernandez Feijoo Date: Thu, 17 Oct 2019 23:05:23 -0300 Subject: [PATCH 4/8] adding json response --- app/controllers/application_controller.rb | 24 +++++++++++++++++++++++ config/routes.rb | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ae1fa95..142cb0f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -50,6 +50,30 @@ def index logger.error e.backtrace.join("\n") @crystal = "no backend found" end + + if params[:type].present? && params[:type] == "json" + response = { } + response[:ruby] = { + :az => @az, + :hash => @code_hash + } + + if @crystal != "no backend found" + response[:crystal] = { :text => @crystal } + end + + if @text != "no backend found" + response[:nodejs] = { :text => @text } + end + + render json: response.to_json + + end + + end + + def json + redirect_to root_path(:type => "json") end # This endpoint is used for health checks. It should return a 200 OK when the app is up and ready to serve requests. diff --git a/config/routes.rb b/config/routes.rb index 878796e..7564554 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,4 +7,8 @@ # This URL is used for health checks get 'health' => 'application#health' + + # This URL is used for json + get 'json' => 'application#json' + end From 7a0c72fa7dc51e430fc16040f20a7a00d0d9dd69 Mon Sep 17 00:00:00 2001 From: Fernandez Feijoo Date: Fri, 18 Oct 2019 23:58:16 -0300 Subject: [PATCH 5/8] adding request headers --- app/controllers/application_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 142cb0f..bcd45d8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,7 @@ def index begin # req = Net::HTTP::Get.new(nodejs_uri.path.presence || "/") req = Net::HTTP::Get.new(nodejs_uri.request_uri) + req["HTTP_FORMAT_HEADER"] = request.headers["HTTP_FORMAT_HEADER"] res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 @@ -33,6 +34,7 @@ def index begin # crystalreq = Net::HTTP::Get.new(crystal_uri.path.presence || "/") crystalreq = Net::HTTP::Get.new(crystal_uri.request_uri) + crystalreq["HTTP_FORMAT_HEADER"] = request.headers["HTTP_FORMAT_HEADER"] crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 From 76e4e5a33157132c70886d00a35904a220985869 Mon Sep 17 00:00:00 2001 From: Fernandez Feijoo Date: Sat, 19 Oct 2019 00:05:54 -0300 Subject: [PATCH 6/8] fixing header name --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bcd45d8..3ded1ba 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,7 +12,7 @@ def index begin # req = Net::HTTP::Get.new(nodejs_uri.path.presence || "/") req = Net::HTTP::Get.new(nodejs_uri.request_uri) - req["HTTP_FORMAT_HEADER"] = request.headers["HTTP_FORMAT_HEADER"] + req["HTTP_CANARY_FLEET"] = request.headers["HTTP_CANARY_FLEET"] res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 @@ -34,7 +34,7 @@ def index begin # crystalreq = Net::HTTP::Get.new(crystal_uri.path.presence || "/") crystalreq = Net::HTTP::Get.new(crystal_uri.request_uri) - crystalreq["HTTP_FORMAT_HEADER"] = request.headers["HTTP_FORMAT_HEADER"] + crystalreq["HTTP_CANARY_FLEET"] = request.headers["HTTP_CANARY_FLEET"] crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 From eb7907124da6a31ed4e70bf27f6a7319a2c7355f Mon Sep 17 00:00:00 2001 From: Fernandez Feijoo Date: Sat, 19 Oct 2019 12:07:24 -0300 Subject: [PATCH 7/8] fixing canary header --- app/controllers/application_controller.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3ded1ba..c516fe3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,7 +12,10 @@ def index begin # req = Net::HTTP::Get.new(nodejs_uri.path.presence || "/") req = Net::HTTP::Get.new(nodejs_uri.request_uri) - req["HTTP_CANARY_FLEET"] = request.headers["HTTP_CANARY_FLEET"] + if request.headers["HTTP_CANARY_FLEET"].present? + req["canary_fleet"] = request.headers["HTTP_CANARY_FLEET"] + end + res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 @@ -34,7 +37,10 @@ def index begin # crystalreq = Net::HTTP::Get.new(crystal_uri.path.presence || "/") crystalreq = Net::HTTP::Get.new(crystal_uri.request_uri) - crystalreq["HTTP_CANARY_FLEET"] = request.headers["HTTP_CANARY_FLEET"] + if request.headers["HTTP_CANARY_FLEET"].present? + crystalreq["canary_fleet"] = request.headers["HTTP_CANARY_FLEET"] + end + crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 @@ -57,7 +63,8 @@ def index response = { } response[:ruby] = { :az => @az, - :hash => @code_hash + :hash => @code_hash, + :canary_fleet => request.headers["HTTP_CANARY_FLEET"].present? } if @crystal != "no backend found" From 15ff409719086adbdec501b20e419b2c8942376d Mon Sep 17 00:00:00 2001 From: Fernandez Feijoo Date: Sat, 19 Oct 2019 23:44:50 -0300 Subject: [PATCH 8/8] add request epoch ms --- app/controllers/application_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c516fe3..7d1dad2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ require 'net/http' require 'resolv' require 'uri' +require 'time' class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. @@ -9,6 +10,9 @@ class ApplicationController < ActionController::Base # Example endpoint that calls the backend nodejs api def index + + epochms = (Time.now.to_f * 1000).to_i + begin # req = Net::HTTP::Get.new(nodejs_uri.path.presence || "/") req = Net::HTTP::Get.new(nodejs_uri.request_uri) @@ -16,6 +20,7 @@ def index req["canary_fleet"] = request.headers["HTTP_CANARY_FLEET"] end + req["epoch_ms"] = epochms res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 @@ -41,6 +46,7 @@ def index crystalreq["canary_fleet"] = request.headers["HTTP_CANARY_FLEET"] end + crystalreq["epoch_ms"] = epochms crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http| http.read_timeout = 2 http.open_timeout = 2 @@ -64,7 +70,8 @@ def index response[:ruby] = { :az => @az, :hash => @code_hash, - :canary_fleet => request.headers["HTTP_CANARY_FLEET"].present? + :canary_fleet => request.headers["HTTP_CANARY_FLEET"].present?, + :epoch_ms => epochms } if @crystal != "no backend found"