@@ -60,6 +60,7 @@ def app_lrp_arguments
6060 host_fingerprint : ssh_key . fingerprint
6161 } )
6262 end
63+
6364 {
6465 process_guid : Diego ::ProcessGuid . from_process ( process ) ,
6566 instances : process . desired_instances ,
@@ -72,19 +73,7 @@ def app_lrp_arguments
7273 log_source : LRP_LOG_SOURCE ,
7374 log_guid : process . app . guid ,
7475 metrics_guid : process . app . guid ,
75- metric_tags : {
76- 'source_id' => METRIC_TAG_VALUE . new ( static : process . app . guid ) ,
77- 'process_id' => METRIC_TAG_VALUE . new ( static : process . guid ) ,
78- 'process_type' => METRIC_TAG_VALUE . new ( static : process . type ) ,
79- 'process_instance_id' => METRIC_TAG_VALUE . new ( dynamic : METRIC_TAG_VALUE ::DynamicValue ::INSTANCE_GUID ) ,
80- 'instance_id' => METRIC_TAG_VALUE . new ( dynamic : METRIC_TAG_VALUE ::DynamicValue ::INDEX ) ,
81- 'organization_id' => METRIC_TAG_VALUE . new ( static : process . organization . guid ) ,
82- 'space_id' => METRIC_TAG_VALUE . new ( static : process . space . guid ) ,
83- 'app_id' => METRIC_TAG_VALUE . new ( static : process . app . guid ) ,
84- 'organization_name' => METRIC_TAG_VALUE . new ( static : process . organization . name ) ,
85- 'space_name' => METRIC_TAG_VALUE . new ( static : process . space . name ) ,
86- 'app_name' => METRIC_TAG_VALUE . new ( static : process . app . name ) ,
87- } ,
76+ metric_tags : metric_tags ( process ) ,
8877 annotation : process . updated_at . to_f . to_s ,
8978 egress_rules : Diego ::EgressRules . new . running_protobuf_rules ( process ) ,
9079 cached_dependencies : desired_lrp_builder . cached_dependencies ,
@@ -111,6 +100,43 @@ def app_lrp_arguments
111100 } . compact
112101 end
113102
103+ def metric_tags ( process )
104+ tags = {
105+ 'source_id' => METRIC_TAG_VALUE . new ( static : process . app . guid ) ,
106+ 'process_id' => METRIC_TAG_VALUE . new ( static : process . guid ) ,
107+ 'process_type' => METRIC_TAG_VALUE . new ( static : process . type ) ,
108+ 'process_instance_id' => METRIC_TAG_VALUE . new ( dynamic : METRIC_TAG_VALUE ::DynamicValue ::INSTANCE_GUID ) ,
109+ 'instance_id' => METRIC_TAG_VALUE . new ( dynamic : METRIC_TAG_VALUE ::DynamicValue ::INDEX ) ,
110+ 'organization_id' => METRIC_TAG_VALUE . new ( static : process . organization . guid ) ,
111+ 'space_id' => METRIC_TAG_VALUE . new ( static : process . space . guid ) ,
112+ 'app_id' => METRIC_TAG_VALUE . new ( static : process . app . guid ) ,
113+ 'organization_name' => METRIC_TAG_VALUE . new ( static : process . organization . name ) ,
114+ 'space_name' => METRIC_TAG_VALUE . new ( static : process . space . name ) ,
115+ 'app_name' => METRIC_TAG_VALUE . new ( static : process . app . name ) ,
116+ }
117+
118+ metric_tag_label_prefixes = Config . config . get ( :custom_metric_tag_prefix_list )
119+ unless metric_tag_label_prefixes . empty?
120+ # These should not be overridden by app developers. This list is based on
121+ # https://github.com/cloudfoundry/loggregator-agent-release/blob/8b714dc6f09cfa8a67d78ec974b77c0d7642f5a3/src/pkg/egress/v1/tagger.go#L32-L44
122+ # and is not expected to change
123+ reserved_key_names = %w( deployment index ip job )
124+
125+ process . app . labels .
126+ select { |label |
127+ metric_tag_label_prefixes . include? ( label . key_prefix ) && !tags . key? ( label . key_name )
128+ } .
129+ reject { |label |
130+ reserved_key_names . include? ( label . key_name )
131+ } .
132+ each { |label |
133+ tags [ label . key_name ] = METRIC_TAG_VALUE . new ( static : label . value )
134+ }
135+ end
136+
137+ tags
138+ end
139+
114140 def routing_info
115141 @routing_info ||= Protocol ::RoutingInfo . new ( process ) . routing_info
116142 end
0 commit comments