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

Add implementation of otlploggrpc configuration #5383

Merged
merged 14 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 72 additions & 30 deletions exporters/otlp/otlplog/otlploggrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,58 @@
package otlploggrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc"

import (
"fmt"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc/internal/otlpconf"
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc/internal/retry"
)

type wrappedOption struct {
otlpconf.Option
}
MrAlias marked this conversation as resolved.
Show resolved Hide resolved

func (w wrappedOption) applyOption(cfg config) config {
cfg.Config = w.Option.ApplyOption(cfg.Config)
return cfg

Check warning on line 24 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L22-L24

Added lines #L22 - L24 were not covered by tests
}

type fnOpt func(config) config

func (f fnOpt) applyOption(c config) config { return f(c) }

Check warning on line 29 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L29

Added line #L29 was not covered by tests

// Option applies an option to the Exporter.
type Option interface {
applyHTTPOption(config) config
applyOption(config) config
}

type config struct {
// TODO: implement.
otlpconf.Config

// gRPC configurations
gRPCCredentials otlpconf.Setting[credentials.TransportCredentials]
serviceConfig otlpconf.Setting[string]
reconnectionPeriod otlpconf.Setting[time.Duration]
dialOptions otlpconf.Setting[[]grpc.DialOption]
gRPCConn otlpconf.Setting[*grpc.ClientConn]
}

func newConfig(options []Option) config {
var c config
for _, opt := range options {
c = opt.applyHTTPOption(c)
c = opt.applyOption(c)

Check warning on line 50 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L50

Added line #L50 was not covered by tests
}

c.Config = otlpconf.LoadConfig(c.Config)

Check warning on line 53 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L53

Added line #L53 was not covered by tests

if !c.gRPCCredentials.Set && c.Config.TLSCfg.Set {
c.gRPCCredentials = otlpconf.NewSetting(credentials.NewTLS(c.Config.TLSCfg.Value))

Check warning on line 56 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L55-L56

Added lines #L55 - L56 were not covered by tests
}

return c
}

Expand All @@ -51,8 +81,7 @@
//
// This option has no effect if WithGRPCConn is used.
func WithInsecure() Option {
// TODO: implement.
return nil
return wrappedOption{Option: otlpconf.WithInsecure()}

Check warning on line 84 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L84

Added line #L84 was not covered by tests
}

// WithEndpoint sets the target endpoint the Exporter will connect to.
Expand All @@ -70,8 +99,7 @@
//
// This option has no effect if WithGRPCConn is used.
func WithEndpoint(endpoint string) Option {
// TODO: implement.
return nil
return wrappedOption{Option: otlpconf.WithEndpoint(endpoint)}

Check warning on line 102 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L102

Added line #L102 was not covered by tests
}

// WithEndpointURL sets the target endpoint URL the Exporter will connect to.
Expand All @@ -91,17 +119,18 @@
//
// This option has no effect if WithGRPCConn is used.
func WithEndpointURL(u string) Option {
// TODO: implement.
return nil
return wrappedOption{Option: otlpconf.WithEndpointURL(u)}

Check warning on line 122 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L122

Added line #L122 was not covered by tests
}

// WithReconnectionPeriod set the minimum amount of time between connection
// attempts to the target endpoint.
//
// This option has no effect if WithGRPCConn is used.
func WithReconnectionPeriod(rp time.Duration) Option {
// TODO: implement.
return nil
return fnOpt(func(c config) config {
c.reconnectionPeriod = otlpconf.NewSetting(rp)
return c
})

Check warning on line 133 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L130-L133

Added lines #L130 - L133 were not covered by tests
}

// WithCompressor sets the compressor the gRPC client uses.
Expand All @@ -118,8 +147,7 @@
//
// This option has no effect if WithGRPCConn is used.
func WithCompressor(compressor string) Option {
// TODO: implement.
return nil
return wrappedOption{Option: otlpconf.WithCompression(compressorToCompression(compressor))}

Check warning on line 150 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L150

Added line #L150 was not covered by tests
}

// WithHeaders will send the provided headers with each gRPC requests.
Expand All @@ -134,8 +162,7 @@
// By default, if an environment variable is not set, and this option is not
// passed, no user headers will be set.
func WithHeaders(headers map[string]string) Option {
// TODO: implement.
return nil
return wrappedOption{Option: otlpconf.WithHeaders(headers)}

Check warning on line 165 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L165

Added line #L165 was not covered by tests
}

