Skip to content

Commit

Permalink
added meter provider to storage grpc factory
Browse files Browse the repository at this point in the history
Signed-off-by: chahatsagarmain <[email protected]>
  • Loading branch information
chahatsagarmain committed Nov 8, 2024
1 parent 8dfaecb commit 199ec2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 7 additions & 5 deletions plugin/storage/grpc/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
noopmetric "go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
"go.uber.org/zap"
Expand Down Expand Up @@ -51,6 +50,7 @@ type Factory struct {
tracedRemoteConn *grpc.ClientConn
untracedRemoteConn *grpc.ClientConn
host component.Host
meterProvider metric.MeterProvider
}

// NewFactory creates a new Factory.
Expand All @@ -66,10 +66,12 @@ func NewFactoryWithConfig(
metricsFactory metrics.Factory,
logger *zap.Logger,
host component.Host,
meterProvider metric.MeterProvider,
) (*Factory, error) {
f := NewFactory()
f.config = cfg
f.host = host
f.meterProvider = meterProvider
if err := f.Initialize(metricsFactory, logger); err != nil {
return nil, err
}
Expand All @@ -93,8 +95,8 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
f.metricsFactory, f.logger = metricsFactory, logger
f.tracerProvider = otel.GetTracerProvider()

tracedTelset := getTelset(logger, f.tracerProvider)
untracedTelset := getTelset(logger, noop.NewTracerProvider())
tracedTelset := getTelset(logger, f.tracerProvider, f.meterProvider)
untracedTelset := getTelset(logger, noop.NewTracerProvider(), f.meterProvider)
newClientFn := func(telset component.TelemetrySettings, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error) {
clientOpts := make([]configgrpc.ToClientConnOption, 0)
for _, opt := range opts {
Expand Down Expand Up @@ -232,13 +234,13 @@ func (f *Factory) Close() error {
return errors.Join(errs...)
}

func getTelset(logger *zap.Logger, tracerProvider trace.TracerProvider) component.TelemetrySettings {
func getTelset(logger *zap.Logger, tracerProvider trace.TracerProvider, meterProvider metric.MeterProvider) component.TelemetrySettings {
return component.TelemetrySettings{
Logger: logger,
TracerProvider: tracerProvider,
// TODO needs to be joined with the metricsFactory
LeveledMeterProvider: func(_ configtelemetry.Level) metric.MeterProvider {
return noopmetric.NewMeterProvider()
return meterProvider
},
}
}
7 changes: 4 additions & 3 deletions plugin/storage/grpc/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"go.opentelemetry.io/collector/config/configauth"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/otel/metric/noop"
"go.uber.org/zap"
"google.golang.org/grpc"

Expand Down Expand Up @@ -106,7 +107,7 @@ func TestNewFactoryError(t *testing.T) {
},
}
t.Run("with_config", func(t *testing.T) {
_, err := NewFactoryWithConfig(*cfg, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost())
_, err := NewFactoryWithConfig(*cfg, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost(), noop.NewMeterProvider())
assert.ErrorContains(t, err, "authenticator")
})

Expand All @@ -120,7 +121,7 @@ func TestNewFactoryError(t *testing.T) {

t.Run("client", func(t *testing.T) {
// this is a silly test to verify handling of error from grpc.NewClient, which cannot be induced via params.
f, err := NewFactoryWithConfig(Config{}, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost())
f, err := NewFactoryWithConfig(Config{}, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost(), noop.NewMeterProvider())
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, f.Close()) })
newClientFn := func(_ component.TelemetrySettings, _ ...grpc.DialOption) (conn *grpc.ClientConn, err error) {
Expand Down Expand Up @@ -171,7 +172,7 @@ func TestGRPCStorageFactoryWithConfig(t *testing.T) {
Enabled: true,
},
}
f, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost())
f, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop(), componenttest.NewNopHost(), noop.NewMeterProvider())
require.NoError(t, err)
require.NoError(t, f.Close())
}
Expand Down

0 comments on commit 199ec2a

Please sign in to comment.