Skip to content

Commit

Permalink
Add Google API application info
Browse files Browse the repository at this point in the history
This will help measure requests to the Google API that
come from train.

Signed-off-by: Nathen Harvey <nathenharvey@google.com>
  • Loading branch information
nathenharvey committed Nov 6, 2018
1 parent b35c439 commit d0b5aaf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/train/transports/gcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def connect
scopes = ['https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/compute']
authorization = Google::Auth.get_application_default(scopes)
Google::Apis::ClientOptions.default.application_name = 'chef-train'
Google::Apis::ClientOptions.default.application_version = Train::VERSION
Google::Apis::RequestOptions.default.authorization = authorization
end

Expand Down
60 changes: 60 additions & 0 deletions test/unit/transports/gcp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ def transport(options = nil)
client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true
cache[:api_call].count.must_equal 0
end

it 'test gcp_compute_client application name' do
client = connection.gcp_compute_client
client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true
client.client_options.application_name.must_equal 'chef-train'
end

it 'test gcp_compute_client application version' do
client = connection.gcp_compute_client
client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true
client.client_options.application_version.must_equal Train::VERSION
end
end

describe 'gcp_iam_client' do
Expand All @@ -114,6 +126,18 @@ def transport(options = nil)
client.is_a?(Google::Apis::IamV1::IamService).must_equal true
cache[:api_call].count.must_equal 0
end

it 'test gcp_iam_client application name' do
client = connection.gcp_iam_client
client.is_a?(Google::Apis::IamV1::IamService).must_equal true
client.client_options.application_name.must_equal 'chef-train'
end

it 'test gcp_iam_client application version' do
client = connection.gcp_iam_client
client.is_a?(Google::Apis::IamV1::IamService).must_equal true
client.client_options.application_version.must_equal Train::VERSION
end
end

describe 'gcp_project_client' do
Expand All @@ -129,6 +153,18 @@ def transport(options = nil)
client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true
cache[:api_call].count.must_equal 0
end

it 'test gcp_project_client application name' do
client = connection.gcp_project_client
client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true
client.client_options.application_name.must_equal 'chef-train'
end

it 'test gcp_project_client application version' do
client = connection.gcp_project_client
client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true
client.client_options.application_version.must_equal Train::VERSION
end
end

describe 'gcp_storage_client' do
Expand All @@ -144,6 +180,18 @@ def transport(options = nil)
client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true
cache[:api_call].count.must_equal 0
end

it 'test gcp_storage_client application name' do
client = connection.gcp_storage_client
client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true
client.client_options.application_name.must_equal 'chef-train'
end

it 'test gcp_storage_client application version' do
client = connection.gcp_storage_client
client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true
client.client_options.application_version.must_equal Train::VERSION
end
end

describe 'gcp_admin_client' do
Expand All @@ -159,6 +207,18 @@ def transport(options = nil)
client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true
cache[:api_call].count.must_equal 0
end

it 'test gcp_admin_client application name' do
client = connection.gcp_admin_client
client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true
client.client_options.application_name.must_equal 'chef-train'
end

it 'test gcp_admin_client application version' do
client = connection.gcp_admin_client
client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true
client.client_options.application_version.must_equal Train::VERSION
end
end

# test options override of env vars in connect
Expand Down

0 comments on commit d0b5aaf

Please sign in to comment.