-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: add-ydb-exporter
Are you sure you want to change the base?
Changes from 3 commits
fcbaba6
c5dbfab
ac483be
7420ba2
942d272
de0ec70
9b1e976
66363d9
2417d20
70cd61e
9a0723e
f736dfd
5fc10b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/exporter/exporterhelper" | ||
) | ||
|
||
const ( | ||
defaultEndpoint = "grpcs://localhost:2135" | ||
defaultAuthType = "anonymous" | ||
defaultDatabase = "/local" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
}, | ||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version: "3" | ||
version: "3.8" | ||
|
||
networks: | ||
otel_ydb: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ package ydbexporter | |
import ( | ||
"context" | ||
"fmt" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/ydbexporter/internal/config" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
@@ -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), | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а зачем так делать?