gcp-observability: trim the string to remove newline for hostname and namespace name from files (#9043)

This commit is contained in:
sanjaypujare 2022-04-01 10:11:54 -07:00 committed by GitHub
parent c53c3ad01b
commit fda3a2d6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -71,10 +71,10 @@ final class GlobalLoggingTags {
String hostnameFile, String cgroupFile) { String hostnameFile, String cgroupFile) {
// namespace name: contents of file /var/run/secrets/kubernetes.io/serviceaccount/namespace // namespace name: contents of file /var/run/secrets/kubernetes.io/serviceaccount/namespace
populateFromFileContents(customTags, "namespace_name", populateFromFileContents(customTags, "namespace_name",
namespaceFile, (value) -> value); namespaceFile, (value) -> value.trim());
// pod_name: hostname i.e. contents of /etc/hostname // pod_name: hostname i.e. contents of /etc/hostname
populateFromFileContents(customTags, "pod_name", hostnameFile, (value) -> value); populateFromFileContents(customTags, "pod_name", hostnameFile, (value) -> value.trim());
// container_id: parsed from /proc/self/cgroup . Note: only works for Linux-based containers // container_id: parsed from /proc/self/cgroup . Note: only works for Linux-based containers
populateFromFileContents(customTags, "container_id", cgroupFile, populateFromFileContents(customTags, "container_id", cgroupFile,

View File

@ -89,7 +89,7 @@ public class GlobalLoggingTagsTest {
File cgroupFile = cgroupFolder.newFile(); File cgroupFile = cgroupFolder.newFile();
Files.write("test-namespace1".getBytes(StandardCharsets.UTF_8), namespaceFile); Files.write("test-namespace1".getBytes(StandardCharsets.UTF_8), namespaceFile);
Files.write("test-hostname2".getBytes(StandardCharsets.UTF_8), hostnameFile); Files.write("test-hostname2\n".getBytes(StandardCharsets.UTF_8), hostnameFile);
Files.write(FILE_CONTENTS.getBytes(StandardCharsets.UTF_8), cgroupFile); Files.write(FILE_CONTENTS.getBytes(StandardCharsets.UTF_8), cgroupFile);
ImmutableMap.Builder<String, String> customTags = ImmutableMap.builder(); ImmutableMap.Builder<String, String> customTags = ImmutableMap.builder();