Use OPENRESTY_URL over protocol + domain (#11289)

* Use OPENRESTY_URL over protocol + domain

* Prefer OpenResty over Openresty
This commit is contained in:
Vaidehi Joshi 2020-11-06 08:58:59 -08:00 committed by GitHub
parent 81dfded1fc
commit 97d5bc47b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 20 deletions

View file

@ -6,10 +6,6 @@ export APP_DOMAIN="localhost:3000"
export APP_PROTOCOL="http://"
export FOREM_OWNER_SECRET="secret"
# Openresty domain + Protocol setting for development
export OPENRESTY_DOMAIN=""
export OPENRESTY_PROTOCOL=""
# Community Related Variables
export COMMUNITY_NAME="DEV(local)"
@ -37,6 +33,9 @@ export REDIS_SIDEKIQ_URL="redis://localhost:6379"
# Elasticsearch
export ELASTICSEARCH_URL="http://localhost:9200"
# OpenResty
export OPENRESTY_URL=""
# SSL config
export FORCE_SSL_IN_RAILS="not applicable in dev"

View file

@ -44,7 +44,7 @@ module EdgeCache
end
def nginx_enabled?
ApplicationConfig["OPENRESTY_PROTOCOL"].present? && ApplicationConfig["OPENRESTY_DOMAIN"].present?
ApplicationConfig["OPENRESTY_URL"].present?
end
end
end

View file

@ -4,7 +4,7 @@ module EdgeCache
def self.call(path)
return unless nginx_available?
uri = URI.parse("#{openresty_path}#{path}")
uri = URI.parse("#{ApplicationConfig['OPENRESTY_URL']}#{path}")
http = Net::HTTP.new(uri.host, uri.port)
response = http.request Net::HTTP::Purge.new(uri.request_uri)
@ -13,10 +13,6 @@ module EdgeCache
response.body
end
def self.openresty_path
"#{ApplicationConfig['OPENRESTY_PROTOCOL']}#{ApplicationConfig['OPENRESTY_DOMAIN']}"
end
def self.nginx_available?
# TODO: (Vaidehi Joshi) - Right now, we are checking that nginx is
# available on every purge request/call to this bust service. If we are going
@ -24,16 +20,17 @@ module EdgeCache
# available just once, and persist it on the class with @provider_available?.
# Then, we could allow for an array of @paths = [] to be passed in,
# and on single bust instance could bust multiple paths in order.
uri = URI.parse(openresty_path)
uri = URI.parse(ApplicationConfig["OPENRESTY_URL"])
http = Net::HTTP.new(uri.host, uri.port)
response = http.get(uri.request_uri)
return true if response.is_a?(Net::HTTPSuccess)
rescue StandardError
# If we can't connect to Openresty, alert ourselves that
# If we can't connect to OpenResty, alert ourselves that
# it is unavailable and return false.
Rails.logger.error("Could not connect to Openresty via #{openresty_path}!")
DatadogStatsClient.increment("edgecache_bust.service_unavailable", tags: ["path:#{openresty_path}"])
Rails.logger.error("Could not connect to OpenResty via #{ApplicationConfig['OPENRESTY_URL']}!")
DatadogStatsClient.increment("edgecache_bust.service_unavailable",
tags: ["path:#{ApplicationConfig['OPENRESTY_URL']}"])
false
end
end

View file

@ -58,7 +58,7 @@ RSpec.describe EdgeCache::Bust, type: :service do
stub_fastly
end
context "when openresty is not configured" do
context "when OpenResty is not configured" do
before do
stub_nginx
end
@ -74,7 +74,7 @@ RSpec.describe EdgeCache::Bust, type: :service do
end
end
context "when openresty is configured and available" do
context "when OpenResty is configured and available" do
before do
configure_nginx
end
@ -97,8 +97,7 @@ RSpec.describe EdgeCache::Bust, type: :service do
end
def stub_nginx
allow(ApplicationConfig).to receive(:[]).with("OPENRESTY_PROTOCOL").and_return(nil)
allow(ApplicationConfig).to receive(:[]).with("OPENRESTY_DOMAIN").and_return(nil)
allow(ApplicationConfig).to receive(:[]).with("OPENRESTY_URL").and_return(nil)
end
def configure_fastly
@ -108,7 +107,6 @@ RSpec.describe EdgeCache::Bust, type: :service do
end
def configure_nginx
allow(ApplicationConfig).to receive(:[]).with("OPENRESTY_PROTOCOL").and_return("http://")
allow(ApplicationConfig).to receive(:[]).with("OPENRESTY_DOMAIN").and_return("localhost:9090")
allow(ApplicationConfig).to receive(:[]).with("OPENRESTY_URL").and_return("http://localhost:9090")
end
end