From c68cafa3f1c2f30de1b66843cccee606a8c2b03e Mon Sep 17 00:00:00 2001 From: Matthew Kocher Date: Sat, 9 Dec 2023 00:28:48 +0000 Subject: [PATCH 1/2] Generate protobufs Generating protobufs requires installing protoc v3.6.1. This commit also adds availability_zone to a bunch of things, should be a noop for most capi things. Co-authored-by: Rebecca Roberts --- lib/diego/bbs/models/actual_lrp_pb.rb | 1 + lib/diego/bbs/models/actual_lrp_requests_pb.rb | 1 + lib/diego/bbs/models/evacuation_pb.rb | 1 + lib/diego/bbs/models/events_pb.rb | 1 + lib/diego/bbs/models/task_pb.rb | 2 ++ 5 files changed, 6 insertions(+) diff --git a/lib/diego/bbs/models/actual_lrp_pb.rb b/lib/diego/bbs/models/actual_lrp_pb.rb index de1c1026903..bbf2a52ba28 100644 --- a/lib/diego/bbs/models/actual_lrp_pb.rb +++ b/lib/diego/bbs/models/actual_lrp_pb.rb @@ -51,6 +51,7 @@ optional :presence, :enum, 10, "diego.bbs.models.ActualLRP.Presence" repeated :actual_lrp_internal_routes, :message, 11, "diego.bbs.models.ActualLRPInternalRoute" map :metric_tags, :string, :string, 12 + optional :availability_zone, :string, 14 oneof :optional_routable do optional :routable, :bool, 13 end diff --git a/lib/diego/bbs/models/actual_lrp_requests_pb.rb b/lib/diego/bbs/models/actual_lrp_requests_pb.rb index 0725838387a..0dea56c340e 100644 --- a/lib/diego/bbs/models/actual_lrp_requests_pb.rb +++ b/lib/diego/bbs/models/actual_lrp_requests_pb.rb @@ -39,6 +39,7 @@ optional :actual_lrp_net_info, :message, 3, "diego.bbs.models.ActualLRPNetInfo" repeated :actual_lrp_internal_routes, :message, 4, "diego.bbs.models.ActualLRPInternalRoute" map :metric_tags, :string, :string, 5 + optional :availability_zone, :string, 7 oneof :optional_routable do optional :Routable, :bool, 6 end diff --git a/lib/diego/bbs/models/evacuation_pb.rb b/lib/diego/bbs/models/evacuation_pb.rb index 57f09ca4f33..333f887fe02 100644 --- a/lib/diego/bbs/models/evacuation_pb.rb +++ b/lib/diego/bbs/models/evacuation_pb.rb @@ -20,6 +20,7 @@ optional :actual_lrp_net_info, :message, 3, "diego.bbs.models.ActualLRPNetInfo" repeated :actual_lrp_internal_routes, :message, 5, "diego.bbs.models.ActualLRPInternalRoute" map :metric_tags, :string, :string, 6 + optional :availability_zone, :string, 8 oneof :optional_routable do optional :Routable, :bool, 7 end diff --git a/lib/diego/bbs/models/events_pb.rb b/lib/diego/bbs/models/events_pb.rb index d9e2b776c69..e4d6c443bee 100644 --- a/lib/diego/bbs/models/events_pb.rb +++ b/lib/diego/bbs/models/events_pb.rb @@ -31,6 +31,7 @@ optional :since, :int64, 8 optional :modification_tag, :message, 9, "diego.bbs.models.ModificationTag" optional :presence, :enum, 10, "diego.bbs.models.ActualLRP.Presence" + optional :availability_zone, :string, 12 oneof :optional_routable do optional :Routable, :bool, 11 end diff --git a/lib/diego/bbs/models/task_pb.rb b/lib/diego/bbs/models/task_pb.rb index e4afd6f8041..0ef8c0a36e4 100644 --- a/lib/diego/bbs/models/task_pb.rb +++ b/lib/diego/bbs/models/task_pb.rb @@ -12,6 +12,7 @@ require 'certificate_properties_pb' require 'image_layer_pb' require 'log_rate_limit_pb' +require 'metric_tags_pb' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "diego.bbs.models.TaskDefinition" do optional :root_fs, :string, 1 @@ -40,6 +41,7 @@ optional :image_password, :string, 24 repeated :image_layers, :message, 25, "diego.bbs.models.ImageLayer" optional :log_rate_limit, :message, 26, "diego.bbs.models.LogRateLimit" + map :metric_tags, :string, :message, 27, "diego.bbs.models.MetricTagValue" end add_message "diego.bbs.models.Task" do optional :task_definition, :message, 1, "diego.bbs.models.TaskDefinition" From a02410149bce282f74db4a9150c1e714f8b85214 Mon Sep 17 00:00:00 2001 From: Rebecca Roberts Date: Tue, 12 Dec 2023 00:39:34 +0000 Subject: [PATCH 2/2] Adds metric tags to task recipe builder Signed-off-by: Carson Long <12767276+ctlong@users.noreply.github.com> Co-authored-by: Carson Long <12767276+ctlong@users.noreply.github.com> Signed-off-by: Rebecca Roberts Co-authored-by: Rebecca Roberts --- .../diego/task_recipe_builder.rb | 16 +++++++ .../diego/task_recipe_builder_spec.rb | 44 ++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/cloud_controller/diego/task_recipe_builder.rb b/lib/cloud_controller/diego/task_recipe_builder.rb index ae41e0c2136..3b6a5527430 100644 --- a/lib/cloud_controller/diego/task_recipe_builder.rb +++ b/lib/cloud_controller/diego/task_recipe_builder.rb @@ -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 @@ -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, @@ -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), @@ -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' diff --git a/spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb b/spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb index 0d3325e5081..b547a76cad0 100644 --- a/spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb +++ b/spec/unit/lib/cloud_controller/diego/task_recipe_builder_spec.rb @@ -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 @@ -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}") @@ -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 @@ -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', @@ -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 @@ -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