-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
exporter.go
71 lines (64 loc) · 3.12 KB
/
exporter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package config
import (
"fmt"
"github.com/xitongsys/parquet-go/parquet"
)
// ExporterConf contains all the field to configure an exporter
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"`
}
func (c *ExporterConf) IsValid() error {
if err := c.Kind.IsValid(); err != nil {
return err
}
if c.Kind == FileExporter && c.OutputDir == "" {
return fmt.Errorf("invalid exporter: no \"outputDir\" property found for kind \"%s\"", c.Kind)
}
if (c.Kind == S3Exporter || c.Kind == GoogleStorageExporter) && c.Bucket == "" {
return fmt.Errorf("invalid exporter: no \"bucket\" property found for kind \"%s\"", c.Kind)
}
if c.Kind == WebhookExporter && c.EndpointURL == "" {
return fmt.Errorf("invalid exporter: no \"endpointUrl\" property found for kind \"%s\"", c.Kind)
}
if len(c.ParquetCompressionCodec) > 0 {
if _, err := parquet.CompressionCodecFromString(c.ParquetCompressionCodec); err != nil {
return fmt.Errorf("invalid exporter: \"parquetCompressionCodec\" err: %v", err)
}
}
if c.Kind == SQSExporter && c.QueueURL == "" {
return fmt.Errorf("invalid exporter: no \"queueUrl\" property found for kind \"%s\"", c.Kind)
}
return nil
}
type ExporterKind string
const (
FileExporter ExporterKind = "file"
WebhookExporter ExporterKind = "webhook"
LogExporter ExporterKind = "log"
S3Exporter ExporterKind = "s3"
GoogleStorageExporter ExporterKind = "googleStorage"
SQSExporter ExporterKind = "sqs"
)
// 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:
return nil
}
return fmt.Errorf("invalid exporter: kind \"%s\" is not supported", r)
}