Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags to task logs #3564

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/cloud_controller/diego/task_recipe_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module Diego
class TaskRecipeBuilder
include ::Diego::ActionBuilder

METRIC_TAG_VALUE = ::Diego::Bbs::Models::MetricTagValue

def initialize
@egress_rules = Diego::EgressRules.new
end
Expand All @@ -30,6 +32,7 @@ def build_app_task(config, task)
log_source: TASK_LOG_SOURCE,
max_pids: config.get(:diego, :pid_limit),
memory_mb: task.memory_in_mb,
metric_tags: metric_tags(task),
network: generate_network(task, Protocol::ContainerNetworkInfo::TASK),
privileged: config.get(:diego, :use_privileged_containers_for_running),
trusted_system_certificates_path: STAGING_TRUSTED_SYSTEM_CERT_PATH,
Expand Down Expand Up @@ -64,6 +67,7 @@ def build_staging_task(config, staging_details)
egress_rules: @egress_rules.staging_protobuf_rules(app_guid: staging_details.package.app_guid),
log_guid: staging_details.package.app_guid,
log_source: STAGING_LOG_SOURCE,
metric_tags: metric_tags(staging_details.package),
memory_mb: staging_details.staging_memory_in_mb,
log_rate_limit: ::Diego::Bbs::Models::LogRateLimit.new(bytes_per_second: staging_details.staging_log_rate_limit_bytes_per_second),
network: generate_network(staging_details.package, Protocol::ContainerNetworkInfo::STAGING),
Expand Down Expand Up @@ -92,6 +96,18 @@ def build_staging_task(config, staging_details)

private

def metric_tags(source)
{
'source_id' => METRIC_TAG_VALUE.new(static: source.app_guid),
'organization_id' => METRIC_TAG_VALUE.new(static: source.app.organization_guid),
'space_id' => METRIC_TAG_VALUE.new(static: source.space_guid),
'app_id' => METRIC_TAG_VALUE.new(static: source.app_guid),
'organization_name' => METRIC_TAG_VALUE.new(static: source.app.organization.name),
'space_name' => METRIC_TAG_VALUE.new(static: source.space.name),
'app_name' => METRIC_TAG_VALUE.new(static: source.app.name)
}
end

def staging_completion_callback(config, staging_details)
port = config.get(:tls_port)
scheme = 'https'
Expand Down
1 change: 1 addition & 0 deletions lib/diego/bbs/models/actual_lrp_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/diego/bbs/models/actual_lrp_requests_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/diego/bbs/models/evacuation_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/diego/bbs/models/events_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/diego/bbs/models/task_pb.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 42 additions & 2 deletions spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ module VCAP::CloudController
module Diego
RSpec.describe TaskRecipeBuilder do
subject(:task_recipe_builder) { TaskRecipeBuilder.new }
let(:org) { Organization.make(name: 'MyOrg', guid: 'org-guid') }
let(:space) { Space.make(name: 'MySpace', guid: 'space-guid', organization: org) }
let(:app) { AppModel.make(name: 'MyApp', guid: 'banana-guid', space: space) }

describe '#build_staging_task' do
let(:app) { AppModel.make(guid: 'banana-guid') }
let(:staging_details) do
Diego::StagingDetails.new.tap do |details|
details.staging_guid = droplet.guid
Expand Down Expand Up @@ -150,6 +152,15 @@ module Diego
expect(result.image_layers).to eq(lifecycle_image_layers)
expect(result.cpu_weight).to eq(50)

expect(result.metric_tags.keys.size).to eq(7)
expect(result.metric_tags['source_id'].static).to eq('banana-guid')
expect(result.metric_tags['organization_id'].static).to eq('org-guid')
expect(result.metric_tags['space_id'].static).to eq('space-guid')
expect(result.metric_tags['app_id'].static).to eq('banana-guid')
expect(result.metric_tags['organization_name'].static).to eq('MyOrg')
expect(result.metric_tags['space_name'].static).to eq('MySpace')
expect(result.metric_tags['app_name'].static).to eq('MyApp')

expect(result.completion_callback_url).to eq("https://#{internal_service_hostname}:#{tls_port}" \
"/internal/v3/staging/#{droplet.guid}/build_completed?start=#{staging_details.start_after_staging}")

Expand Down Expand Up @@ -227,6 +238,18 @@ module Diego
expect(result.log_source).to eq('STG')
end

it 'sets the metric tags' do
result = task_recipe_builder.build_staging_task(config, staging_details)
expect(result.metric_tags.keys.size).to eq(7)
expect(result.metric_tags['source_id'].static).to eq('banana-guid')
expect(result.metric_tags['organization_id'].static).to eq('org-guid')
expect(result.metric_tags['space_id'].static).to eq('space-guid')
expect(result.metric_tags['app_id'].static).to eq('banana-guid')
expect(result.metric_tags['organization_name'].static).to eq('MyOrg')
expect(result.metric_tags['space_name'].static).to eq('MySpace')
expect(result.metric_tags['app_name'].static).to eq('MyApp')
end

it 'does not set the image layers' do
result = task_recipe_builder.build_staging_task(config, staging_details)
expect(result.image_layers).to be_empty
Expand Down Expand Up @@ -320,7 +343,6 @@ module Diego
end

describe '#build_app_task' do
let(:app) { AppModel.make(guid: 'banana-guid') }
let(:task) do
TaskModel.create(
name: 'potato-task',
Expand Down Expand Up @@ -474,6 +496,15 @@ module Diego
expect(result.placement_tags).to eq([isolation_segment])
expect(result.max_pids).to eq(100)
expect(result.certificate_properties).to eq(certificate_properties)

expect(result.metric_tags.keys.size).to eq(7)
expect(result.metric_tags['source_id'].static).to eq('banana-guid')
expect(result.metric_tags['organization_id'].static).to eq('org-guid')
expect(result.metric_tags['space_id'].static).to eq('space-guid')
expect(result.metric_tags['app_id'].static).to eq('banana-guid')
expect(result.metric_tags['organization_name'].static).to eq('MyOrg')
expect(result.metric_tags['space_name'].static).to eq('MySpace')
expect(result.metric_tags['app_name'].static).to eq('MyApp')
end

context 'when a volume mount is provided' do
Expand Down Expand Up @@ -616,6 +647,15 @@ module Diego
expect(result.max_pids).to eq(100)
expect(result.certificate_properties).to eq(certificate_properties)

expect(result.metric_tags.keys.size).to eq(7)
expect(result.metric_tags['source_id'].static).to eq('banana-guid')
expect(result.metric_tags['organization_id'].static).to eq('org-guid')
expect(result.metric_tags['space_id'].static).to eq('space-guid')
expect(result.metric_tags['app_id'].static).to eq('banana-guid')
expect(result.metric_tags['organization_name'].static).to eq('MyOrg')
expect(result.metric_tags['space_name'].static).to eq('MySpace')
expect(result.metric_tags['app_name'].static).to eq('MyApp')

expect(result.image_username).to eq('dockerusername')
expect(result.image_password).to eq('dockerpassword')
end
Expand Down