Skip to content

Commit

Permalink
Adopt the new design of the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
lidizheng committed Mar 16, 2022
1 parent ddc3d4d commit bf52a77
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 139 deletions.
10 changes: 5 additions & 5 deletions observability/config.go
Expand Up @@ -29,15 +29,15 @@ import (
)

const (
envKeyObservabilityConfig = "GRPC_CONFIG_OBSERVABILITY"
envProjectID = "GOOGLE_CLOUD_PROJECT"
envObservabilityConfig = "GRPC_CONFIG_OBSERVABILITY"
envProjectID = "GOOGLE_CLOUD_PROJECT"
)

// fetchDefaultProjectID fetches the default GCP project id from environment.
func fetchDefaultProjectID(ctx context.Context) string {
// Step 1: Check ENV var
if s := os.Getenv(envProjectID); s != "" {
logger.Infof("Found project ID from env GOOGLE_CLOUD_PROJECT: %v", s)
logger.Infof("Found project ID from env %v: %v", envProjectID, s)
return s
}
// Step 2: Check default credential
Expand All @@ -56,10 +56,10 @@ func fetchDefaultProjectID(ctx context.Context) string {

func parseObservabilityConfig() *configpb.ObservabilityConfig {
// Parse the config from ENV var
if content := os.Getenv(envKeyObservabilityConfig); content != "" {
if content := os.Getenv(envObservabilityConfig); content != "" {
var config configpb.ObservabilityConfig
if err := protojson.Unmarshal([]byte(content), &config); err != nil {
logger.Warningf("Error parsing observability config from env GRPC_CONFIG_OBSERVABILITY: %v", err)
logger.Warningf("Error parsing observability config from env %v: %v", envObservabilityConfig, err)
return nil
}
logger.Infof("Parsed ObservabilityConfig: %+v", &config)
Expand Down
9 changes: 5 additions & 4 deletions observability/exporting.go
Expand Up @@ -28,10 +28,9 @@ import (
"google.golang.org/protobuf/encoding/protojson"
)

// loggingExporter is the interface of logging exporter for gRPC
// Observability. Ideally, we should use what OTEL provides, but their Golang
// implementation is in "frozen" state. So, this plugin provides a minimum
// interface to satisfy testing purposes.
// loggingExporter is the interface of logging exporter for gRPC Observability.
// In future, we might expose this to allow users provide custom exporters. But
// now, it exists for testing purposes.
type loggingExporter interface {
// EmitGrpcLogRecord writes a gRPC LogRecord to cache without blocking.
EmitGrpcLogRecord(*grpclogrecordpb.GrpcLogRecord)
Expand Down Expand Up @@ -114,11 +113,13 @@ func (cle *cloudLoggingExporter) Close() error {
if err := cle.logger.Flush(); err != nil {
return err
}
cle.logger = nil
}
if cle.client != nil {
if err := cle.client.Close(); err != nil {
return err
}
cle.client = nil
}
logger.Infof("Closed CloudLogging exporter")
return nil
Expand Down

0 comments on commit bf52a77

Please sign in to comment.