// WithTLSCredentials sets the gRPC connection to use creds.
Expand All @@ -150,17 +177,21 @@
// passed, no TLS credentials will be used.
//
// This option has no effect if WithGRPCConn is used.
func WithTLSCredentials(_ credentials.TransportCredentials) Option {
// TODO: implement.
return nil
func WithTLSCredentials(credential credentials.TransportCredentials) Option {
return fnOpt(func(c config) config {
c.gRPCCredentials = otlpconf.NewSetting(credential)
return c
})

Check warning on line 184 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L180-L184

Added lines #L180 - L184 were not covered by tests
}

// WithServiceConfig defines the default gRPC service config used.
//
// This option has no effect if WithGRPCConn is used.
func WithServiceConfig(serviceConfig string) Option {
// TODO: implement.
return nil
return fnOpt(func(c config) config {
c.serviceConfig = otlpconf.NewSetting(serviceConfig)
return c
})

Check warning on line 194 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L191-L194

Added lines #L191 - L194 were not covered by tests
}

// WithDialOption sets explicit grpc.DialOptions to use when establishing a
Expand All @@ -171,9 +202,11 @@
// grpc.DialOptions are ignored.
//
// This option has no effect if WithGRPCConn is used.
func WithDialOption(_ ...grpc.DialOption) Option {
// TODO: implement.
return nil
func WithDialOption(opts ...grpc.DialOption) Option {
return fnOpt(func(c config) config {
c.dialOptions = otlpconf.NewSetting(opts)
return c
})

Check warning on line 209 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L205-L209

Added lines #L205 - L209 were not covered by tests
}

// WithGRPCConn sets conn as the gRPC ClientConn used for all communication.
Expand All @@ -184,9 +217,11 @@
//
// It is the callers responsibility to close the passed conn. The Exporter
// Shutdown method will not close this connection.
func WithGRPCConn(_ *grpc.ClientConn) Option {
// TODO: implement.
return nil
func WithGRPCConn(conn *grpc.ClientConn) Option {
return fnOpt(func(c config) config {
c.gRPCConn = otlpconf.NewSetting(conn)
return c
})

Check warning on line 224 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L220-L224

Added lines #L220 - L224 were not covered by tests
}

// WithTimeout sets the max amount of time an Exporter will attempt an export.
Expand All @@ -204,8 +239,7 @@
// By default, if an environment variable is not set, and this option is not
// passed, a timeout of 10 seconds will be used.
func WithTimeout(duration time.Duration) Option {
// TODO: implement.
return nil
return wrappedOption{Option: otlpconf.WithTimeout(duration)}

Check warning on line 242 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L242

Added line #L242 was not covered by tests
}

// WithRetry sets the retry policy for transient retryable errors that are
Expand All @@ -222,6 +256,14 @@
// 5 seconds after receiving a retryable error and increase exponentially
// after each error for no more than a total time of 1 minute.
func WithRetry(settings RetryConfig) Option {
// TODO: implement.
return nil
return wrappedOption{Option: otlpconf.WithRetry(retry.Config(settings))}

Check warning on line 259 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L259

Added line #L259 was not covered by tests
}

func compressorToCompression(compressor string) otlpconf.Compression {
if compressor == "gzip" {
return otlpconf.GzipCompression

Check warning on line 264 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L262-L264

Added lines #L262 - L264 were not covered by tests
}

otel.Handle(fmt.Errorf("invalid compression type: '%s', using no compression as default", compressor))
return otlpconf.NoCompression

Check warning on line 268 in exporters/otlp/otlplog/otlploggrpc/config.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlplog/otlploggrpc/config.go#L267-L268

Added lines #L267 - L268 were not covered by tests
}
2 changes: 1 addition & 1 deletion exporters/otlp/otlplog/otlploggrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.26.0
go.opentelemetry.io/otel/sdk/log v0.2.0-alpha
google.golang.org/grpc v1.64.0
)
Expand All @@ -14,7 +15,6 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/log v0.2.0-alpha // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/sdk v1.26.0 // indirect
Expand Down
Loading