Skip to content

Commit cc6be5f

Browse files
authored
gcp-o11y: Remove monitored resource detection for logging (#10020)
* removed populating monitored resource to k8s_conatiner by default for logging; Delegating the resource detection to cloud logging library instead (enabled by default) * remove kubernetes resource detection logic from observability
1 parent 18e274d commit cc6be5f

File tree

8 files changed

+18
-487
lines changed

8 files changed

+18
-487
lines changed

gcp-observability/src/main/java/io/grpc/gcp/observability/GcpObservability.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ public final class GcpObservability implements AutoCloseable {
9090
*/
9191
public static synchronized GcpObservability grpcInit() throws IOException {
9292
if (instance == null) {
93-
GlobalLocationTags globalLocationTags = new GlobalLocationTags();
9493
ObservabilityConfigImpl observabilityConfig = ObservabilityConfigImpl.getInstance();
9594
TraceLoggingHelper traceLoggingHelper = new TraceLoggingHelper(
9695
observabilityConfig.getProjectId());
97-
Sink sink = new GcpLogSink(observabilityConfig.getProjectId(),
98-
globalLocationTags.getLocationTags(), observabilityConfig,
96+
Sink sink = new GcpLogSink(observabilityConfig.getProjectId(), observabilityConfig,
9997
SERVICES_TO_EXCLUDE, traceLoggingHelper);
10098
LogHelper helper = new LogHelper(sink);
10199
ConfigFilterHelper configFilterHelper = ConfigFilterHelper.getInstance(observabilityConfig);

gcp-observability/src/main/java/io/grpc/gcp/observability/GlobalLocationTags.java

Lines changed: 0 additions & 148 deletions
This file was deleted.

gcp-observability/src/main/java/io/grpc/gcp/observability/MetadataConfig.java

Lines changed: 0 additions & 107 deletions
This file was deleted.

gcp-observability/src/main/java/io/grpc/gcp/observability/logging/GcpLogSink.java

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import com.google.api.gax.batching.BatchingSettings;
2222
import com.google.api.gax.batching.FlowController;
23-
import com.google.cloud.MonitoredResource;
2423
import com.google.cloud.logging.LogEntry;
2524
import com.google.cloud.logging.Logging;
2625
import com.google.cloud.logging.LoggingOptions;
@@ -30,7 +29,6 @@
3029
import com.google.common.annotations.VisibleForTesting;
3130
import com.google.common.base.Strings;
3231
import com.google.common.collect.ImmutableMap;
33-
import com.google.common.collect.ImmutableSet;
3432
import com.google.protobuf.util.JsonFormat;
3533
import io.grpc.Internal;
3634
import io.grpc.gcp.observability.ObservabilityConfig;
@@ -42,8 +40,6 @@
4240
import java.util.Collection;
4341
import java.util.Collections;
4442
import java.util.Map;
45-
import java.util.Objects;
46-
import java.util.Set;
4743
import java.util.logging.Level;
4844
import java.util.logging.Logger;
4945
import 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

Comments
 (0)