Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcp-observability: updated config to public preview config #9622

Merged
merged 8 commits into from Oct 18, 2022
Expand Up @@ -76,15 +76,15 @@ public static synchronized GcpObservability grpcInit() throws IOException {
if (instance == null) {
GlobalLocationTags globalLocationTags = new GlobalLocationTags();
ObservabilityConfigImpl observabilityConfig = ObservabilityConfigImpl.getInstance();
Sink sink = new GcpLogSink(observabilityConfig.getDestinationProjectId(),
Sink sink = new GcpLogSink(observabilityConfig.getProjectId(),
globalLocationTags.getLocationTags(), observabilityConfig.getCustomTags(),
SERVICES_TO_EXCLUDE);
LogHelper helper = new LogHelper(sink);
ConfigFilterHelper configFilterHelper = ConfigFilterHelper.factory(observabilityConfig);
ConfigFilterHelper configFilterHelper = ConfigFilterHelper.getInstance(observabilityConfig);
instance = grpcInit(sink, observabilityConfig,
new InternalLoggingChannelInterceptor.FactoryImpl(helper, configFilterHelper),
new InternalLoggingServerInterceptor.FactoryImpl(helper, configFilterHelper));
instance.registerStackDriverExporter(observabilityConfig.getDestinationProjectId(),
instance.registerStackDriverExporter(observabilityConfig.getProjectId(),
observabilityConfig.getCustomTags());
}
return instance;
Expand Down
Expand Up @@ -17,10 +17,11 @@
package io.grpc.gcp.observability;

import io.grpc.Internal;
import io.grpc.observabilitylog.v1.GrpcLogRecord.EventType;
import io.opencensus.trace.Sampler;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.concurrent.ThreadSafe;

@Internal
public interface ObservabilityConfig {
Expand All @@ -33,14 +34,14 @@ public interface ObservabilityConfig {
/** Is Cloud Tracing enabled. */
boolean isEnableCloudTracing();

/** Get destination project ID - where logs will go. */
String getDestinationProjectId();
/** Get project ID - where logs will go. */
String getProjectId();

/** Get filters set for logging. */
List<LogFilter> getLogFilters();
/** Get filters for client logging. */
List<LogFilter> getClientLogFilters();

/** Get event types to log. */
List<EventType> getEventTypes();
/** Get filters for server logging. */
List<LogFilter> getServerLogFilters();

/** Get sampler for TraceConfig - when Cloud Tracing is enabled. */
Sampler getSampler();
Expand All @@ -51,27 +52,44 @@ public interface ObservabilityConfig {
/**
* POJO for representing a filter used in configuration.
*/
@ThreadSafe
class LogFilter {
/** Pattern indicating which service/method to log. */
public final String pattern;
/** Set of services. */
public final Set<String> services;

/** Number of bytes of each header to log. */
public final Integer headerBytes;
/* Set of fullMethodNames. */
public final Set<String> methods;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have alluded to this somewhere else: e.g. when user provides ["service1/method2", "*"] it will be good to sort it to ["*", "service1/method2"] since everything will match "*" and there is no need to do redundant comparison to "service1/method2" in the unsorted one. So it would have been ideal for this to be a List and sorted as per above. But we can make this optimization later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logRpcMethod in ConfigFilterHelper tries to achieve this by comparing in the order:

  1. check for * filter present in the list of methods
  2. check for all methods under service filter i.e service/* instances
  3. Check against exact method i.e service/method


/** Number of bytes of each header to log. */
public final Integer messageBytes;
/** Boolean to indicate all services and methods. */
public final boolean matchAll;

/** Number of bytes of header to log. */
public final int headerBytes;

/** Number of bytes of message to log. */
public final int messageBytes;

/** Boolean to indicate if services and methods matching pattern needs to be excluded. */
public final boolean excludePattern;

/**
* Object used to represent filter used in configuration.
*
* @param pattern Pattern indicating which service/method to log
* @param headerBytes Number of bytes of each header to log
* @param messageBytes Number of bytes of each header to log
* @param services Set of services derived from pattern
* @param serviceMethods Set of fullMethodNames derived from pattern
* @param matchAll If true, match all services and methods
* @param headerBytes Total number of bytes of header to log
* @param messageBytes Total number of bytes of message to log
* @param excludePattern If true, services and methods matching pattern be excluded
*/
public LogFilter(String pattern, Integer headerBytes, Integer messageBytes) {
this.pattern = pattern;
public LogFilter(Set<String> services, Set<String> serviceMethods, boolean matchAll,
int headerBytes, int messageBytes,
boolean excludePattern) {
this.services = services;
this.methods = serviceMethods;
this.matchAll = matchAll;
this.headerBytes = headerBytes;
this.messageBytes = messageBytes;
this.excludePattern = excludePattern;
}
}
}