mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 10:53:34 +00:00
rebase: update kubernetes and libraries to v1.22.0 version
Kubernetes v1.22 version has been released and this update ceph csi dependencies to use the same version. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
e077c1fdf5
commit
aa698bc3e1
278
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/connection.go
generated
vendored
Normal file
278
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/connection.go
generated
vendored
Normal file
@ -0,0 +1,278 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlpgrpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"google.golang.org/grpc/encoding/gzip"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
type connection struct {
|
||||
// Ensure pointer is 64-bit aligned for atomic operations on both 32 and 64 bit machines.
|
||||
lastConnectErrPtr unsafe.Pointer
|
||||
|
||||
// mu protects the connection as it is accessed by the
|
||||
// exporter goroutines and background connection goroutine
|
||||
mu sync.Mutex
|
||||
cc *grpc.ClientConn
|
||||
|
||||
// these fields are read-only after constructor is finished
|
||||
cfg otlpconfig.Config
|
||||
sCfg otlpconfig.SignalConfig
|
||||
metadata metadata.MD
|
||||
newConnectionHandler func(cc *grpc.ClientConn)
|
||||
|
||||
// these channels are created once
|
||||
disconnectedCh chan bool
|
||||
backgroundConnectionDoneCh chan struct{}
|
||||
stopCh chan struct{}
|
||||
|
||||
// this is for tests, so they can replace the closing
|
||||
// routine without a worry of modifying some global variable
|
||||
// or changing it back to original after the test is done
|
||||
closeBackgroundConnectionDoneCh func(ch chan struct{})
|
||||
}
|
||||
|
||||
func newConnection(cfg otlpconfig.Config, sCfg otlpconfig.SignalConfig, handler func(cc *grpc.ClientConn)) *connection {
|
||||
c := new(connection)
|
||||
c.newConnectionHandler = handler
|
||||
c.cfg = cfg
|
||||
c.sCfg = sCfg
|
||||
if len(c.sCfg.Headers) > 0 {
|
||||
c.metadata = metadata.New(c.sCfg.Headers)
|
||||
}
|
||||
c.closeBackgroundConnectionDoneCh = func(ch chan struct{}) {
|
||||
close(ch)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *connection) startConnection(ctx context.Context) {
|
||||
c.stopCh = make(chan struct{})
|
||||
c.disconnectedCh = make(chan bool, 1)
|
||||
c.backgroundConnectionDoneCh = make(chan struct{})
|
||||
|
||||
if err := c.connect(ctx); err == nil {
|
||||
c.setStateConnected()
|
||||
} else {
|
||||
c.setStateDisconnected(err)
|
||||
}
|
||||
go c.indefiniteBackgroundConnection()
|
||||
}
|
||||
|
||||
func (c *connection) lastConnectError() error {
|
||||
errPtr := (*error)(atomic.LoadPointer(&c.lastConnectErrPtr))
|
||||
if errPtr == nil {
|
||||
return nil
|
||||
}
|
||||
return *errPtr
|
||||
}
|
||||
|
||||
func (c *connection) saveLastConnectError(err error) {
|
||||
var errPtr *error
|
||||
if err != nil {
|
||||
errPtr = &err
|
||||
}
|
||||
atomic.StorePointer(&c.lastConnectErrPtr, unsafe.Pointer(errPtr))
|
||||
}
|
||||
|
||||
func (c *connection) setStateDisconnected(err error) {
|
||||
c.saveLastConnectError(err)
|
||||
select {
|
||||
case c.disconnectedCh <- true:
|
||||
default:
|
||||
}
|
||||
c.newConnectionHandler(nil)
|
||||
}
|
||||
|
||||
func (c *connection) setStateConnected() {
|
||||
c.saveLastConnectError(nil)
|
||||
}
|
||||
|
||||
func (c *connection) connected() bool {
|
||||
return c.lastConnectError() == nil
|
||||
}
|
||||
|
||||
const defaultConnReattemptPeriod = 10 * time.Second
|
||||
|
||||
func (c *connection) indefiniteBackgroundConnection() {
|
||||
defer func() {
|
||||
c.closeBackgroundConnectionDoneCh(c.backgroundConnectionDoneCh)
|
||||
}()
|
||||
|
||||
connReattemptPeriod := c.cfg.ReconnectionPeriod
|
||||
if connReattemptPeriod <= 0 {
|
||||
connReattemptPeriod = defaultConnReattemptPeriod
|
||||
}
|
||||
|
||||
// No strong seeding required, nano time can
|
||||
// already help with pseudo uniqueness.
|
||||
rng := rand.New(rand.NewSource(time.Now().UnixNano() + rand.Int63n(1024)))
|
||||
|
||||
// maxJitterNanos: 70% of the connectionReattemptPeriod
|
||||
maxJitterNanos := int64(0.7 * float64(connReattemptPeriod))
|
||||
|
||||
for {
|
||||
// Otherwise these will be the normal scenarios to enable
|
||||
// reconnection if we trip out.
|
||||
// 1. If we've stopped, return entirely
|
||||
// 2. Otherwise block until we are disconnected, and
|
||||
// then retry connecting
|
||||
select {
|
||||
case <-c.stopCh:
|
||||
return
|
||||
|
||||
case <-c.disconnectedCh:
|
||||
// Quickly check if we haven't stopped at the
|
||||
// same time.
|
||||
select {
|
||||
case <-c.stopCh:
|
||||
return
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
// Normal scenario that we'll wait for
|
||||
}
|
||||
|
||||
if err := c.connect(context.Background()); err == nil {
|
||||
c.setStateConnected()
|
||||
} else {
|
||||
// this code is unreachable in most cases
|
||||
// c.connect does not establish connection
|
||||
c.setStateDisconnected(err)
|
||||
}
|
||||
|
||||
// Apply some jitter to avoid lockstep retrials of other
|
||||
// collector-exporters. Lockstep retrials could result in an
|
||||
// innocent DDOS, by clogging the machine's resources and network.
|
||||
jitter := time.Duration(rng.Int63n(maxJitterNanos))
|
||||
select {
|
||||
case <-c.stopCh:
|
||||
return
|
||||
case <-time.After(connReattemptPeriod + jitter):
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *connection) connect(ctx context.Context) error {
|
||||
cc, err := c.dialToCollector(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.setConnection(cc)
|
||||
c.newConnectionHandler(cc)
|
||||
return nil
|
||||
}
|
||||
|
||||
// setConnection sets cc as the client connection and returns true if
|
||||
// the connection state changed.
|
||||
func (c *connection) setConnection(cc *grpc.ClientConn) bool {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
// If previous clientConn is same as the current then just return.
|
||||
// This doesn't happen right now as this func is only called with new ClientConn.
|
||||
// It is more about future-proofing.
|
||||
if c.cc == cc {
|
||||
return false
|
||||
}
|
||||
|
||||
// If the previous clientConn was non-nil, close it
|
||||
if c.cc != nil {
|
||||
_ = c.cc.Close()
|
||||
}
|
||||
c.cc = cc
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *connection) dialToCollector(ctx context.Context) (*grpc.ClientConn, error) {
|
||||
dialOpts := []grpc.DialOption{}
|
||||
if c.cfg.ServiceConfig != "" {
|
||||
dialOpts = append(dialOpts, grpc.WithDefaultServiceConfig(c.cfg.ServiceConfig))
|
||||
}
|
||||
if c.sCfg.GRPCCredentials != nil {
|
||||
dialOpts = append(dialOpts, grpc.WithTransportCredentials(c.sCfg.GRPCCredentials))
|
||||
} else if c.sCfg.Insecure {
|
||||
dialOpts = append(dialOpts, grpc.WithInsecure())
|
||||
}
|
||||
if c.sCfg.Compression == otlp.GzipCompression {
|
||||
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name)))
|
||||
}
|
||||
if len(c.cfg.DialOptions) != 0 {
|
||||
dialOpts = append(dialOpts, c.cfg.DialOptions...)
|
||||
}
|
||||
|
||||
ctx, cancel := c.contextWithStop(ctx)
|
||||
defer cancel()
|
||||
ctx = c.contextWithMetadata(ctx)
|
||||
return grpc.DialContext(ctx, c.sCfg.Endpoint, dialOpts...)
|
||||
}
|
||||
|
||||
func (c *connection) contextWithMetadata(ctx context.Context) context.Context {
|
||||
if c.metadata.Len() > 0 {
|
||||
return metadata.NewOutgoingContext(ctx, c.metadata)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
func (c *connection) shutdown(ctx context.Context) error {
|
||||
close(c.stopCh)
|
||||
// Ensure that the backgroundConnector returns
|
||||
select {
|
||||
case <-c.backgroundConnectionDoneCh:
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
c.mu.Lock()
|
||||
cc := c.cc
|
||||
c.cc = nil
|
||||
c.mu.Unlock()
|
||||
|
||||
if cc != nil {
|
||||
return cc.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *connection) contextWithStop(ctx context.Context) (context.Context, context.CancelFunc) {
|
||||
// Unify the parent context Done signal with the connection's
|
||||
// stop channel.
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
go func(ctx context.Context, cancel context.CancelFunc) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// Nothing to do, either cancelled or deadline
|
||||
// happened.
|
||||
case <-c.stopCh:
|
||||
cancel()
|
||||
}
|
||||
}(ctx, cancel)
|
||||
return ctx, cancel
|
||||
}
|
25
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/doc.go
generated
vendored
Normal file
25
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/doc.go
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
Package otlpgrpc provides an implementation of otlp.ProtocolDriver
|
||||
that connects to the collector and sends traces and metrics using
|
||||
gRPC.
|
||||
|
||||
This package is currently in a pre-GA phase. Backwards incompatible
|
||||
changes may be introduced in subsequent minor version releases as we
|
||||
work to track the evolving OpenTelemetry specification and user
|
||||
feedback.
|
||||
*/
|
||||
package otlpgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
|
195
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/driver.go
generated
vendored
Normal file
195
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/driver.go
generated
vendored
Normal file
@ -0,0 +1,195 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlpgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/internal/transform"
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
tracesdk "go.opentelemetry.io/otel/sdk/trace"
|
||||
colmetricpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
|
||||
coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
|
||||
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
|
||||
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
|
||||
)
|
||||
|
||||
type driver struct {
|
||||
metricsDriver metricsDriver
|
||||
tracesDriver tracesDriver
|
||||
}
|
||||
|
||||
type metricsDriver struct {
|
||||
connection *connection
|
||||
|
||||
lock sync.Mutex
|
||||
metricsClient colmetricpb.MetricsServiceClient
|
||||
}
|
||||
|
||||
type tracesDriver struct {
|
||||
connection *connection
|
||||
|
||||
lock sync.Mutex
|
||||
tracesClient coltracepb.TraceServiceClient
|
||||
}
|
||||
|
||||
var (
|
||||
errNoClient = errors.New("no client")
|
||||
)
|
||||
|
||||
// NewDriver creates a new gRPC protocol driver.
|
||||
func NewDriver(opts ...Option) otlp.ProtocolDriver {
|
||||
cfg := otlpconfig.NewDefaultConfig()
|
||||
otlpconfig.ApplyGRPCEnvConfigs(&cfg)
|
||||
for _, opt := range opts {
|
||||
opt.ApplyGRPCOption(&cfg)
|
||||
}
|
||||
|
||||
d := &driver{}
|
||||
|
||||
d.tracesDriver = tracesDriver{
|
||||
connection: newConnection(cfg, cfg.Traces, d.tracesDriver.handleNewConnection),
|
||||
}
|
||||
|
||||
d.metricsDriver = metricsDriver{
|
||||
connection: newConnection(cfg, cfg.Metrics, d.metricsDriver.handleNewConnection),
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (md *metricsDriver) handleNewConnection(cc *grpc.ClientConn) {
|
||||
md.lock.Lock()
|
||||
defer md.lock.Unlock()
|
||||
if cc != nil {
|
||||
md.metricsClient = colmetricpb.NewMetricsServiceClient(cc)
|
||||
} else {
|
||||
md.metricsClient = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (td *tracesDriver) handleNewConnection(cc *grpc.ClientConn) {
|
||||
td.lock.Lock()
|
||||
defer td.lock.Unlock()
|
||||
if cc != nil {
|
||||
td.tracesClient = coltracepb.NewTraceServiceClient(cc)
|
||||
} else {
|
||||
td.tracesClient = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Start implements otlp.ProtocolDriver. It establishes a connection
|
||||
// to the collector.
|
||||
func (d *driver) Start(ctx context.Context) error {
|
||||
d.tracesDriver.connection.startConnection(ctx)
|
||||
d.metricsDriver.connection.startConnection(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop implements otlp.ProtocolDriver. It shuts down the connection
|
||||
// to the collector.
|
||||
func (d *driver) Stop(ctx context.Context) error {
|
||||
if err := d.tracesDriver.connection.shutdown(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return d.metricsDriver.connection.shutdown(ctx)
|
||||
}
|
||||
|
||||
// ExportMetrics implements otlp.ProtocolDriver. It transforms metrics
|
||||
// to protobuf binary format and sends the result to the collector.
|
||||
func (d *driver) ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error {
|
||||
if !d.metricsDriver.connection.connected() {
|
||||
return fmt.Errorf("metrics exporter is disconnected from the server %s: %w", d.metricsDriver.connection.sCfg.Endpoint, d.metricsDriver.connection.lastConnectError())
|
||||
}
|
||||
ctx, cancel := d.metricsDriver.connection.contextWithStop(ctx)
|
||||
defer cancel()
|
||||
ctx, tCancel := context.WithTimeout(ctx, d.metricsDriver.connection.sCfg.Timeout)
|
||||
defer tCancel()
|
||||
|
||||
rms, err := transform.CheckpointSet(ctx, selector, cps, 1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(rms) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return d.metricsDriver.uploadMetrics(ctx, rms)
|
||||
}
|
||||
|
||||
func (md *metricsDriver) uploadMetrics(ctx context.Context, protoMetrics []*metricpb.ResourceMetrics) error {
|
||||
ctx = md.connection.contextWithMetadata(ctx)
|
||||
err := func() error {
|
||||
md.lock.Lock()
|
||||
defer md.lock.Unlock()
|
||||
if md.metricsClient == nil {
|
||||
return errNoClient
|
||||
}
|
||||
_, err := md.metricsClient.Export(ctx, &colmetricpb.ExportMetricsServiceRequest{
|
||||
ResourceMetrics: protoMetrics,
|
||||
})
|
||||
return err
|
||||
}()
|
||||
if err != nil {
|
||||
md.connection.setStateDisconnected(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ExportTraces implements otlp.ProtocolDriver. It transforms spans to
|
||||
// protobuf binary format and sends the result to the collector.
|
||||
func (d *driver) ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error {
|
||||
if !d.tracesDriver.connection.connected() {
|
||||
return fmt.Errorf("traces exporter is disconnected from the server %s: %w", d.tracesDriver.connection.sCfg.Endpoint, d.tracesDriver.connection.lastConnectError())
|
||||
}
|
||||
ctx, cancel := d.tracesDriver.connection.contextWithStop(ctx)
|
||||
defer cancel()
|
||||
ctx, tCancel := context.WithTimeout(ctx, d.tracesDriver.connection.sCfg.Timeout)
|
||||
defer tCancel()
|
||||
|
||||
protoSpans := transform.SpanData(ss)
|
||||
if len(protoSpans) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return d.tracesDriver.uploadTraces(ctx, protoSpans)
|
||||
}
|
||||
|
||||
func (td *tracesDriver) uploadTraces(ctx context.Context, protoSpans []*tracepb.ResourceSpans) error {
|
||||
ctx = td.connection.contextWithMetadata(ctx)
|
||||
err := func() error {
|
||||
td.lock.Lock()
|
||||
defer td.lock.Unlock()
|
||||
if td.tracesClient == nil {
|
||||
return errNoClient
|
||||
}
|
||||
_, err := td.tracesClient.Export(ctx, &coltracepb.ExportTraceServiceRequest{
|
||||
ResourceSpans: protoSpans,
|
||||
})
|
||||
return err
|
||||
}()
|
||||
if err != nil {
|
||||
td.connection.setStateDisconnected(err)
|
||||
}
|
||||
return err
|
||||
}
|
202
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/options.go
generated
vendored
Normal file
202
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/options.go
generated
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlpgrpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
// Option applies an option to the gRPC driver.
|
||||
type Option interface {
|
||||
otlpconfig.GRPCOption
|
||||
}
|
||||
|
||||
// WithInsecure disables client transport security for the exporter's gRPC connection
|
||||
// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure
|
||||
// does. Note, by default, client security is required unless WithInsecure is used.
|
||||
func WithInsecure() Option {
|
||||
return otlpconfig.WithInsecure()
|
||||
}
|
||||
|
||||
// WithTracesInsecure disables client transport security for the traces exporter's gRPC connection
|
||||
// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure
|
||||
// does. Note, by default, client security is required unless WithInsecure is used.
|
||||
func WithTracesInsecure() Option {
|
||||
return otlpconfig.WithInsecureTraces()
|
||||
}
|
||||
|
||||
// WithInsecureMetrics disables client transport security for the metrics exporter's gRPC connection
|
||||
// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure
|
||||
// does. Note, by default, client security is required unless WithInsecure is used.
|
||||
func WithInsecureMetrics() Option {
|
||||
return otlpconfig.WithInsecureMetrics()
|
||||
}
|
||||
|
||||
// WithEndpoint allows one to set the endpoint that the exporter will
|
||||
// connect to the collector on. If unset, it will instead try to use
|
||||
// connect to DefaultCollectorHost:DefaultCollectorPort.
|
||||
func WithEndpoint(endpoint string) Option {
|
||||
return otlpconfig.WithEndpoint(endpoint)
|
||||
}
|
||||
|
||||
// WithTracesEndpoint allows one to set the traces endpoint that the exporter will
|
||||
// connect to the collector on. If unset, it will instead try to use
|
||||
// connect to DefaultCollectorHost:DefaultCollectorPort.
|
||||
func WithTracesEndpoint(endpoint string) Option {
|
||||
return otlpconfig.WithTracesEndpoint(endpoint)
|
||||
}
|
||||
|
||||
// WithMetricsEndpoint allows one to set the metrics endpoint that the exporter will
|
||||
// connect to the collector on. If unset, it will instead try to use
|
||||
// connect to DefaultCollectorHost:DefaultCollectorPort.
|
||||
func WithMetricsEndpoint(endpoint string) Option {
|
||||
return otlpconfig.WithMetricsEndpoint(endpoint)
|
||||
}
|
||||
|
||||
// WithReconnectionPeriod allows one to set the delay between next connection attempt
|
||||
// after failing to connect with the collector.
|
||||
func WithReconnectionPeriod(rp time.Duration) otlpconfig.GRPCOption {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.ReconnectionPeriod = rp
|
||||
})
|
||||
}
|
||||
|
||||
func compressorToCompression(compressor string) otlp.Compression {
|
||||
switch compressor {
|
||||
case "gzip":
|
||||
return otlp.GzipCompression
|
||||
}
|
||||
|
||||
otel.Handle(fmt.Errorf("invalid compression type: '%s', using no compression as default", compressor))
|
||||
return otlp.NoCompression
|
||||
}
|
||||
|
||||
// WithCompressor will set the compressor for the gRPC client to use when sending requests.
|
||||
// It is the responsibility of the caller to ensure that the compressor set has been registered
|
||||
// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some
|
||||
// compressors auto-register on import, such as gzip, which can be registered by calling
|
||||
// `import _ "google.golang.org/grpc/encoding/gzip"`.
|
||||
func WithCompressor(compressor string) Option {
|
||||
return otlpconfig.WithCompression(compressorToCompression(compressor))
|
||||
}
|
||||
|
||||
// WithTracesCompression will set the compressor for the gRPC client to use when sending traces requests.
|
||||
// It is the responsibility of the caller to ensure that the compressor set has been registered
|
||||
// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some
|
||||
// compressors auto-register on import, such as gzip, which can be registered by calling
|
||||
// `import _ "google.golang.org/grpc/encoding/gzip"`.
|
||||
func WithTracesCompression(compressor string) Option {
|
||||
return otlpconfig.WithTracesCompression(compressorToCompression(compressor))
|
||||
}
|
||||
|
||||
// WithMetricsCompression will set the compressor for the gRPC client to use when sending metrics requests.
|
||||
// It is the responsibility of the caller to ensure that the compressor set has been registered
|
||||
// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some
|
||||
// compressors auto-register on import, such as gzip, which can be registered by calling
|
||||
// `import _ "google.golang.org/grpc/encoding/gzip"`.
|
||||
func WithMetricsCompression(compressor string) Option {
|
||||
return otlpconfig.WithMetricsCompression(compressorToCompression(compressor))
|
||||
}
|
||||
|
||||
// WithHeaders will send the provided headers with gRPC requests.
|
||||
func WithHeaders(headers map[string]string) Option {
|
||||
return otlpconfig.WithHeaders(headers)
|
||||
}
|
||||
|
||||
// WithTracesHeaders will send the provided headers with gRPC traces requests.
|
||||
func WithTracesHeaders(headers map[string]string) Option {
|
||||
return otlpconfig.WithTracesHeaders(headers)
|
||||
}
|
||||
|
||||
// WithMetricsHeaders will send the provided headers with gRPC metrics requests.
|
||||
func WithMetricsHeaders(headers map[string]string) Option {
|
||||
return otlpconfig.WithMetricsHeaders(headers)
|
||||
}
|
||||
|
||||
// WithTLSCredentials allows the connection to use TLS credentials
|
||||
// when talking to the server. It takes in grpc.TransportCredentials instead
|
||||
// of say a Certificate file or a tls.Certificate, because the retrieving of
|
||||
// these credentials can be done in many ways e.g. plain file, in code tls.Config
|
||||
// or by certificate rotation, so it is up to the caller to decide what to use.
|
||||
func WithTLSCredentials(creds credentials.TransportCredentials) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.Traces.GRPCCredentials = creds
|
||||
cfg.Metrics.GRPCCredentials = creds
|
||||
})
|
||||
}
|
||||
|
||||
// WithTracesTLSCredentials allows the connection to use TLS credentials
|
||||
// when talking to the traces server. It takes in grpc.TransportCredentials instead
|
||||
// of say a Certificate file or a tls.Certificate, because the retrieving of
|
||||
// these credentials can be done in many ways e.g. plain file, in code tls.Config
|
||||
// or by certificate rotation, so it is up to the caller to decide what to use.
|
||||
func WithTracesTLSCredentials(creds credentials.TransportCredentials) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.Traces.GRPCCredentials = creds
|
||||
})
|
||||
}
|
||||
|
||||
// WithMetricsTLSCredentials allows the connection to use TLS credentials
|
||||
// when talking to the metrics server. It takes in grpc.TransportCredentials instead
|
||||
// of say a Certificate file or a tls.Certificate, because the retrieving of
|
||||
// these credentials can be done in many ways e.g. plain file, in code tls.Config
|
||||
// or by certificate rotation, so it is up to the caller to decide what to use.
|
||||
func WithMetricsTLSCredentials(creds credentials.TransportCredentials) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.Metrics.GRPCCredentials = creds
|
||||
})
|
||||
}
|
||||
|
||||
// WithServiceConfig defines the default gRPC service config used.
|
||||
func WithServiceConfig(serviceConfig string) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.ServiceConfig = serviceConfig
|
||||
})
|
||||
}
|
||||
|
||||
// WithDialOption opens support to any grpc.DialOption to be used. If it conflicts
|
||||
// with some other configuration the GRPC specified via the collector the ones here will
|
||||
// take preference since they are set last.
|
||||
func WithDialOption(opts ...grpc.DialOption) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.DialOptions = opts
|
||||
})
|
||||
}
|
||||
|
||||
// WithTimeout tells the driver the max waiting time for the backend to process
|
||||
// each spans or metrics batch. If unset, the default will be 10 seconds.
|
||||
func WithTimeout(duration time.Duration) Option {
|
||||
return otlpconfig.WithTimeout(duration)
|
||||
}
|
||||
|
||||
// WithTracesTimeout tells the driver the max waiting time for the backend to process
|
||||
// each spans batch. If unset, the default will be 10 seconds.
|
||||
func WithTracesTimeout(duration time.Duration) Option {
|
||||
return otlpconfig.WithTracesTimeout(duration)
|
||||
}
|
||||
|
||||
// WithMetricsTimeout tells the driver the max waiting time for the backend to process
|
||||
// each metrics batch. If unset, the default will be 10 seconds.
|
||||
func WithMetricsTimeout(duration time.Duration) Option {
|
||||
return otlpconfig.WithMetricsTimeout(duration)
|
||||
}
|
Reference in New Issue
Block a user