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

Ydb exporter tests #1

Open
wants to merge 13 commits into
base: add-ydb-exporter
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
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
56 changes: 56 additions & 0 deletions exporter/ydbexporter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ydbexporter

import (
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexporter/internal/config"
_ "github.com/ydb-platform/ydb-go-sdk/v3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем так делать?

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

const (
defaultEndpoint = "grpcs://localhost:2135"
defaultAuthType = "anonymous"
defaultDatabase = "/local"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давайте не будем разделять единый connection_string на endpoint+database?

defaultLogsTableName = "otel_logs"
defaultMetricsTableName = "otel_metrics"
defaultTracesTableName = "otel_traces"
defaultPartitionsCount = 64
defaultTTL = 0
)

func WithDefaultConfig(fns ...func(*config.Config)) *config.Config {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

обычно их называют opts/options

cfg := DefaultConfig().(*config.Config)
for _, fn := range fns {
fn(cfg)
}
return cfg
}

func DefaultConfig() component.Config {
queueSettings := exporterhelper.NewDefaultQueueSettings()
queueSettings.NumConsumers = 1

return &config.Config{
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
QueueSettings: queueSettings,
ConnectionParams: map[string]string{},
AuthType: defaultAuthType,
Endpoint: defaultEndpoint,
Database: defaultDatabase,
MetricsTable: config.TableConfig{
Name: defaultMetricsTableName,
TTL: defaultTTL,
PartitionsCount: defaultPartitionsCount,
},
LogsTable: config.TableConfig{
Name: defaultLogsTableName,
TTL: defaultTTL,
PartitionsCount: defaultPartitionsCount,
},
TracesTable: config.TableConfig{
Name: defaultTracesTableName,
TTL: defaultTTL,
PartitionsCount: defaultPartitionsCount,
},
}
}
89 changes: 89 additions & 0 deletions exporter/ydbexporter/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package ydbexporter

import (
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexporter/internal/config"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexporter/internal/metadata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"path/filepath"
"testing"
"time"
)

func TestLoadConfig(t *testing.T) {
t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)

defaultCfg := WithDefaultConfig(func(c *config.Config) {
c.Endpoint = defaultEndpoint
})

storageID := component.NewIDWithName(component.Type("file_storage"), "ydb")

tests := []struct {
id component.ID
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно ещё добавить осмысленные имена тестам
тогда будет понятно, какой именно тест упал

expected component.Config
}{
{
id: component.NewIDWithName(metadata.Type, ""),
expected: defaultCfg,
},
{
id: component.NewIDWithName(metadata.Type, "full"),
expected: &config.Config{
AuthType: "accessToken",
Endpoint: defaultEndpoint,
Username: "foo",
Password: "bar",
AccessToken: "token",
ServiceAccountKey: "key",
CertificatePath: "/ydb_certs/ca.pem",
Database: "local",
TimeoutSettings: exporterhelper.TimeoutSettings{
Timeout: 5 * time.Second,
},
ConnectionParams: map[string]string{"param": "param"},
QueueSettings: exporterhelper.QueueSettings{
Enabled: true,
NumConsumers: 1,
QueueSize: 100,
StorageID: &storageID,
},
LogsTable: config.TableConfig{
TTL: 72 * time.Hour,
Name: "otel_logs",
PartitionsCount: 1,
},
TracesTable: config.TableConfig{
TTL: 72 * time.Hour,
Name: "otel_traces",
PartitionsCount: 1,
},
MetricsTable: config.TableConfig{
TTL: 72 * time.Hour,
Name: "otel_metrics",
PartitionsCount: 1,
},
},
},
}

for _, tt := range tests {
t.Run(tt.id.String(), func(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

sub, err := cm.Sub(tt.id.String())
require.NoError(t, err)
require.NoError(t, component.UnmarshalConfig(sub, cfg))

assert.NoError(t, component.ValidateConfig(cfg))
assert.Equal(t, tt.expected, cfg)
})
}
}
2 changes: 1 addition & 1 deletion exporter/ydbexporter/example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3"
version: "3.8"

