1 /* 2 * Copyright 2022 The gRPC Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package io.grpc.gcp.observability; 18 19 import io.grpc.Internal; 20 import io.opencensus.trace.Sampler; 21 import java.util.List; 22 import java.util.Map; 23 import java.util.Set; 24 import javax.annotation.concurrent.ThreadSafe; 25 26 @Internal 27 public interface ObservabilityConfig { 28 /** Is Cloud Logging enabled. */ isEnableCloudLogging()29 boolean isEnableCloudLogging(); 30 31 /** Is Cloud Monitoring enabled. */ isEnableCloudMonitoring()32 boolean isEnableCloudMonitoring(); 33 34 /** Is Cloud Tracing enabled. */ isEnableCloudTracing()35 boolean isEnableCloudTracing(); 36 37 /** Get project ID - where logs will go. */ getProjectId()38 String getProjectId(); 39 40 /** Get filters for client logging. */ getClientLogFilters()41 List<LogFilter> getClientLogFilters(); 42 43 /** Get filters for server logging. */ getServerLogFilters()44 List<LogFilter> getServerLogFilters(); 45 46 /** Get sampler for TraceConfig - when Cloud Tracing is enabled. */ getSampler()47 Sampler getSampler(); 48 49 /** Map of all custom tags used for logging, metrics and traces. */ getCustomTags()50 Map<String, String> getCustomTags(); 51 52 /** 53 * POJO for representing a filter used in configuration. 54 */ 55 @ThreadSafe 56 class LogFilter { 57 /** Set of services. */ 58 public final Set<String> services; 59 60 /* Set of fullMethodNames. */ 61 public final Set<String> methods; 62 63 /** Boolean to indicate all services and methods. */ 64 public final boolean matchAll; 65 66 /** Number of bytes of header to log. */ 67 public final int headerBytes; 68 69 /** Number of bytes of message to log. */ 70 public final int messageBytes; 71 72 /** Boolean to indicate if services and methods matching pattern needs to be excluded. */ 73 public final boolean excludePattern; 74 75 /** 76 * Object used to represent filter used in configuration. 77 * @param services Set of services derived from pattern 78 * @param serviceMethods Set of fullMethodNames derived from pattern 79 * @param matchAll If true, match all services and methods 80 * @param headerBytes Total number of bytes of header to log 81 * @param messageBytes Total number of bytes of message to log 82 * @param excludePattern If true, services and methods matching pattern be excluded 83 */ LogFilter(Set<String> services, Set<String> serviceMethods, boolean matchAll, int headerBytes, int messageBytes, boolean excludePattern)84 public LogFilter(Set<String> services, Set<String> serviceMethods, boolean matchAll, 85 int headerBytes, int messageBytes, 86 boolean excludePattern) { 87 this.services = services; 88 this.methods = serviceMethods; 89 this.matchAll = matchAll; 90 this.headerBytes = headerBytes; 91 this.messageBytes = messageBytes; 92 this.excludePattern = excludePattern; 93 } 94 } 95 } 96