-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathconfig.go
65 lines (55 loc) · 1.81 KB
/
config.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package azureeventhubreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azureeventhubreceiver"
import (
"errors"
"fmt"
"github.com/Azure/azure-amqp-common-go/v4/conn"
"go.opentelemetry.io/collector/component"
)
type logFormat string
const (
defaultLogFormat logFormat = ""
rawLogFormat logFormat = "raw"
azureLogFormat logFormat = "azure"
)
var (
validFormats = []logFormat{defaultLogFormat, rawLogFormat, azureLogFormat}
errMissingConnection = errors.New("missing connection")
)
type Config struct {
Connection string `mapstructure:"connection"`
Partition string `mapstructure:"partition"`
Offset string `mapstructure:"offset"`
StorageID *component.ID `mapstructure:"storage"`
Format string `mapstructure:"format"`
ConsumerGroup string `mapstructure:"group"`
ApplySemanticConventions bool `mapstructure:"apply_semantic_conventions"`
TimeFormats TimeFormat `mapstructure:"time_formats"`
}
type TimeFormat struct {
Logs []string `mapstructure:"logs"`
Metrics []string `mapstructure:"metrics"`
Traces []string `mapstructure:"traces"`
}
func isValidFormat(format string) bool {
for _, validFormat := range validFormats {
if logFormat(format) == validFormat {
return true
}
}
return false
}
// Validate config
func (config *Config) Validate() error {
if config.Connection == "" {
return errMissingConnection
}
if _, err := conn.ParsedConnectionFromStr(config.Connection); err != nil {
return err
}
if !isValidFormat(config.Format) {
return fmt.Errorf("invalid format; must be one of %#v", validFormats)
}
return nil
}