networks:
otel_ydb:
Expand Down
4 changes: 2 additions & 2 deletions exporter/ydbexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package ydbexporter
import (
"context"
"fmt"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexporter/internal/config"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

линтер gofumpt здесь ругнется


"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexporter/internal/config"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexporter/internal/logs"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexporter/internal/metrics"
Expand All @@ -19,7 +19,7 @@ import (
func NewFactory() exporter.Factory {
return exporter.NewFactory(
metadata.Type,
config.DefaultConfig,
DefaultConfig,
exporter.WithLogs(createLogsExporter, metadata.LogsStability),
exporter.WithTraces(createTracesExporter, metadata.TracesStability),
exporter.WithMetrics(createMetricExporter, metadata.MetricsStability),
Expand Down
61 changes: 61 additions & 0 deletions exporter/ydbexporter/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package ydbexporter

import (
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component/componenttest"
"testing"
)

const authType = "anonymous"

func TestCreateDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NotNil(t, cfg, "failed to create default config")
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
}

func TestFactory_CreateLogsExporter(t *testing.T) {
// TODO: Uncomment after understanding problem with connecting to ydb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

попробуй подключаться по 2136 без сертификатов
для тестов вполне норм

//factory := NewFactory()
//params := exportertest.NewNopCreateSettings()
//cfg := config.WithDefaultConfig(func(c *config.Config) {
// c.AuthType = authType
//})
//
//exporter, err := factory.CreateLogsExporter(context.Background(), params, cfg)
//
//require.NoError(t, err)
//require.NotNil(t, exporter)
//require.NoError(t, exporter.Shutdown(context.TODO()))
}

func TestFactory_CreateTracesExporter(t *testing.T) {
// TODO: Uncomment after understanding problem with connecting to ydb
//factory := NewFactory()
//params := exportertest.NewNopCreateSettings()
//cfg := config.WithDefaultConfig(func(c *config.Config) {
// c.AuthType = authType
//})
//
//exporter, err := factory.CreateTracesExporter(context.Background(), params, cfg)
//
//require.NoError(t, err)
//require.NotNil(t, exporter)
//require.NoError(t, exporter.Shutdown(context.TODO()))
}

func TestFactory_CreateMetricsExporter(t *testing.T) {
// TODO: Uncomment after understanding problem with connecting to ydb
//factory := NewFactory()
//params := exportertest.NewNopCreateSettings()
//cfg := config.WithDefaultConfig(func(c *config.Config) {
// c.AuthType = authType
//})
//
//exporter, err := factory.CreateMetricsExporter(context.Background(), params, cfg)
//
//require.NoError(t, err)
//require.NotNil(t, exporter)
//require.NoError(t, exporter.Shutdown(context.TODO()))
}
40 changes: 32 additions & 8 deletions exporter/ydbexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,66 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexp
go 1.20

require (
github.com/google/uuid v1.4.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.92.0
github.com/stretchr/testify v1.8.4
github.com/ydb-platform/ydb-go-sdk/v3 v3.54.2
go.opentelemetry.io/collector/component v0.92.0
go.opentelemetry.io/collector/component v0.92.1-0.20240112172857-83d463ceba06
go.opentelemetry.io/collector/config/configopaque v0.91.0
go.opentelemetry.io/collector/exporter v0.92.0
go.opentelemetry.io/collector/pdata v1.0.1
go.opentelemetry.io/collector/pdata v1.0.2-0.20240112172857-83d463ceba06
go.opentelemetry.io/collector/semconv v0.92.1-0.20240112172857-83d463ceba06
go.opentelemetry.io/otel/metric v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
go.uber.org/zap v1.26.0
)

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/jonboulle/clockwork v0.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/statsd_exporter v0.22.7 // indirect
github.com/ydb-platform/ydb-go-genproto v0.0.0-20231012155159-f85a672542fd // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector v0.92.0 // indirect
go.opentelemetry.io/collector v0.92.1-0.20240112172857-83d463ceba06 // indirect
go.opentelemetry.io/collector/config/configretry v0.92.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.92.0 // indirect
go.opentelemetry.io/collector/confmap v0.92.0 // indirect
go.opentelemetry.io/collector/consumer v0.92.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.92.1-0.20240112172857-83d463ceba06 // indirect
go.opentelemetry.io/collector/confmap v0.92.1-0.20240112172857-83d463ceba06 // indirect
go.opentelemetry.io/collector/consumer v0.92.1-0.20240112172857-83d463ceba06 // indirect
go.opentelemetry.io/collector/extension v0.92.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.1 // indirect
go.opentelemetry.io/collector/featuregate v1.0.2-0.20240112172857-83d463ceba06 // indirect
go.opentelemetry.io/collector/receiver v0.92.1-0.20240112172857-83d463ceba06 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.44.1-0.20231201153405-6027c1ae76f2 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.21.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.4.0 // indirect
Expand All @@ -49,6 +71,8 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../internal/coreinternal
Loading
Loading