Skip to content

Commit

Permalink
confgenerator: sanitize metadata values in the gce_resource detector (#…
Browse files Browse the repository at this point in the history
…1553)

Signed-off-by: Ridwan Sharif <[email protected]>
  • Loading branch information
ridwanmsharif authored Jan 4, 2024
1 parent 68c07b9 commit 68111d6
Show file tree
Hide file tree
Showing 39 changed files with 142 additions and 43 deletions.
2 changes: 1 addition & 1 deletion confgenerator/confgenerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var (
InstanceName: "test-instance-name",
Tags: "test-tag",
MachineType: "test-machine-type",
Metadata: map[string]string{"test-key": "test-value", "test-escape": "${foo:bar}"},
Metadata: map[string]string{"test-key": "test-value", "test-escape": "$foo", "test-escape-parentheses": "${foo:bar}"},
Label: map[string]string{"test-label-key": "test-label-value"},
InterfaceIPv4: map[string]string{"test-interface": "test-interface-ipv4"},
}
Expand Down
7 changes: 6 additions & 1 deletion confgenerator/resourcedetector/gce_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ func (r GCEResource) PrometheusStyleMetadata() map[string]string {
prefix := "__meta_gce_"
for k, v := range r.Metadata {
sanitizedKey := "metadata_" + strutil.SanitizeLabelName(k)
metaLabels[prefix+sanitizedKey] = strings.ReplaceAll(v, "$", "$$")
// Once https://github.com/open-telemetry/opentelemetry-collector/issues/9204
// is fixed, this will no longer be needed.
sanitizedVal := strings.ReplaceAll(v, "${", "_{")
sanitizedVal = strings.ReplaceAll(sanitizedVal, "$", "$$")
metaLabels[prefix+sanitizedKey] = sanitizedVal

}

// Labels are not available using the GCE metadata API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down Expand Up @@ -577,7 +578,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down Expand Up @@ -546,7 +547,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down Expand Up @@ -621,7 +622,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down Expand Up @@ -621,7 +622,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ receivers:
__meta_gce_instance_name: test-instance-name
__meta_gce_interface_ipv4_nictest_interface: test-interface-ipv4
__meta_gce_machine_type: test-machine-type
__meta_gce_metadata_test_escape: $${foo:bar}
__meta_gce_metadata_test_escape: $$foo
__meta_gce_metadata_test_escape_parentheses: _{foo:bar}
__meta_gce_metadata_test_key: test-value
__meta_gce_network: test-network
__meta_gce_private_ip: test-private-ip
Expand Down
Loading

0 comments on commit 68111d6

Please sign in to comment.