Merged in VRFS-5179_resolve_latency_rest_api (pull request #23)

add api endpoint to fetch latency data

Approved-by: Seth Call
This commit is contained in:
Nuwan Chaturanga 2021-05-12 14:53:48 +00:00 committed by Seth Call
commit 96f40aed76
10 changed files with 107 additions and 3 deletions

View File

@ -227,6 +227,7 @@ group :test, :cucumber do
# gem 'growl', '1.0.3'
gem 'resque_spec'
gem 'timecop'
gem 'webmock', '~> 3.11', '>= 3.11.2'
# gem 'thin'
end

View File

@ -136,6 +136,8 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.1.8)
connection_pool (2.2.3)
crack (0.4.5)
rexml
crass (1.0.6)
database_cleaner (1.3.0)
devise (3.3.0)
@ -386,6 +388,7 @@ GEM
haml (>= 4.0.6, < 5.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
hashdiff (1.0.1)
hashie (4.1.0)
html2haml (2.2.0)
erubis (~> 2.7.0)
@ -653,6 +656,7 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retriable (3.0.1)
rexml (3.2.5)
rspec-collection_matchers (1.2.0)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (3.10.1)
@ -780,6 +784,10 @@ GEM
nokogiri (~> 1.6)
rubyzip (~> 1.0)
selenium-webdriver (>= 3.0, < 4.0)
webmock (3.12.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
will_paginate (3.3.0)
xml-simple (1.1.8)
xmlrpc (0.3.1)
@ -918,6 +926,7 @@ DEPENDENCIES
unicorn
uuidtools (= 2.1.2)
webdrivers (~> 4.0)
webmock (~> 3.11, >= 3.11.2)
will_paginate
zip-codes

View File

@ -13,7 +13,7 @@ class ApiUsersController < ApiController
:band_invitation_index, :band_invitation_show, :band_invitation_update, # band invitations
:set_password, :begin_update_email, :update_avatar, :delete_avatar, :generate_filepicker_policy,
:share_session, :share_recording,
:affiliate_report, :audio_latency, :broadcast_notification, :redeem_giftcard]
:affiliate_report, :audio_latency, :get_latencies, :broadcast_notification, :redeem_giftcard]
before_filter :ip_blacklist, :only => [:create, :redeem_giftcard]
respond_to :json, :except => :calendar
@ -935,6 +935,38 @@ class ApiUsersController < ApiController
end
end
#fetch latency information from latency-graph serverless
def get_latencies
query_str = params[:user_ids].split(',').inject(""){|q, id| q.concat("id=#{id}&")}
latency_url = "#{Rails.application.config.latency_data_host}/dev/user_latencies/#{current_user.id}?#{query_str}"
url = URI(latency_url)
begin
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if Rails.application.config.latency_data_host.start_with?("https://")
request = Net::HTTP::Get.new(url)
request["Authorization"] = "Basic #{Rails.application.config.latency_data_host_auth_code}"
response = http.request(request)
if response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPSuccess)
render json: response.body, status: 200
else
Bugsnag.notify(exception) do |report|
report.severity = "error"
report.add_tab(:latency, {
user_id: current_user.id,
name: current_user.name,
user_ids: params[:user_ids],
url: latency_url,
body: response.body
})
end
render json: {}, status: 422
end
rescue
Bugsnag.notify("Latency server returned code: #{response.code}")
render json: {}, status: 500
end
end
def udp_reachable
Connection.transaction do
@connection = Connection.find_by_client_id!(params[:client_id])

View File

@ -505,6 +505,7 @@ if defined?(Bundler)
config.braintree_token = 'sandbox_pgjp8dvs_5v5rwm94m2vrfbms'
config.paypal_admin_only = false
config.video_conferencing_host = "https://webrtc-demo.jamkazam.com"
config.latency_data_host = "http://localhost:4001"
config.latency_data_host_auth_code = "c2VydmVyOnBhc3N3b3Jk"
end
end

View File

@ -1,4 +1,3 @@
def audiomixer_workspace_path
if ENV['WORKSPACE']
dev_path = ENV['WORKSPACE']
@ -115,4 +114,6 @@ SampleApp::Application.configure do
config.video_conferencing_host = "https://webrtc-demo.jamkazam.com"
config.use_video_conferencing_server = true
config.latency_data_host = "http://localhost:4001"
config.latency_data_host_auth_code = "c2VydmVyOnBhc3N3b3Jk"
end

View File

@ -96,4 +96,6 @@ SampleApp::Application.configure do
config.video_conferencing_host = ""
config.use_video_conferencing_server = false
config.latency_data_host = ""
config.latency_data_host_auth_code = ""
end

View File

@ -133,5 +133,7 @@ SampleApp::Application.configure do
config.video_conferencing_host = "https://webrtc-demo.jamkazam.com"
config.use_video_conferencing_server = false
config.latency_data_host = "http://localhost:4001"
config.latency_data_host_auth_code = "c2VydmVyOnBhc3N3b3Jk"
end

View File

@ -510,6 +510,8 @@ Rails.application.routes.draw do
# audio latency
match '/users/:id/audio_latency' => 'api_users#audio_latency', :via => :post
match '/users/:id/latencies' => 'api_users#get_latencies', via: :get
# udp reachable (can stun?)
match '/users/:id/udp_reachable' => 'api_users#udp_reachable', :via => :post
match '/users/:id/is_network_testing' => 'api_users#is_network_testing', :via => :post

View File

@ -1,4 +1,5 @@
require 'spec_helper'
require 'webmock/rspec'
describe ApiUsersController, type: :controller do
render_views
@ -310,6 +311,21 @@ describe ApiUsersController, type: :controller do
end
end
describe "get_latencies" do
let(:user1) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:latency_data_uri) { /\/dev\/user_latencies\// }
let(:response_body) { File.open('./spec/fixtures/latency_reponse.json') }
it "fetch latency graph data" do
stub_request(:get, latency_data_uri)
.to_return( body: response_body, status: 200)
get :get_latencies, id: user.id, user_ids: [user1, user2].map(&:id).join(',')
response.should be_success
JSON.parse(response.body)['users'].size.should eq(2)
end
end
describe "crash_dump" do
include UsesTempFiles
CRASH_TEMP_FILE='crash.txt'

38
web/spec/fixtures/latency_reponse.json vendored Normal file
View File

@ -0,0 +1,38 @@
{
"users": [
{
"user_id": "b9461515-2540-46a6-b973-ff3060806952",
"first_name": "David",
"last_name": "Wilson",
"audio_latency": 4.172335624694824,
"audio_latency_unknown": false,
"ars": {
"internet_latency": 41.301548024602965,
"total_latency": 45.47388364929779
},
"p2p": {
"internet_latency": 10.31944465637207,
"total_latency": 14.491780281066895
},
"wifi": false
},
{
"user_id": "40a88b89-ec4b-43c7-a738-3d88e12c8e8d",
"first_name": "Peter",
"last_name": "Walker",
"audio_latency": 4.172335624694824,
"audio_latency_unknown": false,
"ars": {
"internet_latency": null,
"total_latency": null
},
"p2p": {
"internet_latency": null,
"total_latency": null
},
"wifi": false
}
],
"my_audio_latency": 4.172335624694824,
"my_audio_latency_unknown": false
}