2020
2121import com .google .api .gax .batching .BatchingSettings ;
2222import com .google .api .gax .batching .FlowController ;
23- import com .google .cloud .MonitoredResource ;
2423import com .google .cloud .logging .LogEntry ;
2524import com .google .cloud .logging .Logging ;
2625import com .google .cloud .logging .LoggingOptions ;
3029import com .google .common .annotations .VisibleForTesting ;
3130import com .google .common .base .Strings ;
3231import com .google .common .collect .ImmutableMap ;
33- import com .google .common .collect .ImmutableSet ;
3432import com .google .protobuf .util .JsonFormat ;
3533import io .grpc .Internal ;
3634import io .grpc .gcp .observability .ObservabilityConfig ;
4240import java .util .Collection ;
4341import java .util .Collections ;
4442import java .util .Map ;
45- import java .util .Objects ;
46- import java .util .Set ;
4743import java .util .logging .Level ;
4844import java .util .logging .Logger ;
4945import org .threeten .bp .Duration ;
@@ -58,13 +54,8 @@ public class GcpLogSink implements Sink {
5854 private static final String DEFAULT_LOG_NAME =
5955 "microservices.googleapis.com%2Fobservability%2Fgrpc" ;
6056 private static final Severity DEFAULT_LOG_LEVEL = Severity .DEBUG ;
61- private static final String K8S_MONITORED_RESOURCE_TYPE = "k8s_container" ;
62- private static final Set <String > kubernetesResourceLabelSet
63- = ImmutableSet .of ("project_id" , "location" , "cluster_name" , "namespace_name" ,
64- "pod_name" , "container_name" );
6557 private final String projectId ;
6658 private final Map <String , String > customTags ;
67- private final MonitoredResource kubernetesResource ;
6859 /** Lazily initialize cloud logging client to avoid circular initialization. Because cloud
6960 * logging APIs also uses gRPC. */
7061 private volatile Logging gcpLoggingClient ;
@@ -75,10 +66,10 @@ public class GcpLogSink implements Sink {
7566
7667
7768 @ VisibleForTesting
78- GcpLogSink (Logging loggingClient , String projectId , Map < String , String > locationTags ,
69+ GcpLogSink (Logging loggingClient , String projectId ,
7970 ObservabilityConfig config , Collection <String > servicesToExclude ,
8071 TraceLoggingHelper traceLoggingHelper ) {
81- this (projectId , locationTags , config , servicesToExclude , traceLoggingHelper );
72+ this (projectId , config , servicesToExclude , traceLoggingHelper );
8273 this .gcpLoggingClient = loggingClient ;
8374 }
8475
@@ -88,12 +79,11 @@ public class GcpLogSink implements Sink {
8879 * @param projectId GCP project id to write logs
8980 * @param servicesToExclude service names for which log entries should not be generated
9081 */
91- public GcpLogSink (String projectId , Map < String , String > locationTags ,
82+ public GcpLogSink (String projectId ,
9283 ObservabilityConfig config , Collection <String > servicesToExclude ,
9384 TraceLoggingHelper traceLoggingHelper ) {
9485 this .projectId = projectId ;
95- this .customTags = getCustomTags (config .getCustomTags (), locationTags , projectId );
96- this .kubernetesResource = getResource (locationTags );
86+ this .customTags = getCustomTags (config .getCustomTags ());
9787 this .servicesToExclude = checkNotNull (servicesToExclude , "servicesToExclude" );
9888 this .isTraceEnabled = config .isEnableCloudTracing ();
9989 this .traceLoggingHelper = traceLoggingHelper ;
@@ -126,7 +116,6 @@ public void write(GrpcLogRecord logProto, SpanContext spanContext) {
126116 LogEntry .newBuilder (JsonPayload .of (logProtoMap ))
127117 .setSeverity (DEFAULT_LOG_LEVEL )
128118 .setLogName (DEFAULT_LOG_NAME )
129- .setResource (kubernetesResource )
130119 .setTimestamp (Instant .now ());
131120
132121 if (!customTags .isEmpty ()) {
@@ -178,34 +167,14 @@ Logging createLoggingClient() {
178167 }
179168
180169 @ VisibleForTesting
181- static Map <String , String > getCustomTags (Map <String , String > customTags ,
182- Map <String , String > locationTags , String projectId ) {
170+ static Map <String , String > getCustomTags (Map <String , String > customTags ) {
183171 ImmutableMap .Builder <String , String > tagsBuilder = ImmutableMap .builder ();
184- String sourceProjectId = locationTags .get ("project_id" );
185- if (!Strings .isNullOrEmpty (projectId )
186- && !Strings .isNullOrEmpty (sourceProjectId )
187- && !Objects .equals (sourceProjectId , projectId )) {
188- tagsBuilder .put ("source_project_id" , sourceProjectId );
189- }
190172 if (customTags != null ) {
191173 tagsBuilder .putAll (customTags );
192174 }
193175 return tagsBuilder .buildOrThrow ();
194176 }
195177
196- @ VisibleForTesting
197- static MonitoredResource getResource (Map <String , String > resourceTags ) {
198- MonitoredResource .Builder builder = MonitoredResource .newBuilder (K8S_MONITORED_RESOURCE_TYPE );
199- if ((resourceTags != null ) && !resourceTags .isEmpty ()) {
200- for (Map .Entry <String , String > entry : resourceTags .entrySet ()) {
201- String resourceKey = entry .getKey ();
202- if (kubernetesResourceLabelSet .contains (resourceKey )) {
203- builder .addLabel (resourceKey , entry .getValue ());
204- }
205- }
206- }
207- return builder .build ();
208- }
209178
210179 @ SuppressWarnings ("unchecked" )
211180 private Map <String , Object > protoToMapConverter (GrpcLogRecord logProto )
0 commit comments