Change the gRPC o11y logName when sending logs to GCP. (#9145)

* Change the gRPC o11y logName when sending logs to GCP.
This commit is contained in:
Feng Li 2022-06-08 13:57:45 -07:00 committed by GitHub
parent ecb2210cc1
commit 56e28bc9fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -47,7 +47,8 @@ public class GcpLogSink implements Sink {
// TODO(DNVindhya): Make cloud logging service a configurable value
private static final String SERVICE_TO_EXCLUDE = "google.logging.v2.LoggingServiceV2";
private static final String DEFAULT_LOG_NAME = "grpc";
private static final String DEFAULT_LOG_NAME =
"microservices.googleapis.com%2Fobservability%2Fgrpc";
private static final String K8S_MONITORED_RESOURCE_TYPE = "k8s_container";
private static final Set<String> kubernetesResourceLabelSet
= ImmutableSet.of("project_id", "location", "cluster_name", "namespace_name",
@ -202,4 +203,4 @@ public class GcpLogSink implements Sink {
logger.log(Level.SEVERE, "Caught exception while closing", e);
}
}
}
}

View File

@ -65,6 +65,9 @@ public class GcpLogSinkTest {
private static final Map<String, String> customTags = ImmutableMap.of("KEY1", "Value1",
"KEY2", "VALUE2");
private static final long flushLimit = 10L;
// gRPC is expected to alway use this log name when reporting to GCP cloud logging.
private static final String expectedLogName =
"microservices.googleapis.com%2Fobservability%2Fgrpc";
private final long seqId = 1;
private final String destProjectName = "PROJECT";
private final String serviceName = "service";
@ -122,6 +125,7 @@ public class GcpLogSinkTest {
LogEntry entry = it.next();
System.out.println(entry);
assertThat(entry.getPayload().getData()).isEqualTo(expectedStructLogProto);
assertThat(entry.getLogName()).isEqualTo(expectedLogName);
}
verifyNoMoreInteractions(mockLogging);
}
@ -143,6 +147,7 @@ public class GcpLogSinkTest {
assertThat(entry.getResource()).isEqualTo(expectedMonitoredResource);
assertThat(entry.getLabels()).isEqualTo(customTags);
assertThat(entry.getPayload().getData()).isEqualTo(expectedStructLogProto);
assertThat(entry.getLogName()).isEqualTo(expectedLogName);
}
verifyNoMoreInteractions(mockLogging);
}