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

feat: Feature/opentel #1770

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
45 changes: 27 additions & 18 deletions cmd/relayproxy/config/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@ import (
"fmt"

"github.com/thomaspoignant/go-feature-flag/exporter/kafkaexporter"
"github.com/thomaspoignant/go-feature-flag/exporter/opentelemetryexporter"
"github.com/xitongsys/parquet-go/parquet"
)

// ExporterConf contains all the field to configure an exporter
// The parquet compression line is too long.
// nolint:lll
type ExporterConf struct {
Kind ExporterKind `mapstructure:"kind" koanf:"kind"`
OutputDir string `mapstructure:"outputDir" koanf:"outputdir"`
Format string `mapstructure:"format" koanf:"format"`
Filename string `mapstructure:"filename" koanf:"filename"`
CsvTemplate string `mapstructure:"csvTemplate" koanf:"csvtemplate"`
Bucket string `mapstructure:"bucket" koanf:"bucket"`
Path string `mapstructure:"path" koanf:"path"`
EndpointURL string `mapstructure:"endpointUrl" koanf:"endpointurl"`
Secret string `mapstructure:"secret" koanf:"secret"`
Meta map[string]string `mapstructure:"meta" koanf:"meta"`
LogFormat string `mapstructure:"logFormat" koanf:"logformat"`
FlushInterval int64 `mapstructure:"flushInterval" koanf:"flushinterval"`
MaxEventInMemory int64 `mapstructure:"maxEventInMemory" koanf:"maxeventinmemory"`
ParquetCompressionCodec string `mapstructure:"parquetCompressionCodec" koanf:"parquetcompressioncodec"`
Headers map[string][]string `mapstructure:"headers" koanf:"headers"`
QueueURL string `mapstructure:"queueUrl" koanf:"queueurl"`
Kafka kafkaexporter.Settings `mapstructure:"kafka" koanf:"kafka"`
Kind ExporterKind `mapstructure:"kind" koanf:"kind"`
OutputDir string `mapstructure:"outputDir" koanf:"outputdir"`
Format string `mapstructure:"format" koanf:"format"`
Filename string `mapstructure:"filename" koanf:"filename"`
CsvTemplate string `mapstructure:"csvTemplate" koanf:"csvtemplate"`
Bucket string `mapstructure:"bucket" koanf:"bucket"`
Path string `mapstructure:"path" koanf:"path"`
EndpointURL string `mapstructure:"endpointUrl" koanf:"endpointurl"`
Secret string `mapstructure:"secret" koanf:"secret"`
Meta map[string]string `mapstructure:"meta" koanf:"meta"`
LogFormat string `mapstructure:"logFormat" koanf:"logformat"`
FlushInterval int64 `mapstructure:"flushInterval" koanf:"flushinterval"`
MaxEventInMemory int64 `mapstructure:"maxEventInMemory" koanf:"maxeventinmemory"`
ParquetCompressionCodec string `mapstructure:"parquetCompressionCodec" koanf:"parquetcompressioncodec"`
Headers map[string][]string `mapstructure:"headers" koanf:"headers"`
QueueURL string `mapstructure:"queueUrl" koanf:"queueurl"`
Kafka kafkaexporter.Settings `mapstructure:"kafka" koanf:"kafka"`
ProjectID string `mapstructure:"projectID" koanf:"projectid"`
Topic string `mapstructure:"topic" koanf:"topic"`
OpenTel opentelemetryexporter.Settings `mapstructure:"opentel" koanf:"opentel"`
}

func (c *ExporterConf) IsValid() error {
Expand Down Expand Up @@ -60,6 +64,10 @@ func (c *ExporterConf) IsValid() error {
return fmt.Errorf("invalid exporter: \"projectID\" and \"topic\" are required for kind \"%s\"", c.Kind)
}

if c.Kind == OpenTelExporter && (c.OpenTel.OpentelSettings.URI == "") {
return fmt.Errorf("invalid exporter: \"opentel.uri\" is required for kind \"%s\"", c.Kind)
}

return nil
}

Expand All @@ -74,13 +82,14 @@ const (
SQSExporter ExporterKind = "sqs"
KafkaExporter ExporterKind = "kafka"
PubSubExporter ExporterKind = "pubsub"
OpenTelExporter ExporterKind = "opentel"
)

// IsValid is checking if the value is part of the enum
func (r ExporterKind) IsValid() error {
switch r {
case FileExporter, WebhookExporter, LogExporter, S3Exporter, GoogleStorageExporter, SQSExporter, KafkaExporter,
PubSubExporter:
OpenTelExporter, PubSubExporter:
return nil
}
return fmt.Errorf("invalid exporter: kind \"%s\" is not supported", r)
Expand Down
32 changes: 32 additions & 0 deletions cmd/relayproxy/config/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/thomaspoignant/go-feature-flag/cmd/relayproxy/config"
"github.com/thomaspoignant/go-feature-flag/exporter/opentelemetryexporter"
)

func TestExporterConf_IsValid(t *testing.T) {
Expand All @@ -23,6 +24,7 @@ func TestExporterConf_IsValid(t *testing.T) {
QueueURL string
ProjectID string
Topic string
OpenTel opentelemetryexporter.Settings
}
tests := []struct {
name string
Expand Down Expand Up @@ -186,6 +188,35 @@ func TestExporterConf_IsValid(t *testing.T) {
wantErr: true,
errValue: "invalid exporter: \"projectID\" and \"topic\" are required for kind \"pubsub\"",
},
{
name: "kind OpenTel with no creds",
fields: fields{
Kind: "opentel",
OpenTel: opentelemetryexporter.Settings{OpentelSettings: opentelemetryexporter.OpenTelSettings{URI: "localhost"}},
},
wantErr: false,
},
{
name: "kind OpenTel with creds",
fields: fields{
Kind: "opentel",
OpenTel: opentelemetryexporter.Settings{
OpentelSettings: opentelemetryexporter.OpenTelSettings{URI: "localhost", CACertPath: "/tmp/does-not-exist"},
},
},
wantErr: false,
},
{
name: "kind OpenTel with no uri",
fields: fields{
Kind: "opentel",
OpenTel: opentelemetryexporter.Settings{
OpentelSettings: opentelemetryexporter.OpenTelSettings{CACertPath: "/tmp/does-not-exist"},
},
},
wantErr: true,
errValue: "invalid exporter: \"opentel.uri\" is required for kind \"opentel\"",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -204,6 +235,7 @@ func TestExporterConf_IsValid(t *testing.T) {
QueueURL: tt.fields.QueueURL,
ProjectID: tt.fields.ProjectID,
Topic: tt.fields.Topic,
OpenTel: tt.fields.OpenTel,
}
err := c.IsValid()
assert.Equal(t, tt.wantErr, err != nil)
Expand Down
Loading
Loading